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; }
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; }