mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-06 00:55:50 +00:00
Quick test at getting Morrowinds install path from the registry on windows
This commit is contained in:
parent
022f0fd5bd
commit
96ed96d4dd
@ -30,7 +30,7 @@
|
||||
#include <components/files/linuxpath.hpp>
|
||||
namespace Files { typedef LinuxPath TargetPathType; }
|
||||
|
||||
#elif defined(__WIN32) || defined(__WINDOWS__)
|
||||
#elif defined(__WIN32) || defined(__WINDOWS__) || defined(_WINDOWS)
|
||||
#include <components/files/windowspath.hpp>
|
||||
namespace Files { typedef WindowsPath TargetPathType; }
|
||||
|
||||
|
@ -5,7 +5,10 @@
|
||||
#include <cstring>
|
||||
|
||||
#include <windows.h>
|
||||
#include <shobj.h>
|
||||
#include <shlobj.h>
|
||||
#include <Shlwapi.h>
|
||||
|
||||
#pragma comment(lib, "Shlwapi.lib")
|
||||
|
||||
namespace Files
|
||||
{
|
||||
@ -67,6 +70,38 @@ boost::filesystem::path WindowsPath::getRuntimeDataPath() const
|
||||
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 */
|
||||
|
||||
#endif /* defined(_WIN32) || defined(__WINDOWS__) */
|
||||
|
@ -81,6 +81,13 @@ struct WindowsPath
|
||||
* \return boost::filesystem::path
|
||||
*/
|
||||
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 */
|
||||
|
Loading…
Reference in New Issue
Block a user