Skip to content

Commit

Permalink
Windows: Don't output a warning when sHGetKnownFolderPath fails
Browse files Browse the repository at this point in the history
In the rare case where the known locations for the standard paths are
not known (such as when an application is used without a user logged
in), it will output a warning to indicate this. In the case of the
GenericConfigLocation, this can mean that it will hang due to the fact
that QLoggingCategory is looking for that location too before it can
output anything.

Therefore, the warning output is removed so that if this part fails it
doesn't cause it to hang as a result.

Change-Id: I4f189361899bd1f868292f30c09fbe50982d2288
Reviewed-by: Kai Koehne <[email protected]>
  • Loading branch information
AndyShawQt committed Jul 18, 2018
1 parent 1d33493 commit bebae37
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/corelib/io/qstandardpaths_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static GUID writableSpecialFolderId(QStandardPaths::StandardLocation type)
}

// Convenience for SHGetKnownFolderPath().
static QString sHGetKnownFolderPath(const GUID &clsid, QStandardPaths::StandardLocation type, bool warn = false)
static QString sHGetKnownFolderPath(const GUID &clsid)
{
QString result;
typedef HRESULT (WINAPI *GetKnownFolderPath)(const GUID&, DWORD, HANDLE, LPWSTR*);
Expand All @@ -141,11 +141,6 @@ static QString sHGetKnownFolderPath(const GUID &clsid, QStandardPaths::StandardL
if (Q_LIKELY(sHGetKnownFolderPath && SUCCEEDED(sHGetKnownFolderPath(clsid, KF_FLAG_DONT_VERIFY, 0, &path)))) {
result = convertCharArray(path);
CoTaskMemFree(path);
} else {
if (warn) {
qErrnoWarning("SHGetKnownFolderPath() failed for standard location \"%s\".",
qPrintable(displayName(type)));
}
}
return result;
}
Expand All @@ -155,7 +150,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
QString result;
switch (type) {
case DownloadLocation:
result = sHGetKnownFolderPath(FOLDERID_Downloads, type);
result = sHGetKnownFolderPath(FOLDERID_Downloads);
if (result.isEmpty())
result = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
break;
Expand All @@ -164,7 +159,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
// Although Microsoft has a Cache key it is a pointer to IE's cache, not a cache
// location for everyone. Most applications seem to be using a
// cache directory located in their AppData directory
result = sHGetKnownFolderPath(writableSpecialFolderId(AppLocalDataLocation), type, /* warn */ true);
result = sHGetKnownFolderPath(writableSpecialFolderId(AppLocalDataLocation));
if (!result.isEmpty()) {
appendTestMode(result);
appendOrganizationAndApp(result);
Expand All @@ -173,7 +168,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
break;

case GenericCacheLocation:
result = sHGetKnownFolderPath(writableSpecialFolderId(GenericDataLocation), type, /* warn */ true);
result = sHGetKnownFolderPath(writableSpecialFolderId(GenericDataLocation));
if (!result.isEmpty()) {
appendTestMode(result);
result += QLatin1String("/cache");
Expand All @@ -190,7 +185,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
break;

default:
result = sHGetKnownFolderPath(writableSpecialFolderId(type), type, /* warn */ isConfigLocation(type));
result = sHGetKnownFolderPath(writableSpecialFolderId(type));
if (!result.isEmpty() && isConfigLocation(type)) {
appendTestMode(result);
if (!isGenericConfigLocation(type))
Expand All @@ -214,7 +209,7 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)

// type-specific handling goes here
if (isConfigLocation(type)) {
QString programData = sHGetKnownFolderPath(FOLDERID_ProgramData, type);
QString programData = sHGetKnownFolderPath(FOLDERID_ProgramData);
if (!programData.isEmpty()) {
if (!isGenericConfigLocation(type))
appendOrganizationAndApp(programData);
Expand Down

0 comments on commit bebae37

Please sign in to comment.