mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-09 03:58:55 +01:00
fix(app): a scenery file named in another case than given is found, a scenario that can't be opened goes back to the launcher
The command line gives the name of the scenery lowercased, and the sceneries made on Windows name their files and includes in any case: on a case-sensitive filesystem they weren't found. FileCased() finds the file whose name differs only in case; the parser and the scenario loader use it. A scenario that can't be opened logs the reason and goes back to the launcher instead of ending with an exception.
This commit is contained in:
@@ -471,6 +471,20 @@ bool FileExists(std::string const &Filename)
|
||||
return std::filesystem::exists(Filename);
|
||||
}
|
||||
|
||||
std::string FileCased(std::string const &Filename)
|
||||
{
|
||||
std::error_code error;
|
||||
if (std::filesystem::exists(Filename, error))
|
||||
return Filename;
|
||||
std::filesystem::path const path{Filename};
|
||||
auto const directory{path.has_parent_path() ? path.parent_path() : std::filesystem::path{"."}};
|
||||
auto const wanted{ToLower(path.filename().string())};
|
||||
for (std::filesystem::directory_iterator entry{directory, error}, end; entry != end; entry.increment(error))
|
||||
if (ToLower(entry->path().filename().string()) == wanted)
|
||||
return path.has_parent_path() ? (directory / entry->path().filename()).string() : entry->path().filename().string();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> FileExists(std::vector<std::string> const &Names, std::vector<std::string> const &Extensions)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user