mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-17 23:39:18 +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:
@@ -20,6 +20,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "rendering/renderer.h"
|
||||
#include "application/uilayer.h"
|
||||
#include "utilities/Logs.h"
|
||||
#include "utilities/utilities.h"
|
||||
|
||||
auto const EU07_CONTROLLER_MOUSESLIDERSIZE{ 0.6 };
|
||||
|
||||
@@ -181,21 +182,9 @@ drivermouse_input::recall_bindings() {
|
||||
|
||||
std::string filePath = "eu07_input-mouse.ini";
|
||||
|
||||
#ifdef _WIN32
|
||||
if (const char *appdata = std::getenv("APPDATA"))
|
||||
{
|
||||
fs::path appPath = fs::path(appdata) / "MaSzyna" / "eu07_input-mouse.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-mouse.ini";
|
||||
if (fs::exists(appPath))
|
||||
filePath = appPath.string();
|
||||
}
|
||||
#endif
|
||||
fs::path appPath = user_config_path("eu07_input-mouse.ini");
|
||||
if (!appPath.empty() && fs::exists(appPath))
|
||||
filePath = appPath.string();
|
||||
|
||||
cParser bindingparser(filePath.c_str(), cParser::buffer_FILE);
|
||||
|
||||
|
||||
@@ -156,21 +156,9 @@ bool
|
||||
gamepad_input::recall_bindings() {
|
||||
std::string filePath = "eu07_input-gamepad.ini";
|
||||
|
||||
#ifdef _WIN32
|
||||
if (const char *appdata = std::getenv("APPDATA"))
|
||||
{
|
||||
fs::path appPath = fs::path(appdata) / "MaSzyna" / "eu07_input-gamepad.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-gamepad.ini";
|
||||
if (fs::exists(appPath))
|
||||
filePath = appPath.string();
|
||||
}
|
||||
#endif
|
||||
fs::path appPath = user_config_path("eu07_input-gamepad.ini");
|
||||
if (!appPath.empty() && fs::exists(appPath))
|
||||
filePath = appPath.string();
|
||||
|
||||
// bindingparser tworzony zawsze, z wybran<61> <20>cie<69>k<EFBFBD>
|
||||
cParser bindingparser(filePath.c_str(), cParser::buffer_FILE);
|
||||
|
||||
@@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "utilities/Globals.h"
|
||||
#include "utilities/Logs.h"
|
||||
#include "utilities/parser.h"
|
||||
#include "utilities/utilities.h"
|
||||
|
||||
namespace input {
|
||||
|
||||
@@ -122,19 +123,8 @@ namespace fs = std::filesystem;
|
||||
bool
|
||||
keyboard_input::recall_bindings() {
|
||||
|
||||
fs::path iniPath;
|
||||
fs::path iniPath = user_config_path("eu07_input-keyboard.ini");
|
||||
std::string path = "";
|
||||
#ifdef _WIN32
|
||||
if (const char *appdata = std::getenv("APPDATA"))
|
||||
{
|
||||
iniPath = fs::path(appdata) / "MaSzyna" / "eu07_input-keyboard.ini";
|
||||
}
|
||||
#else
|
||||
if (const char *home = std::getenv("HOME"))
|
||||
{
|
||||
iniPath = fs::path(home) / ".config" / "MaSzyna" / "eu07_input-keyboard.ini";
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!iniPath.empty() && fs::exists(iniPath))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user