mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Improved #ifdef'ing of Windows-specific code.
Should help anyone wanting to do a port.
This commit is contained in:
@@ -283,8 +283,10 @@ namespace loot {
|
||||
|
||||
//First look for local install, then look for Registry.
|
||||
if (gamePath.empty() || !fs::exists(gamePath / "Data" / _masterFile)) {
|
||||
if (fs::exists(fs::path("..") / "Data" / _masterFile))
|
||||
if (fs::exists(fs::path("..") / "Data" / _masterFile)) {
|
||||
gamePath = "..";
|
||||
#ifdef _WIN32
|
||||
}
|
||||
else {
|
||||
string path;
|
||||
string key_parent = fs::path(registryKey).parent_path().string();
|
||||
@@ -292,6 +294,7 @@ namespace loot {
|
||||
path = RegKeyStringValue("HKEY_LOCAL_MACHINE", key_parent, key_name);
|
||||
if (!path.empty() && fs::exists(fs::path(path) / "Data" / _masterFile))
|
||||
gamePath = fs::path(path);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,12 +317,14 @@ namespace loot {
|
||||
if (fs::exists(fs::path("..") / "Data" / _masterFile))
|
||||
return true;
|
||||
|
||||
#ifdef _WIN32
|
||||
string path;
|
||||
string key_parent = fs::path(registryKey).parent_path().string();
|
||||
string key_name = fs::path(registryKey).filename().string();
|
||||
path = RegKeyStringValue("HKEY_LOCAL_MACHINE", key_parent, key_name);
|
||||
if (!path.empty() && fs::exists(fs::path(path) / "Data" / _masterFile))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
+7
-11
@@ -43,7 +43,7 @@
|
||||
#include <sstream>
|
||||
#include <regex>
|
||||
|
||||
#if _WIN32 || _WIN64
|
||||
#ifdef _WIN32
|
||||
# ifndef UNICODE
|
||||
# define UNICODE
|
||||
# endif
|
||||
@@ -161,9 +161,9 @@ namespace loot {
|
||||
return out;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
//Get registry subkey value string.
|
||||
string RegKeyStringValue(const std::string& keyStr, const std::string& subkey, const std::string& value) {
|
||||
#if _WIN32 || _WIN64
|
||||
HKEY hKey, key;
|
||||
DWORD BufferSize = 4096;
|
||||
wchar_t val[4096];
|
||||
@@ -193,13 +193,11 @@ namespace loot {
|
||||
return "";
|
||||
} else
|
||||
return "";
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
boost::filesystem::path GetLocalAppDataPath() {
|
||||
#if _WIN32 || _WIN64
|
||||
#ifdef _WIN32
|
||||
HWND owner = 0;
|
||||
TCHAR path[MAX_PATH];
|
||||
|
||||
@@ -210,8 +208,6 @@ namespace loot {
|
||||
return fs::path(path);
|
||||
else
|
||||
return fs::path("");
|
||||
#else
|
||||
return fs::path("");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -219,7 +215,7 @@ namespace loot {
|
||||
std::string ToFileURL(const fs::path& file) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "Converting file path " << file << " to a URL.";
|
||||
|
||||
#if _WIN32 || _WIN64
|
||||
#ifdef _WIN32
|
||||
wstring wstr(MAX_PATH, 0);
|
||||
DWORD len = MAX_PATH;
|
||||
UrlCreateFromPath(ToWinWide(file.string()).c_str(), &wstr[0], &len, NULL);
|
||||
@@ -230,7 +226,7 @@ namespace loot {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if _WIN32 || _WIN64
|
||||
#ifdef _WIN32
|
||||
//Helper to turn UTF8 strings into strings that can be used by WinAPI.
|
||||
std::wstring ToWinWide(const std::string& str) {
|
||||
|
||||
@@ -337,7 +333,7 @@ namespace loot {
|
||||
: verString(ver) {}
|
||||
|
||||
Version::Version(const fs::path& file) {
|
||||
#if _WIN32 || _WIN64
|
||||
#ifdef _WIN32
|
||||
DWORD dummy = 0;
|
||||
DWORD size = GetFileVersionInfoSize(file.wstring().c_str(), &dummy);
|
||||
|
||||
|
||||
@@ -51,16 +51,18 @@ namespace loot {
|
||||
//Converts an integer to a hex string using BOOST's Spirit.Karma. Faster than a stringstream conversion.
|
||||
std::string IntToHexString(const int n);
|
||||
|
||||
#ifdef _WIN32
|
||||
//Get registry subkey value string.
|
||||
std::string RegKeyStringValue(const std::string& keyStr, const std::string& subkey, const std::string& value);
|
||||
#endif
|
||||
|
||||
//Get the local application data path.
|
||||
//Get the local application data path, within which LOOT's data folder should be stored.
|
||||
boost::filesystem::path GetLocalAppDataPath();
|
||||
|
||||
//Turns an absolute filesystem path into a valid file:// URL.
|
||||
std::string ToFileURL(const boost::filesystem::path& file);
|
||||
|
||||
#if _WIN32 || _WIN64
|
||||
#ifdef _WIN32
|
||||
//Helper to turn UTF8 strings into strings that can be used by WinAPI.
|
||||
std::wstring ToWinWide(const std::string& str);
|
||||
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ namespace loot {
|
||||
// Information used when creating the native window.
|
||||
CefWindowInfo window_info;
|
||||
|
||||
#if _WIN32 || _WIN64
|
||||
#ifdef _WIN32
|
||||
// On Windows we need to specify certain flags that will be passed to CreateWindowEx().
|
||||
window_info.SetAsPopup(NULL, "LOOT");
|
||||
#endif
|
||||
|
||||
+5
-5
@@ -117,8 +117,8 @@ namespace loot {
|
||||
}
|
||||
else if (request == "getGameData") {
|
||||
BOOST_LOG_TRIVIAL(info) << "Setting LOOT window title bar text to include game name: " << g_app_state.CurrentGame().Name();
|
||||
#if defined(OS_WIN)
|
||||
HWND handle = browser->GetHost()->GetWindowHandle();
|
||||
#ifdef _WIN32
|
||||
SetWindowText(handle, ToWinWide("LOOT: " + g_app_state.CurrentGame().Name()).c_str());
|
||||
#endif
|
||||
|
||||
@@ -234,9 +234,9 @@ namespace loot {
|
||||
BOOST_LOG_TRIVIAL(info) << "Changing game to that with folder: " << folder;
|
||||
g_app_state.ChangeGame(folder);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
BOOST_LOG_TRIVIAL(info) << "Setting LOOT window title bar text to include game name: " << g_app_state.CurrentGame().Name();
|
||||
HWND handle = browser->GetHost()->GetWindowHandle();
|
||||
#ifdef _WIN32
|
||||
SetWindowText(handle, ToWinWide("LOOT: " + g_app_state.CurrentGame().Name()).c_str());
|
||||
#endif
|
||||
|
||||
@@ -291,7 +291,7 @@ namespace loot {
|
||||
text = yout.c_str();
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#ifdef _WIN32
|
||||
if (!OpenClipboard(NULL)) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to open the Windows clipboard.";
|
||||
callback->Failure(-1, "Failed to open the Windows clipboard.");
|
||||
@@ -825,15 +825,15 @@ namespace loot {
|
||||
// CefDisplayHandler methods
|
||||
//--------------------------
|
||||
|
||||
#if _WIN32 || _WIN64
|
||||
void LootHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) {
|
||||
assert(CefCurrentlyOn(TID_UI));
|
||||
|
||||
CefWindowHandle hwnd = browser->GetHost()->GetWindowHandle();
|
||||
#ifdef _WIN32
|
||||
SetWindowText(hwnd, std::wstring(title).c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// CefLifeSpanHandler methods
|
||||
//---------------------------
|
||||
|
||||
@@ -101,7 +101,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmd
|
||||
|
||||
// Record command line arguments.
|
||||
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
|
||||
#if defined(OS_WIN)
|
||||
#ifdef _WIN32
|
||||
command_line->InitFromString(::GetCommandLineW());
|
||||
#endif
|
||||
if (command_line->HasSwitch("game")) { // Format is: --game=<game>
|
||||
|
||||
Reference in New Issue
Block a user