File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1985,13 +1985,7 @@ void SetupTempDirectory(void) {
19851985 if (t_arg) {
19861986 Descent3_temp_directory = GameArgs[t_arg + 1 ];
19871987 } else {
1988- std::error_code ec;
1989- std::filesystem::path tempPath = std::filesystem::temp_directory_path (ec);
1990- if (ec) {
1991- Error (" Could not find temporary directory: \" %s\" " , ec.message ().c_str ());
1992- exit (1 );
1993- }
1994- Descent3_temp_directory = tempPath / " Descent3" / " cache" ;
1988+ Descent3_temp_directory = ddio_GetTempPath ();
19951989 }
19961990
19971991 std::error_code ec;
Original file line number Diff line number Diff line change @@ -426,4 +426,10 @@ bool ddio_CreateLockFile(const std::filesystem::path &dir);
426426 */
427427bool ddio_DeleteLockFile (const std::filesystem::path &dir);
428428
429+ /* *
430+ * Gets path where to write temporary/cache files.
431+ * @return path where user can write cache files.
432+ */
433+ std::filesystem::path ddio_GetTempPath ();
434+
429435#endif
Original file line number Diff line number Diff line change @@ -214,3 +214,30 @@ std::filesystem::path ddio_GetBasePath() {
214214 std::filesystem::path result = std::filesystem::canonical (exe_path);
215215 return result;
216216}
217+
218+ std::filesystem::path ddio_GetTempPath () {
219+ std::filesystem::path result;
220+
221+ #if defined(POSIX)
222+ const char *envr = SDL_getenv (" XDG_CACHE_HOME" );
223+ if (envr) {
224+ result = std::filesystem::path (envr) / " Descent3" ;
225+ } else {
226+ envr = SDL_getenv (" HOME" );
227+ if (envr) {
228+ result = std::filesystem::path (envr) / " .cache" / " Descent3" ;
229+ } else {
230+ #endif
231+ std::error_code ec;
232+ std::filesystem::path tempPath = std::filesystem::temp_directory_path (ec);
233+ if (ec) {
234+ Error (" Could not find temporary directory: \" %s\" " , ec.message ().c_str ());
235+ exit (1 );
236+ }
237+ result = tempPath / " Descent3" / " cache" ;
238+ #if defined(POSIX)
239+ }
240+ }
241+ #endif
242+ return result;
243+ }
You can’t perform that action at this time.
0 commit comments