mirror of
https://github.com/OpenRCT2/OpenRCT2.git
synced 2025-01-26 20:32:07 -05:00
Merge pull request #2396 from janisozaur/osx-path
Set path properly for OS X
This commit is contained in:
commit
e77537b27f
5 changed files with 66 additions and 35 deletions
|
@ -158,40 +158,8 @@ static void openrct2_copy_files_over(const utf8 *originalDirectory, const utf8 *
|
||||||
// TODO move to platform
|
// TODO move to platform
|
||||||
static void openrct2_set_exe_path()
|
static void openrct2_set_exe_path()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
platform_get_exe_path(gExePath);
|
||||||
wchar_t exePath[MAX_PATH];
|
log_verbose("Setting exe path to %s", gExePath);
|
||||||
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
|
|
||||||
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';
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,6 +36,28 @@ struct dummy {
|
||||||
struct dummy* ptr;
|
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() {
|
bool platform_check_steam_overlay_attached() {
|
||||||
void* processHandle = dlopen(NULL, RTLD_NOW);
|
void* processHandle = dlopen(NULL, RTLD_NOW);
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,33 @@
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
|
#include <mach-o/dyld.h>
|
||||||
|
|
||||||
bool platform_check_steam_overlay_attached() {
|
bool platform_check_steam_overlay_attached() {
|
||||||
STUB();
|
STUB();
|
||||||
return false;
|
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
|
#endif
|
||||||
|
|
|
@ -113,6 +113,7 @@ void platform_get_date(rct2_date *out_date);
|
||||||
void platform_get_time(rct2_time *out_time);
|
void platform_get_time(rct2_time *out_time);
|
||||||
|
|
||||||
// Platform specific definitions
|
// Platform specific definitions
|
||||||
|
void platform_get_exe_path(utf8 *outPath);
|
||||||
char platform_get_path_separator();
|
char platform_get_path_separator();
|
||||||
bool platform_file_exists(const utf8 *path);
|
bool platform_file_exists(const utf8 *path);
|
||||||
bool platform_directory_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));
|
safe_strncpy(_userDataDirectoryPath, outPathTemp, sizeof(_userDataDirectoryPath));
|
||||||
free(outPathTemp);
|
free(outPathTemp);
|
||||||
free(customUserDataPathW);
|
free(customUserDataPathW);
|
||||||
|
|
||||||
// Ensure path ends with separator
|
// Ensure path ends with separator
|
||||||
int len = strlen(_userDataDirectoryPath);
|
int len = strlen(_userDataDirectoryPath);
|
||||||
if (_userDataDirectoryPath[len - 1] != separator[0]) {
|
if (_userDataDirectoryPath[len - 1] != separator[0]) {
|
||||||
|
@ -835,4 +835,20 @@ char *strndup(const char *src, size_t size)
|
||||||
dst[len] = '\0';
|
dst[len] = '\0';
|
||||||
return (char *)dst;
|
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
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue