mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 12:53:51 +00:00
Quick test at getting Morrowinds install path from the registry on windows
This commit is contained in:
parent
022f0fd5bd
commit
96ed96d4dd
3 changed files with 44 additions and 2 deletions
|
@ -30,7 +30,7 @@
|
||||||
#include <components/files/linuxpath.hpp>
|
#include <components/files/linuxpath.hpp>
|
||||||
namespace Files { typedef LinuxPath TargetPathType; }
|
namespace Files { typedef LinuxPath TargetPathType; }
|
||||||
|
|
||||||
#elif defined(__WIN32) || defined(__WINDOWS__)
|
#elif defined(__WIN32) || defined(__WINDOWS__) || defined(_WINDOWS)
|
||||||
#include <components/files/windowspath.hpp>
|
#include <components/files/windowspath.hpp>
|
||||||
namespace Files { typedef WindowsPath TargetPathType; }
|
namespace Files { typedef WindowsPath TargetPathType; }
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,10 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <shobj.h>
|
#include <shlobj.h>
|
||||||
|
#include <Shlwapi.h>
|
||||||
|
|
||||||
|
#pragma comment(lib, "Shlwapi.lib")
|
||||||
|
|
||||||
namespace Files
|
namespace Files
|
||||||
{
|
{
|
||||||
|
@ -67,6 +70,38 @@ boost::filesystem::path WindowsPath::getRuntimeDataPath() const
|
||||||
return boost::filesystem::path("./data/");
|
return boost::filesystem::path("./data/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::filesystem::path WindowsPath::getInstallPath() const
|
||||||
|
{
|
||||||
|
boost::filesystem::path installPath("");
|
||||||
|
|
||||||
|
HKEY hKey;
|
||||||
|
|
||||||
|
BOOL f64 = FALSE;
|
||||||
|
LPCTSTR regkey;
|
||||||
|
if (IsWow64Process(GetCurrentProcess(), &f64) && f64)
|
||||||
|
{
|
||||||
|
regkey = "SOFTWARE\\Wow6432Node\\Bethesda Softworks\\Morrowind";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
regkey = "SOFTWARE\\Bethesda Softworks\\Morrowind";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(regkey), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
//Key existed, let's try to read the install dir
|
||||||
|
char* data = new char[4096];
|
||||||
|
int len = 4096;
|
||||||
|
|
||||||
|
if (RegQueryValueEx(hKey, TEXT("Installed Path"), NULL, NULL, (LPBYTE)data, (LPDWORD)&len) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
installPath = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return installPath;
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace Files */
|
} /* namespace Files */
|
||||||
|
|
||||||
#endif /* defined(_WIN32) || defined(__WINDOWS__) */
|
#endif /* defined(_WIN32) || defined(__WINDOWS__) */
|
||||||
|
|
|
@ -81,6 +81,13 @@ struct WindowsPath
|
||||||
* \return boost::filesystem::path
|
* \return boost::filesystem::path
|
||||||
*/
|
*/
|
||||||
boost::filesystem::path getRuntimeDataPath() const;
|
boost::filesystem::path getRuntimeDataPath() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Gets the path of the installed Morrowind version if there is one.
|
||||||
|
*
|
||||||
|
* \return boost::filesystem::path
|
||||||
|
*/
|
||||||
|
boost::filesystem::path getInstallPath() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace Files */
|
} /* namespace Files */
|
||||||
|
|
Loading…
Reference in a new issue