Some improvements to OS::known_folder() function.
This commit is contained in:
parent
6d39b858d4
commit
8fa44842da
@ -728,7 +728,7 @@ const QString &MUtils::OS::known_folder(known_folder_t folder_id)
|
|||||||
{
|
{
|
||||||
if(g_known_folders_map->contains(folderId))
|
if(g_known_folders_map->contains(folderId))
|
||||||
{
|
{
|
||||||
return g_known_folders_map->operator[](folderId);
|
return (*g_known_folders_map)[folderId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -741,7 +741,7 @@ const QString &MUtils::OS::known_folder(known_folder_t folder_id)
|
|||||||
{
|
{
|
||||||
if(g_known_folders_map->contains(folderId))
|
if(g_known_folders_map->contains(folderId))
|
||||||
{
|
{
|
||||||
return g_known_folders_map->operator[](folderId);
|
return (*g_known_folders_map)[folderId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -753,14 +753,14 @@ const QString &MUtils::OS::known_folder(known_folder_t folder_id)
|
|||||||
|
|
||||||
QString folderPath;
|
QString folderPath;
|
||||||
|
|
||||||
//Now try to get the folder path!
|
//Try SHGetKnownFolderPath() first!
|
||||||
if(const SHGetKnownFolderPath_t known_folders_fpGetKnownFolderPath = MUtils::Win32Utils::resolve<SHGetKnownFolderPath_t>(QLatin1String("shell32"), QLatin1String("SHGetKnownFolderPath")))
|
if(const SHGetKnownFolderPath_t known_folders_fpGetKnownFolderPath = MUtils::Win32Utils::resolve<SHGetKnownFolderPath_t>(QLatin1String("shell32"), QLatin1String("SHGetKnownFolderPath")))
|
||||||
{
|
{
|
||||||
WCHAR *path = NULL;
|
WCHAR *path = NULL;
|
||||||
if(known_folders_fpGetKnownFolderPath(s_folders[folderId].guid, KF_FLAG_CREATE, NULL, &path) == S_OK)
|
if(known_folders_fpGetKnownFolderPath(s_folders[folderId].guid, KF_FLAG_CREATE, NULL, &path) == S_OK)
|
||||||
{
|
{
|
||||||
//MessageBoxW(0, path, L"SHGetKnownFolderPath", MB_TOPMOST);
|
//MessageBoxW(0, path, L"SHGetKnownFolderPath", MB_TOPMOST);
|
||||||
QDir folderTemp = QDir(QDir::fromNativeSeparators(MUTILS_QSTR(path)));
|
const QDir folderTemp = QDir(QDir::fromNativeSeparators(MUTILS_QSTR(path)));
|
||||||
if(folderTemp.exists())
|
if(folderTemp.exists())
|
||||||
{
|
{
|
||||||
folderPath = folderTemp.canonicalPath();
|
folderPath = folderTemp.canonicalPath();
|
||||||
@ -768,23 +768,33 @@ const QString &MUtils::OS::known_folder(known_folder_t folder_id)
|
|||||||
CoTaskMemFree(path);
|
CoTaskMemFree(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(const SHGetFolderPath_t known_folders_fpGetFolderPath = MUtils::Win32Utils::resolve<SHGetFolderPath_t>(QLatin1String("shell32"), QLatin1String("SHGetFolderPathW")))
|
|
||||||
|
//Fall back to SHGetFolderPathW()
|
||||||
|
if (folderPath.isEmpty())
|
||||||
|
{
|
||||||
|
if (const SHGetFolderPath_t known_folders_fpGetFolderPath = MUtils::Win32Utils::resolve<SHGetFolderPath_t>(QLatin1String("shell32"), QLatin1String("SHGetFolderPathW")))
|
||||||
{
|
{
|
||||||
QScopedArrayPointer<WCHAR> path(new WCHAR[4096]);
|
QScopedArrayPointer<WCHAR> path(new WCHAR[4096]);
|
||||||
if(known_folders_fpGetFolderPath(NULL, s_folders[folderId].csidl | CSIDL_FLAG_CREATE, NULL, NULL, path.data()) == S_OK)
|
if (known_folders_fpGetFolderPath(NULL, s_folders[folderId].csidl | CSIDL_FLAG_CREATE, NULL, NULL, path.data()) == S_OK)
|
||||||
{
|
{
|
||||||
//MessageBoxW(0, path, L"SHGetFolderPathW", MB_TOPMOST);
|
//MessageBoxW(0, path, L"SHGetFolderPathW", MB_TOPMOST);
|
||||||
QDir folderTemp = QDir(QDir::fromNativeSeparators(MUTILS_QSTR(path.data())));
|
const QDir folderTemp = QDir(QDir::fromNativeSeparators(MUTILS_QSTR(path.data())));
|
||||||
if(folderTemp.exists())
|
if (folderTemp.exists())
|
||||||
{
|
{
|
||||||
folderPath = folderTemp.canonicalPath();
|
folderPath = folderTemp.canonicalPath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Update cache
|
//Update cache
|
||||||
|
if (!folderPath.isEmpty())
|
||||||
|
{
|
||||||
|
qWarning("g_known_folders_map->insert");
|
||||||
g_known_folders_map->insert(folderId, folderPath);
|
g_known_folders_map->insert(folderId, folderPath);
|
||||||
return g_known_folders_map->operator[](folderId);
|
}
|
||||||
|
|
||||||
|
return folderPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user