diff --git a/application/application.cpp b/application/application.cpp index fa74c3d7d..69387e13e 100644 --- a/application/application.cpp +++ b/application/application.cpp @@ -922,6 +922,9 @@ void eu07_application::exit() auto const step = [closing](char const *What) { WriteLog(std::format("Closing: {} at {} ms", What, std::chrono::duration_cast(std::chrono::steady_clock::now() - closing).count())); }; + // the files found in another case, counted over the whole run: the vehicles, sounds and textures loaded after the scenery + // count as well as those loaded with it + LogFilesInAnotherCase(); step("the sleepers laid in the background"); // the sleepers laid in the background read the scenery, which goes below track_sleepers::stop_background(); diff --git a/tests/unit/test_utilities.cpp b/tests/unit/test_utilities.cpp index 13924cf25..0986519e8 100644 --- a/tests/unit/test_utilities.cpp +++ b/tests/unit/test_utilities.cpp @@ -31,6 +31,16 @@ struct debug_mode { ~debug_mode() { DebugModeFlag = before; } }; +// puts logs.filecase back as it was +struct file_case_log { + bool const before{Global.FileCaseLog}; + + explicit file_case_log(bool const Enabled) { Global.FileCaseLog = Enabled; } + file_case_log(file_case_log const &) = delete; + file_case_log &operator=(file_case_log const &) = delete; + ~file_case_log() { Global.FileCaseLog = before; } +}; + // the polish letters in windows-1250, as in test_win1250.cpp std::string const kWin1250{"\xA5\xC6\xCA\xA3\xD1\xD3\x8C\x8F\xAF\xB9\xE6\xEA\xB3\xF1\xF3\x9C\x9F\xBF"}; @@ -749,9 +759,10 @@ TEST_CASE("utilities: a file is written over in another case, or made in its fol CHECK(FileOnDiskToWrite("eu07_unit_test_no_such_file.xyz") == "eu07_unit_test_no_such_file.xyz"); } -TEST_CASE("utilities: a file found only in another case is logged once, the folders of a file to write are not") { +TEST_CASE("utilities: a file found only in another case is logged once with logs.filecase, the folders of a file to write are not") { test::scratch_folder const folder{"utilities_cased_log"}; folder.write("Scenery/Braniewo/Base.scm", "x"); + file_case_log const opted{true}; test::log_capture const log; // asked for again, and to be written over @@ -774,6 +785,40 @@ TEST_CASE("utilities: a file found only in another case is logged once, the fold #endif } +TEST_CASE("utilities: the files found only in another case are counted, and without logs.filecase only the count is logged") { + test::scratch_folder const folder{"utilities_cased_count"}; + folder.write("Scenery/Kozki/Base.scm", "x"); + folder.write("Textures/Kozki/Tor.dds", "x"); + file_case_log const opted{false}; + test::log_capture const log; + [[maybe_unused]] auto const before{FilesInAnotherCase()}; + + // two files in another case, one asked for twice, one asked for in its own case, one which isn't there in any case + CHECK_FALSE(FileCased(folder.path("scenery/kozki/base.scm")).empty()); + CHECK_FALSE(FileCased(folder.path("scenery/kozki/base.scm")).empty()); + CHECK_FALSE(FileOnDiskToWrite(folder.path("textures/kozki/tor.dds")).empty()); + CHECK_FALSE(FileCased(folder.path("Scenery/Kozki/Base.scm")).empty()); + CHECK(FileCased(folder.path("scenery/kozki/nothing.scm")).empty()); + // not one of them on its own + CHECK(log.lines().empty()); + + LogFilesInAnotherCase(); + auto const lines{log.lines()}; +#ifdef _WIN32 + // nothing found in another case, nothing to count nor to log + CHECK(FilesInAnotherCase() == 0); + CHECK(lines.empty()); +#else + auto const count{FilesInAnotherCase()}; + CHECK(count == before + 2); + // the one line, with the count of the whole run so far and the way to have them listed + REQUIRE(lines.size() == 1); + CHECK(lines.front().find(": " + std::to_string(count) + " (") != std::string::npos); + CHECK(lines.front().find("logs.filecase yes") != std::string::npos); + CHECK(lines.front().find("Kozki") == std::string::npos); +#endif +} + 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")}; diff --git a/utilities/Globals.cpp b/utilities/Globals.cpp index 4ec2f1197..6f7749517 100644 --- a/utilities/Globals.cpp +++ b/utilities/Globals.cpp @@ -1550,6 +1550,12 @@ bool global_settings::ConfigParseDebug(cParser& Parser, const std::string& token return true; } + if (token == "logs.filecase") + { + ParseOne(Parser, FileCaseLog); + return true; + } + if (token == "rollfix") { ParseOne(Parser, bRollFix); @@ -2551,6 +2557,7 @@ global_settings::export_as_text( std::ostream &Output ) const { export_as_text( Output, "crashdump.full", crashdump_full ); export_as_text( Output, "showsystemconsole", ShowSystemConsole ); export_as_text( Output, "logs.filter", DisabledLogTypes ); + export_as_text( Output, "logs.filecase", FileCaseLog ); Output << "mousescale " << fMouseXScale << " " diff --git a/utilities/Globals.h b/utilities/Globals.h index 5706ee232..7ef5e1a39 100644 --- a/utilities/Globals.h +++ b/utilities/Globals.h @@ -130,6 +130,9 @@ struct global_settings { std::optional BlackBox; bool ShowSystemConsole{ false }; // toggle visibility of the OS console window with log output unsigned int DisabledLogTypes{ 0 }; + // logs.filecase: each file found on the disk only in another case than asked for (not on Windows) is written to the log; + // without it only their count is, once, at the closing + bool FileCaseLog{ false }; bool ParserLogIncludes{ true }; // simulation bool RealisticControlMode{ false }; // controls ability to steer the vehicle from outside views diff --git a/utilities/utilities.cpp b/utilities/utilities.cpp index 233b7eb26..b2d3dd445 100644 --- a/utilities/utilities.cpp +++ b/utilities/utilities.cpp @@ -741,7 +741,7 @@ struct cased_hash using is_transparent = void; std::size_t operator()(std::string_view const Text) const noexcept { return std::hash{}(Text); } }; -// the files found only in another case than asked for, written to the log once each +// the files found only in another case than asked for, counted once each by the name asked for std::unordered_set> &cased_reported() { static std::unordered_set> reported; @@ -858,7 +858,7 @@ bool cased_folder_path(std::string const &Folder, std::string &Cased) namespace { -// FileCased(), the file found only in another case written to the log when Report +// FileCased(), the file found only in another case counted, and written to the log on request, when Report std::string file_cased(std::filesystem::path const &Filename, [[maybe_unused]] bool const Report) { std::error_code error; @@ -904,19 +904,20 @@ std::string file_cased(std::filesystem::path const &Filename, [[maybe_unused]] b return {}; if (Report && (cased != asked)) { - // marked as reported once it's known to be there, and written to the log outside of the lock + // counted once it's known to be there, and written to the log outside of the lock std::unique_lock lock{cased_mutex}; auto const first{cased_reported().insert(asked).second}; lock.unlock(); - // the parser asks for the names in lowercase, so these are mostly the files not named in lowercase on the disk - if (first) + // the parser asks for the names in lowercase, so these are mostly the files not named in lowercase on the disk. as they load + // fine, each is written to the log only on request (logs.filecase); their count is, at the closing (LogFilesInAnotherCase()) + if (first && Global.FileCaseLog) WriteLog("File \"" + asked + "\" is \"" + cased + "\" on disk, in another case", logtype::file); } return cased; #endif } -// FileOnDiskToWrite(), the file found only in another case written to the log when Report; the folders never are +// FileOnDiskToWrite(), the file found only in another case counted and logged as by file_cased() when Report; the folders never are std::string on_disk_to_write(std::string const &Filename, bool const Report) { if (auto const cased{file_cased(Filename, Report)}; false == cased.empty()) @@ -946,6 +947,26 @@ std::string FileOnDiskToWrite(std::string const &Filename) return on_disk_to_write(Filename, true); } +std::size_t FilesInAnotherCase() +{ +#ifdef _WIN32 + return 0; +#else + std::scoped_lock const lock{cased_mutex}; + return cased_reported().size(); +#endif +} + +void LogFilesInAnotherCase() +{ + auto const count{FilesInAnotherCase()}; + if (count == 0) + return; + WriteLog(std::format("Files found on disk only in another case than asked for: {}{}", count, + Global.FileCaseLog ? ", each logged above" : " (\"logs.filecase yes\" in eu07.ini logs each)"), + logtype::file); +} + std::string FileStemOnDisk(std::string const &Folder, std::string const &Name, std::vector const &Extensions) { for (auto const &extension : Extensions) diff --git a/utilities/utilities.h b/utilities/utilities.h index dffcd5df9..a71063694 100644 --- a/utilities/utilities.h +++ b/utilities/utilities.h @@ -260,13 +260,17 @@ template <> bool extract_value(bool &Variable, std::string const &Key, std::stri bool FileExists(std::string const &Filename); // the file as it's named on the disk when only the case of its name or of its folders differs, as in the sceneries made on Windows; // empty when there's none. on Windows, finding the names in any case itself, the file given or none. a file found only in another -// case is written to the log, once +// case is counted, and written to the log once with logs.filecase in eu07.ini 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 file to write: as it's named on the disk when it's there in any case, otherwise a new file of the name given in the folders // as they're named on the disk, those missing in any case named as given, to be made std::string FileOnDiskToWrite(std::string const &Filename); +// how many names asked for so far were found on the disk only in another case; none on Windows +std::size_t FilesInAnotherCase(); +// one line with that count in the log, none when it's 0 +void LogFilesInAnotherCase(); // 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 const &Extensions);