Browse Source

Use proper type to represent a path

adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
8a708fd97e
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 7
      src/base/utils/misc.cpp
  2. 18
      src/base/utils/misc.h

7
src/base/utils/misc.cpp

@ -61,7 +61,6 @@
#include <QDBusInterface> #include <QDBusInterface>
#endif #endif
#include "base/path.h"
#include "base/types.h" #include "base/types.h"
#include "base/unicodestrings.h" #include "base/unicodestrings.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
@ -510,13 +509,13 @@ QString Utils::Misc::zlibVersionString()
} }
#ifdef Q_OS_WIN #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}; WCHAR systemPath[MAX_PATH] = {0};
GetSystemDirectoryW(systemPath, sizeof(systemPath) / sizeof(WCHAR)); GetSystemDirectoryW(systemPath, sizeof(systemPath) / sizeof(WCHAR));
return QString::fromWCharArray(systemPath); return Path(QString::fromWCharArray(systemPath));
}(); }();
return path; return path;
} }

18
src/base/utils/misc.h

@ -37,7 +37,7 @@
#include <QString> #include <QString>
#include "base/pathfwd.h" #include "base/path.h"
enum class ShutdownDialogAction; enum class ShutdownDialogAction;
@ -87,22 +87,14 @@ namespace Utils::Misc
QString getUserIDString(); QString getUserIDString();
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QString windowsSystemPath(); Path windowsSystemPath();
template <typename T> template <typename T>
T loadWinAPI(const QString &source, const char *funcName) T loadWinAPI(const QString &source, const char *funcName)
{ {
QString path = windowsSystemPath(); const QString path = (windowsSystemPath() / Path(source)).toString();
if (!path.endsWith(u'\\')) return reinterpret_cast<T>(::GetProcAddress(::LoadLibraryW(
path += u'\\'; path.toStdWString().c_str()), funcName));
path += source;
auto pathWchar = std::make_unique<wchar_t[]>(path.length() + 1);
path.toWCharArray(pathWchar.get());
return reinterpret_cast<T>(
::GetProcAddress(::LoadLibraryW(pathWchar.get()), funcName));
} }
#endif // Q_OS_WIN #endif // Q_OS_WIN
} }

Loading…
Cancel
Save