-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
234 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
[submodule "third_party/SDL3"] | ||
path = third_party/SDL3 | ||
url = https://github.com/libsdl-org/SDL.git | ||
shallow = true | ||
shallow = true | ||
[submodule "third_party/toml11"] | ||
path = third_party/toml11 | ||
url = https://github.com/ToruNiina/toml11.git | ||
shallow = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2025 Xenon Emulator Project | ||
|
||
#include <iostream> | ||
#include <toml.hpp> | ||
|
||
#include <fstream> | ||
#include <string> | ||
|
||
#include "Config.h" | ||
#include "Path_util.h" | ||
|
||
namespace toml { | ||
template <typename TC, typename K> | ||
std::filesystem::path find_fs_path_or(const basic_value<TC>& v, const K& ky, | ||
std::filesystem::path opt) { | ||
try { | ||
auto str = find<std::string>(v, ky); | ||
if (str.empty()) { | ||
return opt; | ||
} | ||
std::u8string u8str{(char8_t*)&str.front(), (char8_t*)&str.back() + 1}; | ||
return std::filesystem::path{u8str}; | ||
} catch (...) { | ||
return opt; | ||
} | ||
} | ||
} // namespace toml | ||
|
||
namespace Config { | ||
|
||
static bool isFullscreen = false; | ||
|
||
static s32 screenWidth = 1280; | ||
static s32 screenHeight = 720; | ||
// static s32 gpuId = -1; // Vulkan physical device index. Set to negative for auto select | ||
|
||
|
||
bool getIsFullscreen() { | ||
return isFullscreen; | ||
} | ||
|
||
s32 getScreenWidth() { | ||
return screenWidth; | ||
} | ||
|
||
s32 getScreenHeight() { | ||
return screenHeight; | ||
} | ||
|
||
// s32 getGpuId() { | ||
// return gpuId; | ||
// } | ||
|
||
void load(const std::filesystem::path& path) { | ||
// If the configuration file does not exist, create it and return | ||
std::error_code error; | ||
if (!std::filesystem::exists(path, error)) { | ||
save(path); | ||
return; | ||
} | ||
|
||
toml::value data; | ||
|
||
try { | ||
data = toml::parse(path); | ||
} catch (std::exception& ex) { | ||
std::cout << "Got exception trying to load config file. Exception: " << ex.what() << std::endl; | ||
return; | ||
} | ||
if (data.contains("General")) { | ||
const toml::value& general = data.at("General"); | ||
|
||
isFullscreen = toml::find_or<bool>(general, "Fullscreen", false); | ||
} | ||
|
||
if (data.contains("GPU")) { | ||
const toml::value& gpu = data.at("GPU"); | ||
|
||
screenWidth = toml::find_or<int>(gpu, "screenWidth", screenWidth); | ||
screenHeight = toml::find_or<int>(gpu, "screenHeight", screenHeight); | ||
// gpuId = toml::find_or<int>(gpu, "gpuId", -1); | ||
} | ||
} | ||
|
||
void save(const std::filesystem::path& path) { | ||
toml::value data; | ||
|
||
std::error_code error; | ||
if (std::filesystem::exists(path, error)) { | ||
try { | ||
data = toml::parse(path); | ||
} catch (const std::exception& ex) { | ||
std::cout << "Exception trying to parse config file. Exception: " << ex.what() << std::endl; | ||
return; | ||
} | ||
} else { | ||
if (error) { | ||
std::cout << "Filesystem error: " << error.message() << std::endl; | ||
} | ||
std::cout << "Saving new configuration file " << path.string() << std::endl; | ||
} | ||
|
||
data["General"]["Fullscreen"] = isFullscreen; | ||
|
||
data["GPU"]["screenWidth"] = screenWidth; | ||
data["GPU"]["screenHeight"] = screenHeight; | ||
// data["GPU"]["gpuId"] = gpuId; | ||
|
||
std::ofstream file(path, std::ios::binary); | ||
file << data; | ||
file.close(); | ||
} | ||
|
||
} // namespace Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2025 Xenon Emulator Project | ||
|
||
#pragma once | ||
|
||
#include <filesystem> | ||
#include <vector> | ||
#include "Types.h" | ||
|
||
namespace Config { | ||
|
||
void load(const std::filesystem::path& path); | ||
void save(const std::filesystem::path& path); | ||
|
||
bool getIsFullscreen(); | ||
|
||
s32 getScreenWidth(); | ||
s32 getScreenHeight(); | ||
|
||
// s32 getGpuId(); | ||
|
||
}; // namespace Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2025 Xenon Emulator Project | ||
|
||
#include <unordered_map> | ||
#include "Path_util.h" | ||
|
||
namespace Base::FS { | ||
|
||
namespace fs = std::filesystem; | ||
|
||
static auto UserPaths = [] { | ||
|
||
auto user_dir = std::filesystem::current_path() / PORTABLE_DIR; | ||
|
||
std::unordered_map<PathType, fs::path> paths; | ||
|
||
const auto create_path = [&](PathType xenon_path, const fs::path& new_path) { | ||
std::filesystem::create_directory(new_path); | ||
paths.insert_or_assign(xenon_path, new_path); | ||
}; | ||
|
||
create_path(PathType::UserDir, user_dir); | ||
return paths; | ||
}(); | ||
|
||
std::string PathToUTF8String(const std::filesystem::path& path) { | ||
const auto u8_string = path.u8string(); | ||
return std::string{u8_string.begin(), u8_string.end()}; | ||
} | ||
|
||
const fs::path& GetUserPath(PathType xenon_path) { | ||
return UserPaths.at(xenon_path); | ||
} | ||
|
||
std::string GetUserPathString(PathType xenon_path) { | ||
return PathToUTF8String(GetUserPath(xenon_path)); | ||
} | ||
|
||
void SetUserPath(PathType xenon_path, const fs::path& new_path) { | ||
UserPaths.insert_or_assign(xenon_path, new_path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2025 Xenon Emulator Project | ||
|
||
#pragma once | ||
|
||
#include <filesystem> | ||
#include <vector> | ||
|
||
namespace Base::FS { | ||
|
||
enum class PathType { | ||
UserDir | ||
}; | ||
|
||
constexpr auto PORTABLE_DIR = "Xenon"; | ||
|
||
[[nodiscard]] std::string PathToUTF8String(const std::filesystem::path& path); | ||
|
||
[[nodiscard]] const std::filesystem::path& GetUserPath(PathType user_path); | ||
|
||
[[nodiscard]] std::string GetUserPathString(PathType user_path); | ||
|
||
void SetUserPath(PathType user_path, const std::filesystem::path& new_path); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters