Set Aurora config path

This commit is contained in:
PJB3005
2026-04-05 19:03:26 +02:00
parent 98b5166413
commit f732eccf6c
4 changed files with 27 additions and 48 deletions
+1
View File
@@ -4,5 +4,6 @@
#include <aurora/aurora.h>
extern AuroraInfo auroraInfo;
extern const char* configPath;
#endif // DUSK_DUSK_H
-29
View File
@@ -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 <typename T, typename Destructor>
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
+10 -18
View File
@@ -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 <limits>
#include <string>
#include "dusk/dusk.h"
using namespace dusk::config;
constexpr auto ConfigFileName = "config.json";
@@ -25,13 +23,7 @@ static absl::flat_hash_map<std::string_view, ConfigVarBase*> 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) {
+16 -1
View File
@@ -44,6 +44,7 @@
#include <chrono>
#include <thread>
#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 <aurora/dvd.h>
#include <dolphin/dvd.h>
#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;