Skip to content

Commit

Permalink
Initial pass at std::filesystem removal
Browse files Browse the repository at this point in the history
  • Loading branch information
dashodanger committed Jun 8, 2024
1 parent 0ef6e77 commit 39011fc
Show file tree
Hide file tree
Showing 38 changed files with 739 additions and 625 deletions.
10 changes: 7 additions & 3 deletions scripts/obsidian.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ gui.import("level")

gui.import("script_manager")

gui.import("/data/text/random_words_en.lua")
gui.import("/data/text/random_words_en_m.lua")
gui.import("/data/text/dialogues.lua")
gui.set_import_dir("data/text/")

gui.import("random_words_en.lua")
gui.import("random_words_en_m.lua")
gui.import("dialogues.lua")

gui.set_import_dir("")

gui.import("094/oblige_v094.lua")

Expand Down
6 changes: 2 additions & 4 deletions source_files/ajbsp/aj_bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

#define AJBSP_VERSION "1.05"

#include <filesystem>

//
// Node Build Information Structure
//
Expand Down Expand Up @@ -108,7 +106,7 @@ typedef enum
}
build_result_e;

int AJBSP_BuildNodes(std::filesystem::path filename, buildinfo_t *build_info);
int AJBSP_BuildNodes(std::string filename, buildinfo_t *build_info);

namespace ajbsp
{
Expand All @@ -118,7 +116,7 @@ void SetInfo(buildinfo_t *info);

// attempt to open a wad. on failure, the FatalError method in the
// buildinfo_t interface is called.
void OpenWad(std::filesystem::path filename);
void OpenWad(std::string filename);

// close a previously opened wad.
void CloseWad();
Expand Down
8 changes: 4 additions & 4 deletions source_files/ajbsp/ajbsp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ build_result_e BuildFile(buildinfo_t *build_info)
return BUILD_OK;
}

void VisitFile(std::filesystem::path filename, buildinfo_t *build_info)
void VisitFile(std::string filename, buildinfo_t *build_info)
{
build_info->Print(0, "\n");
build_info->Print(0, "Building %s\n", filename.u8string().c_str());
build_info->Print(0, "Building %s\n", filename.c_str());

// this will fatal error if it fails
ajbsp::OpenWad(filename);
Expand Down Expand Up @@ -329,7 +329,7 @@ void CheckTypeSizes(buildinfo_t *build_info)
}


int AJBSP_BuildNodes(std::filesystem::path filename, buildinfo_t *build_info)
int AJBSP_BuildNodes(std::string filename, buildinfo_t *build_info)
{
// need this early, especially for fatal errors in utility/wad code
ajbsp::SetInfo(build_info);
Expand All @@ -347,7 +347,7 @@ int AJBSP_BuildNodes(std::filesystem::path filename, buildinfo_t *build_info)

// validate file before processing it
if (! ajbsp::FileExists(filename))
build_info->FatalError("no such file: %s\n", filename.u8string().c_str());
build_info->FatalError("no such file: %s\n", filename.c_str());

VisitFile(filename, build_info);

Expand Down
8 changes: 4 additions & 4 deletions source_files/ajbsp/level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2922,18 +2922,18 @@ void SetInfo(buildinfo_t *info)
}


void OpenWad(std::filesystem::path filename)
void OpenWad(std::string filename)
{
cur_wad = Wad_file::Open(filename.string().c_str(), 'a');
cur_wad = Wad_file::Open(filename.c_str(), 'a');
if (cur_wad == NULL)
cur_info->FatalError("Cannot open file: %s\n", filename.u8string().c_str());
cur_info->FatalError("Cannot open file: %s\n", filename.c_str());

if (cur_wad->IsReadOnly())
{
delete cur_wad;
cur_wad = NULL;

cur_info->FatalError("file is read only: %s\n", filename.u8string().c_str());
cur_info->FatalError("file is read only: %s\n", filename.c_str());
}
}

Expand Down
4 changes: 2 additions & 2 deletions source_files/ajbsp/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ const char *FindBaseName(const char *filename)
// FILE MANAGEMENT
//------------------------------------------------------------------------

