17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-08 10:31:01 +01:00

refactor: the Sonar remarks on the small fixes taken care of

- the log stops through a flag kept in a function, not a global one
- the messages are put together with std::format
- a vehicle dropped on a trainset in the launcher goes in once the
  trainset is drawn, so the vehicles are gone through with a plain loop
  again; the drop split into a new vehicle and a moved one
- the scenario that can't be opened is caught as the runtime error it
  is, a file name outside of the code page as the system error it is
- a track of an unknown type is left out through the pointer owning it
- the keyword of a track type written out by a function of its own
- the picked node forgotten with ranges::replace_if, the empty
  Forget_Node of the base renderer told why it is empty
- FileCased takes the path it works on
This commit is contained in:
maj00r
2026-11-06 19:54:54 +01:00
parent 8523316006
commit a6778c9fe2
14 changed files with 140 additions and 75 deletions

View File

@@ -73,12 +73,19 @@ std::deque<std::string> ErrorStack;
// lock for log stacks
std::mutex logMutex;
// the log is written through the closing of the simulator, to the end
std::atomic<bool> logStop{false};
namespace
{
// the log is written through the closing of the simulator, to the end: set once the closing has nothing more to tell
std::atomic<bool> &log_stopped()
{
static std::atomic<bool> stopped{false};
return stopped;
}
} // namespace
void StopLogService()
{
logStop = true;
log_stopped() = true;
}
@@ -87,7 +94,7 @@ void LogService()
// one more pass after the stop, so what came just before it gets written too
for (bool last{false}; false == last;)
{
last = logStop;
last = log_stopped();
{
// --- Obsługa InfoStack ---
while (!InfoStack.empty())

View File

@@ -471,23 +471,22 @@ bool FileExists(std::string const &Filename)
return std::filesystem::exists(Filename);
}
std::string FileCased(std::string const &Filename)
std::string FileCased(std::filesystem::path const &Filename)
{
std::error_code error;
if (std::filesystem::exists(Filename, error))
return Filename;
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
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())};
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 path.has_parent_path() ? (directory / entry->path().filename()).string() : entry->path().filename().string();
return Filename.has_parent_path() ? (directory / entry->path().filename()).string() : entry->path().filename().string();
return {};
#endif
}

View File

@@ -219,7 +219,7 @@ 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 differs, as in the sceneries made on Windows; empty when
// there's none. the folders have to be named in their case; on Windows, finding the names in any case itself, the file given or none
std::string FileCased(std::string const &Filename);
std::string FileCased(std::filesystem::path const &Filename);
std::pair<std::string, std::string> FileExists(std::vector<std::string> const &Names, std::vector<std::string> const &Extensions);