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

Merge pull request #244 from MaSzyna-EU07/split/1-small-fixes

Split/1 small fixes
This commit is contained in:
2026-11-07 11:19:45 +00:00
committed by GitHub
24 changed files with 282 additions and 66 deletions

View File

@@ -73,12 +73,28 @@ std::deque<std::string> ErrorStack;
// lock for log stacks
std::mutex logMutex;
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()
{
log_stopped() = true;
}
void LogService()
{
while (!Global.applicationQuitOrder)
// one more pass after the stop, so what came just before it gets written too
for (bool last{false}; false == last;)
{
last = log_stopped();
{
// --- Obsługa InfoStack ---
while (!InfoStack.empty())

View File

@@ -23,7 +23,9 @@ enum class logtype : unsigned int {
traction = 1 << 9,
powergrid = 1 << 10,
};
// writes the log until StopLogService(), and all of it that came before
void LogService();
void StopLogService();
void WriteLog( const char *str, logtype const Type = logtype::generic, bool isError = false );
void Error( const std::string &asMessage, bool box = false );
void Error( const char* &asMessage, bool box = false );

View File

@@ -63,6 +63,15 @@ cParser::cParser(std::string const &Stream, buffertype const Type, std::string P
// the file is read in one go, tokens are then extracted straight from the memory
std::ifstream file(Path, std::ios_base::binary);
if (file.fail())
{
// named in another case than it's on the disk
if (auto const cased{FileCased(Path)}; false == cased.empty())
{
file.clear();
file.open(cased, std::ios_base::binary);
}
}
if (file.fail())
{
mFailBit = true;
}

View File

@@ -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)
{

View File

@@ -217,6 +217,9 @@ template <typename Type_> bool extract_value(Type_ &Variable, std::string const
template <> bool extract_value(bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default);
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::filesystem::path const &Filename);
std::pair<std::string, std::string> FileExists(std::vector<std::string> const &Names, std::vector<std::string> const &Extensions);