mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-08 14:59:43 +01:00
Merge pull request #244 from MaSzyna-EU07/split/1-small-fixes
Split/1 small fixes
This commit is contained in:
@@ -474,6 +474,26 @@ bool FileExists(std::string const &Filename)
|
||||
return std::filesystem::exists(Filename);
|
||||
}
|
||||
|
||||
std::string FileCased(std::filesystem::path const &Filename)
|
||||
{
|
||||
std::error_code error;
|
||||
if (std::filesystem::exists(Filename, error))
|
||||
return Filename.string();
|
||||
#ifdef _WIN32
|
||||
// the names there are found in any case already: no folder to go through for every file missing, nor names outside of the
|
||||
// code page to throw on
|
||||
return {};
|
||||
#else
|
||||
// only the name of the file itself, a folder named in another case isn't found
|
||||
auto const directory{Filename.has_parent_path() ? Filename.parent_path() : std::filesystem::path{"."}};
|
||||
auto const wanted{ToLower(Filename.filename().string())};
|
||||
for (std::filesystem::directory_iterator entry{directory, error}, end; entry != end; entry.increment(error))
|
||||
if (ToLower(entry->path().filename().string()) == wanted)
|
||||
return Filename.has_parent_path() ? (directory / entry->path().filename()).string() : entry->path().filename().string();
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
||||
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