16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-19 07:39:19 +02:00

refactor: extract user_config_path() helper

Consolidates platform-specific config-directory logic (APPDATA on Windows,
~/Library/Application Support on macOS, ~/.config on Linux) into a single
user_config_path(filename) function in utilities/utilities.{cpp,h}, removing
copy-pasted #ifdef blocks from application.cpp, editor/editorSettings.cpp,
input/{keyboard,gamepad,drivermouse,uart}input.cpp.
This commit is contained in:
Mateusz Włodarczyk
2026-06-30 21:30:36 +02:00
parent 7c88907f6b
commit fe603f15eb
8 changed files with 38 additions and 78 deletions

View File

@@ -6,6 +6,7 @@
#include "vehicle/Train.h"
#include "utilities/parser.h"
#include "utilities/Logs.h"
#include "utilities/utilities.h"
#include "simulation/simulationtime.h"
#include "application/application.h"
@@ -194,21 +195,9 @@ uart_input::recall_bindings() {
m_inputbindings.clear();
std::string filePath = "eu07_input-uart.ini";
#ifdef _WIN32
if (const char *appdata = std::getenv("APPDATA"))
{
fs::path appPath = fs::path(appdata) / "MaSzyna" / "eu07_input-uart.ini";
if (fs::exists(appPath))
filePath = appPath.string();
}
#else
if (const char *home = std::getenv("HOME"))
{
fs::path appPath = fs::path(home) / ".config" / "MaSzyna" / "eu07_input-uart.ini";
if (fs::exists(appPath))
filePath = appPath.string();
}
#endif
fs::path appPath = user_config_path("eu07_input-uart.ini");
if (!appPath.empty() && fs::exists(appPath))
filePath = appPath.string();
cParser bindingparser(filePath.c_str(), cParser::buffer_FILE);
if (false == bindingparser.ok())
{