1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Fix mingw

This commit is contained in:
Ted John
2017-11-29 00:09:13 +00:00
parent 679aae801d
commit ea356cd2b9
2 changed files with 67 additions and 27 deletions

View File

@@ -20,6 +20,10 @@
#include <windows.h>
#include <shlobj.h>
#undef GetEnvironmentVariable
#if !defined(__MINGW32__) && ((NTDDI_VERSION >= NTDDI_VISTA) && !defined(_USING_V110_SDK71_) && !defined(_ATL_XP_TARGETING))
#define __USE_SHGETKNOWNFOLDERPATH__
#endif
#else
#include <pwd.h>
#endif
@@ -62,6 +66,7 @@ namespace Platform
#endif
}
#ifndef _WIN32
static std::string GetEnvironmentPath(const char * name)
{
auto value = getenv(name);
@@ -82,6 +87,50 @@ namespace Platform
}
}
}
#endif
static std::string GetHomePathViaEnvironment()
{
#ifdef _WIN32
std::string result;
auto homedrive = GetEnvironmentVariable("HOMEDRIVE");
auto homepath = GetEnvironmentVariable("HOMEPATH");
if (!homedrive.empty() && !homepath.empty())
{
result = Path::Combine(homedrive, homepath);
}
return result;
#else
return GetEnvironmentVariable("HOME");
#endif
}
#ifdef _WIN32
#ifdef __USE_SHGETKNOWNFOLDERPATH__
static std::string WIN32_GetKnownFolderPath(REFKNOWNFOLDERID rfid)
{
std::string path;
wchar_t * wpath = nullptr;
if (SUCCEEDED(SHGetKnownFolderPath(rfid, KF_FLAG_CREATE, nullptr, &wpath)))
{
path = String::ToUtf8(std::wstring(wpath));
}
CoTaskMemFree(wpath);
return path;
}
#else
static std::string WIN32_GetFolderPath(int nFolder)
{
std::string path;
wchar_t wpath[MAX_PATH];
if (SUCCEEDED(SHGetFolderPathW(nullptr, nFolder | CSIDL_FLAG_CREATE, nullptr, 0, wpath)))
{
path = String::ToUtf8(std::wstring(wpath));
}
return path;
}
#endif
#endif
std::string GetFolderPath(SPECIAL_FOLDER folder)
{
@@ -93,41 +142,33 @@ namespace Platform
case SPECIAL_FOLDER::USER_CONFIG:
case SPECIAL_FOLDER::USER_DATA:
{
wchar_t * wpath = nullptr;
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_CREATE, nullptr, &wpath)))
#ifdef __USE_SHGETKNOWNFOLDERPATH__
auto path = WIN32_GetKnownFolderPath(FOLDERID_Documents);
#else
auto path = WIN32_GetFolderPath(CSIDL_PERSONAL);
#endif
if (path.empty())
{
auto path = String::ToUtf8(std::wstring(wpath));
CoTaskMemFree(wpath);
return path;
}
else
{
return GetFolderPath(SPECIAL_FOLDER::USER_HOME);
path = GetFolderPath(SPECIAL_FOLDER::USER_HOME);
}
return path;
}
case SPECIAL_FOLDER::USER_HOME:
{
wchar_t * wpath = nullptr;
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Profile, KF_FLAG_CREATE, nullptr, &wpath)))
#ifdef __USE_SHGETKNOWNFOLDERPATH__
auto path = WIN32_GetKnownFolderPath(FOLDERID_Profile);
#else
auto path = WIN32_GetFolderPath(CSIDL_PROFILE);
#endif
if (path.empty())
{
auto path = String::ToUtf8(std::wstring(wpath));
CoTaskMemFree(wpath);
return path;
}
else
{
// Try default environment variables
auto homedrive = GetEnvironmentVariable("HOMEDRIVE");
auto homepath = GetEnvironmentVariable("HOMEPATH");
if (!homedrive.empty() && !homepath.empty())
path = GetHomePathViaEnvironment();
if (path.empty())
{
return Path::Combine(homedrive, homepath);
}
else
{
return "C:\\";
path = "C:\\";
}
}
return path;
}
#elif defined (__ANDROID__)
// Andorid builds currently only read from /sdcard/openrct2*

View File

@@ -48,7 +48,6 @@
// The name of the mutex used to prevent multiple instances of the game from running
#define SINGLE_INSTANCE_MUTEX_NAME "RollerCoaster Tycoon 2_GSKMUTEX"
static utf8 _userDataDirectoryPath[MAX_PATH] = { 0 };
static utf8 _openrctDataDirectoryPath[MAX_PATH] = { 0 };
#define OPENRCT2_DLL_MODULE_NAME "openrct2.dll"