diff --git a/src/hello_imgui/internal/platform/ini_folder_locations.cpp b/src/hello_imgui/internal/platform/ini_folder_locations.cpp index 4cfe80d7..e6680b5c 100644 --- a/src/hello_imgui/internal/platform/ini_folder_locations.cpp +++ b/src/hello_imgui/internal/platform/ini_folder_locations.cpp @@ -53,38 +53,81 @@ #include #include + #if WINAPI_FAMILY == WINAPI_FAMILY_APP + #include + #include + #include + #endif + + static std::string GetTempPath() { +#if WINAPI_FAMILY == WINAPI_FAMILY_APP + // UWP build + auto tempFolder = winrt::Windows::Storage::ApplicationData::Current().TemporaryFolder().Path(); + std::wstring tempPathW(tempFolder.begin(), tempFolder.end()); + std::wstring_convert> converter; + return converter.to_bytes(tempPathW); +#else + // Non-UWP build TCHAR tempPath[MAX_PATH]; - if (GetTempPath(MAX_PATH, tempPath) > 0) + if (::GetTempPath(MAX_PATH, tempPath) > 0) return std::string(tempPath); return ""; +#endif } + static std::string GetAppUserConfigFolder() { +#if WINAPI_FAMILY == WINAPI_FAMILY_APP + // UWP build + auto folder = winrt::Windows::Storage::ApplicationData::Current().RoamingFolder().Path(); + std::wstring pathW(folder.begin(), folder.end()); + std::wstring_convert> converter; + return converter.to_bytes(pathW); +#else + // Non-UWP build TCHAR appDataPath[MAX_PATH]; if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath) == S_OK) return std::string(appDataPath); return ""; +#endif } static std::string GetDocumentsPath() { +#if WINAPI_FAMILY == WINAPI_FAMILY_APP + // UWP build + auto folder = winrt::Windows::Storage::KnownFolders::DocumentsLibrary().Path(); + std::wstring pathW(folder.begin(), folder.end()); + std::wstring_convert> converter; + return converter.to_bytes(pathW); +#else + // Non-UWP build TCHAR documentsPath[MAX_PATH]; if (SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsPath) == S_OK) return std::string(documentsPath); return ""; +#endif } static std::string GetHomePath() { +#if WINAPI_FAMILY == WINAPI_FAMILY_APP + // UWP build + auto folder = winrt::Windows::Storage::ApplicationData::Current().LocalFolder().Path(); + std::wstring pathW(folder.begin(), folder.end()); + std::wstring_convert> converter; + return converter.to_bytes(pathW); +#else + // Non-UWP build TCHAR homePath[MAX_PATH]; if (SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, homePath) == S_OK) return std::string(homePath); return ""; +#endif } - #elif defined(__APPLE__) #include "hello_imgui/internal/platform/getAppleBundleResourcePath.h" using namespace AppleIniFolderLocations;