8#include <qstringlist.h>
10#ifndef QT_BOOTSTRAPPED
11#include <qcoreapplication.h>
14#include <qt_windows.h>
17#include <qvarlengtharray.h>
19#ifndef QT_NO_STANDARDPATHS
23using namespace Qt::StringLiterals;
27 return QDir::fromNativeSeparators(QString::fromWCharArray(path));
32 return type == QStandardPaths::GenericConfigLocation || type == QStandardPaths::GenericDataLocation;
37 return type == QStandardPaths::ConfigLocation || type == QStandardPaths::AppConfigLocation
38 || type == QStandardPaths::AppDataLocation || type == QStandardPaths::AppLocalDataLocation
39 || isGenericConfigLocation(type);
44#ifndef QT_BOOTSTRAPPED
45 const QString &org = QCoreApplication::organizationName();
48 const QString &appName = QCoreApplication::applicationName();
49 if (!appName.isEmpty())
50 path += u'/' + appName;
58 if (QStandardPaths::isTestModeEnabled())
65 const auto process_token = HANDLE(quintptr(-4));
68 auto* token_info =
reinterpret_cast<TOKEN_MANDATORY_LABEL*>(token_info_buf.data());
69 DWORD token_info_length = token_info_buf.size();
70 if (!GetTokenInformation(process_token, TokenIntegrityLevel, token_info, token_info_length, &token_info_length)) {
72 token_info_buf.resize(token_info_length);
73 token_info =
reinterpret_cast<TOKEN_MANDATORY_LABEL*>(token_info_buf.data());
74 if (!GetTokenInformation(process_token, TokenIntegrityLevel, token_info, token_info_length, &token_info_length))
80 DWORD integrity_level = *GetSidSubAuthority(token_info->Label.Sid, *GetSidSubAuthorityCount(token_info->Label.Sid) - 1);
81 return (integrity_level < SECURITY_MANDATORY_MEDIUM_RID);
88 static const GUID folderIds[] = {
97 FOLDERID_LocalAppData,
99 FOLDERID_LocalAppData,
101 FOLDERID_LocalAppData,
104 FOLDERID_LocalAppData,
105 FOLDERID_RoamingAppData,
106 FOLDERID_LocalAppData,
112 static_assert(
sizeof(folderIds) /
sizeof(folderIds[0]) == size_t(QStandardPaths::GenericStateLocation + 1));
115 static const GUID folderIds_li[] = {
124 FOLDERID_LocalAppDataLow,
126 FOLDERID_LocalAppDataLow,
128 FOLDERID_LocalAppDataLow,
131 FOLDERID_LocalAppDataLow,
132 FOLDERID_RoamingAppData,
133 FOLDERID_LocalAppDataLow,
139 static_assert(
sizeof(folderIds_li) ==
sizeof(folderIds));
141 static bool low_integrity_process = isProcessLowIntegrity();
142 if (size_t(type) <
sizeof(folderIds) /
sizeof(folderIds[0]))
143 return low_integrity_process ? folderIds_li[type] : folderIds[type];
152 if (Q_LIKELY(SUCCEEDED(SHGetKnownFolderPath(clsid, KF_FLAG_DONT_VERIFY, 0, &path)))) {
153 result = convertCharArray(path);
159QString QStandardPaths::writableLocation(StandardLocation type)
167 result = sHGetKnownFolderPath(writableSpecialFolderId(AppLocalDataLocation));
168 if (!result.isEmpty()) {
169 appendTestMode(result);
170 appendOrganizationAndApp(result);
171 result +=
"/cache"_L1;
175 case GenericCacheLocation:
176 result = sHGetKnownFolderPath(writableSpecialFolderId(GenericDataLocation));
177 if (!result.isEmpty()) {
178 appendTestMode(result);
179 result +=
"/cache"_L1;
183 case RuntimeLocation:
185 result = QDir::homePath();
189 result = QDir::tempPath();
193 result = sHGetKnownFolderPath(writableSpecialFolderId(AppLocalDataLocation));
194 if (!result.isEmpty()) {
195 appendTestMode(result);
196 appendOrganizationAndApp(result);
197 result +=
"/State"_L1;
201 case GenericStateLocation:
202 result = sHGetKnownFolderPath(writableSpecialFolderId(GenericDataLocation));
203 if (!result.isEmpty()) {
204 appendTestMode(result);
205 result +=
"/State"_L1;
210 result = sHGetKnownFolderPath(writableSpecialFolderId(type));
211 if (!result.isEmpty() && isConfigLocation(type)) {
212 appendTestMode(result);
213 if (!isGenericConfigLocation(type))
214 appendOrganizationAndApp(result);
221#ifndef QT_BOOTSTRAPPED
225QStringList QStandardPaths::standardLocations(StandardLocation type)
228 const QString localDir = writableLocation(type);
229 if (!localDir.isEmpty())
230 dirs.append(localDir);
233 if (isConfigLocation(type)) {
234 QString programData = sHGetKnownFolderPath(FOLDERID_ProgramData);
235 if (!programData.isEmpty()) {
236 if (!isGenericConfigLocation(type))
237 appendOrganizationAndApp(programData);
238 dirs.append(programData);
240#ifndef QT_BOOTSTRAPPED
244 QString applicationDirPath =
qApp ? QCoreApplication::applicationDirPath()
245 : QFileInfo(qAppFileName()).path();
246 dirs.append(applicationDirPath);
247 const QString dataDir = applicationDirPath +
"/data"_L1;
248 dirs.append(dataDir);
250 if (!isGenericConfigLocation(type)) {
251 QString appDataDir = dataDir;
252 appendOrganizationAndApp(appDataDir);
253 if (appDataDir != dataDir)
254 dirs.append(appDataDir);
static GUID writableSpecialFolderId(QStandardPaths::StandardLocation type)
static bool isGenericConfigLocation(QStandardPaths::StandardLocation type)
static bool isProcessLowIntegrity()
static void appendTestMode(QString &path)
static void appendOrganizationAndApp(QString &path)
static bool isConfigLocation(QStandardPaths::StandardLocation type)
static QString sHGetKnownFolderPath(const GUID &clsid)
static QString convertCharArray(const wchar_t *path)