Skip to content

Commit

Permalink
Common: big refactor FS loading on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleivg committed Nov 6, 2018
1 parent 30d85f1 commit 6850555
Show file tree
Hide file tree
Showing 24 changed files with 67 additions and 112 deletions.
10 changes: 5 additions & 5 deletions src/Common/FSMacros.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once

#if defined(LINUX)
#define _DELIMITER '/' //for looking
#define DELIMITER "/" // for insert
#elif defined(WINDOWS)
//#if defined(LINUX)
//#define _DELIMITER '/' //for looking
//#define DELIMITER "/" // for insert
//#elif defined(WINDOWS)
#define _DELIMITER '\\' //for looking
#define DELIMITER "\\" // for insert
#endif
//#endif

// game path definition
#define _game_data_ "$game_data$"
Expand Down
68 changes: 37 additions & 31 deletions src/Common/PlatformLinux.inl
Original file line number Diff line number Diff line change
Expand Up @@ -89,47 +89,48 @@ inline void Sleep(int ms)
usleep(ms * 1000);
}

#include <libgen.h>
inline void _splitpath (
const char* path, // Path Input
char* drive, // Drive : Output
char* dir, // Directory : Output
char* fname, // Filename : Output
char* ext // Extension : Output
){
char tmp[PATH_MAX] = {0};
if(!realpath(path, tmp))
strcpy(tmp, path);
inline void _splitpath(const char* path, // Path Input
char* drive, // Drive : Output
char* dir, // Directory : Output
char* fname, // Filename : Output
char* ext // Extension : Output
)
{
const char *p, *end;

if(drive)
strcpy(drive, "");

if(dir) {
char tmp_dir[PATH_MAX] = {0};
strcpy(tmp_dir, tmp); // W/A for fname broking
strcpy(dir, dirname(tmp_dir)); // This eval modify dirname argument!!!
if (dir[0] && dir[strlen(dir) - 1] != '/')
strcat(dir, "/");
end = NULL;
for(p = path; *p; p++)
if(*p == '/' || *p == '\\')
end = p + 1;

if(end)
{
if(dir)
{
memcpy(dir, path, end - path);
dir[end - path] = 0;
}
path = end;
}
else if(dir)
dir[0] = 0;

end = strchr(path, '.');

if(!end)
end = p;

if(fname)
{
strcpy(fname, basename(tmp));
char *pos = strrchr(fname, '.');
if(pos != NULL)
*pos = 0;
memcpy(fname, path, end - path);
fname[end - path] = 0;
}

if(ext)
{
char tmp_ext[NAME_MAX] = { 0 };
strcpy(tmp_ext, basename(tmp));
char *pos = strrchr(tmp_ext, '.');
if(pos != NULL)
strcpy(ext, pos);
else
strcpy(ext, "");
}
strcpy(ext, end);
}

#include <iostream>
Expand Down Expand Up @@ -350,7 +351,12 @@ inline int _filelength(int fd)
#define _read read
#define _set_new_handler std::set_new_handler
#define _finite isfinite
#define _mkdir(dir) mkdir(dir, S_IRWXU)
inline int _mkdir(const char *dir)
{
while (char* sep = strchr((char *)dir, '\\')) *sep = '/';
return mkdir(dir, S_IRWXU);
}

#define _wtoi(arg) wcstol(arg, NULL, 10)
#define _wtoi64(arg) wcstoll(arg, NULL, 10)
#undef min
Expand Down
4 changes: 0 additions & 4 deletions src/Layers/xrRender/FBasicVisual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ void dxRender_Visual::Load(const char* N, IReader* data, u32)
string256 fnT, fnS;
data->r_stringZ(fnT, sizeof(fnT));
data->r_stringZ(fnS, sizeof(fnS));
#ifdef LINUX
while (char* sep = strchr(fnT, '\\')) *sep = '/';
while (char* sep = strchr(fnS, '\\')) *sep = '/';
#endif
shader.create(fnS, fnT);
}

Expand Down
3 changes: 0 additions & 3 deletions src/Layers/xrRender/ModelPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,6 @@ dxRender_Visual* CModelPool::Create(const char* name, IReader* data)
string_path low_name;
VERIFY(xr_strlen(name) < sizeof(low_name));
xr_strcpy(low_name, name);
#ifdef LINUX
while (char* sep = strchr(low_name, '\\')) *sep = '/';
#endif
xr_strlwr(low_name);
if (strext(low_name))
*strext(low_name) = 0;
Expand Down
5 changes: 0 additions & 5 deletions src/Layers/xrRender/ParticleEffectDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ void CPEDef::CreateShader()
{
if (*m_ShaderName && *m_TextureName)
{
#ifdef LINUX
while (char* sep = strchr(*m_ShaderName, '\\')) *sep = '/';
while (char* sep = strchr(*m_TextureName, '\\')) *sep = '/';
#endif

m_CachedShader.create(*m_ShaderName, *m_TextureName);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Layers/xrRender/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ Shader* CResourceManager::_cpp_Create(
C.bEditor = FALSE;
C.bDetail = FALSE;
#ifdef _EDITOR
<<<<<<< HEAD
if (!C.BT)
{
ELog.Msg(mtError, "Can't find shader '%s'", s_shader);
Expand Down
3 changes: 0 additions & 3 deletions src/Layers/xrRender/ResourceManager_Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ void CResourceManager::OnDeviceCreate(IReader* F)
{
CBlender_DESC desc;
chunk->r(&desc, sizeof(desc));
#ifdef LINUX
while (char* sep = strchr(desc.cName, '\\')) *sep = '/';
#endif
IBlender* B = IBlender::Create(desc.CLS);
if (nullptr == B)
{
Expand Down
3 changes: 0 additions & 3 deletions src/Layers/xrRender/SkeletonAnimated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,6 @@ void CKinematicsAnimated::Load(const char* N, IReader* data, u32 dwFlags)
for (u32 k = 0; k < set_cnt; ++k)
{
data->r_stringZ(nm, sizeof(nm));
#ifdef LINUX
while (char* sep = strchr(nm, '\\')) *sep = '/';
#endif
xr_strcat(nm, ".omf");
string_path fn;
if (!FS.exist(fn, "$level$", nm))
Expand Down
3 changes: 0 additions & 3 deletions src/Layers/xrRender/SkeletonCustom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ void CKinematics::Load(const char* N, IReader* data, u32 dwFlags)
{
string_path lod_name;
LD->r_string(lod_name, sizeof(lod_name));
#ifdef LINUX
while (char* sep = strchr(lod_name, '\\')) *sep = '/';
#endif
//. strconcat (sizeof(name_load),name_load, short_name, ":lod:", lod_name.c_str());
m_lod = (dxRender_Visual*)GEnv.Render->model_CreateChild(lod_name, nullptr);

Expand Down
3 changes: 0 additions & 3 deletions src/Layers/xrRender/uber_deffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ void uber_deffer(CBlender_Compile& C, bool hq, LPCSTR _vspec, LPCSTR _pspec, BOO
strconcat(sizeof(vs), vs, "deffer_", _vspec, lmap ? "_lmh" : "");
strconcat(sizeof(ps), ps, "deffer_", _pspec, lmap ? "_lmh" : "");
xr_strcpy(dt, sizeof(dt), _detail_replace ? _detail_replace : (C.detail_texture ? C.detail_texture : ""));
#ifdef LINUX
while (char* sep = strchr(dt, '\\')) *sep = '/';
#endif

// detect detail bump
string256 texDetailBump = {'\0'};
Expand Down
6 changes: 0 additions & 6 deletions src/Layers/xrRenderGL/glSH_Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ void CTexture::Load()

// Check for OGM
string_path fn;
#ifdef LINUX
while (char* sep = strchr(*cName, '\\')) *sep = '/';
#endif
if (FS.exist(fn, "$game_textures$", *cName, ".ogm"))
{
// AVI
Expand Down Expand Up @@ -280,9 +277,6 @@ void CTexture::Load()
{
// Load another texture
u32 mem = 0;
#ifdef LINUX
while (char* sep = strchr(buffer, '\\')) *sep = '/';
#endif
pSurface = RImplementation.texture_load(buffer, mem, desc);
if (pSurface)
{
Expand Down
3 changes: 0 additions & 3 deletions src/Layers/xrRenderPC_GL/glResourceManager_Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,6 @@ CTexture* CResourceManager::_CreateTexture(LPCSTR _Name)
R_ASSERT (_Name && _Name[0]);
string_path Name;
strcpy_s(Name, _Name); //. andy if (strext(Name)) *strext(Name)=0;
#ifdef LINUX
while (char* sep = strchr(Name, '\\')) *sep = '/';
#endif

fix_texture_name(Name);

Expand Down
3 changes: 0 additions & 3 deletions src/Layers/xrRenderPC_GL/rgl_shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ static inline void load_includes(LPCSTR pSrcData, UINT SrcDataLen, xr_vector<cha
#if defined(WINDOWS)
while (char* sep = strchr(path, '/'))
*sep = '\\';
#else
while (char* sep = strchr(path, '\\'))
*sep = '/';
#endif

// Open and read file, recursively load includes
Expand Down
6 changes: 6 additions & 0 deletions src/xrCore/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ void VerifyPath(LPCSTR path)
tmp[i] = 0;
_mkdir(tmp);
}
#ifdef LINUX
while (char* sep = strchr((char *)path, '\\')) *sep = '/';
#endif
}

#ifdef _EDITOR
Expand All @@ -111,6 +114,7 @@ static int open_internal(LPCSTR fn, int& handle)
#if defined(WINDOWS)
return (_sopen_s(&handle, fn, _O_RDONLY | _O_BINARY, _SH_DENYNO, _S_IREAD));
#elif defined(LINUX)
while (char* sep = strchr((char *)fn, '\\')) *sep = '/';
handle = open(fn, _O_RDONLY);

return (handle == -1);
Expand Down Expand Up @@ -520,6 +524,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)
while (char* sep = strchr((char *)cFileName, '\\')) *sep = '/';
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;
Expand Down Expand Up @@ -563,6 +568,7 @@ CVirtualFileReader::CVirtualFileReader(const char* cFileName)

data = (char*)MapViewOfFile(hSrcMap, FILE_MAP_READ, 0, 0, 0);
#elif defined(LINUX)
while (char* sep = strchr((char *)cFileName, '\\')) *sep = '/';
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;
Expand Down
19 changes: 14 additions & 5 deletions src/xrCore/LocatorAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,14 @@ 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);
string256 temp_file_name;
xr_strcpy(temp_file_name, sizeof temp_file_name, name);

#ifdef LINUX
while (char* sep = strchr(temp_file_name, '/')) *sep = '\\'; // For backward compability of FS, for real filesystem delimiter set to back
#endif
//Msg("Register[%d] [%s]",vfs,temp_file_name);

// Register file
file desc;
// desc.name = xr_strlwr(xr_strdup(name));
Expand Down Expand Up @@ -433,9 +437,6 @@ void CLocatorAPI::LoadArchive(archive& A, pcstr entrypoint)
buffer += sizeof ptr;

strconcat(sizeof full, full, fs_entry_point, name);
#if defined(LINUX)
while (char* sep = strchr(full, '\\')) *sep = '/';
#endif
Register(full, A.vfs_idx, crc, ptr, size_real, size_compr, 0);
}
hdr->close();
Expand All @@ -458,6 +459,7 @@ void CLocatorAPI::archive::open()
if (hSrcFile)
return;

while (char* sep = strchr((char *)*path, '\\')) *sep = '/';
hSrcFile = ::open(*path, O_RDONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
R_ASSERT(hSrcFile != -1);
struct stat file_info;
Expand Down Expand Up @@ -571,7 +573,8 @@ void CLocatorAPI::ProcessOne(pcstr path, const _finddata_t& entry)
return;
if (0 == xr_strcmp(entry.name, ".."))
return;
xr_strcat(N, DELIMITER);
if(path[xr_strlen(path) - 1] != _DELIMITER || path[xr_strlen(path) - 1] != '/')
xr_strcat(N, DELIMITER);
Register(N, 0xffffffff, 0, 0, entry.size, entry.size, (u32)entry.time_write);
Recurse(N);
}
Expand Down Expand Up @@ -628,6 +631,7 @@ bool ignore_path(const char* _path)
else
return true;
#elif defined(LINUX)
while (char* sep = strchr((char *)_path, '\\')) *sep = '/';
int h = ::open(_path, O_RDONLY | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (h != -1)
{
Expand Down Expand Up @@ -657,6 +661,9 @@ bool CLocatorAPI::Recurse(pcstr path)
#elif defined(LINUX)
glob_t globbuf;

while (char* sep = strchr(scanPath, '\\'))
*sep = '/';

globbuf.gl_offs = 256;
int result = glob(scanPath, GLOB_NOSORT, NULL, &globbuf);

Expand All @@ -682,6 +689,7 @@ bool CLocatorAPI::Recurse(pcstr path)
case S_IFREG: findData.attrib = 0; break; // File
default: findData.attrib = _A_HIDDEN; break; // Skip
}
while (char* sep = strchr(findData.name, '/')) *sep = '\\';
#endif
string1024 fullPath;
bool ignore = false;
Expand Down Expand Up @@ -712,6 +720,7 @@ bool CLocatorAPI::Recurse(pcstr path)
_findclose(handle);
#elif defined(LINUX)
globfree(&globbuf);
while (char* sep = strchr((char *)path, '/')) *sep = '\\';
#endif
size_t newSize = rec_files.size();
if (newSize > oldSize)
Expand Down
5 changes: 1 addition & 4 deletions src/xrCore/LocatorAPI_defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ FS_Path::FS_Path(LPCSTR _Root, LPCSTR _Add, LPCSTR _DefExt, LPCSTR _FilterCaptio
xr_strcpy(temp, sizeof(temp), _Root);
if (_Add)
xr_strcat(temp, _Add);
#if defined(LINUX)
while (char* sep = strchr(temp, '\\')) *sep = '/';
#endif
if (temp[0] && temp[xr_strlen(temp) - 1] != _DELIMITER)
if (temp[0] && temp[xr_strlen(temp) - 1] != _DELIMITER && temp[xr_strlen(temp) - 1] != '/')
xr_strcat(temp, DELIMITER);
m_Path = xr_strdup(temp);
m_DefExt = _DefExt ? xr_strdup(_DefExt) : 0;
Expand Down
3 changes: 0 additions & 3 deletions src/xrCore/XML/XMLDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ void ParseFile(pcstr path, CMemoryWriter& W, IReader* F, XMLDocument* xml)
string256 inc_name;
if (_GetItem(str, 1, inc_name, '"'))
{
#if defined(LINUX)
while (char* sep = strchr(inc_name, '\\')) *sep = '/';
#endif
IReader* I = nullptr;
if (inc_name == strstr(inc_name, UI_PATH_DEFAULT_WITH_DELIMITER))
{
Expand Down
5 changes: 4 additions & 1 deletion src/xrCore/file_stream_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ void CFileStreamReader::construct(LPCSTR file_name, const u32& window_size)

inherited::construct(file_mapping_handle, 0, file_size, file_size, window_size);
#elif defined(LINUX)
m_file_handle = ::open(file_name, O_RDONLY);
char path[PATH_MAX] = { 0 };
strcpy(path, file_name);
while (char* sep = strchr(path, '\\')) *sep = '/';
m_file_handle = ::open(path, O_RDONLY);
VERIFY(m_file_handle != -1);
struct stat file_info;
::fstat(m_file_handle, &file_info);
Expand Down
8 changes: 0 additions & 8 deletions src/xrCore/xr_ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,6 @@ CInifile::CInifile(pcstr fileName, bool readOnly, bool loadAtStart, bool saveAtE
if (fileName && strstr(fileName, "system"))
Msg("-----loading %s", fileName);

#ifdef LINUX
if (fileName)
while (char* sep = strchr((char *)fileName, '\\')) *sep = '/';
#endif

m_file_name[0] = 0;
m_flags.zero();
if (fileName)
Expand Down Expand Up @@ -455,9 +450,6 @@ void CInifile::Load(IReader* F, pcstr path, allow_include_func_t allow_include_f
R_ASSERT(path && path[0]);
if (_GetItem(str, 1, inc_name, '"'))
{
#ifdef LINUX
while (char* sep = strchr(inc_name, '\\')) *sep = '/';
#endif
xr_strlwr(inc_name); // compensate removed xr_strlwr on path

string_path fn;
Expand Down
Loading

0 comments on commit 6850555

Please sign in to comment.