Skip to content

Commit

Permalink
Fix resource search. Linux now same path search.
Browse files Browse the repository at this point in the history
Fix resource search path. Linux now same path search.
  • Loading branch information
UnrealKaraulov committed Dec 17, 2023
1 parent 5c73af3 commit ba1d473
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 37 deletions.
71 changes: 35 additions & 36 deletions src/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,114 +1368,113 @@ void SimpeColorReduce(COLOR3* image, int size)
}
}

bool FindPathInAssets(Bsp* map, const std::string& path, std::string& outpath, bool tracesearch)
bool FindPathInAssets(Bsp* map, const std::string & filename, std::string& outpath, bool tracesearch)
{
int fPathId = 1;
if (fileExists(path))
if (fileExists(filename))
{
outpath = path;
outpath = filename;
return true;
}

tracesearch = tracesearch && g_settings.verboseLogs;

std::ostringstream outTrace;

if (tracesearch)
{
outTrace << "-------------START PATH TRACING-------------\n";
outTrace << "Search paths [" << fPathId++ << "] : [" << path.c_str() << "]\n";
outTrace << "Search paths [" << fPathId++ << "] : [" << filename.c_str() << "]\n";
}
if (fileExists(path))
if (fileExists(filename))
{
outpath = path;
outpath = filename;
return true;
}
if (tracesearch)
{
outTrace << "Search paths [" << fPathId++ << "] : [" << (GetCurrentDir() + path) << "]\n";
outTrace << "Search paths [" << fPathId++ << "] : [" << (GetCurrentDir() + filename) << "]\n";
}
if (fileExists(GetCurrentDir() + path))
if (fileExists(GetCurrentDir() + filename))
{
outpath = GetCurrentDir() + path;
outpath = GetCurrentDir() + filename;
return true;
}
if (tracesearch)
{
outTrace << "Search paths [" << fPathId++ << "] : [" << (g_working_dir + path) << "]\n";
outTrace << "Search paths [" << fPathId++ << "] : [" << (g_working_dir + filename) << "]\n";
}
if (fileExists(g_working_dir + path))
if (fileExists(g_working_dir + filename))
{
outpath = g_working_dir + path;
outpath = g_working_dir + filename;
return true;
}

if (tracesearch)
{
outTrace << "Search paths [" << fPathId++ << "] : [" << (g_game_dir + path) << "]\n";
outTrace << "Search paths [" << fPathId++ << "] : [" << (g_game_dir + filename) << "]\n";
}
if (fileExists(g_game_dir + path))
if (fileExists(g_game_dir + filename))
{
outpath = g_game_dir + path;
outpath = g_game_dir + filename;
return true;
}

for (auto const& dir : g_settings.resPaths)
{
if (dir.enabled)
{
#ifndef WIN32
if (tracesearch)
{
outTrace << "Search paths [" << fPathId++ << "] : [" << (dir.path + path) << "]\n";
outTrace << "Search paths [" << fPathId++ << "] : [" << (dir.path + filename) << "]\n";
}
if (fileExists(dir.path + path))
if (fileExists(dir.path + filename))
{
outpath = dir.path + path;
outpath = dir.path + filename;
return true;
}
#else
if (tracesearch && dir.path.find(':') == std::string::npos)

if (tracesearch)
{
outTrace << "Search paths [" << fPathId++ << "] : [" << (dir.path + path) << "]\n";
outTrace << "Search paths [" << fPathId++ << "] : [" << (dir.path + basename(filename)) << "]\n";
}
if (dir.path.find(':') == std::string::npos && fileExists(dir.path + path))
if (fileExists(dir.path + basename(filename)))
{
outpath = dir.path + path;
outpath = dir.path + basename(filename);
return true;
}

if (tracesearch)
{
outTrace << "Search paths [" << fPathId++ << "] : [" << (GetCurrentDir() + dir.path + path) << "]\n";
outTrace << "Search paths [" << fPathId++ << "] : [" << (GetCurrentDir() + dir.path + filename) << "]\n";
}
if (fileExists(GetCurrentDir() + dir.path + path))
if (fileExists(GetCurrentDir() + dir.path + filename))
{
outpath = GetCurrentDir() + dir.path + path;
outpath = GetCurrentDir() + dir.path + filename;
return true;
}

if (tracesearch)
{
outTrace << "Search paths [" << fPathId++ << "] : [" << (g_game_dir + dir.path + path) << "]\n";
outTrace << "Search paths [" << fPathId++ << "] : [" << (g_game_dir + dir.path + filename) << "]\n";
}
if (fileExists(g_game_dir + dir.path + path))
if (fileExists(g_game_dir + dir.path + filename))
{
outpath = g_game_dir + dir.path + path;
outpath = g_game_dir + dir.path + filename;
return true;
}

#endif
}
}

if (map)
{
if (tracesearch)
{
outTrace << "Search paths [" << fPathId++ << "] : [" << (stripFileName(stripFileName(map->bsp_path)) + "/" + path) << "]\n";
outTrace << "Search paths [" << fPathId++ << "] : [" << (stripFileName(stripFileName(map->bsp_path)) + "/" + filename) << "]\n";
}
if (fileExists((stripFileName(stripFileName(map->bsp_path)) + "/" + path)))
if (fileExists((stripFileName(stripFileName(map->bsp_path)) + "/" + filename)))
{
outpath = stripFileName(stripFileName(map->bsp_path)) + "/" + path;
outpath = stripFileName(stripFileName(map->bsp_path)) + "/" + filename;
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ int GetImageColors(COLOR3* image, int size);
int ColorDistance(COLOR3 color, COLOR3 other);
void SimpeColorReduce(COLOR3* image, int size);

bool FindPathInAssets(Bsp * map, const std::string& path, std::string& outpath, bool tracesearch = false);
bool FindPathInAssets(Bsp * map, const std::string& filename, std::string& outpath, bool tracesearch = false);
void FixupAllSystemPaths();

int BoxOnPlaneSide(const vec3& emins, const vec3& emaxs, const BSPPLANE* p);
Expand Down

0 comments on commit ba1d473

Please sign in to comment.