Replace ddio_GetTempFileName() with ddio_GetTmpFileName()

Convert global variable Descent3_temp_directory to std::fs::path.
This commit is contained in:
Azamat H. Hackimov
2024-09-11 15:17:15 +03:00
parent 511743d4b3
commit 3e402d78d5
13 changed files with 145 additions and 153 deletions

View File

@@ -40,7 +40,7 @@
// input_channels (default 1)
// input_factor (compression factor) (default 4 for 22K, 8 for 44K)
// input_volscale (Volume scaling) (slightly <= 1.0, default ,97)
bool aenc_Compress(char *input_filename, char *output_filename, const int *input_levels = nullptr,
bool aenc_Compress(const char *input_filename, const char *output_filename, const int *input_levels = nullptr,
const int *input_samples = nullptr, const int *input_rate = nullptr,
const int *input_channels = nullptr, const float *input_factor = nullptr,
const float *input_volscale = nullptr);

View File

@@ -36,7 +36,7 @@ int32_t aenc_ReadSamp(void *data) {
return (b << 8) | a;
}
bool aenc_Compress(char *input_filename, char *output_filename, const int *input_levels, const int *input_samples,
bool aenc_Compress(const char *input_filename, const char *output_filename, const int *input_levels, const int *input_samples,
const int *input_rate, const int *input_channels, const float *input_factor,
const float *input_volscale) {
FILE *in, *out;

View File

@@ -645,10 +645,10 @@ void ForceEffectsInit(void) {
int lowid;
Force_time_since_last_shake = 0;
FORCEPROJECT prj;
char path[_MAX_PATH];
std::filesystem::path path;
if (cfexist("D3Force.ifr")) {
ddio_MakePath(path, Descent3_temp_directory, "D3Force.ifr", NULL);
path = Descent3_temp_directory / "D3Force.ifr";
cf_CopyFile(path, "D3Force.ifr", 0);
prj = ddio_ForceLoadProject(IGNORE_TABLE(path), kJoy1);
} else {
@@ -708,6 +708,6 @@ void ForceEffectsInit(void) {
ddio_ForceUnloadProject(prj);
if (cfexist(path)) {
ddio_DeleteFile(path);
std::filesystem::remove(path);
}
}

View File

@@ -111,7 +111,7 @@ DLLGameClose_fp DLLGameClose = NULL;
DLLGetGameInfo_fp DLLGetGameInfo = NULL;
dllinfo DLLInfo;
tOSIRISModuleInit Multi_d3m_osiris_funcs;
char Multi_game_dll_name[_MAX_PATH * 2];
std::filesystem::path Multi_game_dll_name;
static void DUMMYrend_DrawScaledBitmap(int x1, int y1, int x2, int y2, int bm, float u0, float v0, float u1, float v1,
float zval, int color, float *alphas) {
@@ -551,9 +551,9 @@ void CloseGameModule(module *mod) {
// Clear out error queue
mod_GetLastError();
mod_FreeModule(mod);
if (Multi_game_dll_name[0] != '\0') {
if (Multi_game_dll_name.empty()) {
// Try deleting the file now!
if (!ddio_DeleteFile(Multi_game_dll_name)) {
if (!std::filesystem::remove(Multi_game_dll_name)) {
LOG_WARNING << "Couldn't delete the tmp dll";
}
}
@@ -561,30 +561,26 @@ void CloseGameModule(module *mod) {
}
// this function will load up the DLL, but not get any symbols
bool InitGameModule(const char *name, module *mod) {
char lib_name[_MAX_PATH * 2];
char dll_name[_MAX_PATH * 2];
char tmp_dll_name[_MAX_PATH * 2];
std::filesystem::path lib_name;
std::filesystem::path dll_name;
std::filesystem::path tmp_dll_name;
// Make the hog filename
ddio_MakePath(lib_name, Base_directory, "netgames", name, NULL);
strcat(lib_name, ".d3m");
// Make the dll filename
#if defined(WIN32)
snprintf(dll_name, sizeof(dll_name), "%s.dll", name);
#elif defined(MACOSX)
snprintf(dll_name, sizeof(dll_name), "%s.dylib", name);
#else
snprintf(dll_name, sizeof(dll_name), "%s.so", name);
#endif
lib_name = std::filesystem::path(Base_directory) / "netgames" / name;
lib_name.replace_extension(".d3m");
// Make the dll filename
dll_name = name;
dll_name.replace_extension(MODULE_EXT);
// Open the hog file
if (!cf_OpenLibrary(lib_name)) {
ddio_MakePath(tmp_dll_name, Base_directory, "netgames", name, NULL);
strcat(tmp_dll_name, ".d3m");
Multi_game_dll_name[0] = '\0';
tmp_dll_name = std::filesystem::path(Base_directory) / "netgames" / name;
tmp_dll_name.replace_extension(".d3m");
Multi_game_dll_name.clear();
goto loaddll;
}
// get a temp file name
if (!ddio_GetTempFileName(Descent3_temp_directory, "d3m", tmp_dll_name)) {
tmp_dll_name = ddio_GetTmpFileName(Descent3_temp_directory, "d3m");
if (tmp_dll_name.empty()) {
return false;
}
// Copy the DLL
@@ -592,7 +588,7 @@ bool InitGameModule(const char *name, module *mod) {
LOG_WARNING << "DLL copy failed!";
return false;
}
strcpy(Multi_game_dll_name, tmp_dll_name);
Multi_game_dll_name = tmp_dll_name;
loaddll:
// Clear out error queue
mod_GetLastError();

View File

@@ -1,5 +1,5 @@
/*
* Descent 3
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
@@ -425,7 +425,6 @@
#define OSIRISDEBUG
#endif
bool Show_osiris_debug = false;
#define MAX_LOADED_MODULES 96 // maximum number of dlls that can be loaded at a time
@@ -772,13 +771,12 @@ void Osiris_DumpLoadedObjects(char *file) {
int Osiris_FindLoadedModule(char *module_name) {
// search through the list of loaded modules and see if we can find a match
// strip off the extension
char real_name[_MAX_PATH];
ddio_SplitPath(module_name, NULL, real_name, NULL);
std::filesystem::path real_name = std::filesystem::path(module_name).stem();
int i;
for (i = 0; i < MAX_LOADED_MODULES; i++) {
for (int i = 0; i < MAX_LOADED_MODULES; i++) {
if (OSIRIS_loaded_modules[i].flags & OSIMF_INUSE) {
if (OSIRIS_loaded_modules[i].module_name && (!stricmp(OSIRIS_loaded_modules[i].module_name, real_name))) {
if (OSIRIS_loaded_modules[i].module_name &&
(stricmp(OSIRIS_loaded_modules[i].module_name, real_name.u8string().c_str()) == 0)) {
// we found a match
return i;
}
@@ -797,8 +795,8 @@ void Osiris_UnloadModule(int module_id) {
return;
if (OSIRIS_loaded_modules[module_id].flags & OSIMF_INUSE) {
// the module is in use
LOG_DEBUG_IF(Show_osiris_debug).printf("OSIRIS: Decrementing reference count for module (%s)",
OSIRIS_loaded_modules[module_id].module_name);
LOG_DEBUG_IF(Show_osiris_debug)
.printf("OSIRIS: Decrementing reference count for module (%s)", OSIRIS_loaded_modules[module_id].module_name);
OSIRIS_loaded_modules[module_id].reference_count--;
ASSERT(OSIRIS_loaded_modules[module_id].reference_count >= 0);
@@ -815,8 +813,9 @@ void Osiris_UnloadModule(int module_id) {
OSIRIS_loaded_modules[module_id].module_name);
} else {
// time to unload this module
LOG_DEBUG_IF(Show_osiris_debug).printf("OSIRIS: Module (%s) reference count is at 0, unloading",
OSIRIS_loaded_modules[module_id].module_name);
LOG_DEBUG_IF(Show_osiris_debug)
.printf("OSIRIS: Module (%s) reference count is at 0, unloading",
OSIRIS_loaded_modules[module_id].module_name);
Osiris_FreeModule(module_id);
}
}
@@ -964,8 +963,9 @@ int Osiris_LoadLevelModule(char *module_name) {
if (loaded_id != -1) {
// the module is already loaded
OSIRIS_loaded_modules[loaded_id].reference_count++;
LOG_DEBUG_IF(Show_osiris_debug).printf("OSIRIS: Level Module (%s) reference count increased to %d",
module_name, OSIRIS_loaded_modules[loaded_id].reference_count);
LOG_DEBUG_IF(Show_osiris_debug)
.printf("OSIRIS: Level Module (%s) reference count increased to %d", module_name,
OSIRIS_loaded_modules[loaded_id].reference_count);
return loaded_id;
}
@@ -1134,7 +1134,7 @@ int Osiris_LoadLevelModule(char *module_name) {
OSIRIS_loaded_modules[loaded_id].CreateInstance(0); // level scripts always have id of 0 in a level dll
LOG_INFO.printf("OSIRIS: Level Module (%s) loaded successfully (%d custom handles)", basename,
tOSIRISCurrentLevel.num_customs);
tOSIRISCurrentLevel.num_customs);
Osiris_level_script_loaded = true;
return loaded_id;
}
@@ -1158,7 +1158,7 @@ int Osiris_LoadGameModule(char *module_name) {
OSIRIS_loaded_modules[loaded_id].reference_count++;
if (Show_osiris_debug) {
LOG_DEBUG.printf("OSIRIS: Game Module (%s) reference count increased to %d", module_name,
OSIRIS_loaded_modules[loaded_id].reference_count);
OSIRIS_loaded_modules[loaded_id].reference_count);
}
return loaded_id;
}
@@ -1653,7 +1653,7 @@ bool Osiris_BindScriptsToObject(object *obj) {
if (!gos_instance) {
// we had an error obtaining the instance of the COS...doh!
LOG_FATAL.printf("OSIRIS: Unable to create COS instance from level dll for (%s)",
(page_name) ? (page_name) : "<No Name>");
(page_name) ? (page_name) : "<No Name>");
Int3();
} else {
// ok, everything is valid
@@ -2740,9 +2740,9 @@ bool Osiris_RestoreSystemState(CFILE *file) {
// when the state was saved. This means that things are not going to be restored exactly for
// sure. We'll skip over those that are not loaded. We're int3 here because I want to know
// when this happens.
LOG_ERROR.printf(
"OSIRIS: Restoring global state, the number of loaded modules is not the same as the restored count (%d vs. %d)",
loaded_module_count, read_module_count);
LOG_ERROR.printf("OSIRIS: Restoring global state, the number of loaded modules is not the same as the restored "
"count (%d vs. %d)",
loaded_module_count, read_module_count);
if (Demo_flags != DF_PLAYBACK) {
Int3();
}
@@ -3098,7 +3098,9 @@ void Osiris_RestoreMemoryChunks(CFILE *file) {
}
}
void _extractscript(char *script, char *tempfilename) { cf_CopyFile(tempfilename, script); }
void _extractscript(const std::filesystem::path &script, const std::filesystem::path &tempfilename) {
cf_CopyFile(tempfilename, script);
}
int _getfreeextractslot(void) {
// find a free slot
@@ -3118,17 +3120,19 @@ int Osiris_ExtractScriptsFromHog(int library_handle, bool is_mission_hog) {
LOG_INFO << "OSIRIS: Extracting Scripts From Hog";
char filename[_MAX_PATH], temp_filename[_MAX_PATH];
char tempdir[_MAX_PATH], temp_file[_MAX_PATH], temp_fileext[_MAX_EXT];
char temp_realname[_MAX_PATH];
char filename[_MAX_PATH];
std::filesystem::path temp_filename;
std::filesystem::path tempdir;
std::filesystem::path temp_file;
std::filesystem::path temp_realname;
if (!OSIRIS_Extracted_script_dir) {
strcpy(tempdir, Descent3_temp_directory);
OSIRIS_Extracted_script_dir = mem_strdup(tempdir);
tempdir = Descent3_temp_directory;
OSIRIS_Extracted_script_dir = mem_strdup(Descent3_temp_directory.u8string().c_str());
if (!OSIRIS_Extracted_script_dir)
Error("Out of memory");
} else {
strcpy(tempdir, OSIRIS_Extracted_script_dir);
tempdir = OSIRIS_Extracted_script_dir;
}
int count = 0;
@@ -3141,7 +3145,7 @@ int Osiris_ExtractScriptsFromHog(int library_handle, bool is_mission_hog) {
#elif defined(WIN32)
script_extension = "*.dll";
#else
#error Unsupported platform!
#error Unsupported platform!
#endif
int index;
@@ -3154,25 +3158,26 @@ int Osiris_ExtractScriptsFromHog(int library_handle, bool is_mission_hog) {
LOG_DEBUG << "Search started";
if (cf_LibraryFindFirst(library_handle, script_extension, filename)) {
if (!ddio_GetTempFileName(tempdir, "d3s", temp_filename))
temp_filename = ddio_GetTmpFileName(tempdir, "d3s");
if (temp_filename.empty())
Int3();
else {
ddio_SplitPath(temp_filename, NULL, temp_file, temp_fileext);
strcat(temp_file, temp_fileext);
// extract it out
_extractscript(filename, temp_filename);
temp_file = temp_filename.filename();
OSIRIS_Extracted_scripts[index].flags = OESF_USED;
OSIRIS_Extracted_scripts[index].temp_filename = mem_strdup(temp_file);
OSIRIS_Extracted_scripts[index].temp_filename = mem_strdup(temp_file.u8string().c_str());
ddio_SplitPath(filename, NULL, temp_realname, NULL);
OSIRIS_Extracted_scripts[index].real_filename = mem_strdup(temp_realname);
temp_realname = std::filesystem::path(filename).stem();
OSIRIS_Extracted_scripts[index].real_filename = mem_strdup(temp_realname.u8string().c_str());
if (is_mission_hog) {
OSIRIS_Extracted_scripts[index].flags |= OESF_MISSION;
}
// extract it out
_extractscript(filename, temp_filename);
LOG_DEBUG.printf("Extracted %s as %s", filename, temp_filename);
LOG_DEBUG.printf("Extracted %s as %s", filename, temp_filename.u8string().c_str());
count++;
@@ -3185,25 +3190,25 @@ int Osiris_ExtractScriptsFromHog(int library_handle, bool is_mission_hog) {
}
// generate temp filename
if (!ddio_GetTempFileName(tempdir, "d3s", temp_filename))
temp_filename = ddio_GetTmpFileName(tempdir, "d3s");
if (temp_filename.empty())
Int3();
else {
ddio_SplitPath(temp_filename, NULL, temp_file, temp_fileext);
strcat(temp_file, temp_fileext);
// extract it out
_extractscript(filename, temp_filename);
temp_file = temp_filename.filename();
OSIRIS_Extracted_scripts[index].flags = OESF_USED;
OSIRIS_Extracted_scripts[index].temp_filename = mem_strdup(temp_file);
OSIRIS_Extracted_scripts[index].temp_filename = mem_strdup(temp_file.u8string().c_str());
ddio_SplitPath(filename, NULL, temp_realname, NULL);
OSIRIS_Extracted_scripts[index].real_filename = mem_strdup(temp_realname);
temp_realname = std::filesystem::path(filename).stem();
OSIRIS_Extracted_scripts[index].real_filename = mem_strdup(temp_realname.u8string().c_str());
if (is_mission_hog) {
OSIRIS_Extracted_scripts[index].flags |= OESF_MISSION;
}
// extract it out
_extractscript(filename, temp_filename);
LOG_DEBUG.printf("Extracted %s as %s", filename, temp_filename);
LOG_DEBUG.printf("Extracted %s as %s", filename, temp_filename.u8string().c_str());
count++;
}
@@ -3211,7 +3216,7 @@ int Osiris_ExtractScriptsFromHog(int library_handle, bool is_mission_hog) {
}
}
LOG_DEBUG << "Done Extracting";
LOG_DEBUG.printf("Extracted %d scripts", count);
ex_error:
cf_LibraryFindClose();
@@ -3229,29 +3234,27 @@ ex_error:
void Osiris_ClearExtractedScripts(bool mission_only) {
LOG_DEBUG << "OSIRIS: Removing Extracted DLLs";
char fullpath[_MAX_PATH];
if (!OSIRIS_Extracted_script_dir) {
return;
}
for (int i = 0; i < MAX_LOADED_MODULES; i++) {
if (OSIRIS_Extracted_scripts[i].flags & OESF_USED) {
if (mission_only && (!(OSIRIS_Extracted_scripts[i].flags & OESF_MISSION)))
for (auto &item : OSIRIS_Extracted_scripts) {
if (item.flags & OESF_USED) {
if (mission_only && (!(item.flags & OESF_MISSION)))
continue;
ASSERT(OSIRIS_Extracted_scripts[i].temp_filename);
ASSERT(OSIRIS_Extracted_scripts[i].real_filename);
if (!(OSIRIS_Extracted_scripts[i].temp_filename && OSIRIS_Extracted_scripts[i].real_filename))
ASSERT(item.temp_filename);
ASSERT(item.real_filename);
if (!(item.temp_filename && item.real_filename))
continue;
ddio_MakePath(fullpath, OSIRIS_Extracted_script_dir, OSIRIS_Extracted_scripts[i].temp_filename, NULL);
ddio_DeleteFile(fullpath);
std::filesystem::remove(std::filesystem::path(OSIRIS_Extracted_script_dir) / item.temp_filename);
mem_free(OSIRIS_Extracted_scripts[i].temp_filename);
mem_free(OSIRIS_Extracted_scripts[i].real_filename);
OSIRIS_Extracted_scripts[i].temp_filename = NULL;
OSIRIS_Extracted_scripts[i].real_filename = NULL;
OSIRIS_Extracted_scripts[i].flags &= ~OESF_USED;
mem_free(item.temp_filename);
mem_free(item.real_filename);
item.temp_filename = NULL;
item.real_filename = NULL;
item.flags &= ~OESF_USED;
}
}
@@ -3313,7 +3316,8 @@ OMMSHANDLE OMMS_Find(uint32_t unique_identifier,char *script_identifier);
// Returns information about the OMMS memory given its handle returned from the OMMS_Find() or
// OMMS_Malloc(). Returns 0 if the handle was invalid, 1 if the information has been filled in;
// Pass NULL in for those parameters you don't need information about.
char OMMS_GetInfo(OMMSHANDLE handle,uint32_t *mem_size,uint32_t *uid,uint16_t *reference_count,uint8_t *has_free_been_called);
char OMMS_GetInfo(OMMSHANDLE handle,uint32_t *mem_size,uint32_t *uid,uint16_t *reference_count,uint8_t
*has_free_been_called);
******************************************************************************
@@ -3537,7 +3541,7 @@ void Osiris_RestoreOMMS(CFILE *file) {
cf_ReadBytes((uint8_t *)node->memory_ptr, node->size_of_memory, file);
}
} // end reading nodes
} // end reading hash nodes
} // end reading hash nodes
}
// Searches through the hash nodes and looks for the one associated with

View File

@@ -221,10 +221,9 @@ bool taunt_ImportWave(const char *wave_filename, const char *outputfilename) {
int amount_to_flush;
tWaveFile wavdata;
int samples, rate, chan;
char temp_filename[_MAX_PATH];
char osftemp_filename[_MAX_PATH];
std::filesystem::path temp_filename;
std::filesystem::path osftemp_filename;
uint8_t *StaticFileBuffer = NULL;
*temp_filename = *osftemp_filename = '\0';
OSFArchive osf;
CFILE *fpin = NULL;
bool osfopened;
@@ -291,7 +290,8 @@ bool taunt_ImportWave(const char *wave_filename, const char *outputfilename) {
// now we need to compress it, first it must be written as raw data to a temp
// file.
if (!ddio_GetTempFileName(Descent3_temp_directory, "d3o", temp_filename)) {
temp_filename = ddio_GetTmpFileName(Descent3_temp_directory, "d3o");
if (temp_filename.empty()) {
LOG_WARNING << "TAUNT: Unable to create temp filename";
ret = false;
TauntLastError = TAUNTIMPERR_INTERNALERR;
@@ -346,14 +346,15 @@ bool taunt_ImportWave(const char *wave_filename, const char *outputfilename) {
rate = wavdata.samples_per_second;
chan = wavdata.number_channels;
if (!ddio_GetTempFileName(Descent3_temp_directory, "d3o", osftemp_filename)) {
osftemp_filename = ddio_GetTmpFileName(Descent3_temp_directory, "d3o");
if (osftemp_filename.empty()) {
LOG_WARNING << "TAUNT: Unable to create osftemp filename";
TauntLastError = TAUNTIMPERR_INTERNALERR;
ret = false;
goto error;
}
if (!aenc_Compress(temp_filename, osftemp_filename, NULL, &samples, &rate, &chan, NULL, NULL)) {
if (!aenc_Compress(temp_filename.u8string().c_str(), osftemp_filename.u8string().c_str(), NULL, &samples, &rate, &chan, NULL, NULL)) {
// unable to compress
LOG_WARNING << "Unable to compress";
ret = false;
@@ -467,11 +468,11 @@ error:
}
if (cfexist(osftemp_filename)) {
ddio_DeleteFile(osftemp_filename);
std::filesystem::remove(osftemp_filename);
}
if (cfexist(temp_filename)) {
ddio_DeleteFile(temp_filename);
std::filesystem::remove(temp_filename);
}
if (StaticFileBuffer) {

View File

@@ -427,7 +427,7 @@ bool Descent_overrided_intro = false;
bool Katmai = true;
char Descent3_temp_directory[_MAX_PATH]; // temp directory to put temp files
std::filesystem::path Descent3_temp_directory; // temp directory to put temp files
// ---------------------------------------------------------------------------
// Descent3: Choke 1
// Initializes game elements and invokes the MainLoop

View File

@@ -193,7 +193,7 @@ extern std::filesystem::path orig_pwd;
extern grScreen *Game_screen; // The Descent 3 screen.
extern oeApplication *Descent; // The Descent object
extern oeAppDatabase *Database; // The Database
extern char Descent3_temp_directory[_MAX_PATH]; // temp directory to put temp files
extern std::filesystem::path Descent3_temp_directory; // temp directory to put temp files
extern bool Katmai; // whether or not katmai is detected
// ---------------------------------------------------------------------------
// Functions

View File

@@ -1468,7 +1468,7 @@ void InitIOSystems(bool editor) {
// Init hogfiles
INIT_MESSAGE(("Checking for HOG files."));
int d3_hid = -1, extra_hid = -1, sys_hid = -1, extra13_hid = -1;
int d3_hid, extra_hid, sys_hid, extra13_hid;
char fullname[_MAX_PATH];
#ifdef DEMO
@@ -1536,14 +1536,10 @@ void InitIOSystems(bool editor) {
// extract from extra.hog first, so its DLL files are listed ahead of d3.hog's
INIT_MESSAGE(("Initializing OSIRIS."));
Osiris_InitModuleLoader();
if (extra13_hid != -1)
Osiris_ExtractScriptsFromHog(extra13_hid, false);
if (extra_hid != -1)
Osiris_ExtractScriptsFromHog(extra_hid, false);
if (merc_hid != -1)
Osiris_ExtractScriptsFromHog(merc_hid, false);
if (sys_hid != -1)
Osiris_ExtractScriptsFromHog(sys_hid, false);
Osiris_ExtractScriptsFromHog(extra13_hid, false);
Osiris_ExtractScriptsFromHog(extra_hid, false);
Osiris_ExtractScriptsFromHog(merc_hid, false);
Osiris_ExtractScriptsFromHog(sys_hid, false);
Osiris_ExtractScriptsFromHog(d3_hid, false);
}
@@ -1968,7 +1964,7 @@ void SetupTempDirectory(void) {
int t_arg = FindArg("-tempdir");
if (t_arg) {
strcpy(Descent3_temp_directory, GameArgs[t_arg + 1]);
Descent3_temp_directory = GameArgs[t_arg + 1];
} else {
std::error_code ec;
std::filesystem::path tempPath = std::filesystem::temp_directory_path(ec);
@@ -1976,29 +1972,22 @@ void SetupTempDirectory(void) {
Error("Could not find temporary directory: \"%s\"", ec.message().c_str() );
exit(1);
}
ddio_MakePath(Descent3_temp_directory, tempPath.u8string().c_str(), "Descent3",
"cache", NULL);
Descent3_temp_directory = tempPath / "Descent3" / "cache";
}
std::error_code ec;
std::filesystem::create_directories(Descent3_temp_directory, ec);
if (ec) {
Error("Could not create temporary directory: \"%s\"", Descent3_temp_directory);
Error("Could not create temporary directory: \"%s\"", Descent3_temp_directory.u8string().c_str());
exit(1);
}
// verify that temp directory exists
if (!ddio_SetWorkingDir(Descent3_temp_directory)) {
Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory);
exit(1);
}
char tempfilename[_MAX_PATH];
std::filesystem::path tempfilename = ddio_GetTmpFileName(Descent3_temp_directory, "d3t");
// verify that we can write to the temp directory
if (!ddio_GetTempFileName(Descent3_temp_directory, "d3t", tempfilename)) {
if (tempfilename.empty()) {
LOG_WARNING << "Unable to get temp file name";
Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory);
Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory.u8string().c_str());
exit(1);
}
@@ -2007,7 +1996,7 @@ void SetupTempDirectory(void) {
if (!file) {
// unable to open file for writing
LOG_WARNING << "Unable to open temp file name for writing";
Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory);
Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory.u8string().c_str());
exit(1);
}
@@ -2019,8 +2008,8 @@ void SetupTempDirectory(void) {
if (!file) {
// unable to open file for reading
LOG_WARNING << "Unable to open temp file name for reading";
ddio_DeleteFile(tempfilename);
Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory);
std::filesystem::remove(tempfilename);
Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory.u8string().c_str());
exit(1);
}
@@ -2028,22 +2017,23 @@ void SetupTempDirectory(void) {
// verify failed
LOG_WARNING << "Temp file verify failed";
cfclose(file);
ddio_DeleteFile(tempfilename);
Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory);
std::filesystem::remove(tempfilename);
Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory.u8string().c_str());
exit(1);
}
cfclose(file);
// temp directory is valid!
ddio_DeleteFile(tempfilename);
std::filesystem::remove(tempfilename);
LOG_INFO << "Temp directory set to: " << Descent3_temp_directory;
// Lock the directory
if (!ddio_CreateLockFile(std::filesystem::path(Descent3_temp_directory))) {
LOG_WARNING << "Lock file NOT created in temp dir " << Descent3_temp_directory;
Error("Unable to set temporary directory to: \"%s\"\nUnable to create lock file", Descent3_temp_directory);
Error("Unable to set temporary directory to: \"%s\"\nUnable to create lock file",
Descent3_temp_directory.u8string().c_str());
exit(1);
}
// restore working dir

View File

@@ -277,6 +277,8 @@
* $NoKeywords: $
*/
#include <filesystem>
#include "chrono_timer.h"
#include "ui.h"
#include "newui.h"
@@ -370,7 +372,7 @@ char Auto_login_name[MAX_AUTO_LOGIN_STUFF_LEN];
char Auto_login_pass[MAX_AUTO_LOGIN_STUFF_LEN];
char Auto_login_addr[MAX_AUTO_LOGIN_STUFF_LEN];
char Auto_login_port[MAX_AUTO_LOGIN_STUFF_LEN];
char Multi_conn_dll_name[_MAX_PATH * 2] = "";
std::filesystem::path Multi_conn_dll_name;
char PXO_hosted_lobby_name[100] = "global";
bool Supports_score_api = false;
#ifdef USE_DIRECTPLAY
@@ -576,19 +578,20 @@ void FreeMultiDLL() {
DLLMultiClose();
mod_FreeModule(&MultiDLLHandle);
// Try deleting the file now!
if (!ddio_DeleteFile(Multi_conn_dll_name)) {
if (!std::filesystem::remove(Multi_conn_dll_name)) {
LOG_WARNING << "Couldn't delete the tmp dll";
}
DLLMultiCall = NULL;
DLLMultiInit = NULL;
DLLMultiClose = NULL;
}
// Loads the Multi dll. Returns 1 on success, else 0 on failure
int LoadMultiDLL(const char *name) {
static int first = 1;
char lib_name[_MAX_PATH * 2];
char dll_name[_MAX_PATH * 2];
char tmp_dll_name[_MAX_PATH * 2];
std::filesystem::path lib_name;
std::filesystem::path dll_name;
std::filesystem::path tmp_dll_name;
MultiFlushAllIncomingBuffers();
// Delete old dlls
@@ -605,35 +608,30 @@ int LoadMultiDLL(const char *name) {
});
// Make the hog filename
ddio_MakePath(lib_name, Base_directory, "online", name, NULL);
strcat(lib_name, ".d3c");
// Make the dll filename
#if defined(WIN32)
snprintf(dll_name, sizeof(dll_name), "%s.dll", name);
#elif defined(MACOSX)
snprintf(dll_name, sizeof(dll_name), "%s.dylib", name);
#else
snprintf(dll_name, sizeof(dll_name), "%s.so", name);
#endif
lib_name = std::filesystem::path(Base_directory) / "online" / name;
lib_name.replace_extension(".d3c");
// Make the dll filename
dll_name = name;
dll_name.replace_extension(MODULE_EXT);
// Open the hog file
if (!cf_OpenLibrary(lib_name)) {
ddio_MakePath(tmp_dll_name, Base_directory, "online", name, NULL);
strcat(tmp_dll_name, ".d3c");
Multi_conn_dll_name[0] = 0;
tmp_dll_name = std::filesystem::path(Base_directory) / "online" / name;
tmp_dll_name.replace_extension(".d3c");
Multi_conn_dll_name.clear();
goto loaddll;
}
// get a temp file name
if (!ddio_GetTempFileName(Descent3_temp_directory, "d3c", tmp_dll_name)) {
tmp_dll_name = ddio_GetTmpFileName(Descent3_temp_directory, "d3c");
if (tmp_dll_name.empty()) {
return 0;
}
// Copy the DLL
// ddio_MakePath(dll_path_name,Base_directory,"online",tmp_dll_name,NULL);
if (!cf_CopyFile(tmp_dll_name, dll_name)) {
LOG_WARNING << "DLL copy failed!";
return 0;
}
strcpy(Multi_conn_dll_name, tmp_dll_name);
Multi_conn_dll_name = tmp_dll_name;
loaddll:
if (!mod_LoadModule(&MultiDLLHandle, tmp_dll_name)) {
@@ -700,6 +698,7 @@ loaddll:
}
return 1;
}
// The chokepoint function to call the dll function
void CallMultiDLL(int eventnum) {
if (MultiDLLHandle.handle && DLLMultiCall)

View File

@@ -1965,10 +1965,10 @@ bool ImportGraphic(const char *pathname, char *newfile) {
bm_ChangeSize(bm_handle, 64, 64);
char tempfilename[_MAX_PATH];
std::filesystem::path tempfilename = ddio_GetTmpFileName(Descent3_temp_directory, "d3i");
// Create a temporary filename, so that we can temporarily save the graphic to this file
if (!ddio_GetTempFileName(Descent3_temp_directory, "d3i", tempfilename)) {
if (tempfilename.empty()) {
// there was an error trying to create a temporary filename
bm_FreeBitmap(bm_handle);
LOG_WARNING << "Error creating temp filename";
@@ -2004,7 +2004,7 @@ bool ImportGraphic(const char *pathname, char *newfile) {
// p contains the real filename
// tempfilename contains old filename
bm_handle = bm_AllocLoadFileBitmap(IGNORE_TABLE(tempfilename), 0);
bm_handle = bm_AllocLoadFileBitmap(IGNORE_TABLE(tempfilename.u8string().c_str()), 0);
if (bm_handle <= BAD_BITMAP_HANDLE) {
LOG_WARNING << "Error reloading bitmap for rename";
std::filesystem::remove(tempfilename, ec);

View File

@@ -40,6 +40,7 @@
* $NoKeywords: $
*/
#include <filesystem>
#include "pstring.h"
#include "forcefeedback.h"
@@ -286,7 +287,7 @@ bool ddio_ffjoy_SupportAutoCenter(tDevice) { return false; }
// for it. It returns a handle to that resource.
// If it returns NULL, then it couldn't load the project.
// Make sure device is aquired before calling.
FORCEPROJECT ddio_ForceLoadProject(char *filename, tDevice dev) { return NULL; }
FORCEPROJECT ddio_ForceLoadProject(std::filesystem::path &filename, tDevice dev) { return NULL; }
// Unloads a FORCEPROJECT file
void ddio_ForceUnloadProject(FORCEPROJECT prj) {}

View File

@@ -73,6 +73,7 @@
#ifndef __DDIO_FORCEFEEDBACK_H_
#define __DDIO_FORCEFEEDBACK_H_
#include <cstdint>
#include <filesystem>
#include "pstypes.h"
#include "string.h"
#define kMAX_Str 80
@@ -430,7 +431,7 @@ bool ddio_ffjoy_SupportAutoCenter(tDevice dev);
// for it. It returns a handle to that resource.
// If it returns NULL, then it couldn't load the project.
// Make sure device is aquired before calling.
FORCEPROJECT ddio_ForceLoadProject(char *filename, tDevice dev);
FORCEPROJECT ddio_ForceLoadProject(std::filesystem::path &filename, tDevice dev);
// Unloads a FORCEPROJECT file
void ddio_ForceUnloadProject(FORCEPROJECT prj);
// Given a handle to a resource, and the name of the effect to load