|
49 | 49 | } |
50 | 50 |
|
51 | 51 | #elif defined(_WIN32) |
52 | | - #include <windows.h> |
53 | | - #include <ShlObj.h> |
54 | | - #include <tchar.h> |
| 52 | + #if (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) |
| 53 | + #define IS_STANDARD_WINDOWS |
| 54 | + #else |
| 55 | + #define IS_UWP |
| 56 | + #endif |
55 | 57 |
|
56 | | - static std::string GetTempPath() |
57 | | - { |
58 | | - TCHAR tempPath[MAX_PATH]; |
59 | | - if (GetTempPath(MAX_PATH, tempPath) > 0) |
60 | | - return std::string(tempPath); |
61 | | - return ""; |
62 | | - } |
| 58 | + #ifdef IS_UWP |
| 59 | + // UWP build |
| 60 | + |
| 61 | + #include <winrt/Windows.Storage.h> |
| 62 | + #include <locale> |
| 63 | + #include <codecvt> |
| 64 | + |
| 65 | + static std::string GetTempPath() |
| 66 | + { |
| 67 | + auto tempFolder = winrt::Windows::Storage::ApplicationData::Current().TemporaryFolder().Path(); |
| 68 | + std::wstring tempPathW(tempFolder.begin(), tempFolder.end()); |
| 69 | + std::wstring_convert<std::codecvt_utf8<wchar_t> > converter; |
| 70 | + return converter.to_bytes(tempPathW); |
| 71 | + } |
| 72 | + |
| 73 | + static std::string GetAppUserConfigFolder() |
| 74 | + { |
| 75 | + auto folder = winrt::Windows::Storage::ApplicationData::Current().RoamingFolder().Path(); |
| 76 | + std::wstring pathW(folder.begin(), folder.end()); |
| 77 | + std::wstring_convert<std::codecvt_utf8<wchar_t> > converter; |
| 78 | + return converter.to_bytes(pathW); |
| 79 | + } |
| 80 | + |
| 81 | + static std::string GetDocumentsPath() |
| 82 | + { |
| 83 | + auto folder = winrt::Windows::Storage::KnownFolders::DocumentsLibrary().Path(); |
| 84 | + std::wstring pathW(folder.begin(), folder.end()); |
| 85 | + std::wstring_convert<std::codecvt_utf8<wchar_t> > converter; |
| 86 | + return converter.to_bytes(pathW); |
| 87 | + } |
| 88 | + |
| 89 | + static std::string GetHomePath() |
| 90 | + { |
| 91 | + auto folder = winrt::Windows::Storage::ApplicationData::Current().LocalFolder().Path(); |
| 92 | + std::wstring pathW(folder.begin(), folder.end()); |
| 93 | + std::wstring_convert<std::codecvt_utf8<wchar_t> > converter; |
| 94 | + return converter.to_bytes(pathW); |
| 95 | + } |
| 96 | + |
| 97 | + #else // IS_UWP |
| 98 | + // Standard windows build |
| 99 | + #include <Windows.h> |
| 100 | + #include <ShlObj.h> |
| 101 | + #include <tchar.h> |
| 102 | + |
| 103 | + static std::string GetTempPath() |
| 104 | + { |
| 105 | + // Non-UWP build |
| 106 | + TCHAR tempPath[MAX_PATH]; |
| 107 | + if (::GetTempPath(MAX_PATH, tempPath) > 0) |
| 108 | + return std::string(tempPath); |
| 109 | + return ""; |
| 110 | + } |
| 111 | + |
| 112 | + static std::string GetAppUserConfigFolder() |
| 113 | + { |
| 114 | + TCHAR appDataPath[MAX_PATH]; |
| 115 | + if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath) == S_OK) |
| 116 | + return std::string(appDataPath); |
| 117 | + return ""; |
| 118 | + } |
| 119 | + |
| 120 | + static std::string GetDocumentsPath() |
| 121 | + { |
| 122 | + TCHAR documentsPath[MAX_PATH]; |
| 123 | + if (SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsPath) == S_OK) |
| 124 | + return std::string(documentsPath); |
| 125 | + return ""; |
| 126 | + } |
| 127 | + |
| 128 | + static std::string GetHomePath() |
| 129 | + { |
| 130 | + // Non-UWP build |
| 131 | + TCHAR homePath[MAX_PATH]; |
| 132 | + if (SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, homePath) == S_OK) |
| 133 | + return std::string(homePath); |
| 134 | + return ""; |
| 135 | + } |
| 136 | + |
| 137 | + |
| 138 | + #endif // IS_UWP |
63 | 139 |
|
64 | | - static std::string GetAppUserConfigFolder() |
65 | | - { |
66 | | - TCHAR appDataPath[MAX_PATH]; |
67 | | - if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath) == S_OK) |
68 | | - return std::string(appDataPath); |
69 | | - return ""; |
70 | | - } |
71 | 140 |
|
72 | | - static std::string GetDocumentsPath() |
73 | | - { |
74 | | - TCHAR documentsPath[MAX_PATH]; |
75 | | - if (SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsPath) == S_OK) |
76 | | - return std::string(documentsPath); |
77 | | - return ""; |
78 | | - } |
79 | 141 |
|
80 | | - static std::string GetHomePath() |
81 | | - { |
82 | | - TCHAR homePath[MAX_PATH]; |
83 | | - if (SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, homePath) == S_OK) |
84 | | - return std::string(homePath); |
85 | | - return ""; |
86 | | - } |
87 | 142 |
|
88 | 143 | #elif defined(__APPLE__) |
89 | 144 | #include "hello_imgui/internal/platform/getAppleBundleResourcePath.h" |
|
0 commit comments