Skip to content

Commit

Permalink
xrCore: fixed linux FS (open/read archives)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleivg committed Aug 19, 2018
1 parent 2152c23 commit 277dab3
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/xrCore/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 16 additions & 6 deletions src/xrCore/LocatorAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/xrCore/LocatorAPI_defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 :)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/xrCore/_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down
11 changes: 4 additions & 7 deletions src/xrCore/xrCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}

Expand Down Expand Up @@ -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)
Expand All @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion src/xrCore/xrCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion src/xr_3da/entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 277dab3

Please sign in to comment.