Skip to content
Open
4 changes: 2 additions & 2 deletions Descent3/Game2DLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ void GetGameAPI(game_api *api) {
api->fp[149] = (int *)ui_HideCursor;
api->fp[150] = (int *)GameFrame;
api->fp[151] = (int *)PrintDedicatedMessage;
api->fp[152] = (int *)ddio_MakePath;
api->fp[153] = (int *)ddio_SplitPath;
api->fp[152] = (int *)nullptr; // ddio_MakePath;
api->fp[153] = (int *)nullptr; // ddio_SplitPath;
api->fp[154] = (int *)D3W_Play2dSound;
api->fp[155] = (int *)D3W_TouchSound;
api->fp[156] = (int *)dDatabaseRead1;
Expand Down
2 changes: 1 addition & 1 deletion Descent3/OsirisLoadandBind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ int get_full_path_to_module(const std::filesystem::path &module_name, std::files
int exist = cfexist(modfilename);
switch (exist) {
case CFES_ON_DISK:
fullpath = std::filesystem::path(LocalScriptDir) / modfilename;
fullpath = LocalScriptDir / modfilename;
return -1;
break;
case CFES_IN_LIBRARY: {
Expand Down
6 changes: 3 additions & 3 deletions Descent3/ambient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,13 @@ extern char D3HogDir[_MAX_PATH * 2];

// Writes data from the ambient sound data file
void WriteAmbientData() {
char filename[_MAX_PATH];
std::filesystem::path filename;
CFILE *ofile;

#ifndef NEWEDITOR
ddio_MakePath(filename, (const char*)cf_GetWritableBaseDirectory().u8string().c_str(), "data", "misc", AMBIENT_FILE_NAME, NULL);
filename = cf_GetWritableBaseDirectory() / "data" / "misc" / AMBIENT_FILE_NAME;
#else
ddio_MakePath(filename, D3HogDir, "data", "misc", AMBIENT_FILE_NAME, NULL);
filename = D3HogDir / "data" / "misc" / AMBIENT_FILE_NAME;
#endif
ofile = cfopen(filename, "wb");

Expand Down
2 changes: 1 addition & 1 deletion Descent3/gamefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int GetPrevGamefile(int n) {
}
// Searches thru all gamefiles for a specific name, returns -1 if not found
// or index of gamefile with name
int FindGamefileName(char *name) {
int FindGamefileName(const char *name) {
int i;

ASSERT(name != NULL);
Expand Down
2 changes: 1 addition & 1 deletion Descent3/gamefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ int GetPrevGamefile(int n);

// Searches thru all gamefile for a specific name, returns -1 if not found
// or index of gamefile with name
int FindGamefileName(char *name);
int FindGamefileName(const char *name);

#endif
5 changes: 1 addition & 4 deletions Descent3/gamesave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,6 @@ void __cdecl LoadGameDialogCB(newuiTiledWindow *wnd, void *data)
if (id < (SAVE_HOTSPOT_ID + N_SAVE_SLOTS) && id != cb_data->cur_slot) {
// new bitmap to be displayed!
char filename[PSFILENAME_LEN + 1];
char pathname[_MAX_PATH];
char savegame_dir[_MAX_PATH];
char desc[GAMESAVE_DESCLEN + 1];
int bm_handle;

Expand All @@ -542,9 +540,8 @@ void __cdecl LoadGameDialogCB(newuiTiledWindow *wnd, void *data)

LOG_DEBUG.printf("savegame slot=%d", id - SAVE_HOTSPOT_ID);

ddio_MakePath(savegame_dir, (const char*)cf_GetWritableBaseDirectory().u8string().c_str(), "savegame", NULL);
snprintf(filename, sizeof(filename), "saveg00%d", (id - SAVE_HOTSPOT_ID));
ddio_MakePath(pathname, savegame_dir, filename, NULL);
std::filesystem::path pathname = cf_GetWritableBaseDirectory() / "savegame" / filename;

if (GetGameStateInfo(pathname, desc, &bm_handle)) {
if (bm_handle > 0) {
Expand Down
49 changes: 14 additions & 35 deletions Descent3/localization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@
* $NoKeywords: $
*/

#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <filesystem>
#include <string>

#include "cfile.h"
#include "ddio.h"
#include "descent.h"
#include "game.h"
#include "localization.h"
#include "log.h"
Expand Down Expand Up @@ -235,29 +236,12 @@ const char *GetStringFromTable(int index) {
return String_table[index];
}

void FixFilenameCase(const char *filename, char *newfile) {
char path[_MAX_PATH], file[_MAX_FNAME], ext[_MAX_EXT];
ddio_SplitPath(filename, path, file, ext);

char *p;

p = file;
while (*p) {
*p = tolower(*p);
p++;
};
p = ext;
while (*p) {
*p = tolower(*p);
p++;
};

strcat(file, ext);

if (strlen(path) > 0)
ddio_MakePath(newfile, path, file, NULL);
else
strcpy(newfile, file);
std::filesystem::path FixFilenameCase(const std::filesystem::path &filename) {
std::string local_file = filename.filename().u8string();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string local_file = filename.filename().u8string();
std::string local_file = filename.filename().string();

or use std::u8string


std::transform(local_file.begin(), local_file.end(), local_file.begin(),
[](unsigned char c){ return std::tolower(c); });
return filename.parent_path() / local_file;
}

// Given a filename, pointer to a char * array and a pointer to an int,
Expand All @@ -273,11 +257,9 @@ bool CreateStringTable(const char *filename, char ***table, int *size) {
*size = 0;
return false;
}
CFILE *file;

char fname[_MAX_PATH];
FixFilenameCase(filename, fname);
file = cfopen(fname, "rt");
std::filesystem::path fname = FixFilenameCase(filename);
CFILE *file = cfopen(fname, "rt");
if (!file) {
if (table)
*table = NULL;
Expand Down Expand Up @@ -450,8 +432,7 @@ int GetTotalStringCount(void) {

while (String_table_list[findex]) {
// open the file up
char fname[_MAX_PATH];
FixFilenameCase(String_table_list[findex], fname);
std::filesystem::path fname = FixFilenameCase(String_table_list[findex]);
file = cfopen(fname, "rt");
if (!file)
return 0;
Expand All @@ -475,10 +456,8 @@ int LoadStringFile(const char *filename, int starting_offset) {
if (!filename)
return 0;

CFILE *file;
char fname[_MAX_PATH];
FixFilenameCase(filename, fname);
file = cfopen(fname, "rt");
std::filesystem::path fname = FixFilenameCase(filename);
CFILE *file = cfopen(fname, "rt");
if (!file)
return 0;

Expand Down
32 changes: 12 additions & 20 deletions Descent3/mission_download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@
*/

#include <cstdio>
#include <future>
#include <filesystem>
#include <fstream>
#include <future>

#include "mem.h"
#include "args.h"
Expand Down Expand Up @@ -673,16 +674,6 @@ char *msn_SecondsToString(int time_sec) {
return fmttime;
}

void _get_zipfilename(char *output, char *directory, char *zipfilename) {
char *s = strrchr(zipfilename, '/');
if (s)
s++;
else
s = zipfilename;

ddio_MakePath(output, directory, s, NULL);
}

// return 0 on failure
// return 1 on success
int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::filesystem::path &mn3name) {
Expand All @@ -693,11 +684,9 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file
return 0;
}

char mission_directory[_MAX_PATH];
char output_filename[_MAX_PATH];
char buffer[256 + 32];

ddio_MakePath(mission_directory, LocalD3Dir, "missions", NULL);
std::filesystem::path mission_directory = std::filesystem::path(LocalD3Dir) / "missions";

// now go through the zip file and extract all the files out that we can
ZIP zfile;
Expand Down Expand Up @@ -740,14 +729,15 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file
console.puts(GR_GREEN, buffer);

// create the filename for this file
_get_zipfilename(output_filename, mission_directory, ze->name);
std::filesystem::path output_filename = mission_directory / ze->name;

if (cfexist(output_filename)) {
snprintf(buffer, sizeof(buffer), "%s already exists. Overwrite?", output_filename);
snprintf(buffer, sizeof(buffer), "%s already exists. Overwrite?", output_filename.u8string().c_str());
if (DoMessageBox("Confirm", buffer, MSGBOX_YESNO, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL)) {
// delete the file
LOG_DEBUG.printf("Deleting %s", zipfilename.u8string().c_str());
if (!ddio_DeleteFile(output_filename)) {
std::error_code ec;
if (!std::filesystem::remove(output_filename, ec)) {
process_file = false;
console.puts(GR_GREEN, "[Unable to Write] ");
} else {
Expand All @@ -765,7 +755,7 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file
DoUIFrame();
rend_Flip();

int ret = zfile.ExtractFile(ze, output_filename);
int ret = zfile.ExtractFile(ze, output_filename.u8string().c_str());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int ret = zfile.ExtractFile(ze, output_filename.u8string().c_str());
int ret = zfile.ExtractFile(ze, (const char*)output_filename.u8string().c_str());

if (ret < 0) {
if (ret == -9) {
LOG_WARNING << " Error writing to file";
Expand All @@ -776,7 +766,8 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file
}
console.puts(GR_GREEN, buffer);
if (cfexist(output_filename)) {
ddio_DeleteFile(output_filename);
std::error_code ec;
std::filesystem::remove(output_filename, ec);
}
} else {
// check the CRC
Expand All @@ -790,7 +781,8 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file
}
} else {
console.puts(GR_GREEN, "CRC FAIL!");
ddio_DeleteFile(output_filename);
std::error_code ec;
std::filesystem::remove(output_filename, ec);
}
}
}
Expand Down
Loading
Loading