From 277dab32e253f20dbdf81ac992cd7da61ad43fd2 Mon Sep 17 00:00:00 2001 From: Ilya Orlov Date: Sun, 19 Aug 2018 14:05:04 +0300 Subject: [PATCH] xrCore: fixed linux FS (open/read archives) --- src/xrCore/FS.cpp | 4 ++-- src/xrCore/LocatorAPI.cpp | 22 ++++++++++++++++------ src/xrCore/LocatorAPI_defs.cpp | 10 +++++----- src/xrCore/_math.cpp | 4 +--- src/xrCore/xrCore.cpp | 11 ++++------- src/xrCore/xrCore.h | 2 +- src/xr_3da/entry_point.cpp | 2 +- 7 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/xrCore/FS.cpp b/src/xrCore/FS.cpp index 0e29aa98e37..f92ae92901e 100644 --- a/src/xrCore/FS.cpp +++ b/src/xrCore/FS.cpp @@ -520,7 +520,7 @@ CVirtualFileRW::CVirtualFileRW(const char* cFileName) data = (char*)MapViewOfFile(hSrcMap, FILE_MAP_ALL_ACCESS, 0, 0, 0); R_ASSERT3(data, cFileName, xrDebug::ErrorToString(GetLastError())); #elif defined(LINUX) - hSrcFile = ::open(cFileName, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет + hSrcFile = ::open(cFileName, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет R_ASSERT3(hSrcFile != -1, cFileName, xrDebug::ErrorToString(GetLastError())); struct stat file_info; ::fstat(hSrcFile, &file_info); @@ -563,7 +563,7 @@ CVirtualFileReader::CVirtualFileReader(const char* cFileName) data = (char*)MapViewOfFile(hSrcMap, FILE_MAP_READ, 0, 0, 0); #elif defined(LINUX) - hSrcFile = ::open(cFileName, O_RDONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет + hSrcFile = ::open(cFileName, O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); //за такое использование указателя нужно убивать, но пока пусть будет R_ASSERT3(hSrcFile != -1, cFileName, xrDebug::ErrorToString(GetLastError())); struct stat file_info; ::fstat(hSrcFile, &file_info); diff --git a/src/xrCore/LocatorAPI.cpp b/src/xrCore/LocatorAPI.cpp index 7c8653693a3..5bc1a0a8ac4 100644 --- a/src/xrCore/LocatorAPI.cpp +++ b/src/xrCore/LocatorAPI.cpp @@ -193,7 +193,7 @@ const CLocatorAPI::file* CLocatorAPI::RegisterExternal(pcstr name) const CLocatorAPI::file* CLocatorAPI::Register( pcstr name, u32 vfs, u32 crc, u32 ptr, u32 size_real, u32 size_compressed, u32 modif) { - // Msg("Register[%d] [%s]",vfs,name); + Msg("Register[%d] [%s]",vfs,name); string256 temp_file_name; xr_strcpy(temp_file_name, sizeof temp_file_name, name); xr_strlwr(temp_file_name); @@ -265,7 +265,7 @@ IReader* open_chunk(void* ptr, u32 ID) u32 pt = SetFilePointer(ptr, 0, nullptr, FILE_BEGIN); VERIFY(pt != INVALID_SET_FILE_POINTER); #else - ::rewind(ptr); + ::lseek(ptr, 0L, SEEK_SET); #endif while (true) { @@ -314,7 +314,7 @@ IReader* open_chunk(void* ptr, u32 ID) if (pt == INVALID_SET_FILE_POINTER) return nullptr; #else - if(-1 == ::fseek(ptr, dwSize, SEEK_CUR)) + if(-1 == ::lseek(ptr, dwSize, SEEK_CUR)) return nullptr; #endif } @@ -422,7 +422,7 @@ void CLocatorAPI::archive::open() R_ASSERT(hSrcMap != INVALID_HANDLE_VALUE); size = GetFileSize(hSrcFile, nullptr); #elif defined(LINUX) - hSrcFile = ::open(*path, O_RDONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + hSrcFile = ::open(*path, O_RDONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); R_ASSERT(hSrcFile != -1); struct stat file_info; ::fstat(hSrcFile, &file_info); @@ -513,9 +513,12 @@ bool CLocatorAPI::load_all_unloaded_archives() void CLocatorAPI::ProcessOne(pcstr path, const _finddata_t& entry) { string_path N; +#if defined(WINDOWS) xr_strcpy(N, sizeof N, path); xr_strcat(N, entry.name); - xr_strlwr(N); +#elif defined(LINUX) + xr_strcpy(N, sizeof N, entry.name); +#endif if (entry.attrib & _A_HIDDEN) return; @@ -629,7 +632,7 @@ bool CLocatorAPI::Recurse(pcstr path) while (done != -1) { #if defined(LINUX) - xr_strcpy(findData.name, sizeof globbuf.gl_pathv[handle - done], globbuf.gl_pathv[handle - done]); + xr_strcpy(findData.name, globbuf.gl_pathv[handle - done]); struct stat fi; stat(findData.name, &fi); findData.size = fi.st_size; @@ -638,9 +641,14 @@ bool CLocatorAPI::Recurse(pcstr path) bool ignore = false; if (m_Flags.test(flNeedCheck)) { +#ifdef WINDOWS xr_strcpy(fullPath, sizeof fullPath, path); xr_strcat(fullPath, findData.name); ignore = ignore_name(findData.name) || ignore_path(fullPath); +#elif defined(LINUX) + xr_strcpy(fullPath, sizeof fullPath, findData.name); // glob return full path to file + ignore = ignore_name(findData.name); +#endif } else { @@ -704,6 +712,8 @@ void CLocatorAPI::setup_fs_path(pcstr fs_name) if (SDL_strlen(fs_path) != 0) { char *tmp_path = realpath(fs_path, NULL); + CHECK_OR_EXIT(tmp_path && tmp_path[0], + make_string("Cannot get realpath for \"%s\": %s", fs_path, strerror(errno))); SDL_strlcpy(full_current_directory, tmp_path, sizeof full_current_directory); free(tmp_path); } diff --git a/src/xrCore/LocatorAPI_defs.cpp b/src/xrCore/LocatorAPI_defs.cpp index 24ce60de912..01ba43cd4ac 100644 --- a/src/xrCore/LocatorAPI_defs.cpp +++ b/src/xrCore/LocatorAPI_defs.cpp @@ -57,11 +57,11 @@ FS_Path::FS_Path(LPCSTR _Root, LPCSTR _Add, LPCSTR _DefExt, LPCSTR _FilterCaptio #endif if (temp[0] && temp[xr_strlen(temp) - 1] != _DELIMITER) xr_strcat(temp, DELIMITER); - m_Path = xr_strlwr(xr_strdup(temp)); + m_Path = xr_strdup(temp); m_DefExt = _DefExt ? xr_strlwr(xr_strdup(_DefExt)) : 0; m_FilterCaption = _FilterCaption ? xr_strlwr(xr_strdup(_FilterCaption)) : 0; m_Add = _Add ? xr_strlwr(xr_strdup(_Add)) : 0; - m_Root = _Root ? xr_strlwr(xr_strdup(_Root)) : 0; + m_Root = _Root ? xr_strdup(_Root) : 0; m_Flags.assign(flags); #ifdef _EDITOR // Editor(s)/User(s) wants pathes already created in "real" file system :) @@ -91,7 +91,7 @@ void FS_Path::_set(LPCSTR add) if (temp[xr_strlen(temp) - 1] != '\\') xr_strcat(temp, "\\"); xr_free(m_Path); - m_Path = xr_strlwr(xr_strdup(temp)); + m_Path = xr_strdup(temp); } void FS_Path::_set_root(LPCSTR root) @@ -101,14 +101,14 @@ void FS_Path::_set_root(LPCSTR root) if (m_Root[0] && m_Root[xr_strlen(m_Root) - 1] != '\\') xr_strcat(temp, "\\"); xr_free(m_Root); - m_Root = xr_strlwr(xr_strdup(temp)); + m_Root = xr_strdup(temp); // m_Path strconcat(sizeof(temp), temp, m_Root, m_Add ? m_Add : ""); if (*temp && temp[xr_strlen(temp) - 1] != '\\') xr_strcat(temp, "\\"); xr_free(m_Path); - m_Path = xr_strlwr(xr_strdup(temp)); + m_Path = xr_strdup(temp); } LPCSTR FS_Path::_update(string_path& dest, LPCSTR src) const diff --git a/src/xrCore/_math.cpp b/src/xrCore/_math.cpp index e320e1952ac..f3c5a77f8d1 100644 --- a/src/xrCore/_math.cpp +++ b/src/xrCore/_math.cpp @@ -275,9 +275,7 @@ void Detect() clk_overhead /= 256; // Detect QPC Overhead -#if defined(WINDOWS) //TODO Linux can doesn`t have ticks (tikless systems). Need think about it - QueryPerformanceFrequency((PLARGE_INTEGER)&qpc_freq); -#endif + qpc_freq = SDL_GetPerformanceFrequency(); qpc_overhead = 0; for (int i = 0; i < 256; i++) { diff --git a/src/xrCore/xrCore.cpp b/src/xrCore/xrCore.cpp index 8fe64eec6ac..30fd62c6a6e 100644 --- a/src/xrCore/xrCore.cpp +++ b/src/xrCore/xrCore.cpp @@ -79,7 +79,7 @@ void PrintBuildInfo() if (builder) strconcat(sizeof(buf), buf, buf, " (built by ", builder, ")"); // " (built by builder)" - + Log(buf); // "%s build %s from commit[%s] branch[%s] (built by %s)" } @@ -184,7 +184,7 @@ void SDLLogOutput(void* /*userdata*/, Log(buf); } -void xrCore::Initialize(pcstr _ApplicationName, LogCallback cb, bool init_fs, pcstr fs_fname, bool plugin) +void xrCore::Initialize(pcstr _ApplicationName, pcstr commandLine, LogCallback cb, bool init_fs, pcstr fs_fname, bool plugin) { xr_strcpy(ApplicationName, _ApplicationName); if (0 == init_counter) @@ -193,11 +193,8 @@ void xrCore::Initialize(pcstr _ApplicationName, LogCallback cb, bool init_fs, pc PluginMode = plugin; // Init COM so we can use CoCreateInstance // HRESULT co_res = -#if defined(WINDOWS) - Params = xr_strdup(GetCommandLine()); -#elif defined(LINUX) - Params = xr_strdup(""); //TODO handle /proc/self/cmdline -#endif + + Params = xr_strdup (commandLine); #if defined(WINDOWS) if (!strstr(Params, "-weather")) diff --git a/src/xrCore/xrCore.h b/src/xrCore/xrCore.h index 8ce923d506f..0b3452dd1aa 100644 --- a/src/xrCore/xrCore.h +++ b/src/xrCore/xrCore.h @@ -132,7 +132,7 @@ class XRCORE_API xrCore bool PluginMode; void Initialize( - pcstr ApplicationName, LogCallback cb = nullptr, bool init_fs = true, pcstr fs_fname = nullptr, bool plugin = false); + pcstr ApplicationName, pcstr commandLine = nullptr, LogCallback cb = nullptr, bool init_fs = true, pcstr fs_fname = nullptr, bool plugin = false); void _destroy(); const char* GetBuildDate() const { return buildDate; } u32 GetBuildId() const { return buildId; } diff --git a/src/xr_3da/entry_point.cpp b/src/xr_3da/entry_point.cpp index 4cef9cca961..fec03f96a9a 100644 --- a/src/xr_3da/entry_point.cpp +++ b/src/xr_3da/entry_point.cpp @@ -40,7 +40,7 @@ int entry_point(pcstr commandLine) const u32 sz = xr_strlen(fsltx); sscanf(strstr(commandLine, fsltx) + sz, "%[^ ] ", fsgame); } - Core.Initialize("OpenXRay", nullptr, true, *fsgame ? fsgame : nullptr); + Core.Initialize("OpenXRay", commandLine, nullptr, true, *fsgame ? fsgame : nullptr); auto result = RunApplication();