2011-08-19 19:06:09 +00:00
|
|
|
#include "windowspath.hpp"
|
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(__WINDOWS__)
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
2012-01-16 22:09:25 +00:00
|
|
|
#include <shlobj.h>
|
2013-06-22 09:33:22 +00:00
|
|
|
#include <shlwapi.h>
|
2015-09-24 13:21:42 +00:00
|
|
|
#include <WinReg.h>
|
2011-08-19 19:06:09 +00:00
|
|
|
|
2014-01-14 13:20:41 +00:00
|
|
|
#include <boost/locale.hpp>
|
|
|
|
namespace bconv = boost::locale::conv;
|
|
|
|
|
2012-02-19 22:39:37 +00:00
|
|
|
/**
|
|
|
|
* FIXME: Someone with Windows system should check this and correct if necessary
|
2014-01-14 13:20:41 +00:00
|
|
|
* FIXME: MAX_PATH is irrelevant for extended-length paths, i.e. \\?\...
|
2012-02-19 22:39:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \namespace Files
|
|
|
|
*/
|
2011-08-19 19:06:09 +00:00
|
|
|
namespace Files
|
|
|
|
{
|
|
|
|
|
2012-09-08 16:47:31 +00:00
|
|
|
WindowsPath::WindowsPath(const std::string& application_name)
|
|
|
|
: mName(application_name)
|
|
|
|
{
|
2014-05-22 12:35:57 +00:00
|
|
|
/* Since on Windows boost::path.string() returns string of narrow
|
|
|
|
characters in local encoding, it is required to path::imbue()
|
|
|
|
with UTF-8 encoding (generated for empty name from boost::locale)
|
|
|
|
to handle Unicode in platform-agnostic way using std::string.
|
|
|
|
|
|
|
|
See boost::filesystem and boost::locale reference for details.
|
|
|
|
*/
|
2014-01-14 19:30:56 +00:00
|
|
|
boost::filesystem::path::imbue(boost::locale::generator().generate(""));
|
2012-09-08 16:47:31 +00:00
|
|
|
}
|
|
|
|
|
2013-12-25 23:28:19 +00:00
|
|
|
boost::filesystem::path WindowsPath::getUserConfigPath() const
|
2011-08-19 19:06:09 +00:00
|
|
|
{
|
2012-01-21 00:14:35 +00:00
|
|
|
boost::filesystem::path userPath(".");
|
2011-08-19 19:06:09 +00:00
|
|
|
|
2014-01-14 13:20:41 +00:00
|
|
|
WCHAR path[MAX_PATH + 1];
|
2011-08-19 19:06:09 +00:00
|
|
|
memset(path, 0, sizeof(path));
|
|
|
|
|
2018-10-09 06:21:12 +00:00
|
|
|
if(SUCCEEDED(SHGetFolderPathW(nullptr, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, nullptr, 0, path)))
|
2011-08-19 19:06:09 +00:00
|
|
|
{
|
2014-01-14 13:20:41 +00:00
|
|
|
userPath = boost::filesystem::path(bconv::utf_to_utf<char>(path));
|
2011-08-19 19:06:09 +00:00
|
|
|
}
|
|
|
|
|
2014-01-14 19:08:54 +00:00
|
|
|
return userPath / "My Games" / mName;
|
2011-08-19 19:06:09 +00:00
|
|
|
}
|
|
|
|
|
2013-12-26 00:24:43 +00:00
|
|
|
boost::filesystem::path WindowsPath::getUserDataPath() const
|
|
|
|
{
|
|
|
|
// Have some chaos, windows people!
|
|
|
|
return getUserConfigPath();
|
|
|
|
}
|
|
|
|
|
2013-12-25 23:28:19 +00:00
|
|
|
boost::filesystem::path WindowsPath::getGlobalConfigPath() const
|
2011-08-19 19:06:09 +00:00
|
|
|
{
|
2012-01-21 00:14:35 +00:00
|
|
|
boost::filesystem::path globalPath(".");
|
2011-08-19 19:06:09 +00:00
|
|
|
|
2014-01-14 13:20:41 +00:00
|
|
|
WCHAR path[MAX_PATH + 1];
|
2011-08-19 19:06:09 +00:00
|
|
|
memset(path, 0, sizeof(path));
|
|
|
|
|
2018-10-09 06:21:12 +00:00
|
|
|
if(SUCCEEDED(SHGetFolderPathW(nullptr, CSIDL_PROGRAM_FILES | CSIDL_FLAG_CREATE, nullptr, 0, path)))
|
2011-08-19 19:06:09 +00:00
|
|
|
{
|
2014-01-14 13:20:41 +00:00
|
|
|
globalPath = boost::filesystem::path(bconv::utf_to_utf<char>(path));
|
2011-08-19 19:06:09 +00:00
|
|
|
}
|
|
|
|
|
2012-09-08 18:34:43 +00:00
|
|
|
return globalPath / mName;
|
2011-08-19 19:06:09 +00:00
|
|
|
}
|
|
|
|
|
2012-01-21 00:14:35 +00:00
|
|
|
boost::filesystem::path WindowsPath::getLocalPath() const
|
2011-08-19 19:06:09 +00:00
|
|
|
{
|
|
|
|
return boost::filesystem::path("./");
|
|
|
|
}
|
|
|
|
|
2012-01-21 16:58:49 +00:00
|
|
|
boost::filesystem::path WindowsPath::getGlobalDataPath() const
|
|
|
|
{
|
2013-12-28 17:16:01 +00:00
|
|
|
return getGlobalConfigPath();
|
2012-01-21 16:58:49 +00:00
|
|
|
}
|
|
|
|
|
2012-09-02 17:40:26 +00:00
|
|
|
boost::filesystem::path WindowsPath::getCachePath() const
|
|
|
|
{
|
2013-12-28 17:16:01 +00:00
|
|
|
return getUserConfigPath() / "cache";
|
2012-09-02 17:40:26 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 22:09:25 +00:00
|
|
|
boost::filesystem::path WindowsPath::getInstallPath() const
|
2012-01-21 16:58:49 +00:00
|
|
|
{
|
2012-01-16 22:09:25 +00:00
|
|
|
boost::filesystem::path installPath("");
|
|
|
|
|
|
|
|
HKEY hKey;
|
|
|
|
|
2015-03-14 19:08:55 +00:00
|
|
|
LPCTSTR regkey = TEXT("SOFTWARE\\Bethesda Softworks\\Morrowind");
|
|
|
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ | KEY_WOW64_32KEY, &hKey) == ERROR_SUCCESS)
|
2012-01-16 22:09:25 +00:00
|
|
|
{
|
|
|
|
//Key existed, let's try to read the install dir
|
2012-01-17 08:02:45 +00:00
|
|
|
std::vector<char> buf(512);
|
|
|
|
int len = 512;
|
2012-01-16 22:09:25 +00:00
|
|
|
|
2018-10-09 06:21:12 +00:00
|
|
|
if (RegQueryValueEx(hKey, TEXT("Installed Path"), nullptr, nullptr, (LPBYTE)&buf[0], (LPDWORD)&len) == ERROR_SUCCESS)
|
2012-01-16 22:09:25 +00:00
|
|
|
{
|
2012-01-17 08:02:45 +00:00
|
|
|
installPath = &buf[0];
|
2012-01-16 22:09:25 +00:00
|
|
|
}
|
2015-03-14 19:08:55 +00:00
|
|
|
RegCloseKey(hKey);
|
2012-01-16 22:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return installPath;
|
2012-01-21 16:58:49 +00:00
|
|
|
}
|
|
|
|
|
2011-08-19 19:06:09 +00:00
|
|
|
} /* namespace Files */
|
|
|
|
|
|
|
|
#endif /* defined(_WIN32) || defined(__WINDOWS__) */
|