From f732eccf6c99b6703e8b34ff2b0ff40d66854531 Mon Sep 17 00:00:00 2001 From: PJB3005 Date: Sun, 5 Apr 2026 19:03:26 +0200 Subject: [PATCH] Set Aurora config path --- include/dusk/dusk.h | 1 + include/dusk/scope.hpp | 29 ----------------------------- src/dusk/config.cpp | 28 ++++++++++------------------ src/m_Do/m_Do_main.cpp | 17 ++++++++++++++++- 4 files changed, 27 insertions(+), 48 deletions(-) delete mode 100644 include/dusk/scope.hpp diff --git a/include/dusk/dusk.h b/include/dusk/dusk.h index d84e496827..7fc2a23070 100644 --- a/include/dusk/dusk.h +++ b/include/dusk/dusk.h @@ -4,5 +4,6 @@ #include extern AuroraInfo auroraInfo; +extern const char* configPath; #endif // DUSK_DUSK_H diff --git a/include/dusk/scope.hpp b/include/dusk/scope.hpp deleted file mode 100644 index e1cfcb9a58..0000000000 --- a/include/dusk/scope.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef DUSK_SCOPE_HPP -#define DUSK_SCOPE_HPP - -namespace dusk { - -/** - * A simple value wrapper that will destroy the value at the end of its scope. - * @tparam T The type of value contained. - * @tparam Destructor The type of function used to destroy the value. - */ -template - struct ScopeValue { - T value; - Destructor destructor; - - explicit ScopeValue(T value, Destructor destructor) : value(value), destructor(destructor) { - } - - ~ScopeValue() { - destructor(value); - } - - constexpr operator T&() const noexcept { - return value; - } - }; -} - -#endif // DUSK_SCOPE_HPP diff --git a/src/dusk/config.cpp b/src/dusk/config.cpp index aeafb5ab56..159706fac8 100644 --- a/src/dusk/config.cpp +++ b/src/dusk/config.cpp @@ -1,8 +1,4 @@ #include "dusk/config.hpp" -#include "SDL3/SDL_filesystem.h" -#include "SDL3/SDL_iostream.h" -#include "dusk/appname.hpp" -#include "dusk/scope.hpp" #include "fmt/format.h" #include "nlohmann/json.hpp" #include "absl/container/flat_hash_map.h" @@ -13,6 +9,8 @@ #include #include +#include "dusk/dusk.h" + using namespace dusk::config; constexpr auto ConfigFileName = "config.json"; @@ -25,13 +23,7 @@ static absl::flat_hash_map RegisteredConfigVar static bool RegistrationDone; static std::string GetConfigJsonPath() { - dusk::ScopeValue folder(SDL_GetPrefPath(dusk::OrgName, dusk::AppName), SDL_free); - if (folder.value == nullptr) { - DuskConfigLog.error("Failed to get user preference path: %s", SDL_GetError()); - return ""; - } - - return fmt::format("{}{}", folder.value, ConfigFileName); + return fmt::format("{}{}", configPath, ConfigFileName); } ConfigVarBase::ConfigVarBase(const char* name, const ConfigImplBase* impl) : name(name), registered(false), layer(ConfigVarLayer::Default), impl(impl) { @@ -151,11 +143,11 @@ void dusk::config::FinishRegistration() { } void dusk::config::LoadFromUserPreferences() { - const auto configPath = GetConfigJsonPath(); - if (configPath.empty()) { + const auto configJsonPath = GetConfigJsonPath(); + if (configJsonPath.empty()) { return; } - LoadFromFileName(configPath.c_str()); + LoadFromFileName(configJsonPath.c_str()); } static void LoadFromPath(const char* path) { @@ -202,12 +194,12 @@ void dusk::config::LoadFromFileName(const char* path) { } void dusk::config::Save() { - const auto configPath = GetConfigJsonPath(); - if (configPath.empty()) { + const auto configJsonPath = GetConfigJsonPath(); + if (configJsonPath.empty()) { return; } - DuskConfigLog.info("Saving config to '{}'", configPath); + DuskConfigLog.info("Saving config to '{}'", configJsonPath); json j; @@ -217,7 +209,7 @@ void dusk::config::Save() { } } - io::FileStream::WriteAllText(configPath.c_str(), j.dump(4)); + io::FileStream::WriteAllText(configJsonPath.c_str(), j.dump(4)); } ConfigVarBase* dusk::config::GetConfigVar(std::string_view name) { diff --git a/src/m_Do/m_Do_main.cpp b/src/m_Do/m_Do_main.cpp index ba86f17d79..16d2644f69 100644 --- a/src/m_Do/m_Do_main.cpp +++ b/src/m_Do/m_Do_main.cpp @@ -44,6 +44,7 @@ #include #include #include "SSystem/SComponent/c_API.h" +#include "dusk/appname.hpp" #include "dusk/dusk.h" #include "dusk/logging.h" #include "dusk/time.h" @@ -56,6 +57,7 @@ #include #include +#include "SDL3/SDL_filesystem.h" #include "cxxopts.hpp" #include "dusk/config.hpp" @@ -108,6 +110,7 @@ s32 LOAD_COPYDATE(void*) { } AuroraInfo auroraInfo; +const char* configPath; void main01(void) { OS_REPORT("\x1b[m"); @@ -263,6 +266,15 @@ static void ApplyCVarOverrides(const cxxopts::OptionValue& option) { } } +static const char* CalculateConfigPath() { + const auto result = SDL_GetPrefPath(dusk::OrgName, dusk::AppName); + if (!result) { + DuskLog.fatal("Unable to get PrefPath: {}", SDL_GetError()); + } + + return result; +} + // ========================================================================= // PC ENTRY POINT // ========================================================================= @@ -299,11 +311,14 @@ int game_main(int argc, char* argv[]) { exit(1); } + configPath = CalculateConfigPath(); + dusk::config::LoadFromUserPreferences(); ApplyCVarOverrides(parsed_arg_options["cvar"]); AuroraConfig config{}; - config.appName = "Dusk"; + config.appName = dusk::AppName; + config.configPath = configPath; config.windowPosX = -1; config.windowPosY = -1; config.windowWidth = 608 * 2;