mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2026-05-10 19:01:53 +00:00
Add registering of config path
This commit is contained in:
parent
edcb97422b
commit
d38e10eac4
4 changed files with 12 additions and 39 deletions
|
|
@ -5,11 +5,6 @@
|
|||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#ifdef HAVE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
typedef uint64_t gpr;
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ namespace recomp {
|
|||
IncorrectVersion,
|
||||
OtherError
|
||||
};
|
||||
void register_config_path(std::filesystem::path path);
|
||||
bool register_game(const recomp::GameEntry& entry);
|
||||
void register_patch(const char* patch, std::size_t size);
|
||||
void check_all_stored_roms();
|
||||
|
|
@ -42,7 +43,6 @@ namespace recomp {
|
|||
void do_rom_pio(uint8_t* rdram, gpr ram_address, uint32_t physical_addr);
|
||||
void start(ultramodern::WindowHandle window_handle, const recomp::rsp::callbacks_t& rsp_callbacks, const ultramodern::audio_callbacks_t& audio_callbacks, const ultramodern::input_callbacks_t& input_callbacks, const ultramodern::gfx_callbacks_t& gfx_callbacks, const ultramodern::events::callbacks_t& thread_callbacks, const ultramodern::error_handling::callbacks_t& error_handling_callbacks_);
|
||||
void start_game(const std::u8string& game_id);
|
||||
std::filesystem::path get_app_folder_path();
|
||||
std::u8string current_game_id();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ struct {
|
|||
const std::u8string save_folder = u8"saves";
|
||||
|
||||
std::filesystem::path get_save_file_path() {
|
||||
return recomp::get_app_folder_path() / save_folder / (std::u8string{recomp::current_game_id()} + u8".bin");
|
||||
return config_path / save_folder / (std::u8string{recomp::current_game_id()} + u8".bin");
|
||||
}
|
||||
|
||||
void update_save_file() {
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ std::mutex patch_data_mutex;
|
|||
std::mutex current_game_mutex;
|
||||
|
||||
// Global variables
|
||||
std::filesystem::path config_path;
|
||||
std::vector<char> patch_data;
|
||||
std::unordered_map<std::u8string, recomp::GameEntry> game_roms {};
|
||||
|
||||
|
|
@ -53,6 +54,10 @@ std::u8string recomp::GameEntry::stored_filename() const {
|
|||
return game_id + u8".z64";
|
||||
}
|
||||
|
||||
void recomp::register_config_path(std::filesystem::path path) {
|
||||
config_path = path;
|
||||
}
|
||||
|
||||
bool recomp::register_game(const recomp::GameEntry& entry) {
|
||||
std::lock_guard<std::mutex> lock(game_roms_mutex);
|
||||
game_roms.insert({ entry.game_id, entry });
|
||||
|
|
@ -98,39 +103,12 @@ bool write_file(const std::filesystem::path& path, const std::vector<uint8_t>& d
|
|||
return true;
|
||||
}
|
||||
|
||||
std::filesystem::path recomp::get_app_folder_path() {
|
||||
std::filesystem::path recomp_dir{};
|
||||
|
||||
#if defined(_WIN32)
|
||||
// Deduce local app data path.
|
||||
PWSTR known_path = NULL;
|
||||
HRESULT result = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &known_path);
|
||||
if (result == S_OK) {
|
||||
recomp_dir = std::filesystem::path{known_path} / recomp::current_game_id();
|
||||
}
|
||||
|
||||
CoTaskMemFree(known_path);
|
||||
#elif defined(__linux__)
|
||||
const char *homedir;
|
||||
|
||||
if ((homedir = getenv("HOME")) == nullptr) {
|
||||
homedir = getpwuid(getuid())->pw_dir;
|
||||
}
|
||||
|
||||
if (homedir != nullptr) {
|
||||
recomp_dir = std::filesystem::path{homedir} / (std::u8string{u8".config/"} + recomp::current_game_id());
|
||||
}
|
||||
#endif
|
||||
|
||||
return recomp_dir;
|
||||
}
|
||||
|
||||
bool check_stored_rom(const recomp::GameEntry& game_entry) {
|
||||
std::vector stored_rom_data = read_file(recomp::get_app_folder_path() / game_entry.stored_filename());
|
||||
std::vector stored_rom_data = read_file(config_path / game_entry.stored_filename());
|
||||
|
||||
if (!check_hash(stored_rom_data, game_entry.rom_hash)) {
|
||||
// Incorrect hash, remove the stored ROM file if it exists.
|
||||
std::filesystem::remove(recomp::get_app_folder_path() / game_entry.stored_filename());
|
||||
std::filesystem::remove(config_path / game_entry.stored_filename());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -158,11 +136,11 @@ bool recomp::load_stored_rom(std::u8string& game_id) {
|
|||
return false;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> stored_rom_data = read_file(recomp::get_app_folder_path() / find_it->second.stored_filename());
|
||||
std::vector<uint8_t> stored_rom_data = read_file(config_path / find_it->second.stored_filename());
|
||||
|
||||
if (!check_hash(stored_rom_data, find_it->second.rom_hash)) {
|
||||
// The ROM no longer has the right hash, delete it.
|
||||
std::filesystem::remove(recomp::get_app_folder_path() / find_it->second.stored_filename());
|
||||
std::filesystem::remove(config_path / find_it->second.stored_filename());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -273,7 +251,7 @@ recomp::RomValidationError recomp::select_rom(const std::filesystem::path& rom_p
|
|||
}
|
||||
}
|
||||
|
||||
write_file(recomp::get_app_folder_path() / game_entry.stored_filename(), rom_data);
|
||||
write_file(config_path / game_entry.stored_filename(), rom_data);
|
||||
|
||||
return recomp::RomValidationError::Good;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue