| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Use faster initialization functions to detect install location for Windows | ||
| 2 | + Store package | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | 11 | #include <string> | |
| 12 | 12 | ||
| 13 | + #include <appmodel.h> | ||
| 13 | 14 | #include <winrt\Windows.ApplicationModel.h> | |
| 14 | 15 | #include <winrt\Windows.Storage.h> | |
| 15 | 16 | ||
@@ -28,37 +29,49 @@ const wchar_t *PROGNAME = L"python.exe"; | |||
| 28 | 29 | #endif | |
| 29 | 30 | ||
| 30 | 31 | static std::wstring | |
| 31 | - get_user_base() | ||
| 32 | + get_package_family() | ||
| 32 | 33 | { | |
| 33 | 34 | try { | |
| 34 | - const auto appData = winrt::Windows::Storage::ApplicationData::Current(); | ||
| 35 | - if (appData) { | ||
| 36 | - const auto localCache = appData.LocalCacheFolder(); | ||
| 37 | - if (localCache) { | ||
| 38 | - auto path = localCache.Path(); | ||
| 39 | - if (!path.empty()) { | ||
| 40 | - return std::wstring(path) + L"\\local-packages"; | ||
| 41 | - } | ||
| 42 | - } | ||
| 35 | + UINT32 nameLength = MAX_PATH; | ||
| 36 | + std::wstring name; | ||
| 37 | + name.resize(nameLength); | ||
| 38 | + DWORD rc = GetCurrentPackageFamilyName(&nameLength, name.data()); | ||
| 39 | + if (rc == ERROR_SUCCESS) { | ||
| 40 | + name.resize(nameLength - 1); | ||
| 41 | + return name; | ||
| 43 | 42 | } | |
| 44 | - } catch (...) { | ||
| 43 | + else if (rc != ERROR_INSUFFICIENT_BUFFER) { | ||
| 44 | + throw rc; | ||
| 45 | + } | ||
| 46 | + name.resize(nameLength); | ||
| 47 | + rc = GetCurrentPackageFamilyName(&nameLength, name.data()); | ||
| 48 | + if (rc != ERROR_SUCCESS) { | ||
| 49 | + throw rc; | ||
| 50 | + } | ||
| 51 | + name.resize(nameLength - 1); | ||
| 52 | + return name; | ||
| 45 | 53 | } | |
| 54 | + catch (...) { | ||
| 55 | + } | ||
| 56 | + | ||
| 46 | 57 | return std::wstring(); | |
| 47 | 58 | } | |
| 48 | 59 | ||
| 49 | 60 | static std::wstring | |
| 50 | - get_package_family() | ||
| 61 | + get_user_base() | ||
| 51 | 62 | { | |
| 52 | 63 | try { | |
| 53 | - const auto package = winrt::Windows::ApplicationModel::Package::Current(); | ||
| 54 | - if (package) { | ||
| 55 | - const auto id = package.Id(); | ||
| 56 | - if (id) { | ||
| 57 | - return std::wstring(id.FamilyName()); | ||
| 64 | + const auto appData = winrt::Windows::Storage::ApplicationData::Current(); | ||
| 65 | + if (appData) { | ||
| 66 | + const auto localCache = appData.LocalCacheFolder(); | ||
| 67 | + if (localCache) { | ||
| 68 | + std::wstring path { localCache.Path().c_str() }; | ||
| 69 | + if (!path.empty()) { | ||
| 70 | + return path + L"\\local-packages"; | ||
| 71 | + } | ||
| 58 | 72 | } | |
| 59 | 73 | } | |
| 60 | - } | ||
| 61 | - catch (...) { | ||
| 74 | + } catch (...) { | ||
| 62 | 75 | } | |
| 63 | 76 | ||
| 64 | 77 | return std::wstring(); | |
@@ -68,13 +81,24 @@ static std::wstring | |||
| 68 | 81 | get_package_home() | |
| 69 | 82 | { | |
| 70 | 83 | try { | |
| 71 | - const auto package = winrt::Windows::ApplicationModel::Package::Current(); | ||
| 72 | - if (package) { | ||
| 73 | - const auto path = package.InstalledLocation(); | ||
| 74 | - if (path) { | ||
| 75 | - return std::wstring(path.Path()); | ||
| 76 | - } | ||
| 84 | + UINT32 pathLength = MAX_PATH; | ||
| 85 | + std::wstring path; | ||
| 86 | + path.resize(pathLength); | ||
| 87 | + DWORD rc = GetCurrentPackagePath(&pathLength, path.data()); | ||
| 88 | + if (rc == ERROR_SUCCESS) { | ||
| 89 | + path.resize(pathLength - 1); | ||
| 90 | + return path; | ||
| 91 | + } | ||
| 92 | + else if (rc != ERROR_INSUFFICIENT_BUFFER) { | ||
| 93 | + throw rc; | ||
| 94 | + } | ||
| 95 | + path.resize(pathLength); | ||
| 96 | + rc = GetCurrentPackagePath(&pathLength, path.data()); | ||
| 97 | + if (rc != ERROR_SUCCESS) { | ||
| 98 | + throw rc; | ||
| 77 | 99 | } | |
| 100 | + path.resize(pathLength - 1); | ||
| 101 | + return path; | ||
| 78 | 102 | } | |
| 79 | 103 | catch (...) { | |
| 80 | 104 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments