@@ -10,11 +10,12 @@ namespace fs = std::filesystem;
1010
1111extern " C" struct SaveBuffer gSaveBuffer ;
1212
13+ const fs::path savesPath (Ship::Context::GetPathRelativeToAppDirectory(" saves" , " sm64" ));
14+
1315static void Init () {
1416 // Create saves directory if it doesn't exist
15- fs::path dir (" saves" );
16- if (!fs::exists (dir)) {
17- fs::create_directory (dir);
17+ if (!fs::exists (savesPath)) {
18+ fs::create_directory (savesPath);
1819 }
1920}
2021
@@ -33,7 +34,7 @@ void RestoreSaveFileData(int32_t fileIndex, int32_t srcSlot) {
3334}
3435
3536void SaveFileDoSave (int32_t fileIndex) {
36- std::ofstream file (fs::path ( " saves/ save_" + std::to_string (fileIndex) + " .json" ), std::ios::out);
37+ std::ofstream file (savesPath / ( " save_" + std::to_string (fileIndex) + " .json" ), std::ios::out);
3738 if (!file.is_open ()) {
3839 return ;
3940 }
@@ -44,24 +45,23 @@ void SaveFileDoSave(int32_t fileIndex) {
4445}
4546
4647bool ShouldLoadOldSaveFile (void ) {
47- fs::path save (" default.sav" );
48- return fs::exists (save);
48+ return fs::exists (Ship::Context::GetPathRelativeToAppDirectory (" default.sav" ));
4949}
5050
5151void SaveFileLoadAll (void ) {
52- fs::path save (" default.sav" );
53- if (fs::exists (save )) {
52+ auto oldSave = Ship::Context::GetPathRelativeToAppDirectory (" default.sav" );
53+ if (fs::exists (oldSave )) {
5454 for (int32_t fileIndex = 0 ; fileIndex < NUM_SAVE_FILES ; fileIndex++) {
5555 SaveFileDoSave (fileIndex);
5656 }
5757 // Move old save files to backup
58- fs::rename (save, " default.sav.bak" );
58+ fs::rename (oldSave, Ship::Context::GetPathRelativeToAppDirectory ( " default.sav.bak" ) );
5959 return ;
6060 }
6161
6262 // Read save files
6363 for (int32_t fileIndex = 0 ; fileIndex < NUM_SAVE_FILES ; fileIndex++) {
64- fs::path filepath = fs::path ( " saves/ save_" + std::to_string (fileIndex) + " .json" );
64+ fs::path filepath = savesPath / ( " save_" + std::to_string (fileIndex) + " .json" );
6565 if (!fs::exists (filepath)) {
6666 continue ;
6767 }
@@ -84,7 +84,7 @@ void SaveFileLoadAll(void) {
8484 }
8585
8686 // Read global save file
87- fs::path globalpath = fs::path ( " saves/ global.json" ) ;
87+ fs::path globalpath = savesPath / " global.json" ;
8888 if (fs::exists (globalpath)) {
8989 std::ifstream file (globalpath, std::ios::in);
9090 if (file.is_open ()) {
@@ -97,7 +97,7 @@ void SaveFileLoadAll(void) {
9797}
9898
9999void SaveMainMenuData (void ) {
100- std::ofstream file (fs::path ( " saves/ global.json" ) , std::ios::out);
100+ std::ofstream file (savesPath / " global.json" , std::ios::out);
101101 if (!file.is_open ()) {
102102 return ;
103103 }
0 commit comments