mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-20 05:44:59 +01:00
fix(files): terrain files named in another case are found on Linux
The terrain directive names .txtf/.btf files in lowercase, as the parser gives every token. The name is now taken as it is on disk, from the text file first, so the binary file is made next to the text and the editor's references and layers keep one name.
This commit is contained in:
@@ -1200,6 +1200,8 @@ include_terrain_file( std::string File, std::string &Includes, scene::scratch_da
|
||||
|
||||
replace_slashes( File );
|
||||
erase_extension( File );
|
||||
// the parser gives the name in lowercase, the files may be named in another case; the binary file is made next to the text
|
||||
File = FileStemOnDisk( Global.asCurrentSceneryPath, File, { ".txtf", ".btf" } );
|
||||
if( std::find( binary.terrain_textfiles.begin(), binary.terrain_textfiles.end(), File ) != binary.terrain_textfiles.end() ) {
|
||||
WriteLog( "Terrain file: " + File + " is already in use, ignored" );
|
||||
return;
|
||||
|
||||
@@ -610,6 +610,24 @@ TEST_CASE("utilities: a file is found in folders named in another case, the way
|
||||
CHECK(std::filesystem::exists(added));
|
||||
}
|
||||
|
||||
TEST_CASE("utilities: a terrain file is found in another case, by its text or by its binary file") {
|
||||
test::scratch_folder const folder{"utilities_cased_terrain"};
|
||||
folder.write("Scenery/L204/Teren/Woda_ter.txtf", "x");
|
||||
folder.write("Scenery/Nmt/Gory_ter.btf", "x");
|
||||
auto const scenery{folder.path("Scenery/")};
|
||||
std::vector<std::string> const extensions{".txtf", ".btf"};
|
||||
|
||||
// the name as the parser gives it: the files are there under the name given back, which differs only in case
|
||||
auto const text{FileStemOnDisk(scenery, "l204/teren/woda_ter", extensions)};
|
||||
CHECK(ToLower(text) == "l204/teren/woda_ter");
|
||||
CHECK(std::filesystem::exists(scenery + text + ".txtf"));
|
||||
auto const binary{FileStemOnDisk(scenery, "nmt/gory_ter", extensions)};
|
||||
CHECK(ToLower(binary) == "nmt/gory_ter");
|
||||
CHECK(std::filesystem::exists(scenery + binary + ".btf"));
|
||||
// neither file in any case: the name stays as given
|
||||
CHECK(FileStemOnDisk(scenery, "nmt/nowhere_ter", extensions) == "nmt/nowhere_ter");
|
||||
}
|
||||
|
||||
TEST_CASE("utilities: the time a file was changed is given, zero for a file which isn't there") {
|
||||
test::scratch_folder const folder{"utilities_modified"};
|
||||
auto const name{folder.write("fresh.txt", "x")};
|
||||
|
||||
@@ -692,6 +692,19 @@ std::string FileOnDisk(std::string const &Filename)
|
||||
return cased.empty() ? Filename : cased;
|
||||
}
|
||||
|
||||
std::string FileStemOnDisk(std::string const &Folder, std::string const &Name, std::vector<std::string> const &Extensions)
|
||||
{
|
||||
for (auto const &extension : Extensions)
|
||||
{
|
||||
auto const cased{FileCased(Folder + Name + extension)};
|
||||
if (cased.size() > Folder.size() + extension.size() && cased.starts_with(Folder) && cased.ends_with(extension))
|
||||
{
|
||||
return cased.substr(Folder.size(), cased.size() - Folder.size() - extension.size());
|
||||
}
|
||||
}
|
||||
return Name;
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> FileExists(std::vector<std::string> const &Names, std::vector<std::string> const &Extensions)
|
||||
{
|
||||
|
||||
|
||||
@@ -227,6 +227,9 @@ bool FileExists(std::string const &Filename);
|
||||
std::string FileCased(std::filesystem::path const &Filename);
|
||||
// the file to open: as it's named on the disk, the name given when there's none
|
||||
std::string FileOnDisk(std::string const &Filename);
|
||||
// the name (relative to the folder, without extension) as it's named on the disk with the first of the extensions it has a file with,
|
||||
// found in any case; the name given when there's none
|
||||
std::string FileStemOnDisk(std::string const &Folder, std::string const &Name, std::vector<std::string> const &Extensions);
|
||||
|
||||
// the first name with one of the extensions which has a file in any case, in the order given; given back as named here, the file
|
||||
// is opened by FileOnDisk()
|
||||
|
||||
Reference in New Issue
Block a user