Krita Source Code Documentation
Loading...
Searching...
No Matches
KisWindowsPackageUtils Namespace Reference

Functions

QString getPackageRoamingAppDataLocation ()
 
bool isRunningInPackage ()
 
bool tryGetCurrentPackageFamilyName (QString *outName)
 
bool tryGetCurrentPackageFullName (QString *outName)
 

Function Documentation

◆ getPackageRoamingAppDataLocation()

KRITAGLOBAL_EXPORT QString KisWindowsPackageUtils::getPackageRoamingAppDataLocation ( )

Get the RoamingAppData location. If the current process is a packaged app, the redirected private app location is returned. Uses SHGetKnownFolderPath therefore the path uses native path separators and does not include a trailing backslash.

See also: https://docs.microsoft.com/en-us/windows/msix/desktop/desktop-to-uwp-behind-the-scenes#appdata-operations-on-windows-10-version-1903-and-later

Definition at line 205 of file KisWindowsPackageUtils.cpp.

206{
207 PWSTR path = nullptr;
208 HRESULT result =
209 SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_RETURN_FILTER_REDIRECTION_TARGET, nullptr, &path);
210 if (result != S_OK) {
211 qWarning() << "SHGetKnownFolderPath returned error HRESULT:" << result;
212 return {};
213 }
214 if (!path) {
215 qWarning() << "SHGetKnownFolderPath did not return a path";
216 return {};
217 }
218 QString appData = QString::fromWCharArray(path);
219 CoTaskMemFree(path);
220 return appData;
221}
constexpr int KF_FLAG_RETURN_FILTER_REDIRECTION_TARGET

References KF_FLAG_RETURN_FILTER_REDIRECTION_TARGET.

◆ isRunningInPackage()

KRITAGLOBAL_EXPORT bool KisWindowsPackageUtils::isRunningInPackage ( )

Definition at line 108 of file KisWindowsPackageUtils.cpp.

109{
110 return tryGetCurrentPackageFamilyName(nullptr);
111}
bool tryGetCurrentPackageFamilyName(QString *outName)

References tryGetCurrentPackageFamilyName().

◆ tryGetCurrentPackageFamilyName()

KRITAGLOBAL_EXPORT bool KisWindowsPackageUtils::tryGetCurrentPackageFamilyName ( QString * outName)

Definition at line 113 of file KisWindowsPackageUtils.cpp.

114{
115 if (!AppmodelFunctions::instance().getCurrentPackageFamilyName) {
116 // We are probably on Windows 7 or earlier.
117 return false;
118 }
119
120 std::array<WCHAR, PACKAGE_FULL_NAME_MAX_LENGTH + 1> name{}; // includes null terminator
121 UINT32 nameLength = name.size();
122 const LONG result = AppmodelFunctions::instance().getCurrentPackageFamilyName(&nameLength, name.data());
123 if (result == APPMODEL_ERROR_NO_PACKAGE) {
124 // Process not running from a package.
125 return false;
126 }
127 if (result == ERROR_INSUFFICIENT_BUFFER) {
128 // This shouldn't happen!
129 qWarning() << "GetCurrentPackageFamilyName returned "
130 "ERROR_INSUFFICIENT_BUFFER, required length is"
131 << nameLength;
132 if (outName) {
133 *outName = QString();
134 }
135 return true;
136 }
137 if (result != ERROR_SUCCESS) {
138 qWarning() << "GetCurrentPackageFamilyName returned unexpected error code:" << result;
139 return false;
140 }
141
142 if (outName) {
143 // Sanity check
144 if (nameLength > name.size()) {
145 qWarning() << "GetCurrentPackageFamilyName returned a length "
146 "exceeding the buffer size:"
147 << nameLength;
148 nameLength = name.size();
149 }
150 // Exclude null terminator
151 if (nameLength > 0 && name.at(nameLength - 1) == L'\0') {
152 nameLength -= 1;
153 }
154 *outName = QString::fromWCharArray(name.data(), static_cast<int>(nameLength));
155 }
156 return true;
157}
constexpr LONG APPMODEL_ERROR_NO_PACKAGE
const char * name(StandardAction id)
pGetCurrentPackageFamilyName_t getCurrentPackageFamilyName
static const AppmodelFunctions & instance()

References APPMODEL_ERROR_NO_PACKAGE, AppmodelFunctions::getCurrentPackageFamilyName, and AppmodelFunctions::instance().

◆ tryGetCurrentPackageFullName()

KRITAGLOBAL_EXPORT bool KisWindowsPackageUtils::tryGetCurrentPackageFullName ( QString * outName)

Definition at line 159 of file KisWindowsPackageUtils.cpp.

160{
161 if (!AppmodelFunctions::instance().getCurrentPackageFullName) {
162 // We are probably on Windows 7 or earlier.
163 return false;
164 }
165
166 std::array<WCHAR, PACKAGE_FULL_NAME_MAX_LENGTH + 1> name{}; // includes null terminator
167 UINT32 nameLength = name.size();
168 const LONG result = AppmodelFunctions::instance().getCurrentPackageFullName(&nameLength, name.data());
169 if (result == APPMODEL_ERROR_NO_PACKAGE) {
170 // Process not running from a package.
171 return false;
172 }
173 if (result == ERROR_INSUFFICIENT_BUFFER) {
174 // This shouldn't happen!
175 qWarning() << "GetCurrentPackageFullName returned "
176 "ERROR_INSUFFICIENT_BUFFER, required length is"
177 << nameLength;
178 if (outName) {
179 *outName = QString();
180 }
181 return true;
182 }
183 if (result != ERROR_SUCCESS) {
184 qWarning() << "GetCurrentPackageFullName returned unexpected error code:" << result;
185 return false;
186 }
187
188 if (outName) {
189 // Sanity check
190 if (nameLength > name.size()) {
191 qWarning() << "GetCurrentPackageFullName returned a length "
192 "exceeding the buffer size:"
193 << nameLength;
194 nameLength = name.size();
195 }
196 // Exclude null terminator
197 if (nameLength > 0 && name.at(nameLength - 1) == L'\0') {
198 nameLength -= 1;
199 }
200 *outName = QString::fromWCharArray(name.data(), static_cast<int>(nameLength));
201 }
202 return true;
203}
pGetCurrentPackageFullName_t getCurrentPackageFullName

References APPMODEL_ERROR_NO_PACKAGE, AppmodelFunctions::getCurrentPackageFullName, and AppmodelFunctions::instance().