Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
[linux] ScanResourcePaths now checks current path and executable path
Browse files Browse the repository at this point in the history
  • Loading branch information
q4a committed Jun 9, 2022
1 parent 6812860 commit a940cfd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/libs/core/include/file_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class FILE_SERVICE : public VFILE_SERVICE
void FlushIniFiles();

// Resource paths
void AddEntryToResourcePaths(const std::filesystem::directory_entry &entry, std::string &CheckingPath);
void ScanResourcePaths() override;
std::string ConvertPathResource(const char *path) override;
};
40 changes: 24 additions & 16 deletions src/libs/core/src/file_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,21 @@ std::string convert_path(const char *path)
return conv;
}

void FILE_SERVICE::AddEntryToResourcePaths(const std::filesystem::directory_entry &entry, std::string &CheckingPath)
{
if (entry.is_regular_file() || entry.is_directory())
{
std::string path = get_dir_iterator_path(entry.path());
std::string path_lwr = convert_path(path.c_str());
tolwr(path_lwr.data());
if (starts_with(path_lwr, CheckingPath + "program") || starts_with(path_lwr, CheckingPath + "resource") ||
starts_with(path_lwr, CheckingPath + "save") || ends_with(path_lwr, ".ini"))
{
ResourcePaths[path_lwr] = path;
}
}
}

void FILE_SERVICE::ScanResourcePaths()
{
#ifndef _WIN32
Expand All @@ -442,24 +457,17 @@ void FILE_SERVICE::ScanResourcePaths()
ResourcePaths = std::unordered_map<std::string, std::string>();
}
ResourcePaths.clear();
std::string ExePath = "";
for (const auto &entry : std::filesystem::recursive_directory_iterator("."))
{
if (entry.is_regular_file() || entry.is_directory())
{
std::string path = get_dir_iterator_path(entry.path());
std::string path_lwr = convert_path(path.c_str());
tolwr(path_lwr.data());
if (starts_with(path_lwr, "program") || starts_with(path_lwr, "resource") ||
starts_with(path_lwr, "save") || ends_with(path_lwr, ".ini"))
{
ResourcePaths[path_lwr] = path;
if (entry.is_directory())
{
terminate_with_char(path_lwr, PATH_SEP);
ResourcePaths[path_lwr] = path;
}
}
}
AddEntryToResourcePaths(entry, ExePath);
}
ExePath = fio->_GetExecutableDirectory();
auto it = std::filesystem::recursive_directory_iterator(ExePath);
tolwr(ExePath.data());
for (const auto &entry : it)
{
AddEntryToResourcePaths(entry, ExePath);
}
#endif
ResourcePathsFirstScan = false;
Expand Down

0 comments on commit a940cfd

Please sign in to comment.