Skip to content

Commit 277dab3

Browse files
committed
xrCore: fixed linux FS (open/read archives)
1 parent 2152c23 commit 277dab3

File tree

7 files changed

+30
-25
lines changed

7 files changed

+30
-25
lines changed

src/xrCore/FS.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ CVirtualFileRW::CVirtualFileRW(const char* cFileName)
520520
data = (char*)MapViewOfFile(hSrcMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
521521
R_ASSERT3(data, cFileName, xrDebug::ErrorToString(GetLastError()));
522522
#elif defined(LINUX)
523-
hSrcFile = ::open(cFileName, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет
523+
hSrcFile = ::open(cFileName, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет
524524
R_ASSERT3(hSrcFile != -1, cFileName, xrDebug::ErrorToString(GetLastError()));
525525
struct stat file_info;
526526
::fstat(hSrcFile, &file_info);
@@ -563,7 +563,7 @@ CVirtualFileReader::CVirtualFileReader(const char* cFileName)
563563

564564
data = (char*)MapViewOfFile(hSrcMap, FILE_MAP_READ, 0, 0, 0);
565565
#elif defined(LINUX)
566-
hSrcFile = ::open(cFileName, O_RDONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет
566+
hSrcFile = ::open(cFileName, O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет
567567
R_ASSERT3(hSrcFile != -1, cFileName, xrDebug::ErrorToString(GetLastError()));
568568
struct stat file_info;
569569
::fstat(hSrcFile, &file_info);

src/xrCore/LocatorAPI.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const CLocatorAPI::file* CLocatorAPI::RegisterExternal(pcstr name)
193193
const CLocatorAPI::file* CLocatorAPI::Register(
194194
pcstr name, u32 vfs, u32 crc, u32 ptr, u32 size_real, u32 size_compressed, u32 modif)
195195
{
196-
// Msg("Register[%d] [%s]",vfs,name);
196+
Msg("Register[%d] [%s]",vfs,name);
197197
string256 temp_file_name;
198198
xr_strcpy(temp_file_name, sizeof temp_file_name, name);
199199
xr_strlwr(temp_file_name);
@@ -265,7 +265,7 @@ IReader* open_chunk(void* ptr, u32 ID)
265265
u32 pt = SetFilePointer(ptr, 0, nullptr, FILE_BEGIN);
266266
VERIFY(pt != INVALID_SET_FILE_POINTER);
267267
#else
268-
::rewind(ptr);
268+
::lseek(ptr, 0L, SEEK_SET);
269269
#endif
270270
while (true)
271271
{
@@ -314,7 +314,7 @@ IReader* open_chunk(void* ptr, u32 ID)
314314
if (pt == INVALID_SET_FILE_POINTER)
315315
return nullptr;
316316
#else
317-
if(-1 == ::fseek(ptr, dwSize, SEEK_CUR))
317+
if(-1 == ::lseek(ptr, dwSize, SEEK_CUR))
318318
return nullptr;
319319
#endif
320320
}
@@ -422,7 +422,7 @@ void CLocatorAPI::archive::open()
422422
R_ASSERT(hSrcMap != INVALID_HANDLE_VALUE);
423423
size = GetFileSize(hSrcFile, nullptr);
424424
#elif defined(LINUX)
425-
hSrcFile = ::open(*path, O_RDONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
425+
hSrcFile = ::open(*path, O_RDONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
426426
R_ASSERT(hSrcFile != -1);
427427
struct stat file_info;
428428
::fstat(hSrcFile, &file_info);
@@ -513,9 +513,12 @@ bool CLocatorAPI::load_all_unloaded_archives()
513513
void CLocatorAPI::ProcessOne(pcstr path, const _finddata_t& entry)
514514
{
515515
string_path N;
516+
#if defined(WINDOWS)
516517
xr_strcpy(N, sizeof N, path);
517518
xr_strcat(N, entry.name);
518-
xr_strlwr(N);
519+
#elif defined(LINUX)
520+
xr_strcpy(N, sizeof N, entry.name);
521+
#endif
519522

520523
if (entry.attrib & _A_HIDDEN)
521524
return;
@@ -629,7 +632,7 @@ bool CLocatorAPI::Recurse(pcstr path)
629632
while (done != -1)
630633
{
631634
#if defined(LINUX)
632-
xr_strcpy(findData.name, sizeof globbuf.gl_pathv[handle - done], globbuf.gl_pathv[handle - done]);
635+
xr_strcpy(findData.name, globbuf.gl_pathv[handle - done]);
633636
struct stat fi;
634637
stat(findData.name, &fi);
635638
findData.size = fi.st_size;
@@ -638,9 +641,14 @@ bool CLocatorAPI::Recurse(pcstr path)
638641
bool ignore = false;
639642
if (m_Flags.test(flNeedCheck))
640643
{
644+
#ifdef WINDOWS
641645
xr_strcpy(fullPath, sizeof fullPath, path);
642646
xr_strcat(fullPath, findData.name);
643647
ignore = ignore_name(findData.name) || ignore_path(fullPath);
648+
#elif defined(LINUX)
649+
xr_strcpy(fullPath, sizeof fullPath, findData.name); // glob return full path to file
650+
ignore = ignore_name(findData.name);
651+
#endif
644652
}
645653
else
646654
{
@@ -704,6 +712,8 @@ void CLocatorAPI::setup_fs_path(pcstr fs_name)
704712
if (SDL_strlen(fs_path) != 0)
705713
{
706714
char *tmp_path = realpath(fs_path, NULL);
715+
CHECK_OR_EXIT(tmp_path && tmp_path[0],
716+
make_string("Cannot get realpath for \"%s\": %s", fs_path, strerror(errno)));
707717
SDL_strlcpy(full_current_directory, tmp_path, sizeof full_current_directory);
708718
free(tmp_path);
709719
}

src/xrCore/LocatorAPI_defs.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ FS_Path::FS_Path(LPCSTR _Root, LPCSTR _Add, LPCSTR _DefExt, LPCSTR _FilterCaptio
5757
#endif
5858
if (temp[0] && temp[xr_strlen(temp) - 1] != _DELIMITER)
5959
xr_strcat(temp, DELIMITER);
60-
m_Path = xr_strlwr(xr_strdup(temp));
60+
m_Path = xr_strdup(temp);
6161
m_DefExt = _DefExt ? xr_strlwr(xr_strdup(_DefExt)) : 0;
6262
m_FilterCaption = _FilterCaption ? xr_strlwr(xr_strdup(_FilterCaption)) : 0;
6363
m_Add = _Add ? xr_strlwr(xr_strdup(_Add)) : 0;
64-
m_Root = _Root ? xr_strlwr(xr_strdup(_Root)) : 0;
64+
m_Root = _Root ? xr_strdup(_Root) : 0;
6565
m_Flags.assign(flags);
6666
#ifdef _EDITOR
6767
// Editor(s)/User(s) wants pathes already created in "real" file system :)
@@ -91,7 +91,7 @@ void FS_Path::_set(LPCSTR add)
9191
if (temp[xr_strlen(temp) - 1] != '\\')
9292
xr_strcat(temp, "\\");
9393
xr_free(m_Path);
94-
m_Path = xr_strlwr(xr_strdup(temp));
94+
m_Path = xr_strdup(temp);
9595
}
9696

9797
void FS_Path::_set_root(LPCSTR root)
@@ -101,14 +101,14 @@ void FS_Path::_set_root(LPCSTR root)
101101
if (m_Root[0] && m_Root[xr_strlen(m_Root) - 1] != '\\')
102102
xr_strcat(temp, "\\");
103103
xr_free(m_Root);
104-
m_Root = xr_strlwr(xr_strdup(temp));
104+
m_Root = xr_strdup(temp);
105105

106106
// m_Path
107107
strconcat(sizeof(temp), temp, m_Root, m_Add ? m_Add : "");
108108
if (*temp && temp[xr_strlen(temp) - 1] != '\\')
109109
xr_strcat(temp, "\\");
110110
xr_free(m_Path);
111-
m_Path = xr_strlwr(xr_strdup(temp));
111+
m_Path = xr_strdup(temp);
112112
}
113113

114114
LPCSTR FS_Path::_update(string_path& dest, LPCSTR src) const

src/xrCore/_math.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,7 @@ void Detect()
275275
clk_overhead /= 256;
276276

277277
// Detect QPC Overhead
278-
#if defined(WINDOWS) //TODO Linux can doesn`t have ticks (tikless systems). Need think about it
279-
QueryPerformanceFrequency((PLARGE_INTEGER)&qpc_freq);
280-
#endif
278+
qpc_freq = SDL_GetPerformanceFrequency();
281279
qpc_overhead = 0;
282280
for (int i = 0; i < 256; i++)
283281
{

src/xrCore/xrCore.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void PrintBuildInfo()
7979

8080
if (builder)
8181
strconcat(sizeof(buf), buf, buf, " (built by ", builder, ")"); // " (built by builder)"
82-
82+
8383
Log(buf); // "%s build %s from commit[%s] branch[%s] (built by %s)"
8484
}
8585

@@ -184,7 +184,7 @@ void SDLLogOutput(void* /*userdata*/,
184184
Log(buf);
185185
}
186186

187-
void xrCore::Initialize(pcstr _ApplicationName, LogCallback cb, bool init_fs, pcstr fs_fname, bool plugin)
187+
void xrCore::Initialize(pcstr _ApplicationName, pcstr commandLine, LogCallback cb, bool init_fs, pcstr fs_fname, bool plugin)
188188
{
189189
xr_strcpy(ApplicationName, _ApplicationName);
190190
if (0 == init_counter)
@@ -193,11 +193,8 @@ void xrCore::Initialize(pcstr _ApplicationName, LogCallback cb, bool init_fs, pc
193193
PluginMode = plugin;
194194
// Init COM so we can use CoCreateInstance
195195
// HRESULT co_res =
196-
#if defined(WINDOWS)
197-
Params = xr_strdup(GetCommandLine());
198-
#elif defined(LINUX)
199-
Params = xr_strdup(""); //TODO handle /proc/self/cmdline
200-
#endif
196+
197+
Params = xr_strdup (commandLine);
201198

202199
#if defined(WINDOWS)
203200
if (!strstr(Params, "-weather"))

src/xrCore/xrCore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class XRCORE_API xrCore
132132
bool PluginMode;
133133

134134
void Initialize(
135-
pcstr ApplicationName, LogCallback cb = nullptr, bool init_fs = true, pcstr fs_fname = nullptr, bool plugin = false);
135+
pcstr ApplicationName, pcstr commandLine = nullptr, LogCallback cb = nullptr, bool init_fs = true, pcstr fs_fname = nullptr, bool plugin = false);
136136
void _destroy();
137137
const char* GetBuildDate() const { return buildDate; }
138138
u32 GetBuildId() const { return buildId; }

src/xr_3da/entry_point.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int entry_point(pcstr commandLine)
4040
const u32 sz = xr_strlen(fsltx);
4141
sscanf(strstr(commandLine, fsltx) + sz, "%[^ ] ", fsgame);
4242
}
43-
Core.Initialize("OpenXRay", nullptr, true, *fsgame ? fsgame : nullptr);
43+
Core.Initialize("OpenXRay", commandLine, nullptr, true, *fsgame ? fsgame : nullptr);
4444

4545
auto result = RunApplication();
4646

0 commit comments

Comments
 (0)