QStringList QStandardPaths::standardLocations(StandardLocation type) { QStringList dirs; // type-specific handling goes here #ifndef Q_OS_WINCE static GetSpecialFolderPath SHGetSpecialFolderPath = resolveGetSpecialFolderPath(); if (SHGetSpecialFolderPath) { wchar_t path[MAX_PATH]; switch (type) { case ConfigLocation: // same as DataLocation, on Windows case DataLocation: case GenericDataLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_COMMON_APPDATA, FALSE)) { QString result = convertCharArray(path); if (type != GenericDataLocation) { if (!QCoreApplication::organizationName().isEmpty()) result += QLatin1Char('/') + QCoreApplication::organizationName(); if (!QCoreApplication::applicationName().isEmpty()) result += QLatin1Char('/') + QCoreApplication::applicationName(); } dirs.append(result); } break; default: break; } } #endif const QString localDir = writableLocation(type); dirs.prepend(localDir); return dirs; }
QStringList QStandardPaths::standardLocations(StandardLocation type) { QStringList dirs; // type-specific handling goes here #ifndef Q_OS_WINCE { wchar_t path[MAX_PATH]; switch (type) { case ConfigLocation: // same as AppLocalDataLocation, on Windows (oversight, but too late to fix it) case GenericConfigLocation: // same as GenericDataLocation, on Windows case AppDataLocation: case AppLocalDataLocation: case GenericDataLocation: if (SHGetSpecialFolderPath(0, path, clsidForAppDataLocation(type), FALSE)) { QString result = convertCharArray(path); if (type != GenericDataLocation && type != GenericConfigLocation) { #ifndef QT_BOOTSTRAPPED if (!QCoreApplication::organizationName().isEmpty()) result += QLatin1Char('/') + QCoreApplication::organizationName(); if (!QCoreApplication::applicationName().isEmpty()) result += QLatin1Char('/') + QCoreApplication::applicationName(); #endif } dirs.append(result); #ifndef QT_BOOTSTRAPPED if (type != GenericDataLocation) { dirs.append(QCoreApplication::applicationDirPath()); dirs.append(QCoreApplication::applicationDirPath() + QLatin1String("/data")); } #endif } break; default: break; } } #endif const QString localDir = writableLocation(type); dirs.prepend(localDir); return dirs; }
QString QStandardPaths::writableLocation(StandardLocation type) { QString result; static GetSpecialFolderPath SHGetSpecialFolderPath = resolveGetSpecialFolderPath(); if (!SHGetSpecialFolderPath) return QString(); wchar_t path[MAX_PATH]; switch (type) { case ConfigLocation: // same as DataLocation, on Windows (oversight, but too late to fix it) case GenericConfigLocation: // same as GenericDataLocation, on Windows case DataLocation: case GenericDataLocation: #if defined Q_OS_WINCE if (SHGetSpecialFolderPath(0, path, CSIDL_APPDATA, FALSE)) #else if (SHGetSpecialFolderPath(0, path, CSIDL_LOCAL_APPDATA, FALSE)) #endif result = convertCharArray(path); if (isTestModeEnabled()) result += QLatin1String("/qttest"); #ifndef QT_BOOTSTRAPPED if (type != GenericDataLocation && type != GenericConfigLocation) { if (!QCoreApplication::organizationName().isEmpty()) result += QLatin1Char('/') + QCoreApplication::organizationName(); if (!QCoreApplication::applicationName().isEmpty()) result += QLatin1Char('/') + QCoreApplication::applicationName(); } #endif break; case DesktopLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, FALSE)) result = convertCharArray(path); break; case DownloadLocation: // TODO implement with SHGetKnownFolderPath(FOLDERID_Downloads) (starting from Vista) case DocumentsLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_PERSONAL, FALSE)) result = convertCharArray(path); break; case FontsLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_FONTS, FALSE)) result = convertCharArray(path); break; case ApplicationsLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_PROGRAMS, FALSE)) result = convertCharArray(path); break; case MusicLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_MYMUSIC, FALSE)) result = convertCharArray(path); break; case MoviesLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_MYVIDEO, FALSE)) result = convertCharArray(path); break; case PicturesLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_MYPICTURES, FALSE)) result = convertCharArray(path); break; case CacheLocation: // 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 return writableLocation(DataLocation) + QLatin1String("/cache"); case GenericCacheLocation: return writableLocation(GenericDataLocation) + QLatin1String("/cache"); case RuntimeLocation: case HomeLocation: result = QDir::homePath(); break; case TempLocation: result = QDir::tempPath(); break; } return result; }
QString QStandardPaths::writableLocation(StandardLocation type) { QString result; #if !defined(Q_OS_WINCE) static GetKnownFolderPath SHGetKnownFolderPath = (GetKnownFolderPath)QSystemLibrary::resolve(QLatin1String("shell32"), "SHGetKnownFolderPath"); #endif wchar_t path[MAX_PATH]; switch (type) { case ConfigLocation: // same as AppLocalDataLocation, on Windows case GenericConfigLocation: // same as GenericDataLocation on Windows case AppDataLocation: case AppLocalDataLocation: case GenericDataLocation: if (SHGetSpecialFolderPath(0, path, clsidForAppDataLocation(type), FALSE)) result = convertCharArray(path); if (isTestModeEnabled()) result += QLatin1String("/qttest"); #ifndef QT_BOOTSTRAPPED if (type != GenericDataLocation && type != GenericConfigLocation) { if (!QCoreApplication::organizationName().isEmpty()) result += QLatin1Char('/') + QCoreApplication::organizationName(); if (!QCoreApplication::applicationName().isEmpty()) result += QLatin1Char('/') + QCoreApplication::applicationName(); } #endif break; case DesktopLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, FALSE)) result = convertCharArray(path); break; case DownloadLocation: #if !defined(Q_OS_WINCE) if (SHGetKnownFolderPath) { LPWSTR path; if (SHGetKnownFolderPath(qCLSID_FOLDERID_Downloads, 0, 0, &path) == S_OK) { result = convertCharArray(path); CoTaskMemFree(path); } break; } #endif // fall through case DocumentsLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_PERSONAL, FALSE)) result = convertCharArray(path); break; case FontsLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_FONTS, FALSE)) result = convertCharArray(path); break; case ApplicationsLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_PROGRAMS, FALSE)) result = convertCharArray(path); break; case MusicLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_MYMUSIC, FALSE)) result = convertCharArray(path); break; case MoviesLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_MYVIDEO, FALSE)) result = convertCharArray(path); break; case PicturesLocation: if (SHGetSpecialFolderPath(0, path, CSIDL_MYPICTURES, FALSE)) result = convertCharArray(path); break; case CacheLocation: // 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 return writableLocation(AppLocalDataLocation) + QLatin1String("/cache"); case GenericCacheLocation: return writableLocation(GenericDataLocation) + QLatin1String("/cache"); case RuntimeLocation: case HomeLocation: result = QDir::homePath(); break; case TempLocation: result = QDir::tempPath(); break; } return result; }