Skip to content

Commit

Permalink
Win uwp code
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Feb 2, 2024
1 parent aab809f commit b122279
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions src/hello_imgui/internal/platform/ini_folder_locations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,81 @@
#include <ShlObj.h>
#include <tchar.h>

#if WINAPI_FAMILY == WINAPI_FAMILY_APP
#include <winrt/Windows.Storage.h>
#include <locale>
#include <codecvt>
#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<std::codecvt_utf8<wchar_t>> 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<std::codecvt_utf8<wchar_t>> 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<std::codecvt_utf8<wchar_t>> 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<std::codecvt_utf8<wchar_t>> 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;
Expand Down

0 comments on commit b122279

Please sign in to comment.