mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-03 17:37:18 +00:00
28131fd62b
These warnings were always enabled, but we didn't see them due to https://gitlab.com/OpenMW/openmw/-/issues/7882. I do not fully understand the cause of 7822 as I can't repro it in a minimal CMake project. Some of these fixes are thought through. Some are sensible best guesses. Some are kind of a stab in the dark as I don't know whether there was a possible bug the warning was telling me about that I've done nothing to help by introducing a static_cast. Nearly all of these warnings were about some kind of narrowing conversion, so I'm not sure why they weren't firing with GCC and Clang, which have -Wall -Wextra -pedantic set, which should imply -Wnarrowing, and they can't have been affected by 7882. There were also some warnings being triggered from Boost code. The vast majority of library headers that do questionable things weren't firing warnings off, but for some reason, /external:I wasn't putting these Boost headers into external mode. We need these warnings dealt with one way or another so we can switch the default Windows CI from MSBuild (which doesn't do ccache) to Ninja (which does). I have the necessary magic for that on a branch, but the branch won't build because of these warnings.
120 lines
3.1 KiB
C++
120 lines
3.1 KiB
C++
#include "windowspath.hpp"
|
|
|
|
#if defined(_WIN32) || defined(__WINDOWS__)
|
|
|
|
#include <array>
|
|
#include <cstring>
|
|
|
|
#define FAR
|
|
#define NEAR
|
|
|
|
#include <shlobj.h>
|
|
#include <shlwapi.h>
|
|
#include <winreg.h>
|
|
|
|
#undef NEAR
|
|
#undef FAR
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
/**
|
|
* \namespace Files
|
|
*/
|
|
namespace Files
|
|
{
|
|
|
|
WindowsPath::WindowsPath(const std::string& application_name)
|
|
: mName(application_name)
|
|
{
|
|
std::error_code ec;
|
|
current_path(getLocalPath(), ec);
|
|
if (ec.value() != 0)
|
|
Log(Debug::Warning) << "Error " << ec.value() << " when changing current directory";
|
|
}
|
|
|
|
std::filesystem::path WindowsPath::getUserConfigPath() const
|
|
{
|
|
std::filesystem::path userPath = std::filesystem::current_path();
|
|
|
|
WCHAR path[MAX_PATH + 1] = {};
|
|
|
|
if (SUCCEEDED(SHGetFolderPathW(nullptr, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, nullptr, 0, path)))
|
|
{
|
|
userPath = std::filesystem::path(path);
|
|
}
|
|
|
|
return userPath / "My Games" / mName;
|
|
}
|
|
|
|
std::filesystem::path WindowsPath::getUserDataPath() const
|
|
{
|
|
// Have some chaos, windows people!
|
|
return getUserConfigPath();
|
|
}
|
|
|
|
std::filesystem::path WindowsPath::getGlobalConfigPath() const
|
|
{
|
|
std::filesystem::path globalPath = std::filesystem::current_path();
|
|
|
|
WCHAR path[MAX_PATH + 1] = {};
|
|
|
|
if (SUCCEEDED(SHGetFolderPathW(nullptr, CSIDL_PROGRAM_FILES | CSIDL_FLAG_CREATE, nullptr, 0, path)))
|
|
{
|
|
globalPath = std::filesystem::path(path);
|
|
}
|
|
|
|
return globalPath / mName;
|
|
}
|
|
|
|
std::filesystem::path WindowsPath::getLocalPath() const
|
|
{
|
|
std::filesystem::path localPath = std::filesystem::current_path() / "";
|
|
|
|
WCHAR path[MAX_PATH + 1] = {};
|
|
|
|
if (GetModuleFileNameW(nullptr, path, MAX_PATH + 1) > 0)
|
|
{
|
|
localPath = std::filesystem::path(path).parent_path() / "";
|
|
}
|
|
|
|
// lookup exe path
|
|
return localPath;
|
|
}
|
|
|
|
std::filesystem::path WindowsPath::getGlobalDataPath() const
|
|
{
|
|
return getGlobalConfigPath();
|
|
}
|
|
|
|
std::filesystem::path WindowsPath::getCachePath() const
|
|
{
|
|
return getUserConfigPath() / "cache";
|
|
}
|
|
|
|
std::filesystem::path WindowsPath::getInstallPath() const
|
|
{
|
|
std::filesystem::path installPath{};
|
|
|
|
if (HKEY hKey; RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Bethesda Softworks\\Morrowind", 0,
|
|
KEY_READ | KEY_WOW64_32KEY, &hKey)
|
|
== ERROR_SUCCESS)
|
|
{
|
|
// Key existed, let's try to read the install dir
|
|
std::array<wchar_t, 512> buf{};
|
|
DWORD len = static_cast<DWORD>(buf.size() * sizeof(wchar_t));
|
|
|
|
if (RegQueryValueExW(hKey, L"Installed Path", nullptr, nullptr, reinterpret_cast<LPBYTE>(buf.data()), &len)
|
|
== ERROR_SUCCESS)
|
|
{
|
|
installPath = std::filesystem::path(buf.data());
|
|
}
|
|
RegCloseKey(hKey);
|
|
}
|
|
|
|
return installPath;
|
|
}
|
|
|
|
} /* namespace Files */
|
|
|
|
#endif /* defined(_WIN32) || defined(__WINDOWS__) */
|