From 96ed96d4dd432b3ee78c081575f888d0692c78c5 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Mon, 16 Jan 2012 23:09:25 +0100 Subject: [PATCH] Quick test at getting Morrowinds install path from the registry on windows --- components/files/path.hpp | 2 +- components/files/windowspath.cpp | 37 +++++++++++++++++++++++++++++++- components/files/windowspath.hpp | 7 ++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/components/files/path.hpp b/components/files/path.hpp index 0788cefb15..5a4cf337b6 100644 --- a/components/files/path.hpp +++ b/components/files/path.hpp @@ -30,7 +30,7 @@ #include namespace Files { typedef LinuxPath TargetPathType; } -#elif defined(__WIN32) || defined(__WINDOWS__) +#elif defined(__WIN32) || defined(__WINDOWS__) || defined(_WINDOWS) #include namespace Files { typedef WindowsPath TargetPathType; } diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index f42f149c14..5c87eba92c 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -5,7 +5,10 @@ #include #include -#include +#include +#include + +#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__) */ diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp index 47dfc08d8e..4550fc05ff 100644 --- a/components/files/windowspath.hpp +++ b/components/files/windowspath.hpp @@ -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 */