From 8a708fd97ee2804d23701154b2b59c84434d9a7a Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 23 Mar 2022 15:20:05 +0800 Subject: [PATCH] Use proper type to represent a path --- src/base/utils/misc.cpp | 7 +++---- src/base/utils/misc.h | 18 +++++------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index c516f4848..317c4d83a 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -61,7 +61,6 @@ #include #endif -#include "base/path.h" #include "base/types.h" #include "base/unicodestrings.h" #include "base/utils/fs.h" @@ -510,13 +509,13 @@ QString Utils::Misc::zlibVersionString() } #ifdef Q_OS_WIN -QString Utils::Misc::windowsSystemPath() +Path Utils::Misc::windowsSystemPath() { - static const QString path = []() -> QString + static const Path path = []() -> Path { WCHAR systemPath[MAX_PATH] = {0}; GetSystemDirectoryW(systemPath, sizeof(systemPath) / sizeof(WCHAR)); - return QString::fromWCharArray(systemPath); + return Path(QString::fromWCharArray(systemPath)); }(); return path; } diff --git a/src/base/utils/misc.h b/src/base/utils/misc.h index a1513a965..27fe7d155 100644 --- a/src/base/utils/misc.h +++ b/src/base/utils/misc.h @@ -37,7 +37,7 @@ #include -#include "base/pathfwd.h" +#include "base/path.h" enum class ShutdownDialogAction; @@ -87,22 +87,14 @@ namespace Utils::Misc QString getUserIDString(); #ifdef Q_OS_WIN - QString windowsSystemPath(); + Path windowsSystemPath(); template T loadWinAPI(const QString &source, const char *funcName) { - QString path = windowsSystemPath(); - if (!path.endsWith(u'\\')) - path += u'\\'; - - path += source; - - auto pathWchar = std::make_unique(path.length() + 1); - path.toWCharArray(pathWchar.get()); - - return reinterpret_cast( - ::GetProcAddress(::LoadLibraryW(pathWchar.get()), funcName)); + const QString path = (windowsSystemPath() / Path(source)).toString(); + return reinterpret_cast(::GetProcAddress(::LoadLibraryW( + path.toStdWString().c_str()), funcName)); } #endif // Q_OS_WIN }