mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-26 04:12:07 -05:00
Make each platform set its own exe path
This commit is contained in:
parent
b4b1624e08
commit
d1b6d175c7
5 changed files with 66 additions and 47 deletions
|
@ -47,9 +47,6 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#include <mach-o/dyld.h>
|
||||
#endif // defined(__APPLE__) && defined(__MACH__)
|
||||
#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
|
||||
int gOpenRCT2StartupAction = STARTUP_ACTION_TITLE;
|
||||
|
@ -161,49 +158,8 @@ static void openrct2_copy_files_over(const utf8 *originalDirectory, const utf8 *
|
|||
// TODO move to platform
|
||||
static void openrct2_set_exe_path()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
wchar_t exePath[MAX_PATH];
|
||||
wchar_t tempPath[MAX_PATH];
|
||||
wchar_t *exeDelimiter;
|
||||
int exeDelimiterIndex;
|
||||
|
||||
GetModuleFileNameW(NULL, exePath, MAX_PATH);
|
||||
exeDelimiter = wcsrchr(exePath, platform_get_path_separator());
|
||||
exeDelimiterIndex = (int)(exeDelimiter - exePath);
|
||||
lstrcpynW(tempPath, exePath, exeDelimiterIndex + 1);
|
||||
tempPath[exeDelimiterIndex] = L'\0';
|
||||
_wfullpath(exePath, tempPath, MAX_PATH);
|
||||
WideCharToMultiByte(CP_UTF8, 0, exePath, countof(exePath), gExePath, countof(gExePath), NULL, NULL);
|
||||
#else // _WIN32
|
||||
char exePath[MAX_PATH];
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
int size = MAX_PATH;
|
||||
int result = _NSGetExecutablePath(exePath, &size);
|
||||
if (result != 0) {
|
||||
log_fatal("failed to get path");
|
||||
}
|
||||
exePath[MAX_PATH - 1] = '\0';
|
||||
#else // defined(__APPLE__) && defined(__MACH__)
|
||||
ssize_t bytesRead;
|
||||
bytesRead = readlink("/proc/self/exe", exePath, MAX_PATH);
|
||||
if (bytesRead == -1) {
|
||||
log_fatal("failed to read /proc/self/exe");
|
||||
}
|
||||
exePath[bytesRead - 1] = '\0';
|
||||
#endif // defined(__APPLE__) && defined(__MACH__)
|
||||
log_verbose("######################################## Setting exe path to %s", exePath);
|
||||
char *exeDelimiter = strrchr(exePath, platform_get_path_separator());
|
||||
if (exeDelimiter == NULL)
|
||||
{
|
||||
log_error("should never happen here");
|
||||
gExePath[0] = '\0';
|
||||
return;
|
||||
}
|
||||
int exeDelimiterIndex = (int)(exeDelimiter - exePath);
|
||||
|
||||
safe_strncpy(gExePath, exePath, exeDelimiterIndex + 1);
|
||||
gExePath[exeDelimiterIndex] = '\0';
|
||||
#endif // _WIN32
|
||||
platform_get_exe_path(gExePath);
|
||||
log_verbose("Setting exe path to %s", gExePath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,6 +36,28 @@ struct dummy {
|
|||
struct dummy* ptr;
|
||||
};
|
||||
|
||||
void platform_get_exe_path(utf8 *outPath)
|
||||
{
|
||||
char exePath[MAX_PATH];
|
||||
ssize_t bytesRead;
|
||||
bytesRead = readlink("/proc/self/exe", exePath, MAX_PATH);
|
||||
if (bytesRead == -1) {
|
||||
log_fatal("failed to read /proc/self/exe");
|
||||
}
|
||||
exePath[bytesRead - 1] = '\0';
|
||||
char *exeDelimiter = strrchr(exePath, platform_get_path_separator());
|
||||
if (exeDelimiter == NULL)
|
||||
{
|
||||
log_error("should never happen here");
|
||||
outPath[0] = '\0';
|
||||
return;
|
||||
}
|
||||
int exeDelimiterIndex = (int)(exeDelimiter - exePath);
|
||||
|
||||
safe_strncpy(outPath, exePath, exeDelimiterIndex + 1);
|
||||
outPath[exeDelimiterIndex] = '\0';
|
||||
}
|
||||
|
||||
bool platform_check_steam_overlay_attached() {
|
||||
void* processHandle = dlopen(NULL, RTLD_NOW);
|
||||
|
||||
|
|
|
@ -22,9 +22,33 @@
|
|||
|
||||
#include "platform.h"
|
||||
|
||||
#include <mach-o/dyld.h>
|
||||
|
||||
bool platform_check_steam_overlay_attached() {
|
||||
STUB();
|
||||
return false;
|
||||
}
|
||||
|
||||
void platform_get_exe_path(utf8 *outPath)
|
||||
{
|
||||
char exePath[MAX_PATH];
|
||||
int size = MAX_PATH;
|
||||
int result = _NSGetExecutablePath(exePath, &size);
|
||||
if (result != 0) {
|
||||
log_fatal("failed to get path");
|
||||
}
|
||||
exePath[MAX_PATH - 1] = '\0';
|
||||
char *exeDelimiter = strrchr(exePath, platform_get_path_separator());
|
||||
if (exeDelimiter == NULL)
|
||||
{
|
||||
log_error("should never happen here");
|
||||
outPath[0] = '\0';
|
||||
return;
|
||||
}
|
||||
int exeDelimiterIndex = (int)(exeDelimiter - exePath);
|
||||
|
||||
safe_strncpy(outPath, exePath, exeDelimiterIndex + 1);
|
||||
outPath[exeDelimiterIndex] = '\0';
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -113,6 +113,7 @@ void platform_get_date(rct2_date *out_date);
|
|||
void platform_get_time(rct2_time *out_time);
|
||||
|
||||
// Platform specific definitions
|
||||
void platform_get_exe_path(utf8 *outPath);
|
||||
char platform_get_path_separator();
|
||||
bool platform_file_exists(const utf8 *path);
|
||||
bool platform_directory_exists(const utf8 *path);
|
||||
|
|
|
@ -427,7 +427,7 @@ void platform_resolve_user_data_path()
|
|||
safe_strncpy(_userDataDirectoryPath, outPathTemp, sizeof(_userDataDirectoryPath));
|
||||
free(outPathTemp);
|
||||
free(customUserDataPathW);
|
||||
|
||||
|
||||
// Ensure path ends with separator
|
||||
int len = strlen(_userDataDirectoryPath);
|
||||
if (_userDataDirectoryPath[len - 1] != separator[0]) {
|
||||
|
@ -835,4 +835,20 @@ char *strndup(const char *src, size_t size)
|
|||
dst[len] = '\0';
|
||||
return (char *)dst;
|
||||
}
|
||||
|
||||
void platform_get_exe_path(utf8 *outPath)
|
||||
{
|
||||
wchar_t exePath[MAX_PATH];
|
||||
wchar_t tempPath[MAX_PATH];
|
||||
wchar_t *exeDelimiter;
|
||||
int exeDelimiterIndex;
|
||||
|
||||
GetModuleFileNameW(NULL, exePath, MAX_PATH);
|
||||
exeDelimiter = wcsrchr(exePath, platform_get_path_separator());
|
||||
exeDelimiterIndex = (int)(exeDelimiter - exePath);
|
||||
lstrcpynW(tempPath, exePath, exeDelimiterIndex + 1);
|
||||
tempPath[exeDelimiterIndex] = L'\0';
|
||||
_wfullpath(exePath, tempPath, MAX_PATH);
|
||||
WideCharToMultiByte(CP_UTF8, 0, exePath, countof(exePath), outPath, MAX_PATH, NULL, NULL);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue