Skip to content

Commit

Permalink
honor the $XDG_CACHE_HOME env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
twolife committed Oct 7, 2024
1 parent 48c8775 commit 3f8764d
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Descent3/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1957,13 +1957,23 @@ void SetupTempDirectory(void) {
if (t_arg) {
Descent3_temp_directory = GameArgs[t_arg + 1];
} else {
std::error_code ec;
std::filesystem::path tempPath = std::filesystem::temp_directory_path(ec);
if (ec) {
Error("Could not find temporary directory: \"%s\"", ec.message().c_str() );
exit(1);
char *envr = SDL_getenv("XDG_CACHE_HOME");
if (envr) {
Descent3_temp_directory = std::filesystem::path(envr) / "Descent3";
} else {
envr = SDL_getenv("HOME");
if (envr) {
Descent3_temp_directory = std::filesystem::path(envr) / ".cache" / "Descent3";
} else {
std::error_code ec;
std::filesystem::path tempPath = std::filesystem::temp_directory_path(ec);
if (ec) {
Error("Could not find temporary directory: \"%s\"", ec.message().c_str() );
exit(1);
}
Descent3_temp_directory = tempPath / "Descent3" / "cache";
}
}
Descent3_temp_directory = tempPath / "Descent3" / "cache";
}

std::error_code ec;
Expand Down

0 comments on commit 3f8764d

Please sign in to comment.