1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Now load / save scenario scores to user folder, fallback to install directory for loading.

This commit is contained in:
IntelOrca
2015-02-05 22:51:03 +00:00
parent cbe2bda2af
commit 71202b7c10

View File

@@ -19,6 +19,7 @@
*****************************************************************************/
#include "addresses.h"
#include "platform/osinterface.h"
#include "platform/platform.h"
#include "scenario.h"
@@ -143,14 +144,24 @@ static void scenario_list_sort()
}
/**
* Basic scenario information compare function for sorting.
* rct2: 0x00677C08
*/
* Basic scenario information compare function for sorting.
* rct2: 0x00677C08
*/
static int scenario_list_sort_compare(const void *a, const void *b)
{
return strcmp(((rct_scenario_basic*)a)->name, ((rct_scenario_basic*)b)->name);
}
/**
* Gets the path for the scenario scores path.
*/
static void scenario_scores_get_path(char *outPath)
{
char *homePath = osinterface_get_orct2_homefolder();
sprintf(outPath, "%s%c%s", homePath, osinterface_get_path_separator(), "scores.dat");
free(homePath);
}
/**
*
* rct2: 0x006775A8
@@ -158,6 +169,9 @@ static int scenario_list_sort_compare(const void *a, const void *b)
static int scenario_scores_load()
{
FILE *file;
char scoresPath[MAX_PATH];
scenario_scores_get_path(scoresPath);
// Free scenario list if already allocated
if (gScenarioList != NULL) {
@@ -166,10 +180,15 @@ static int scenario_scores_load()
}
// Try and load the scores file
file = fopen(get_file_path(PATH_ID_SCORES), "rb");
// First check user folder and then fallback to install directory
file = fopen(scoresPath, "rb");
if (file == NULL) {
RCT2_ERROR("Unable to load scenario scores.");
return 0;
file = fopen(get_file_path(PATH_ID_SCORES), "rb");
if (file == NULL) {
RCT2_ERROR("Unable to load scenario scores.");
return 0;
}
}
// Load header
@@ -206,8 +225,11 @@ static int scenario_scores_load()
int scenario_scores_save()
{
FILE *file;
file = fopen(get_file_path(PATH_ID_SCORES), "wb");
char scoresPath[MAX_PATH];
scenario_scores_get_path(scoresPath);
file = fopen(scoresPath, "wb");
if (file == NULL) {
RCT2_ERROR("Unable to save scenario scores.");
return 0;