Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions Descent3/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1985,13 +1985,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;
Expand Down
6 changes: 6 additions & 0 deletions ddio/ddio.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,10 @@ bool ddio_CreateLockFile(const std::filesystem::path &dir);
*/
bool ddio_DeleteLockFile(const std::filesystem::path &dir);

/**
* Gets path where to write temporary/cache files.
* @return path where user can write cache files.
*/
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
Expand Up @@ -214,3 +214,30 @@ std::filesystem::path ddio_GetBasePath() {
std::filesystem::path result = std::filesystem::canonical(exe_path);
return result;
}

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

#if defined(POSIX)
const 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;
}