Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
honor the $XDG_CACHE_HOME env variable
Browse files Browse the repository at this point in the history
twolife committed Oct 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 48c8775 commit 3de8770
Showing 3 changed files with 34 additions and 7 deletions.
8 changes: 1 addition & 7 deletions Descent3/init.cpp
Original file line number Diff line number Diff line change
@@ -1957,13 +1957,7 @@ 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);
}
Descent3_temp_directory = tempPath / "Descent3" / "cache";
Descent3_temp_directory = ddio_GetTempPath();
}

std::error_code ec;
6 changes: 6 additions & 0 deletions ddio/ddio.h
Original file line number Diff line number Diff line change
@@ -412,4 +412,10 @@ bool ddio_CreateLockFile(const std::filesystem::path &dir);
*/
bool ddio_DeleteLockFile(const std::filesystem::path &dir);

/**
* Gets path directory of executable
* @return parent path of executable or empty path on error
*/
std::filesystem::path ddio_GetTempPath();

#endif
27 changes: 27 additions & 0 deletions ddio/file.cpp
Original file line number Diff line number Diff line change
@@ -192,3 +192,30 @@ std::filesystem::path ddio_GetTmpFileName(const std::filesystem::path &basedir,
mem_free(random_name);
return result;
}

std::filesystem::path ddio_GetTempPath() {
std::filesystem::path result;

#if defined(POSIX)
char *envr = SDL_getenv("XDG_CACHE_HOME");
if (envr) {
result = std::filesystem::path(envr) / "Descent3";
} else {
envr = SDL_getenv("HOME");
if (envr) {
result = std::filesystem::path(envr) / ".cache" / "Descent3";
} else {
#endif
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);
}
result = tempPath / "Descent3" / "cache";
#if defined(POSIX)
}
}
#endif
return result;
}

0 comments on commit 3de8770

Please sign in to comment.