Skip to content

Commit 975e0f7

Browse files
committed
Add platform-specific functions for path retrieval
Set to use in CLocatorAPI::setup_fs_path. TODO: need to cover other use cases.
1 parent a1ffdef commit 975e0f7

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

src/xrCore/LocatorAPI.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -760,12 +760,7 @@ void CLocatorAPI::setup_fs_path (LPCSTR fs_name)
760760

761761
if (!TryTestPath(full_current_directory))
762762
{
763-
#ifdef IXR_WINDOWS
764-
string256 BinPath;
765-
int bytes = GetModuleFileNameA(NULL, BinPath, sizeof(BinPath));
766-
std::filesystem::path TryPath = BinPath;
767-
TryTestPath(TryPath.parent_path());
768-
#endif
763+
TryTestPath(Platform::GetBinaryFolderPath());
769764
}
770765
}
771766

src/xrCore/Platform/Linux/OSFile.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,27 @@ namespace Platform
140140
return NewPath.c_str();
141141
}
142142

143+
IC std::filesystem::path GetBinaryFolderPath()
144+
{
145+
char result[PATH_MAX];
146+
ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
147+
if (count == -1)
148+
{
149+
return {};
150+
}
151+
return std::filesystem::path(std::string(result, count)).parent_path();
152+
}
153+
154+
IC std::string GetModuleName() {
155+
char result[PATH_MAX];
156+
ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
157+
if (count == -1)
158+
{
159+
return {};
160+
}
161+
return std::string(result, count);
162+
}
163+
143164
IC bool OpenFileWnd(char* buffer, size_t sz_buf, FS_Path* P, int start_flt_ext, char flt[1024], LPCSTR offset, bool bMulti)
144165
{
145166
return true;

src/xrCore/Platform/Windows/OSFile.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@ namespace Platform
1919
return NewPath.c_str();
2020
}
2121

22+
IC std::filesystem::path GetBinaryFolderPath()
23+
{
24+
char BinPath[MAX_PATH];
25+
int bytes = GetModuleFileNameA(NULL, BinPath, sizeof(BinPath));
26+
if (bytes == 0)
27+
{
28+
return {};
29+
}
30+
return std::filesystem::path(BinPath).parent_path();
31+
}
32+
33+
IC std::string GetModuleName()
34+
{
35+
char ModuleName[MAX_PATH];
36+
int bytes = GetModuleFileNameA(NULL, ModuleName, sizeof(ModuleName));
37+
if (bytes == 0)
38+
{
39+
return {};
40+
}
41+
return std::string(ModuleName);
42+
}
43+
2244
IC const xr_special_char* ValidPath(const xr_special_char* In)
2345
{
2446
return In;

0 commit comments

Comments
 (0)