bool FileExists(std::filesystem::path filename)
bool FileExists(std::string filename)
{
FILE *fp = fopen(filename.string().c_str(), "rb");
FILE *fp = fopen(filename.c_str(), "rb");

if (fp)
{
Expand Down
2 changes: 1 addition & 1 deletion source_files/ajbsp/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ char *ReplaceExtension(const char *filename, const char *ext);
const char *FindBaseName(const char *filename);

// file utilities
bool FileExists(std::filesystem::path filename);
bool FileExists(std::string filename);

// memory allocation, guaranteed to not return NULL.
void *UtilCalloc(int size);
Expand Down
11 changes: 3 additions & 8 deletions source_files/gif-h/gif.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,18 +705,13 @@ typedef struct {
// The input GIFWriter is assumed to be uninitialized.
// The delay value is the time between frames in hundredths of a second - note
// that not all viewers pay much attention to this value.
bool GifBegin(GifWriter *writer, const char *filename, uint32_t width,
bool GifBegin(GifWriter *writer, FILE *filename, uint32_t width,
uint32_t height, uint32_t delay, int32_t bitDepth = 8,
bool dither = false) {
(void)bitDepth;
(void)dither; // Mute "Unused argument" warnings
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
writer->f = 0;
fopen_s(&writer->f, filename, "wb");
#else
writer->f = fopen(filename, "wb");
#endif
if (!writer->f) return false;
if (!filename) return false;
writer->f = filename;

writer->firstFrame = true;

Expand Down
22 changes: 11 additions & 11 deletions source_files/obsidian_main/dm_extra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -982,11 +982,11 @@ int wad_transfer_lump(lua_State *L) {
//
// Open an existing wad file and copy the lump into our wad.

std::filesystem::path pkg_name = luaL_checkstring(L, 1);
std::string pkg_name = luaL_checkstring(L, 1);
const char *src_lump = luaL_checkstring(L, 2);
const char *dest_lump = luaL_checkstring(L, 3);

if (pkg_name.extension() != ".wad") {
if (GetExtension(pkg_name) != ".wad") {
return luaL_error(L,
"wad_transfer_lump: file extension is not WAD: %s\n",
pkg_name.c_str());
Expand Down Expand Up @@ -1016,11 +1016,11 @@ int wad_transfer_map(lua_State *L) {
//
// Open an existing wad file and copy the map into our wad.

std::filesystem::path pkg_name = luaL_checkstring(L, 1);
std::string pkg_name = luaL_checkstring(L, 1);
const char *src_map = luaL_checkstring(L, 2);
const char *dest_map = luaL_checkstring(L, 3);

if (pkg_name.extension() != ".wad") {
if (GetExtension(pkg_name) != ".wad") {
return luaL_error(L,
"wad_transfer_map: file extension is not WAD: %s\n",
pkg_name.c_str());
Expand Down Expand Up @@ -1106,19 +1106,19 @@ int wad_merge_sections(lua_State *L) {
// and other stuff (which occur in between P_START/P_END and similar
// marker lumps).

std::filesystem::path pkg_name = std::filesystem::u8path(luaL_checkstring(L, 1));
std::string pkg_name = luaL_checkstring(L, 1);

LogPrintf("Merging WAD sections from: %s\n", pkg_name.u8string().c_str());
LogPrintf("Merging WAD sections from: %s\n", pkg_name.c_str());

if (pkg_name.extension() != ".wad") {
if (GetExtension(pkg_name) != ".wad") {
return luaL_error(L,
"wad_merge_sections: file extension is not WAD: %s\n",
pkg_name.u8string().c_str());
pkg_name.c_str());
}

if (!WAD_OpenRead(pkg_name)) {
return luaL_error(L, "wad_merge_sections: bad WAD file: %s",
pkg_name.u8string().c_str());
pkg_name.c_str());
}

DoMergeSection('P', "P_START", "PP_START", "P_END", "PP_END");
Expand Down Expand Up @@ -1164,10 +1164,10 @@ int wad_read_text_lump(lua_State *L) {
// If the lump does not exist, NIL is returned.
// If the _file_ does not exist, an error is raised.

std::filesystem::path pkg_name = luaL_checkstring(L, 1);
std::string pkg_name = luaL_checkstring(L, 1);
const char *src_lump = luaL_checkstring(L, 2);

if (pkg_name.extension() != ".wad") {
if (GetExtension(pkg_name) != ".wad") {
return luaL_error(L,
"wad_read_text_lump: file extension is not WAD: %s\n",
pkg_name.c_str());
Expand Down
61 changes: 31 additions & 30 deletions source_files/obsidian_main/g_doom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include "slump_main.h"

extern void CSG_DOOM_Write();
extern std::filesystem::path BestDirectory();
extern std::string BestDirectory();

// extern void CSG_TestRegions_Doom();

Expand Down Expand Up @@ -338,7 +338,7 @@ void Send_Prog_Nodes(int progress, int num_maps) {
#endif
}

bool BuildNodes(std::filesystem::path filename) {
bool BuildNodes(std::string filename) {
LogPrintf("\n");

if (!build_nodes) {
Expand Down Expand Up @@ -478,7 +478,7 @@ void Doom::AddSectionLump(char ch, std::string name, qLump_c *lump) {
sections[k]->push_back(lump);
}

bool Doom::StartWAD(std::filesystem::path filename) {
bool Doom::StartWAD(std::string filename) {
if (!WAD_OpenWrite(filename)) {
#ifndef CONSOLE_ONLY
DLG_ShowError(_("Unable to create wad file:\n\n%s"), strerror(errno));
Expand Down Expand Up @@ -570,7 +570,7 @@ void Doom::EndLevel(std::string level_name) {
}

// in case we need it
std::filesystem::path level_wad = std::filesystem::temp_directory_path().append(StringFormat("%s.wad", level_name.c_str()));
std::string level_wad = PathAppend(home_dir, StringFormat("%s.wad", level_name.c_str()));

if (game_object->file_per_map) {
WAD_CloseWrite();
Expand Down Expand Up @@ -611,13 +611,13 @@ void Doom::EndLevel(std::string level_name) {
WAD_CloseWrite();
Doom::BuildNodes(level_wad);
if (!ZIPF_AddFile(level_wad, "maps")) {
std::filesystem::remove(level_wad);
FileDelete(level_wad);
ZIPF_CloseWrite();
std::filesystem::remove(game_object->ZIP_Filename());
std::filesystem::remove(game_object->Filename());
Main::FatalError(_("Error writing map WAD to %s\n"), game_object->ZIP_Filename().u8string().c_str());
FileDelete(game_object->ZIP_Filename());
FileDelete(game_object->Filename());
Main::FatalError(_("Error writing map WAD to %s\n"), game_object->ZIP_Filename().c_str());
} else {
std::filesystem::remove(level_wad);
FileDelete(level_wad);
}
WAD_OpenWrite(game_object->Filename());
}
Expand Down Expand Up @@ -1173,8 +1173,8 @@ int Doom::NumThings() {
namespace Doom {
class game_interface_c : public ::game_interface_c {
private:
std::filesystem::path filename;
std::filesystem::path zip_filename;
std::string filename;
std::string zip_filename;
bool compress_output;

public:
Expand All @@ -1189,8 +1189,8 @@ class game_interface_c : public ::game_interface_c {
void BeginLevel();
void EndLevel();
void Property(std::string key, std::string value);
std::filesystem::path Filename();
std::filesystem::path ZIP_Filename();
std::string Filename();
std::string ZIP_Filename();
};
} // namespace Doom

Expand All @@ -1208,20 +1208,21 @@ bool Doom::game_interface_c::Start(const char *preset) {
ob_invoke_hook("pre_setup");

if (batch_mode) {
if (batch_output_file.is_absolute()) {
if (IsPathAbsolute(batch_output_file)) {
filename = batch_output_file;
} else {
filename = std::filesystem::current_path().append(batch_output_file.generic_u8string());
filename = PathAppend(CurrentDirectoryGet(), batch_output_file);
}
if (compress_output) {
zip_filename = filename;
zip_filename.replace_extension("pk3");
ReplaceExtension(zip_filename, ".pk3");
}
} else {
#ifndef CONSOLE_ONLY
if (compress_output) {
filename = DLG_OutputFilename("pk3",
std::filesystem::path{preset}.replace_extension("pk3").u8string().c_str());
std::string zip_preset = preset;
ReplaceExtension(zip_preset, ".pk3");
filename = DLG_OutputFilename("pk3", zip_preset.c_str());
zip_filename = filename;
} else {
filename = DLG_OutputFilename("wad", preset);
Expand All @@ -1236,12 +1237,12 @@ bool Doom::game_interface_c::Start(const char *preset) {

gif_filename = filename;

gif_filename.replace_extension("gif");
ReplaceExtension(gif_filename, ".gif");

if (file_per_map) {
filename = std::filesystem::temp_directory_path().append("resources.wad");
filename = PathAppend(home_dir, "resources.wad");
} else {
filename.replace_extension("wad");
ReplaceExtension(filename, ".wad");
}

if (create_backups && !file_per_map) {
Expand All @@ -1262,16 +1263,16 @@ bool Doom::game_interface_c::Start(const char *preset) {
}

if (compress_output) {
if (std::filesystem::exists(zip_filename)) {
if (FileExists(zip_filename)) {
if (create_backups) {
Main::BackupFile(zip_filename);
}
std::filesystem::remove(zip_filename);
FileDelete(zip_filename);
}
if (!ZIPF_OpenWrite(zip_filename)) {
Main::ProgStatus(
_("Error (create PK3/ZIP)"),
zip_filename.u8string().c_str());
zip_filename.c_str());
return false;
}
}
Expand Down Expand Up @@ -1346,7 +1347,7 @@ bool Doom::game_interface_c::Finish(bool build_ok) {
if (!build_ok) {
// remove the WAD if an error occurred
if (!preserve_failures) {
std::filesystem::remove(filename);
FileDelete(filename);
}
} else {
Recent_AddFile(RECG_Output, filename);
Expand All @@ -1359,15 +1360,15 @@ bool Doom::game_interface_c::Finish(bool build_ok) {
"Adding WAD to PK3 failed! Retaining original "
"WAD.\n");
ZIPF_CloseWrite();
std::filesystem::remove(zip_filename);
FileDelete(zip_filename);
} else {
if (!ZIPF_CloseWrite()) {
LogPrintf(
"Corrupt PK3! Retaining original WAD.\n");
std::filesystem::remove(zip_filename);
FileDelete(zip_filename);
}
else {
std::filesystem::remove(filename);
FileDelete(filename);
}
}
}
Expand Down Expand Up @@ -1416,11 +1417,11 @@ void Doom::game_interface_c::Property(std::string key, std::string value) {
}
}

std::filesystem::path Doom::game_interface_c::Filename() {
std::string Doom::game_interface_c::Filename() {
return filename;
}

std::filesystem::path Doom::game_interface_c::ZIP_Filename() {
std::string Doom::game_interface_c::ZIP_Filename() {
return zip_filename;
}

Expand Down
Loading

0 comments on commit 39011fc

Please sign in to comment.