MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / SetupTempDirectory

Function SetupTempDirectory

Descent3/init.cpp:1976–2064  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1974}
1975
1976void SetupTempDirectory(void) {
1977 // NOTE: No string tables are available at this point
1978 //--------------------------------------------------
1979
1980 mprintf(0, "Setting up temp directory\n");
1981
1982 int t_arg = FindArg("-tempdir");
1983 if (t_arg) {
1984 strcpy(Descent3_temp_directory, GameArgs[t_arg + 1]);
1985 } else {
1986 std::error_code ec;
1987 std::filesystem::path tempPath = std::filesystem::temp_directory_path(ec);
1988 if (ec) {
1989 Error("Could not find temporary directory: \"%s\"", ec.message().c_str() );
1990 exit(1);
1991 }
1992 ddio_MakePath(Descent3_temp_directory, tempPath.u8string().c_str(), "Descent3",
1993 "cache", NULL);
1994 }
1995
1996 std::error_code ec;
1997 std::filesystem::create_directories(Descent3_temp_directory, ec);
1998 if (ec) {
1999 Error("Could not create temporary directory: \"%s\"", Descent3_temp_directory);
2000 exit(1);
2001 }
2002
2003 // verify that temp directory exists
2004 if (!ddio_SetWorkingDir(Descent3_temp_directory)) {
2005 Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory);
2006 exit(1);
2007 }
2008
2009 char tempfilename[_MAX_PATH];
2010
2011 // verify that we can write to the temp directory
2012 if (!ddio_GetTempFileName(Descent3_temp_directory, "d3t", tempfilename)) {
2013 mprintf(0, "Unable to get temp file name\n");
2014 Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory);
2015 exit(1);
2016 }
2017
2018 // try to create a file in temp directory
2019 CFILE *file = cfopen(tempfilename, "wb");
2020 if (!file) {
2021 // unable to open file for writing
2022 mprintf(0, "Unable to open temp file name for writing\n");
2023 Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory);
2024 exit(1);
2025 }
2026
2027 cf_WriteInt(file, 0x56);
2028 cfclose(file);
2029
2030 // now open up the file and make sure it is correct
2031 file = cfopen(tempfilename, "rb");
2032 if (!file) {
2033 // unable to open file for reading

Callers 1

InitIOSystemsFunction · 0.85

Calls 11

ErrorFunction · 0.85
cfopenFunction · 0.85
cf_WriteIntFunction · 0.85
cfcloseFunction · 0.85
cf_ReadIntFunction · 0.85
ddio_CreateLockFileFunction · 0.85
FindArgFunction · 0.70
ddio_MakePathFunction · 0.50
ddio_SetWorkingDirFunction · 0.50
ddio_GetTempFileNameFunction · 0.50
ddio_DeleteFileFunction · 0.50

Tested by

no test coverage detected