Skip to content

Commit

Permalink
If the SDLPOP_SAVE_PATH environment variable is set, put all saves in…
Browse files Browse the repository at this point in the history
…to the directory it points to. (#301)
  • Loading branch information
NagyD committed Apr 15, 2023
1 parent 7c79c0b commit 808485e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ See their contents for license information.
* `mute` -- Start the game with sound off. (You can still enable sound with Ctrl+S.)
* `playdemo` -- Make the demo level playable. You may want to use it together with options which start the demo level immediately, such as `megahit 0 playdemo` or `record 0 playdemo`.

### Environment variables

* `SDLPOP_SAVE_PATH` -- If set, all save (SAV) and hall-of-fame (HOF) files will be created in the directory it points to.
* Hall-of-Fame and saved game files of mods will be placed in a subdirectory named after the mod.

### Which keys can I use?

#### Controlling the kid
Expand Down
2 changes: 2 additions & 0 deletions doc/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -739,3 +739,5 @@ DONE: Updated doc/mod.ini based on SDLPoP.ini.

FIXED: Letters above potions not showing up on the copy protection level.
Details: https://github.com/NagyD/SDLPoP/pull/299
DONE: If the SDLPOP_SAVE_PATH environment variable is set, put all saves into the directory it points to.
Details: https://github.com/NagyD/SDLPoP/issues/301
23 changes: 23 additions & 0 deletions src/seg000.c
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,29 @@ void show_splash() {
}

const char* get_writable_file_path(char* custom_path_buffer, size_t max_len, const char* file_name) {
// If the SDLPOP_SAVE_PATH environment variable is set, put all saves into the directory it points to.
const char* save_path = getenv("SDLPOP_SAVE_PATH");
if (save_path != NULL && save_path[0] != '\0') {
#if defined WIN32 || _WIN32 || WIN64 || _WIN64
mkdir (save_path);
#else
mkdir (save_path, 0700);
#endif
if (use_custom_levelset) {
// First create the directory...
snprintf_check(custom_path_buffer, max_len, "%s/%s", save_path, levelset_name);
#if defined WIN32 || _WIN32 || WIN64 || _WIN64
mkdir (custom_path_buffer);
#else
mkdir (custom_path_buffer, 0700);
#endif
snprintf_check(custom_path_buffer, max_len, "%s/%s/%s", save_path, levelset_name, file_name);
} else {
snprintf_check(custom_path_buffer, max_len, "%s/%s", save_path, file_name);
}
return custom_path_buffer;
}

if (!use_custom_levelset) {
return file_name;
}
Expand Down

0 comments on commit 808485e

Please sign in to comment.