Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd74117a

Browse files
Use faster APIs to calculate paths at startup for Store packaged Python on Windows (GH-99345)
(cherry picked from commit71a4a2d)Co-authored-by: Steve Dower <steve.dower@python.org>
1 parent24fad64 commitd74117a

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Use faster initialization functions to detect install location for Windows
2+
Store package

‎PC/python_uwp.cpp‎

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include<string>
1212

13+
#include<appmodel.h>
1314
#include<winrt\Windows.ApplicationModel.h>
1415
#include<winrt\Windows.Storage.h>
1516

@@ -28,37 +29,49 @@ const wchar_t *PROGNAME = L"python.exe";
2829
#endif
2930

3031
static std::wstring
31-
get_user_base()
32+
get_package_family()
3233
{
3334
try {
34-
constauto appData =winrt::Windows::Storage::ApplicationData::Current();
35-
if (appData) {
36-
constauto localCache = appData.LocalCacheFolder();
37-
if (localCache) {
38-
auto path = localCache.Path();
39-
if (!path.empty()) {
40-
returnstd::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;
4342
}
44-
}catch (...) {
43+
elseif (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;
4553
}
54+
catch (...) {
55+
}
56+
4657
returnstd::wstring();
4758
}
4859

4960
static std::wstring
50-
get_package_family()
61+
get_user_base()
5162
{
5263
try {
53-
constauto package =winrt::Windows::ApplicationModel::Package::Current();
54-
if (package) {
55-
constauto id = package.Id();
56-
if (id) {
57-
returnstd::wstring(id.FamilyName());
64+
constauto appData =winrt::Windows::Storage::ApplicationData::Current();
65+
if (appData) {
66+
constauto 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+
}
5872
}
5973
}
60-
}
61-
catch (...) {
74+
}catch (...) {
6275
}
6376

6477
returnstd::wstring();
@@ -68,13 +81,24 @@ static std::wstring
6881
get_package_home()
6982
{
7083
try {
71-
constauto package =winrt::Windows::ApplicationModel::Package::Current();
72-
if (package) {
73-
constauto path = package.InstalledLocation();
74-
if (path) {
75-
returnstd::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+
elseif (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;
7799
}
100+
path.resize(pathLength -1);
101+
return path;
78102
}
79103
catch (...) {
80104
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp