diff --git a/scripts/obsidian.lua b/scripts/obsidian.lua index 28c965dc40..9e12d6fe5f 100644 --- a/scripts/obsidian.lua +++ b/scripts/obsidian.lua @@ -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") diff --git a/source_files/ajbsp/aj_bsp.h b/source_files/ajbsp/aj_bsp.h index 943163214c..171be17dd5 100644 --- a/source_files/ajbsp/aj_bsp.h +++ b/source_files/ajbsp/aj_bsp.h @@ -23,8 +23,6 @@ #define AJBSP_VERSION "1.05" -#include - // // Node Build Information Structure // @@ -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 { @@ -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(); diff --git a/source_files/ajbsp/ajbsp.cc b/source_files/ajbsp/ajbsp.cc index d42ba8bc3e..a24dc492df 100644 --- a/source_files/ajbsp/ajbsp.cc +++ b/source_files/ajbsp/ajbsp.cc @@ -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); @@ -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); @@ -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); diff --git a/source_files/ajbsp/level.cc b/source_files/ajbsp/level.cc index 5d9e3bf209..7a26fae6eb 100644 --- a/source_files/ajbsp/level.cc +++ b/source_files/ajbsp/level.cc @@ -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()); } } diff --git a/source_files/ajbsp/utility.cc b/source_files/ajbsp/utility.cc index 0046a1796a..579475f2d3 100644 --- a/source_files/ajbsp/utility.cc +++ b/source_files/ajbsp/utility.cc @@ -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) { diff --git a/source_files/ajbsp/utility.h b/source_files/ajbsp/utility.h index 467cbd6690..246361c00e 100644 --- a/source_files/ajbsp/utility.h +++ b/source_files/ajbsp/utility.h @@ -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); diff --git a/source_files/gif-h/gif.h b/source_files/gif-h/gif.h index 64efd68cdb..143aafc3b7 100644 --- a/source_files/gif-h/gif.h +++ b/source_files/gif-h/gif.h @@ -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; diff --git a/source_files/obsidian_main/dm_extra.cc b/source_files/obsidian_main/dm_extra.cc index 7768d23b7e..52e43e2013 100644 --- a/source_files/obsidian_main/dm_extra.cc +++ b/source_files/obsidian_main/dm_extra.cc @@ -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()); @@ -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()); @@ -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"); @@ -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()); diff --git a/source_files/obsidian_main/g_doom.cc b/source_files/obsidian_main/g_doom.cc index 704296bf35..a40b1f6c12 100644 --- a/source_files/obsidian_main/g_doom.cc +++ b/source_files/obsidian_main/g_doom.cc @@ -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(); @@ -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) { @@ -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)); @@ -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(); @@ -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()); } @@ -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: @@ -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 @@ -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); @@ -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) { @@ -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; } } @@ -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); @@ -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); } } } @@ -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; } diff --git a/source_files/obsidian_main/g_doom.h b/source_files/obsidian_main/g_doom.h index 251c8993e3..0f75c3afb2 100644 --- a/source_files/obsidian_main/g_doom.h +++ b/source_files/obsidian_main/g_doom.h @@ -22,7 +22,6 @@ #ifndef G_DOOM_H_ #define G_DOOM_H_ -#include #include "m_lua.h" class qLump_c { @@ -72,7 +71,7 @@ extern int sub_format; /***** FUNCTIONS ****************/ -bool StartWAD(std::filesystem::path filename); +bool StartWAD(std::string filename); bool EndWAD(); void BeginLevel(); diff --git a/source_files/obsidian_main/g_wolf.cc b/source_files/obsidian_main/g_wolf.cc index c65d2855fb..af105b253c 100644 --- a/source_files/obsidian_main/g_wolf.cc +++ b/source_files/obsidian_main/g_wolf.cc @@ -55,8 +55,8 @@ static std::string level_name; #define PL_START 2 -std::filesystem::path wolf_output_dir; -extern std::filesystem::path BestDirectory(); +std::string wolf_output_dir; +extern std::string BestDirectory(); //------------------------------------------------------------------------ // WOLF OUTPUT @@ -331,8 +331,8 @@ class wolf_game_interface_c : public game_interface_c { void EndLevel(); void Property(std::string key, std::string value); // Don't really need this, but whatever - std::filesystem::path Filename(); - std::filesystem::path ZIP_Filename(); + std::string Filename(); + std::string ZIP_Filename(); private: void Rename(); @@ -345,8 +345,8 @@ bool wolf_game_interface_c::Start(const char *ext) { write_errors_seen = 0; if (batch_mode) { - if (batch_output_file.is_absolute()) { - wolf_output_dir = batch_output_file.remove_filename(); + if (IsPathAbsolute(batch_output_file)) { + wolf_output_dir = GetDirectory(batch_output_file); } else { wolf_output_dir = Resolve_DefaultOutputPath(); } @@ -359,7 +359,7 @@ bool wolf_game_interface_c::Start(const char *ext) { chooser.title(_("Select output directory")); - chooser.directory(BestDirectory().generic_u8string().c_str()); + chooser.directory(BestDirectory().c_str()); chooser.type(Fl_Native_File_Chooser::BROWSE_DIRECTORY); @@ -381,7 +381,7 @@ bool wolf_game_interface_c::Start(const char *ext) { break; // OK } - std::filesystem::path dir_name = std::filesystem::u8path(chooser.filename()); + std::string dir_name = chooser.filename(); if (dir_name.empty()) { LogPrintf(_("Empty directory provided???:\n")); @@ -467,31 +467,31 @@ bool wolf_game_interface_c::Finish(bool build_ok) { } void wolf_game_interface_c::Rename() { - std::filesystem::path gamemaps = - wolf_output_dir / (StringCompare(file_ext, "BC") == 0 ? StringFormat("MAPTEMP.%s", file_ext.c_str()) : StringFormat("GAMEMAPS.%s", file_ext.c_str())); - std::filesystem::path maphead = - wolf_output_dir / StringFormat("MAPHEAD.%s", file_ext.c_str()); + std::string gamemaps = + PathAppend(wolf_output_dir, (StringCompare(file_ext, "BC") == 0 ? StringFormat("MAPTEMP.%s", file_ext.c_str()) : StringFormat("GAMEMAPS.%s", file_ext.c_str()))); + std::string maphead = + PathAppend(wolf_output_dir, StringFormat("MAPHEAD.%s", file_ext.c_str())); if (create_backups) { Main::BackupFile(gamemaps); Main::BackupFile(maphead); } - std::filesystem::remove(gamemaps); - std::filesystem::remove(maphead); + FileDelete(gamemaps); + FileDelete(maphead); if (StringCompare(file_ext, "BC") == 0) { - std::filesystem::rename(TEMP_MAPTEMP, gamemaps); + FileRename(TEMP_MAPTEMP, gamemaps); } else { - std::filesystem::rename(TEMP_GAMEFILE, gamemaps); + FileRename(TEMP_GAMEFILE, gamemaps); } - std::filesystem::rename(TEMP_HEADFILE, maphead); + FileRename(TEMP_HEADFILE, maphead); } void wolf_game_interface_c::Tidy() { - std::filesystem::remove(TEMP_MAPTEMP); - std::filesystem::remove(TEMP_GAMEFILE); - std::filesystem::remove(TEMP_HEADFILE); + FileDelete(TEMP_MAPTEMP); + FileDelete(TEMP_GAMEFILE); + FileDelete(TEMP_HEADFILE); } void wolf_game_interface_c::BeginLevel() { @@ -537,11 +537,11 @@ void wolf_game_interface_c::Property(std::string key, std::string value) { } } -std::filesystem::path wolf_game_interface_c::Filename() { +std::string wolf_game_interface_c::Filename() { return ""; } -std::filesystem::path wolf_game_interface_c::ZIP_Filename() { +std::string wolf_game_interface_c::ZIP_Filename() { return ""; } diff --git a/source_files/obsidian_main/lib_util.cc b/source_files/obsidian_main/lib_util.cc index 80bb5730db..afce450c09 100644 --- a/source_files/obsidian_main/lib_util.cc +++ b/source_files/obsidian_main/lib_util.cc @@ -24,6 +24,285 @@ #include "headers.h" #include "grapheme.h" #include +#ifndef _WIN32 +#include +#include +#include +#include +#include +#endif +#ifdef __MINGW32__ +#include +#endif + +#ifdef _WIN32 // Windows API +static inline bool IsDirectorySeparator(const char c) +{ + return (c == '\\' || c == '/' || c == ':'); // Kester added ':' +} +bool IsPathAbsolute(std::string_view path) +{ + SYS_ASSERT(!path.empty()); + + // Check for Drive letter, colon and slash... + if (path.size() > 2 && path[1] == ':' && (path[2] == '\\' || path[2] == '/') && IsAlphaASCII(path[0])) + { + return true; + } + else if (path.size() == 2 && path[1] == ':' && IsAlphaASCII(path[0])) + { + return true; + } + + // Check for share name... + if (path.size() > 1 && path[0] == '\\' && path[1] == '\\') + return true; + + return false; +} +FILE *FileOpen(std::string_view name, std::string_view mode) +{ + std::wstring wname = UTF8ToWString(name); + std::wstring wmode = UTF8ToWString(mode); + return _wfopen(wname.c_str(), wmode.c_str()); +} +bool FileRename(std::string_view oldname, std::string_view newname) +{ + std::wstring woldname = UTF8ToWString(oldname); + std::wstring wnewname = UTF8ToWString(newname); + return _wrename(woldname.c_str(), wnewname.c_str()) == 0; +} +bool FileDelete(std::string_view name) +{ + SYS_ASSERT(!name.empty()); + std::wstring wname = UTF8ToWString(name); + return _wremove(wname.c_str()) == 0; +} +std::string CurrentDirectoryGet() +{ + std::string directory; + const wchar_t *dir = _wgetcwd(nullptr, 0); + if (dir) + directory = WStringToUTF8(dir); + return directory; // can be empty +} +static bool CurrentDirectorySet(std::string_view dir) +{ + SYS_ASSERT(!dir.empty()); + std::wstring wdir = UTF8ToWString(dir); + return _wchdir(wdir.c_str()) == 0; +} +bool MakeDirectory(std::string_view dir) +{ + SYS_ASSERT(!dir.empty()); + std::wstring wdirectory = UTF8ToWString(dir); + return _wmkdir(wdirectory.c_str()) == 0; +} +bool FileExists(std::string_view name) +{ + SYS_ASSERT(!name.empty()); + std::wstring wname = UTF8ToWString(name); + return _waccess(wname.c_str(), 0) == 0; +} +#else // POSIX API +static inline bool IsDirectorySeparator(const char c) +{ + return (c == '\\' || c == '/'); +} +bool IsPathAbsolute(std::string_view path) +{ + SYS_ASSERT(!path.empty()); + + if (IsDirectorySeparator(path[0])) + return true; + else + return false; +} +FILE *FileOpen(std::string_view name, std::string_view mode) +{ + SYS_ASSERT(!name.empty()); + return fopen(std::string(name).c_str(), std::string(mode).c_str()); +} +bool FileRename(std::string_view oldname, std::string_view newname) +{ + return rename(oldname.c_str(), newname.c_str()) == 0; +} +bool FileDelete(std::string_view name) +{ + SYS_ASSERT(!name.empty()); + return remove(std::string(name).c_str()) == 0; +} +std::string CurrentDirectoryGet() +{ + std::string directory; + const char *dir = getcwd(nullptr, 0); + if (dir) + directory = dir; + return directory; +} +static bool CurrentDirectorySet(std::string_view dir) +{ + SYS_ASSERT(!dir.empty()); + return chdir(std::string(dir).c_str()) == 0; +} +bool MakeDirectory(std::string_view dir) +{ + SYS_ASSERT(!dir.empty()); + return (mkdir(std::string(dir).c_str(), 0774) == 0); +} +bool FileExists(std::string_view name) +{ + SYS_ASSERT(!name.empty()); + return access(std::string(name).c_str(), F_OK) == 0; +} +#endif + +// Universal Functions + +std::string GetStem(std::string_view path) +{ + SYS_ASSERT(!path.empty()); + // back up until a slash or the start + for (int p = path.size() - 1; p > 1; p--) + { + if (IsDirectorySeparator(path[p - 1])) + { + path.remove_prefix(p); + break; + } + } + // back up until a dot + for (int p = path.size() - 2; p >= 0; p--) + { + const char ch = path[p]; + if (IsDirectorySeparator(ch)) + break; + + if (ch == '.') + { + // handle filenames that being with a dot + // (un*x style hidden files) + if (p == 0 || IsDirectorySeparator(path[p - 1])) + break; + + path.remove_suffix(path.size() - p); + break; + } + } + std::string filename(path); + return filename; +} + +std::string GetFilename(std::string_view path) +{ + SYS_ASSERT(!path.empty()); + // back up until a slash or the start + for (int p = path.size() - 1; p > 0; p--) + { + if (IsDirectorySeparator(path[p - 1])) + { + path.remove_prefix(p); + break; + } + } + std::string filename(path); + return filename; +} + +std::string PathAppend(std::string_view parent, std::string_view child) +{ + SYS_ASSERT(!parent.empty() && !child.empty()); + + if (IsDirectorySeparator(parent.back())) + parent.remove_suffix(1); + + std::string new_path(parent); + + new_path.push_back('/'); + + if (IsDirectorySeparator(child[0])) + child.remove_prefix(1); + + new_path.append(child); + + return new_path; +} + +std::string GetDirectory(std::string_view path) +{ + SYS_ASSERT(!path.empty()); + std::string directory; + // back up until a slash or the start + for (int p = path.size() - 1; p >= 0; p--) + { + if (IsDirectorySeparator(path[p])) + { + directory = path.substr(0, p); + break; + } + } + + return directory; // nothing +} + +std::string GetExtension(std::string_view path) +{ + SYS_ASSERT(!path.empty()); + std::string extension; + // back up until a dot + for (int p = path.size() - 1; p >= 0; p--) + { + const char ch = path[p]; + if (IsDirectorySeparator(ch)) + break; + + if (ch == '.') + { + // handle filenames that being with a dot + // (un*x style hidden files) + if (p == 0 || IsDirectorySeparator(path[p - 1])) + break; + + extension = path.substr(p); + break; + } + } + return extension; // can be empty +} + +void ReplaceExtension(std::string &path, std::string_view ext) +{ + SYS_ASSERT(!path.empty() && !ext.empty()); + int extpos = -1; + // back up until a dot + for (int p = path.size() - 1; p >= 0; p--) + { + char &ch = path[p]; + if (IsDirectorySeparator(ch)) + break; + + if (ch == '.') + { + // handle filenames that being with a dot + // (un*x style hidden files) + if (p == 0 || IsDirectorySeparator(path[p - 1])) + break; + + extpos = p; + break; + } + } + if (extpos == -1) // No extension found, add it + path.append(ext); + else + { + while (path.size() > extpos) + { + path.pop_back(); + } + path.append(ext); + } +} #ifdef _WIN32 std::wstring UTF8ToWString(std::string_view instring) diff --git a/source_files/obsidian_main/lib_util.h b/source_files/obsidian_main/lib_util.h index fa04d2d25d..e73c53bb54 100644 --- a/source_files/obsidian_main/lib_util.h +++ b/source_files/obsidian_main/lib_util.h @@ -25,6 +25,24 @@ #include #include +/* file utilities */ + +std::string GetFilename(std::string_view path); +std::string GetStem(std::string_view path); +std::string GetDirectory(std::string_view path); +std::string GetExtension(std::string_view path); +std::string PathAppend(std::string_view parent, std::string_view child); +bool IsPathAbsolute(std::string_view path); +void ReplaceExtension(std::string &path, std::string_view ext); + +std::string CurrentDirectoryGet(); +bool MakeDirectory(std::string_view dir); + +bool FileExists(std::string_view name); +FILE *FileOpen(std::string_view name, std::string_view mode); +bool FileRename(std::string_view oldname, std::string_view newname); +bool FileDelete(std::string_view name); + /* string utilities */ #ifdef _WIN32 @@ -34,6 +52,55 @@ std::string WStringToUTF8(std::wstring_view instring); std::wstring UTF8ToWString(std::string_view instring); #endif +inline bool IsUpperASCII(int character) +{ + return (character > '@' && character < '['); +} +inline bool IsLowerASCII(int character) +{ + return (character > '`' && character < '{'); +} +inline bool IsAlphaASCII(int character) +{ + return ((character > '@' && character < '[') || (character > '`' && character < '{')); +} +inline bool IsAlphanumericASCII(int character) +{ + return ((character > '@' && character < '[') || (character > '`' && character < '{') || + (character > '/' && character < ':')); +} +inline bool IsDigitASCII(int character) +{ + return (character > '/' && character < ':'); +} +inline bool IsXDigitASCII(int character) +{ + return ((character > '@' && character < 'G') || (character > '`' && character < 'g') || + (character > '/' && character < ':')); +} +inline bool IsPrintASCII(int character) +{ + return (character > 0x1F && character < 0x7F); +} +inline bool IsSpaceASCII(int character) +{ + return ((character > 0x8 && character < 0xE) || character == 0x20); +} +inline int ToLowerASCII(int character) +{ + if (character > '@' && character < '[') + return character ^ 0x20; + else + return character; +} +inline int ToUpperASCII(int character) +{ + if (character > '`' && character < '{') + return character ^ 0x20; + else + return character; +} + int StringCompare(std::string_view A, std::string_view B); int StringPrefixCompare(std::string_view A, std::string_view B); diff --git a/source_files/obsidian_main/lib_wad.cc b/source_files/obsidian_main/lib_wad.cc index 531f5237c4..81e8013c5d 100644 --- a/source_files/obsidian_main/lib_wad.cc +++ b/source_files/obsidian_main/lib_wad.cc @@ -46,19 +46,19 @@ static FILE *wad_R_fp; static raw_wad_header_t wad_R_header; static raw_wad_lump_t *wad_R_dir; -bool WAD_OpenRead(std::filesystem::path filename) { +bool WAD_OpenRead(std::string filename) { #ifdef HAVE_PHYSFS - wad_R_fp = PHYSFS_openRead(filename.generic_u8string().c_str()); + wad_R_fp = PHYSFS_openRead(filename.c_str()); #else - wad_R_fp = fopen(filename.generic_u8string().c_str(), "rb"); + wad_R_fp = fopen(filename.c_str(), "rb"); #endif if (!wad_R_fp) { - LogPrintf("WAD_OpenRead: no such file: %s\n", filename.u8string().c_str()); + LogPrintf("WAD_OpenRead: no such file: %s\n", filename.c_str()); return false; } - LogPrintf("Opened WAD file: %s\n", filename.u8string().c_str()); + LogPrintf("Opened WAD file: %s\n", filename.c_str()); #ifdef HAVE_PHYSFS if ((PHYSFS_readBytes(wad_R_fp, &wad_R_header, sizeof(wad_R_header)) / @@ -235,15 +235,15 @@ static std::list wad_W_directory; static raw_wad_lump_t wad_W_lump; -bool WAD_OpenWrite(std::filesystem::path filename) { +bool WAD_OpenWrite(std::string filename) { wad_W_fp.open(filename, std::ios::out | std::ios::binary); if (!wad_W_fp.is_open()) { - LogPrintf("WAD_OpenWrite: cannot create file: %s\n", filename.u8string().c_str()); + LogPrintf("WAD_OpenWrite: cannot create file: %s\n", filename.c_str()); return false; } - LogPrintf("Created WAD file: %s\n", filename.u8string().c_str()); + LogPrintf("Created WAD file: %s\n", filename.c_str()); // write out a dummy header raw_wad_header_t header; diff --git a/source_files/obsidian_main/lib_wad.h b/source_files/obsidian_main/lib_wad.h index f5aa81026d..1b3e417955 100644 --- a/source_files/obsidian_main/lib_wad.h +++ b/source_files/obsidian_main/lib_wad.h @@ -24,10 +24,9 @@ /* WAD reading */ -#include #include -bool WAD_OpenRead(std::filesystem::path filename); +bool WAD_OpenRead(std::string filename); void WAD_CloseRead(); int WAD_NumEntries(); @@ -39,7 +38,7 @@ bool WAD_ReadData(int entry, int offset, int length, void *buffer); /* WAD writing */ -bool WAD_OpenWrite(std::filesystem::path filename); +bool WAD_OpenWrite(std::string filename); void WAD_CloseWrite(); void WAD_NewLump(std::string name); diff --git a/source_files/obsidian_main/lib_zip.cc b/source_files/obsidian_main/lib_zip.cc index be0ae60761..57d49e503b 100644 --- a/source_files/obsidian_main/lib_zip.cc +++ b/source_files/obsidian_main/lib_zip.cc @@ -28,17 +28,17 @@ #include "miniz.h" static mz_zip_archive *zip_writer = nullptr; -static std::filesystem::path current_zip; +static std::string current_zip; //------------------------------------------------------------------------ // ZIP WRITING //------------------------------------------------------------------------ -bool ZIPF_OpenWrite(const std::filesystem::path &filename) { +bool ZIPF_OpenWrite(const std::string &filename) { // Make sure the last ZIPF operation was closed properly and that // the target archive doesn't already exist (unlike our WAD stuff // there should only ever be one pk3 going on at a time) - if (std::filesystem::exists(filename)) { + if (FileExists(filename)) { return false; } if (zip_writer) { @@ -48,7 +48,7 @@ bool ZIPF_OpenWrite(const std::filesystem::path &filename) { } zip_writer = new mz_zip_archive; mz_zip_zero_struct(zip_writer); - if (!mz_zip_writer_init_file(zip_writer, filename.generic_u8string().c_str(), 0)) { + if (!mz_zip_writer_init_file(zip_writer, filename.c_str(), 0)) { mz_zip_writer_end(zip_writer); delete zip_writer; zip_writer = nullptr; @@ -58,13 +58,13 @@ bool ZIPF_OpenWrite(const std::filesystem::path &filename) { return true; } -bool ZIPF_AddFile(const std::filesystem::path &filename, std::filesystem::path directory) { +bool ZIPF_AddFile(const std::string &filename, std::string directory) { if (!zip_writer) { return false; } return mz_zip_writer_add_file(zip_writer, - !directory.empty() ? (directory / filename.filename()).generic_u8string().c_str() : - filename.filename().generic_u8string().c_str(), filename.generic_u8string().c_str(), + !directory.empty() ? PathAppend(directory, filename).c_str() : + filename.c_str(), filename.c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION); } diff --git a/source_files/obsidian_main/lib_zip.h b/source_files/obsidian_main/lib_zip.h index 314a591f89..8b4b23d343 100644 --- a/source_files/obsidian_main/lib_zip.h +++ b/source_files/obsidian_main/lib_zip.h @@ -22,12 +22,12 @@ #ifndef LIB_ZIP_H_ #define LIB_ZIP_H_ -#include +#include /* ZIP writing */ -bool ZIPF_OpenWrite(const std::filesystem::path &filename); -bool ZIPF_AddFile(const std::filesystem::path &filename, std::filesystem::path directory); +bool ZIPF_OpenWrite(const std::string &filename); +bool ZIPF_AddFile(const std::string &filename, std::string directory); bool ZIPF_AddMem(std::string name, uint8_t *data, size_t length); bool ZIPF_CloseWrite(); diff --git a/source_files/obsidian_main/m_addons.cc b/source_files/obsidian_main/m_addons.cc index 14ce453c7e..ac824387be 100644 --- a/source_files/obsidian_main/m_addons.cc +++ b/source_files/obsidian_main/m_addons.cc @@ -36,18 +36,17 @@ // need this because the OPTIONS file is loaded *before* the addons // folder is scanned for valid archives, so remember enabled ones here. -std::map initial_enabled_addons; +std::map initial_enabled_addons; std::vector all_addons; -std::vector all_presets; +std::vector all_presets; void VFS_AddFolder(std::string name) { - std::filesystem::path path = install_dir; - path /= name; + std::string path = PathAppend(install_dir, name); std::string mount = StringFormat("/%s", name.c_str()); - if (!PHYSFS_mount(path.generic_u8string().c_str(), mount.c_str(), 0)) { + if (!PHYSFS_mount(path.c_str(), mount.c_str(), 0)) { Main::FatalError("Failed to mount '%s' folder in PhysFS:\n%s\n", name.c_str(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); return; /* NOT REACHED */ @@ -56,30 +55,44 @@ void VFS_AddFolder(std::string name) { DebugPrintf("mounted folder '%s'\n", name.c_str()); } -bool VFS_AddArchive(std::filesystem::path filename, bool options_file) { - LogPrintf(" using: %s\n", filename.u8string().c_str()); +// install and home directories if different +void VFS_AddBothFolders(std::string name) { + std::string path = PathAppend(install_dir, name); + std::string mount = StringFormat("/%s", name.c_str()); + if (!PHYSFS_mount(path.c_str(), mount.c_str(), 0)) { + Main::FatalError("Failed to mount '%s' folder in PhysFS:\n%s\n", name.c_str(), + PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + return; /* NOT REACHED */ + } + path = PathAppend(home_dir, name); + PHYSFS_mount(path.c_str(), mount.c_str(), 0); // this one can fail if not present, that's fine + + DebugPrintf("mounted folder '%s'\n", name.c_str()); +} + +bool VFS_AddArchive(std::string filename, bool options_file) { + LogPrintf(" using: %s\n", filename.c_str()); // when handling "bare" filenames from the command line (i.e. ones // containing no paths or drive spec) and the file does not exist in // the current dir, look for it in the standard addons/ folder. - if ((!std::filesystem::exists(filename) && !filename.has_parent_path())) { - std::filesystem::path new_name = - std::filesystem::u8path(StringFormat("%s/addons/%s", home_dir.generic_u8string().c_str(), filename.string().c_str())); - if (!std::filesystem::exists(new_name)) { - new_name = StringFormat("%s/addons/%s", install_dir.generic_u8string().c_str(), - filename.string().c_str()); + if ((!FileExists(filename) && GetDirectory(filename).empty())) { + std::string new_name = StringFormat("%s/addons/%s", home_dir.c_str(), filename.c_str()); + if (!FileExists(new_name)) { + new_name = StringFormat("%s/addons/%s", install_dir.c_str(), + filename.c_str()); } filename = new_name; } - if (!PHYSFS_mount(filename.generic_u8string().c_str(), "/", 0)) { + if (!PHYSFS_mount(filename.c_str(), "/", 0)) { if (options_file) { LogPrintf("Failed to mount '%s' archive in PhysFS:\n%s\n", - filename.u8string().c_str(), + filename.c_str(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); } else { Main::FatalError("Failed to mount '%s' archive in PhysFS:\n%s\n", - filename.u8string().c_str(), + filename.c_str(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); } @@ -89,20 +102,17 @@ bool VFS_AddArchive(std::filesystem::path filename, bool options_file) { return true; // Ok } -void VFS_InitAddons(std::filesystem::path search_dir) { +void VFS_InitAddons(std::string search_dir) { LogPrintf("Initializing VFS...\n"); - if (!PHYSFS_init(search_dir.generic_u8string().c_str())) { - Main::FatalError("Failed to init PhysFS:\n%s\n", - PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - } - VFS_AddFolder("scripts"); VFS_AddFolder("games"); VFS_AddFolder("engines"); VFS_AddFolder("modules"); VFS_AddFolder("data"); VFS_AddFolder("ports"); + VFS_AddBothFolders("presets"); + VFS_AddBothFolders("addons"); LogPrintf("DONE.\n\n"); } @@ -120,7 +130,7 @@ void VFS_ParseCommandLine() { LogPrintf("Command-line addons....\n"); for (; arg < argv::list.size() && !argv::IsOption(arg); arg++, count++) { - VFS_AddArchive(std::filesystem::u8path(argv::list[arg]), false /* options_file */); + VFS_AddArchive(argv::list[arg], false /* options_file */); } if (!count) { @@ -144,7 +154,7 @@ void VFS_OptWrite(std::ofstream &fp) { const addon_info_t *info = &all_addons[i]; if (info->enabled) { - fp << "addon = " << info->name.string() << "\n"; + fp << "addon = " << info->name << "\n"; } } @@ -156,53 +166,22 @@ void VFS_ScanForPresets() { all_presets.clear(); - std::filesystem::path dir_name = install_dir; - dir_name /= "presets"; - - std::vector list; - int result1 = 0; - int result2 = 0; + char **got_names = PHYSFS_enumerateFiles("presets"); - for (auto &file : std::filesystem::directory_iterator(dir_name)) { - if (StringCompare(file.path().extension().string(), ".txt") == 0) { - result1 += 1; - list.push_back(file.path()); - } + // seems this only happens on out-of-memory error + if (!got_names) { + LogPrintf("DONE (none found)\n"); } - if (home_dir != install_dir) { - dir_name = home_dir; - dir_name /= "presets"; - if (!std::filesystem::exists(dir_name)) { - goto no_home_preset_dir; - } - - std::vector list2; + char **p; - for (auto &file : std::filesystem::directory_iterator(dir_name)) { - if (StringCompare(file.path().extension().string(), ".txt") == 0) { - result2 += 1; - list2.push_back(file.path()); - } - } - // std::vector().swap(list2); - for (auto x : list2) { - list.push_back(x); + for (p = got_names; *p; p++) { + if (GetExtension(*p) == ".txt") { + all_presets.push_back(*p); } } -no_home_preset_dir: - - if ((result1 < 0) && (result2 < 0)) { - LogPrintf("FAILED -- no preset directory found.\n\n"); - return; - } - - for (auto preset : list) { - all_presets.push_back(preset); - } - - if (list.size() == 0) { + if (all_presets.size() == 0) { LogPrintf("DONE (none found)\n"); } else { LogPrintf("DONE\n"); @@ -216,91 +195,41 @@ void VFS_ScanForAddons() { all_addons.clear(); - std::filesystem::path dir_name = install_dir; - dir_name /= "addons"; - - std::vector list; - int result1 = 0; - int result2 = 0; - - for (auto &file : std::filesystem::directory_iterator(dir_name)) { - if (file.is_directory() || StringCompare(file.path().extension().string(), ".oaf") == 0) { - if (PHYSFS_mount(file.path().generic_u8string().c_str(), nullptr, 0)) { - PHYSFS_unmount(file.path().generic_u8string().c_str()); - result1 += 1; - list.push_back(file.path()); - } - else { - LogPrintf("Failed to mount '%s' archive in PhysFS:\n%s\n", - file.path().u8string().c_str(), - PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - } - } - } - - if (home_dir != install_dir) { - dir_name = home_dir; - dir_name /= "addons"; - if (!std::filesystem::exists(dir_name)) { - goto no_home_addon_dir; - } - - std::vector list2; - - for (auto &file : std::filesystem::directory_iterator(dir_name)) { - if (file.is_directory() || StringCompare(file.path().extension().string(), ".oaf") == 0) { - if (PHYSFS_mount(file.path().generic_u8string().c_str(), nullptr, 0)) { - PHYSFS_unmount(file.path().generic_u8string().c_str()); - result2 += 1; - list2.push_back(file.path()); - } - else { - LogPrintf("Failed to mount '%s' archive in PhysFS:\n%s\n", - file.path().u8string().c_str(), - PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - } - } - } - // std::vector().swap(list2); - for (auto x : list2) { - list.push_back(x); - } - } - -no_home_addon_dir: + char **got_names = PHYSFS_enumerateFiles("addons"); - if ((result1 < 0) && (result2 < 0)) { - LogPrintf("FAILED -- no addon directory found.\n\n"); - return; + // seems this only happens on out-of-memory error + if (!got_names) { + LogPrintf("DONE (none found)\n"); } - for (unsigned int i = 0; i < list.size(); i++) { - addon_info_t info; + char **p; - info.name = list[i]; + for (p = got_names; *p; p++) { + if (GetExtension(*p) == ".oaf") { + addon_info_t info; - info.enabled = false; + info.name = *p; - if (initial_enabled_addons.find(list[i]) != - initial_enabled_addons.end()) { - info.enabled = true; - } + info.enabled = false; - // DEBUG - // info.enabled = true; + if (initial_enabled_addons.find(*p) != + initial_enabled_addons.end()) { + info.enabled = true; + } - LogPrintf(" found: %s%s\n", info.name.u8string().c_str(), - info.enabled ? " (Enabled)" : " (Disabled)"); + LogPrintf(" found: %s%s\n", info.name.c_str(), + info.enabled ? " (Enabled)" : " (Disabled)"); - all_addons.push_back(info); + all_addons.push_back(info); - // if enabled, install into the VFS - if (info.enabled) { - VFS_AddArchive(info.name, true /* options_file */); + // if enabled, install into the VFS + if (info.enabled) { + VFS_AddArchive(info.name, true /* options_file */); + } } } - if (list.size() == 0) { + if (all_addons.size() == 0) { LogPrintf("DONE (none found)\n"); } else { LogPrintf("DONE\n"); diff --git a/source_files/obsidian_main/m_addons.h b/source_files/obsidian_main/m_addons.h index 8bdab7c6c1..9e0ee5c14d 100644 --- a/source_files/obsidian_main/m_addons.h +++ b/source_files/obsidian_main/m_addons.h @@ -25,11 +25,10 @@ #include #include #include -#include #include #include -void VFS_InitAddons(std::filesystem::path search_dir); +void VFS_InitAddons(std::string search_dir); void VFS_ParseCommandLine(); void VFS_ScanForAddons(); void VFS_ScanForPresets(); @@ -43,7 +42,7 @@ uint8_t *VFS_LoadFile(const char *filename, int *length); void VFS_FreeFile(const uint8_t *mem); typedef struct { - std::filesystem::path name; // base filename, includes ".pk3" extension + std::string name; // base filename, includes extension bool enabled; @@ -51,9 +50,9 @@ typedef struct { extern std::vector all_addons; -extern std::vector all_presets; +extern std::vector all_presets; -extern std::map initial_enabled_addons; +extern std::map initial_enabled_addons; #endif /* __OBLIGE_ADDONS_H__ */ diff --git a/source_files/obsidian_main/m_cookie.cc b/source_files/obsidian_main/m_cookie.cc index 03ee2cbeba..9011fbe76a 100644 --- a/source_files/obsidian_main/m_cookie.cc +++ b/source_files/obsidian_main/m_cookie.cc @@ -137,7 +137,7 @@ static bool Cookie_ParseLine(std::string buf) { //---------------------------------------------------------------------- -bool Cookie_Load(std::filesystem::path filename) { +bool Cookie_Load(std::string filename) { context = cookie_context_e::Load; keep_seed = (argv::Find('k', "keep") >= 0); @@ -162,7 +162,7 @@ bool Cookie_Load(std::filesystem::path filename) { } if (main_action != MAIN_SOFT_RESTART) { - LogPrintf("Loading config file: %s\n", filename.u8string().c_str()); + LogPrintf("Loading config file: %s\n", filename.c_str()); } int error_count = 0; @@ -216,7 +216,7 @@ bool Cookie_LoadString(std::string str, bool _keep_seed) { return true; } -bool Cookie_Save(std::filesystem::path filename) { +bool Cookie_Save(std::string filename) { context = cookie_context_e::Save; #ifdef __APPLE__ setlocale(LC_NUMERIC, "C"); @@ -232,7 +232,7 @@ bool Cookie_Save(std::filesystem::path filename) { std::ofstream cookie_fp(filename, std::ios::out); if (!cookie_fp.is_open()) { - LogPrintf("Error: unable to create file: %s\n(%s)\n\n", filename.u8string().c_str(), + LogPrintf("Error: unable to create file: %s\n(%s)\n\n", filename.c_str(), strerror(errno)); return false; } @@ -343,7 +343,7 @@ class RecentFiles_c { int size; // newest is at index [0] - std::filesystem::path filenames[MAX_RECENT]; + std::string filenames[MAX_RECENT]; public: RecentFiles_c() : size(0) { @@ -362,13 +362,12 @@ class RecentFiles_c { size = 0; } - int find(const std::filesystem::path &file) { + int find(const std::string &file) { // ignore the path when matching filenames - const std::filesystem::path a = file.filename(); + const std::string a = GetFilename(file); for (int k = 0; k < size; k++) { - if (a.lexically_normal() == - filenames[k].filename().lexically_normal()) { + if (a == GetFilename(filenames[k])) { return k; } } @@ -390,7 +389,7 @@ class RecentFiles_c { filenames[index].clear(); } - void push_front(const std::filesystem::path &file) { + void push_front(const std::string &file) { if (size >= MAX_RECENT) { erase(MAX_RECENT - 1); } @@ -405,7 +404,7 @@ class RecentFiles_c { size++; } - void insert(const std::filesystem::path &file) { + void insert(const std::string &file) { // ensure filename (without any path) is unique int f = find(file); @@ -430,7 +429,7 @@ class RecentFiles_c { // order they are read. for (int k = size - 1; k >= 0; k--) { - std::string fn = StringFormat("%s = %s\n", keyword.c_str(), filenames[k].u8string().c_str()); + std::string fn = StringFormat("%s = %s\n", keyword.c_str(), filenames[k].c_str()); fp.write(fn.c_str(), fn.size()); } @@ -439,16 +438,16 @@ class RecentFiles_c { } } - bool get_name(int index, std::filesystem::path buffer, + bool get_name(int index, std::string buffer, bool for_menu) const { if (index >= size) { return false; } - const std::filesystem::path &name = filenames[index]; + const std::string &name = filenames[index]; if (for_menu) { - buffer = StringFormat("%-.32s", name.filename().c_str()); + buffer = StringFormat("%-.32s", name.c_str()); } else { buffer = name; } @@ -462,10 +461,10 @@ static RecentFiles_c recent_configs; void Recent_Parse(std::string name, std::string value) { if (StringCompare(name, "recent_wad") == 0) { - recent_wads.insert(std::filesystem::u8path(value)); + recent_wads.insert(value); } else if (StringCompare(name, "recent_config") == 0) { - recent_configs.insert(std::filesystem::u8path(value)); + recent_configs.insert(value); } } @@ -476,7 +475,7 @@ void Recent_Write(std::ofstream &fp) { recent_configs.write_all(fp, "recent_config"); } -void Recent_AddFile(int group, std::filesystem::path filename) { +void Recent_AddFile(int group, std::string filename) { SYS_ASSERT(0 <= group && group < RECG_NUM_GROUPS); switch (group) { diff --git a/source_files/obsidian_main/m_cookie.h b/source_files/obsidian_main/m_cookie.h index 8f5d8dded2..c697f71be0 100644 --- a/source_files/obsidian_main/m_cookie.h +++ b/source_files/obsidian_main/m_cookie.h @@ -23,11 +23,10 @@ #define __OBLIGE_COOKIE_H__ #include -#include #include -bool Cookie_Load(std::filesystem::path filename); -bool Cookie_Save(std::filesystem::path filename); +bool Cookie_Load(std::string filename); +bool Cookie_Save(std::string filename); bool Cookie_LoadString(std::string str, bool _keep_seed); @@ -36,10 +35,10 @@ void Cookie_ParseArguments(void); /* option stuff */ void Parse_Option(const std::string &name, const std::string &value); -bool Options_Load(std::filesystem::path filename); -bool Options_Save(std::filesystem::path filename); -bool Theme_Options_Load(std::filesystem::path filename); -bool Theme_Options_Save(std::filesystem::path filename); +bool Options_Load(std::string filename); +bool Options_Save(std::string filename); +bool Theme_Options_Load(std::string filename); +bool Theme_Options_Save(std::string filename); /* recent file stuff */ @@ -54,7 +53,7 @@ typedef enum { } recent_group_e; -void Recent_AddFile(int group, std::filesystem::path filename); +void Recent_AddFile(int group, std::string filename); void Recent_RemoveFile(int group, std::string filename); bool Recent_GetName(int group, int index, std::string name_buf, bool for_menu = false); diff --git a/source_files/obsidian_main/m_dialog.cc b/source_files/obsidian_main/m_dialog.cc index 08cdbb5535..c26df12510 100644 --- a/source_files/obsidian_main/m_dialog.cc +++ b/source_files/obsidian_main/m_dialog.cc @@ -38,7 +38,7 @@ #include "m_lua.h" -std::filesystem::path last_directory; +std::string last_directory; static int dialog_result; @@ -218,7 +218,7 @@ void DLG_ShowError(const char *msg, ...) { //---------------------------------------------------------------------- -std::filesystem::path BestDirectory() { +std::string BestDirectory() { if (!last_directory.empty()) { return last_directory; } else { @@ -226,7 +226,7 @@ std::filesystem::path BestDirectory() { } } -std::filesystem::path DLG_OutputFilename(const char *ext, const char *preset) { +std::string DLG_OutputFilename(const char *ext, const char *preset) { std::string kind_buf = StringFormat("%s %s\t*.%s", ext, _("files"), ext); // uppercase the first word @@ -253,9 +253,9 @@ std::filesystem::path DLG_OutputFilename(const char *ext, const char *preset) { auto best_dir = BestDirectory(); if (preset) { - chooser.preset_file((best_dir / preset).generic_u8string().c_str()); + chooser.preset_file(PathAppend(best_dir, preset).c_str()); } else { - chooser.directory(best_dir.generic_u8string().c_str()); + chooser.directory(best_dir.c_str()); } int result = chooser.show(); @@ -278,10 +278,9 @@ std::filesystem::path DLG_OutputFilename(const char *ext, const char *preset) { break; // OK } - std::filesystem::path src_name = - std::filesystem::u8path(chooser.filename()); + std::string src_name = chooser.filename(); - std::filesystem::path dir_name = src_name.parent_path(); + std::string dir_name = GetDirectory(src_name); if (!dir_name.empty()) { last_directory = dir_name; @@ -289,11 +288,11 @@ std::filesystem::path DLG_OutputFilename(const char *ext, const char *preset) { #ifdef WIN32 // add extension if missing - if (src_name.extension().empty()) { - src_name.replace_extension(ext); + if (GetExtension(src_name).empty()) { + ReplaceExtension(src_name, ext); // check if exists, ask for confirmation - if (std::filesystem::exists(src_name)) { + if (FileExists(src_name)) { if (!fl_choice("%s", fl_cancel, fl_ok, NULL, Fl_Native_File_Chooser::file_exists_message)) { return ""; // cancelled @@ -584,7 +583,7 @@ void UI_LogViewer::save_callback(Fl_Widget *w, void *data) { tryagain:; if (!last_directory.empty()) { - chooser.directory(last_directory.generic_u8string().c_str()); + chooser.directory(last_directory.c_str()); } switch (chooser.show()) { @@ -601,23 +600,22 @@ tryagain:; break; // OK } - std::filesystem::path filename = - std::filesystem::u8path(chooser.filename()); + std::string filename = chooser.filename(); // add an extension if missing - if (!filename.has_extension()) { - filename.replace_extension(".txt"); + if (GetExtension(filename).empty()) { + ReplaceExtension(filename, ".txt"); } - if (std::filesystem::exists(filename)) { + if (FileExists(filename)) { // clang-format off switch (fl_choice(_("%s already exists.\nChoose Yes to overwrite or No to choose a new filename."), _("Yes"), _("No"), 0, // clang-format on - filename.u8string().c_str())) { + filename.c_str())) { case 0: - std::filesystem::remove(filename); + FileDelete(filename); break; case 1: goto tryagain; @@ -625,7 +623,7 @@ tryagain:; } } - if (filename.extension() != ".txt") { + if (GetExtension(filename) != ".txt") { DLG_ShowError(_("Please choose a filename ending in .txt")); goto tryagain; } @@ -724,11 +722,10 @@ UI_GlossaryViewer::UI_GlossaryViewer(int W, int H, const char *l) UI_GlossaryViewer::~UI_GlossaryViewer() {} void UI_GlossaryViewer::ReadGlossary() { - std::filesystem::path glossary = std::filesystem::u8path( - StringFormat("%s/language/%s.txt", install_dir.u8string().c_str(), - selected_lang.c_str())); + std::string glossary = StringFormat("%s/language/%s.txt", install_dir.c_str(), + selected_lang.c_str()); - if (!std::filesystem::exists(glossary)) { + if (!FileExists(glossary)) { return; } diff --git a/source_files/obsidian_main/m_lua.cc b/source_files/obsidian_main/m_lua.cc index ddfca5f90a..910b04aff1 100644 --- a/source_files/obsidian_main/m_lua.cc +++ b/source_files/obsidian_main/m_lua.cc @@ -49,7 +49,7 @@ static std::vector *conf_line_buffer; static std::string import_dir; -void Script_Load(std::filesystem::path script_name); +void Script_Load(std::string script_name); // color maps color_mapping_t color_mappings[MAX_COLOR_MAPS]; @@ -185,7 +185,7 @@ int gui_config_line(lua_State *L) { int gui_mkdir(lua_State *L) { const char *name = luaL_checkstring(L, 1); - bool result = std::filesystem::create_directory(name); + bool result = MakeDirectory(name); lua_pushboolean(L, result ? 1 : 0); return 1; @@ -194,24 +194,24 @@ int gui_mkdir(lua_State *L) { // LUA: get_filename_base() // int gui_get_filename_base(lua_State *L) { - std::filesystem::path base = game_object->Filename(); - lua_pushstring(L, base.stem().generic_u8string().c_str()); + std::string base = game_object->Filename(); + lua_pushstring(L, GetStem(base).c_str()); return 1; } // LUA: get_file_extension() // int gui_get_file_extension(lua_State *L) { - std::filesystem::path base = luaL_checkstring(L, 1); - lua_pushstring(L, base.extension().generic_u8string().c_str()); + std::string base = luaL_checkstring(L, 1); + lua_pushstring(L, GetExtension(base).c_str()); return 1; } // LUA: get_save_path() // int gui_get_save_path(lua_State *L) { - std::filesystem::path path = game_object->Filename(); - lua_pushstring(L, path.remove_filename().generic_u8string().c_str()); + std::string path = game_object->Filename(); + lua_pushstring(L, GetDirectory(path).c_str()); return 1; } @@ -271,20 +271,23 @@ int gui_set_import_dir(lua_State *L) { import_dir = dir_name; + if (import_dir.empty()) + import_dir = "scripts"; + return 0; } // LUA: get_install_dir() --> string // int gui_get_install_dir(lua_State *L) { - lua_pushstring(L, install_dir.generic_u8string().c_str()); + lua_pushstring(L, install_dir.c_str()); return 1; } -static bool scan_dir_process_name(const std::filesystem::path &name, - const std::filesystem::path &parent, +static bool scan_dir_process_name(const std::string &name, + const std::string &parent, std::string match) { - if (name.native()[0] == '.') { + if (name[0] == '.') { return false; } @@ -293,11 +296,11 @@ static bool scan_dir_process_name(const std::filesystem::path &name, // check if it is a directory // [ generally skip directories, unless match is "DIRS" ] - std::filesystem::path temp_name = parent / name; + std::string temp_name = PathAppend(parent, name); PHYSFS_Stat dir_checker; - PHYSFS_stat(temp_name.generic_u8string().c_str(), &dir_checker); + PHYSFS_stat(temp_name.c_str(), &dir_checker); bool is_it_dir = (dir_checker.filetype == PHYSFS_FILETYPE_DIRECTORY); @@ -314,7 +317,7 @@ static bool scan_dir_process_name(const std::filesystem::path &name, uint8_t buffer[1]; - PHYSFS_File *fp = PHYSFS_openRead(temp_name.generic_u8string().c_str()); + PHYSFS_File *fp = PHYSFS_openRead(temp_name.c_str()); if (!fp) { return false; @@ -331,7 +334,7 @@ static bool scan_dir_process_name(const std::filesystem::path &name, if (match == "*") { return true; } else if (match[0] == '*' && match[1] == '.' && isalnum(match[2])) { - return name.extension().string() == + return GetExtension(name) == "." + std::string{match.begin() + 2, match.end()}; } @@ -1642,15 +1645,15 @@ static const char *my_reader(lua_State *L, void *ud, size_t *size) { return info->buffer; // OK } -static int my_loadfile(lua_State *L, const std::filesystem::path &filename) { +static int my_loadfile(lua_State *L, const std::string &filename) { /* index of filename on the stack */ int fnameindex = lua_gettop(L) + 1; - lua_pushfstring(L, "@%s", filename.generic_u8string().c_str()); + lua_pushfstring(L, "@%s", filename.c_str()); load_info_t info; - info.fp = PHYSFS_openRead(filename.generic_u8string().c_str()); + info.fp = PHYSFS_openRead(filename.c_str()); info.error_msg.clear(); if (!info.fp) { @@ -1682,18 +1685,17 @@ static int my_loadfile(lua_State *L, const std::filesystem::path &filename) { return status; } -void Script_Load(std::filesystem::path script_name) { +void Script_Load(std::string script_name) { SYS_ASSERT(!import_dir.empty()); // add extension if missing - if (script_name.extension().empty()) { - script_name.replace_extension("lua"); + if (GetExtension(script_name).empty()) { + ReplaceExtension(script_name, ".lua"); } - std::filesystem::path filename = - std::filesystem::path{import_dir} / script_name; + std::string filename = PathAppend(import_dir, script_name); - DebugPrintf(" loading script: '%s'\n", filename.u8string().c_str()); + DebugPrintf(" loading script: '%s'\n", filename.c_str()); int status = my_loadfile(LUA_ST, filename); @@ -1704,7 +1706,7 @@ void Script_Load(std::filesystem::path script_name) { if (status != 0) { const char *msg = lua_tolstring(LUA_ST, -1, NULL); - Main::FatalError("Unable to load script '%s'\n%s", filename.u8string().c_str(), msg); + Main::FatalError("Unable to load script '%s'\n%s", filename.c_str(), msg); } } @@ -1949,7 +1951,7 @@ void ob_print_reference() { // clang-format on } StdOutPrintf("\nA copy of this output can be found at %s\n", - reference_file.u8string().c_str()); + reference_file.c_str()); } void ob_print_reference_json() { diff --git a/source_files/obsidian_main/m_manage.cc b/source_files/obsidian_main/m_manage.cc index 31b1d5af3c..eacc5c0756 100644 --- a/source_files/obsidian_main/m_manage.cc +++ b/source_files/obsidian_main/m_manage.cc @@ -283,9 +283,9 @@ class UI_Manage_Config : public Fl_Double_Window { redraw(); } - void MarkSource_FILE(std::filesystem::path filename) { + void MarkSource_FILE(std::string filename) { conf_disp->copy_label( - StringFormat("[ %s ]", filename.filename().u8string().c_str()) + StringFormat("[ %s ]", filename.c_str()) .c_str()); redraw(); @@ -364,9 +364,9 @@ class UI_Manage_Config : public Fl_Double_Window { chooser.filter("Text files\t*.txt"); if (!last_directory.empty()) { - chooser.directory(last_directory.generic_u8string().c_str()); + chooser.directory(last_directory.c_str()); } else { - chooser.directory(install_dir.generic_u8string().c_str()); + chooser.directory(install_dir.c_str()); } switch (chooser.show()) { @@ -416,16 +416,16 @@ class UI_Manage_Config : public Fl_Double_Window { } } - std::filesystem::path AskLoadFilename() { + std::string AskLoadFilename() { Fl_Native_File_Chooser chooser; chooser.title(_("Select file to load")); chooser.type(Fl_Native_File_Chooser::BROWSE_FILE); if (!last_directory.empty()) { - chooser.directory(last_directory.generic_u8string().c_str()); + chooser.directory(last_directory.c_str()); } else { - chooser.directory(install_dir.generic_u8string().c_str()); + chooser.directory(install_dir.c_str()); } switch (chooser.show()) { @@ -444,17 +444,17 @@ class UI_Manage_Config : public Fl_Double_Window { break; // OK } - std::filesystem::path filename = std::filesystem::u8path(chooser.filename()); + std::string filename = chooser.filename(); return filename; } - bool LoadFromFile(std::filesystem::path filename) { - FILE *fp = fl_fopen(filename.generic_u8string().c_str(), "rb"); + bool LoadFromFile(std::string filename) { + FILE *fp = fl_fopen(filename.c_str(), "rb"); if (!fp) { DLG_ShowError(_("Cannot open: %s\n\n%s"), - filename.filename().u8string().c_str(), + filename.c_str(), strerror(errno)); return false; } @@ -498,8 +498,8 @@ class UI_Manage_Config : public Fl_Double_Window { private: static void callback_Defaults(Fl_Widget *w, void *data) { UI_Manage_Config *that = (UI_Manage_Config *)data; - if (std::filesystem::exists(config_file)) { - std::filesystem::remove(config_file); + if (FileExists(config_file)) { + FileDelete(config_file); } config_file.clear(); main_action = MAIN_HARD_RESTART; // MAIN_SOFT_RESTART??? @@ -516,7 +516,7 @@ class UI_Manage_Config : public Fl_Double_Window { int old_font_h = FL_NORMAL_SIZE; FL_NORMAL_SIZE = 14 + KF; - std::filesystem::path filename = that->AskLoadFilename(); + std::string filename = that->AskLoadFilename(); FL_NORMAL_SIZE = old_font_h; diff --git a/source_files/obsidian_main/m_options.cc b/source_files/obsidian_main/m_options.cc index 3c63d6186c..4f602fd6e3 100644 --- a/source_files/obsidian_main/m_options.cc +++ b/source_files/obsidian_main/m_options.cc @@ -32,7 +32,7 @@ #include "m_lua.h" #include "main.h" -extern std::filesystem::path BestDirectory(); +extern std::string BestDirectory(); void Parse_Option(const std::string &name, const std::string &value) { if (StringPrefixCompare(name, "recent") == 0) { @@ -76,7 +76,7 @@ void Parse_Option(const std::string &name, const std::string &value) { } else if (StringCompare(name, "custom_prefix") == 0) { custom_prefix = value; } else if (StringCompare(name, "default_output_path") == 0) { - default_output_path = std::filesystem::u8path(value); + default_output_path = value; } else { StdOutPrintf("%s '%s'\n", _("Unknown option: "), name.c_str()); } @@ -116,7 +116,7 @@ static bool Options_ParseLine(std::string buf) { return true; } -bool Options_Load(std::filesystem::path filename) { +bool Options_Load(std::string filename) { std::ifstream option_fp(filename, std::ios::in); if (!option_fp.is_open()) { @@ -133,12 +133,12 @@ bool Options_Load(std::filesystem::path filename) { return true; } -bool Options_Save(std::filesystem::path filename) { +bool Options_Save(std::string filename) { std::ofstream option_fp(filename, std::ios::out); if (!option_fp.is_open()) { LogPrintf("Error: unable to create file: %s\n(%s)\n\n", - filename.u8string().c_str(), strerror(errno)); + filename.c_str(), strerror(errno)); return false; } @@ -179,7 +179,7 @@ bool Options_Save(std::filesystem::path filename) { option_fp << "custom_prefix = " << custom_prefix << "\n"; std::string dop = StringFormat( "default_output_path = %s\n", - default_output_path.u8string().c_str()); + default_output_path.c_str()); option_fp.write(dop.c_str(), dop.size()); option_fp << "\n"; @@ -501,7 +501,7 @@ class UI_OptionsWin : public Fl_Window { chooser.title(_("Select default save directory")); chooser.type(Fl_Native_File_Chooser::BROWSE_DIRECTORY); - chooser.directory(BestDirectory().generic_u8string().c_str()); + chooser.directory(BestDirectory().c_str()); int result = chooser.show(); @@ -521,8 +521,7 @@ class UI_OptionsWin : public Fl_Window { break; // OK } - std::filesystem::path dir_name = - std::filesystem::u8path(chooser.filename()); + std::string dir_name = chooser.filename(); if (dir_name.empty()) { LogPrintf(_("Empty default directory provided???:\n")); @@ -537,7 +536,7 @@ class UI_OptionsWin : public Fl_Window { that->opt_current_output_path->redraw_label(); that->opt_current_output_path->copy_label( StringFormat("%s: %s", _("Current Path"), - BestDirectory().u8string().c_str()) + BestDirectory().c_str()) .c_str()); that->opt_current_output_path->redraw_label(); } @@ -630,7 +629,7 @@ UI_OptionsWin::UI_OptionsWin(int W, int H, const char *label) opt_current_output_path->labelfont(font_style); opt_current_output_path->labelcolor(FONT2_COLOR); // clang-format off - opt_current_output_path->copy_label(StringFormat("%s: %s", _("Current Path"), BestDirectory().u8string().c_str()).c_str()); + opt_current_output_path->copy_label(StringFormat("%s: %s", _("Current Path"), BestDirectory().c_str()).c_str()); // clang-format on cy += opt_current_output_path->h() + y_step; diff --git a/source_files/obsidian_main/m_theme.cc b/source_files/obsidian_main/m_theme.cc index 033a3c3696..ac03585481 100644 --- a/source_files/obsidian_main/m_theme.cc +++ b/source_files/obsidian_main/m_theme.cc @@ -28,13 +28,12 @@ #include "m_cookie.h" #include "m_trans.h" #include "main.h" -#include bool skip_color_picker = false; //---------------------------------------------------------------------- -std::filesystem::path Theme_OutputFilename() { +std::string Theme_OutputFilename() { // save and restore the font height // (because FLTK's own browser get totally borked) int old_font_h = FL_NORMAL_SIZE; @@ -51,9 +50,8 @@ std::filesystem::path Theme_OutputFilename() { chooser.filter("Text files\t*.txt"); - std::filesystem::path theme_dir = install_dir; - theme_dir /= "theme"; - chooser.directory(theme_dir.generic_u8string().c_str()); + std::string theme_dir = PathAppend(install_dir, "theme"); + chooser.directory(theme_dir.c_str()); FL_NORMAL_SIZE = old_font_h; @@ -73,10 +71,10 @@ std::filesystem::path Theme_OutputFilename() { break; // OK } - std::filesystem::path filename = std::filesystem::u8path(chooser.filename()); - filename.replace_extension(".txt"); + std::string filename = chooser.filename(); + ReplaceExtension(filename, ".txt"); // re-check for overwriting - if (std::filesystem::exists(filename)) { + if (FileExists(filename)) { if (!fl_choice("%s", fl_cancel, fl_ok, NULL, Fl_Native_File_Chooser::file_exists_message)) { return ""; // cancelled @@ -86,7 +84,7 @@ std::filesystem::path Theme_OutputFilename() { return filename; } -std::filesystem::path Theme_AskLoadFilename() { +std::string Theme_AskLoadFilename() { Fl_Native_File_Chooser chooser; chooser.title(_("Select Theme file to load")); @@ -94,9 +92,8 @@ std::filesystem::path Theme_AskLoadFilename() { chooser.filter("Text files\t*.txt"); - std::filesystem::path theme_dir = install_dir; - theme_dir /= "theme"; - chooser.directory(theme_dir.generic_u8string().c_str()); + std::string theme_dir = PathAppend(install_dir, "theme"); + chooser.directory(theme_dir.c_str()); int result = chooser.show(); @@ -116,7 +113,7 @@ std::filesystem::path Theme_AskLoadFilename() { break; // OK } - std::filesystem::path filename = std::filesystem::u8path(chooser.filename()); + std::string filename = chooser.filename(); return filename; } @@ -221,7 +218,7 @@ static bool Theme_Options_ParseLine(std::string buf) { return true; } -bool Theme_Options_Load(std::filesystem::path filename) { +bool Theme_Options_Load(std::string filename) { std::ifstream option_fp(filename, std::ios::in); if (!option_fp.is_open()) { @@ -229,7 +226,7 @@ bool Theme_Options_Load(std::filesystem::path filename) { return false; } - LogPrintf("Loading theme file: %s\n", filename.u8string().c_str()); + LogPrintf("Loading theme file: %s\n", filename.c_str()); int error_count = 0; @@ -250,12 +247,12 @@ bool Theme_Options_Load(std::filesystem::path filename) { return true; } -bool Theme_Options_Save(std::filesystem::path filename) { +bool Theme_Options_Save(std::string filename) { std::ofstream option_fp(filename); if (!option_fp.is_open()) { LogPrintf("Error: unable to create file: %s\n(%s)\n\n", - filename.u8string().c_str(), strerror(errno)); + filename.c_str(), strerror(errno)); return false; } @@ -1461,7 +1458,7 @@ class UI_ThemeWin : public Fl_Window { static void callback_LoadTheme(Fl_Widget *w, void *data) { UI_ThemeWin *that = (UI_ThemeWin *)data; - std::filesystem::path theme_file = Theme_AskLoadFilename(); + std::string theme_file = Theme_AskLoadFilename(); if (!theme_file.empty()) { Theme_Options_Load(theme_file); // clang-format off @@ -1475,7 +1472,7 @@ class UI_ThemeWin : public Fl_Window { } static void callback_SaveTheme(Fl_Widget *w, void *data) { - std::filesystem::path new_theme_file = Theme_OutputFilename(); + std::string new_theme_file = Theme_OutputFilename(); if (!new_theme_file.empty()) { Theme_Options_Save(new_theme_file); } diff --git a/source_files/obsidian_main/m_trans.cc b/source_files/obsidian_main/m_trans.cc index 98cd3c7667..3ac38afde2 100644 --- a/source_files/obsidian_main/m_trans.cc +++ b/source_files/obsidian_main/m_trans.cc @@ -26,7 +26,6 @@ //---------------------------------------------------------------------- #include "m_trans.h" -#include #include "hdr_lua.h" #include "headers.h" @@ -1023,10 +1022,9 @@ void Trans_Init() { /* read the list of languages */ - std::filesystem::path path = install_dir; - path /= "language/LANGS.txt"; + std::string path = PathAppend(install_dir, "language/LANGS.txt"); - if (!std::filesystem::exists(path)) { + if (!FileExists(path)) { LogPrintf("WARNING: missing language/LANGS.txt file\n"); return; } @@ -1038,7 +1036,7 @@ void Trans_Init() { return; } - LogPrintf("Loading language list: %s\n", path.u8string().c_str()); + LogPrintf("Loading language list: %s\n", path.c_str()); for (std::string line; std::getline(trans_fp, line);) { Trans_ParseLangLine((char *)line.c_str()); @@ -1069,18 +1067,16 @@ void Trans_SetLanguage() { } // see if the translation file exists - std::filesystem::path path = - std::filesystem::u8path(StringFormat("%s/language/%s.po", install_dir.generic_u8string().c_str(), langcode.c_str())); + std::string path = StringFormat("%s/language/%s.po", install_dir.c_str(), langcode.c_str()); - if (!std::filesystem::exists(path)) { + if (!FileExists(path)) { // if language has a territory field (like zh_TW or en_AU) then // try again with the plain language code. - path = - std::filesystem::u8path(StringFormat("%s/language/%s.po", install_dir.generic_u8string().c_str(), lang_plain.c_str())); + path = StringFormat("%s/language/%s.po", install_dir.c_str(), lang_plain.c_str()); } - FILE *fp = fopen(path.generic_u8string().c_str(), "rb"); + FILE *fp = fopen(path.c_str(), "rb"); if (!fp) { LogPrintf("No translation file: language/%s.po\n", lang_plain.c_str()); LogPrintf("Using the default language (English)\n\n"); diff --git a/source_files/obsidian_main/main.cc b/source_files/obsidian_main/main.cc index 07de274641..7d08c86be0 100644 --- a/source_files/obsidian_main/main.cc +++ b/source_files/obsidian_main/main.cc @@ -50,13 +50,13 @@ */ constexpr size_t TICKER_TIME = 50; -std::filesystem::path home_dir; -std::filesystem::path install_dir; -std::filesystem::path config_file; -std::filesystem::path options_file; -std::filesystem::path theme_file; -std::filesystem::path logging_file; -std::filesystem::path reference_file; +std::string home_dir; +std::string install_dir; +std::string config_file; +std::string options_file; +std::string theme_file; +std::string logging_file; +std::string reference_file; struct UpdateKv { char section; @@ -77,7 +77,7 @@ int main_action; unsigned long long next_rand_seed; bool batch_mode = false; -std::filesystem::path batch_output_file; +std::string batch_output_file; std::string numeric_locale; std::vector batch_randomize_groups; @@ -154,8 +154,8 @@ bool password_mode = false; bool mature_word_lists = false; bool did_specify_seed = false; -std::filesystem::path gif_filename = "gif_output.gif"; -std::filesystem::path default_output_path; +std::string gif_filename = "gif_output.gif"; +std::string default_output_path; std::string string_seed; @@ -230,7 +230,7 @@ static void main_win_addon_CB(Fl_Widget *w, void *data) { std::string menu_item = _("Addons/"); Fl_Menu_Bar *menu = (Fl_Menu_Bar *)w; addon_info_t *addon = (addon_info_t *)data; - menu_item.append(addon->name.filename().string()); + menu_item.append(addon->name); const Fl_Menu_Item *checkbox = menu->find_item(menu_item.c_str()); addon->enabled = (checkbox->value() != 0) ? true : false; } @@ -252,13 +252,13 @@ static void main_win_apply_addon_CB(Fl_Widget *w, void *data) { } static void main_win_preset_CB(Fl_Widget *w, void *data) { - std::filesystem::path *preset = (std::filesystem::path *)data; + std::string *preset = (std::string *)data; // adapted from our Config Manager Load/Use callbacks - FILE *fp = fl_fopen(preset->generic_u8string().c_str(), "rb"); + FILE *fp = fl_fopen(preset->c_str(), "rb"); if (!fp) { DLG_ShowError(_("Cannot open: %s\n\n%s"), - preset->filename().u8string().c_str(), + preset->c_str(), strerror(errno)); return; } @@ -348,69 +348,20 @@ static void ShowVersion() { fflush(stdout); } -void Determine_WorkingPath(std::filesystem::path &path_check) { - // firstly find the "Working directory" : that's the place where - // the CONFIG.txt and LOGS.txt files are, as well the temp files. - - if (const int home_arg = argv::Find(0, "home"); home_arg >= 0) { - if (home_arg + 1 >= argv::list.size() || argv::IsOption(home_arg + 1)) { - StdErrPrintf("OBSIDIAN ERROR: missing path for --home\n"); - exit(EXIT_FAILURE); - } - - home_dir = std::filesystem::u8path(argv::list[home_arg + 1]); - return; - } - +void Determine_WorkingPath() { #ifdef _WIN32 - home_dir = path_check; - home_dir.remove_filename(); + home_dir = PHYSFS_getBaseDir(); #else - const char *xdg_config_home = std::getenv("XDG_CONFIG_HOME"); - if (xdg_config_home == nullptr) { - xdg_config_home = std::getenv("HOME"); - if (xdg_config_home == nullptr) { - home_dir = "."; - } else { - home_dir = xdg_config_home; - home_dir /= ".config"; - } - } else { - home_dir = xdg_config_home; - } - home_dir /= "obsidian"; - if (!home_dir.is_absolute()) { - home_dir = std::getenv("HOME"); - home_dir /= ".config/obsidian"; - - if (!home_dir.is_absolute()) { - Main::FatalError("Unable to find $HOME directory!\n"); - } - } -// FLTK is going to want a ~/.config directory as well I think - Dasho -#ifdef __OpenBSD__ - std::filesystem::path config_checker = std::getenv("HOME"); - config_checker /= ".config"; - if (!std::filesystem::exists(config_checker)) { - std::filesystem::create_directory(config_checker); - } -#endif - // try to create it (doesn't matter if it already exists) - if (!std::filesystem::exists(home_dir)) { - std::filesystem::create_directory(home_dir); - } + home_dir = PHYSFS_getUserDir(); #endif - if (home_dir.empty()) { - home_dir = std::filesystem::canonical("."); - } } -std::filesystem::path Resolve_DefaultOutputPath() { +std::string Resolve_DefaultOutputPath() { if (default_output_path.empty()) { default_output_path = install_dir; } - if (default_output_path.generic_u8string()[0] == '$') { - const char *var = getenv(default_output_path.generic_u8string().c_str() + 1); + if (default_output_path[0] == '$') { + const char *var = getenv(default_output_path.c_str() + 1); if (var != nullptr) { return var; } @@ -418,146 +369,51 @@ std::filesystem::path Resolve_DefaultOutputPath() { return default_output_path; } -static bool Verify_InstallDir(const std::filesystem::path &path) { - const std::filesystem::path filename = path / "scripts" / "obsidian.lua"; +static bool Verify_InstallDir(const std::string &path) { + const std::string filename = PathAppend(path, "scripts/obsidian.lua"); - return exists(filename); + return FileExists(filename); } -void Determine_InstallDir(std::filesystem::path &path_check) { - // secondly find the "Install directory", and store the - // result in the global variable 'install_dir'. This is - // where all the LUA scripts and other data files are. - - if (const int inst_arg = argv::Find(0, "install"); inst_arg >= 0) { - if (inst_arg + 1 >= argv::list.size() || argv::IsOption(inst_arg + 1)) { - StdErrPrintf("OBSIDIAN ERROR: missing path for --install\n"); - exit(EXIT_FAILURE); - } - - install_dir = std::filesystem::u8path(argv::list[inst_arg + 1]); - - if (Verify_InstallDir(install_dir)) { - return; - } - - Main::FatalError("Bad install directory specified!\n"); - } - - // if run from current directory, look there - if (path_check == "." && Verify_InstallDir(".")) { - install_dir = std::filesystem::canonical("."); - return; - } - -#ifdef WIN32 - install_dir = home_dir; -#else - if (Verify_InstallDir(std::filesystem::canonical("."))) { - install_dir = std::filesystem::canonical("."); - } -#endif - - if (install_dir.empty()) { - Main::FatalError("Unable to find Obsidian's install directory!\n"); - } +void Determine_InstallDir() { + install_dir = PHYSFS_getBaseDir(); } void Determine_ConfigFile() { - if (const int conf_arg = argv::Find(0, "config"); conf_arg >= 0) { - if (conf_arg + 1 >= argv::list.size() || argv::IsOption(conf_arg + 1)) { - StdErrPrintf("OBSIDIAN ERROR: missing path for --config\n"); - exit(EXIT_FAILURE); - } - - config_file = argv::list[conf_arg + 1]; - } else { - config_file /= home_dir; - config_file /= CONFIG_FILENAME; - } + config_file = PathAppend(home_dir, CONFIG_FILENAME); } void Determine_OptionsFile() { - if (const int optf_arg = argv::Find(0, "options"); optf_arg >= 0) { - if (optf_arg + 1 >= argv::list.size() || argv::IsOption(optf_arg + 1)) { - StdErrPrintf("OBSIDIAN ERROR: missing path for --options\n"); - exit(EXIT_FAILURE); - } - - options_file = argv::list[optf_arg + 1]; - } else { - options_file /= home_dir; - options_file /= OPTIONS_FILENAME; - } + options_file = PathAppend(home_dir, OPTIONS_FILENAME); } #ifndef CONSOLE_ONLY void Determine_ThemeFile() { - if (const int themef_arg = argv::Find(0, "theme"); themef_arg >= 0) { - if (themef_arg + 1 >= argv::list.size() || - argv::IsOption(themef_arg + 1)) { - StdErrPrintf("OBSIDIAN ERROR: missing path for --theme\n"); - exit(EXIT_FAILURE); - } - - theme_file = argv::list[themef_arg + 1]; - } else { - theme_file /= home_dir; - theme_file /= THEME_FILENAME; - } + theme_file = PathAppend(home_dir, THEME_FILENAME); } #endif void Determine_LoggingFile() { - if (const int logf_arg = argv::Find(0, "log"); logf_arg >= 0) { - if (logf_arg + 1 >= argv::list.size() || argv::IsOption(logf_arg + 1)) { - StdErrPrintf("OBSIDIAN ERROR: missing path for --log\n"); - exit(EXIT_FAILURE); - } - - logging_file = std::filesystem::u8path(argv::list[logf_arg + 1]); - - // test that it can be created - std::ofstream fp{logging_file}; - - if (!fp.is_open()) { - Main::FatalError("Cannot create log file: %s\n", - logging_file.u8string().c_str()); - } - - fp.close(); - } else if (!batch_mode) { - logging_file /= home_dir; - logging_file /= LOG_FILENAME; - } else { - logging_file = std::filesystem::current_path(); - logging_file /= LOG_FILENAME; - } + logging_file = PathAppend(home_dir, LOG_FILENAME); } void Determine_ReferenceFile() { if (argv::Find('p', "printref") >= 0) { - if (!batch_mode) { - reference_file /= home_dir; - reference_file /= REF_FILENAME; - } else { - reference_file = std::filesystem::current_path(); - reference_file /= REF_FILENAME; - } + reference_file = PathAppend(home_dir, REF_FILENAME); } } -bool Main::BackupFile(const std::filesystem::path &filename) { - if (std::filesystem::exists(filename)) { - std::filesystem::path backup_name = filename; +bool Main::BackupFile(const std::string &filename) { + if (FileExists(filename)) { + std::string backup_name = filename; - backup_name.replace_extension(StringFormat( - "%s.%s", backup_name.filename().extension().string().c_str(), "bak")); + ReplaceExtension(backup_name, StringFormat( + "%s.%s", GetExtension(backup_name).c_str(), ".bak")); - LogPrintf("Backing up existing file to: %s\n", backup_name.u8string().c_str()); + LogPrintf("Backing up existing file to: %s\n", backup_name.c_str()); - std::filesystem::remove(backup_name); - std::filesystem::rename(filename, backup_name); + FileDelete(backup_name); + FileRename(filename, backup_name); } return true; @@ -1034,7 +890,7 @@ void Main::Detail::Shutdown(const bool error) { main_win = nullptr; } #else - if (!std::filesystem::exists(options_file)) { + if (!FileExists(options_file)) { Options_Save(options_file); } #endif @@ -1236,11 +1092,11 @@ bool Build_Cool_Shit() { ZIPF_CloseWrite(); if (!was_ok) { - if (std::filesystem::exists(game_object->Filename())) { - std::filesystem::remove(game_object->Filename()); + if (FileExists(game_object->Filename())) { + FileDelete(game_object->Filename()); } - if (std::filesystem::exists(game_object->ZIP_Filename())) { - std::filesystem::remove(game_object->ZIP_Filename()); + if (FileExists(game_object->ZIP_Filename())) { + FileDelete(game_object->ZIP_Filename()); } } @@ -1306,6 +1162,11 @@ int main(int argc, char **argv) { hardrestart:; + if (!PHYSFS_init(argv::list[0].c_str())) { + Main::FatalError("Failed to init PhysFS:\n%s\n", + PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + } + if (argv::Find('?', NULL) >= 0 || argv::Find('h', "help") >= 0) { #if defined WIN32 && !defined CONSOLE_ONLY if (AllocConsole()) { @@ -1411,10 +1272,9 @@ hardrestart:; #endif } - std::filesystem::path path_check = std::filesystem::u8path(argv::list[0]); - Determine_WorkingPath(path_check); - Determine_InstallDir(path_check); - + Determine_WorkingPath(); + Determine_InstallDir(); + Trans_Init(); Determine_ConfigFile(); Determine_OptionsFile(); #ifndef CONSOLE_ONLY @@ -1451,11 +1311,9 @@ hardrestart:; FL_MINOR_VERSION, FL_PATCH_VERSION); #endif - LogPrintf("home_dir: %s\n", home_dir.u8string().c_str()); - LogPrintf("install_dir: %s\n", install_dir.u8string().c_str()); - LogPrintf("config_file: %s\n\n", config_file.u8string().c_str()); - - Trans_Init(); + LogPrintf("home_dir: %s\n", home_dir.c_str()); + LogPrintf("install_dir: %s\n", install_dir.c_str()); + LogPrintf("config_file: %s\n\n", config_file.c_str()); if (!batch_mode) { #ifndef CONSOLE_ONLY @@ -1560,7 +1418,7 @@ softrestart:; Main::FatalError(_("No such config file: %s\n"), load_file.c_str()); } } else { - if (!std::filesystem::exists(config_file)) { + if (!FileExists(config_file)) { Cookie_Save(config_file); } if (!Cookie_Load(config_file)) { @@ -1718,7 +1576,7 @@ softrestart:; nullptr, main_win_apply_addon_CB, nullptr, 0); for (int i = 0; i < all_addons.size(); i++) { std::string addon_entry = _("Addons/"); - addon_entry.append(all_addons[i].name.filename().string()); + addon_entry.append(all_addons[i].name); main_win->menu_bar->add( addon_entry.c_str(), nullptr, main_win_addon_CB, (void *)&all_addons[i], @@ -1736,7 +1594,7 @@ softrestart:; nullptr, nullptr, nullptr, FL_MENU_INACTIVE); for (int i = 0; i < all_presets.size(); i++) { std::string preset_entry = _("Presets/"); - preset_entry.append(all_presets[i].stem().string()); + preset_entry.append(GetStem(all_presets[i])); main_win->menu_bar->add( preset_entry.c_str(), nullptr, main_win_preset_CB, (void *)&all_presets[i], 0); diff --git a/source_files/obsidian_main/main.h b/source_files/obsidian_main/main.h index 4a9eff6508..08ecc009b9 100644 --- a/source_files/obsidian_main/main.h +++ b/source_files/obsidian_main/main.h @@ -27,7 +27,6 @@ #include #include #include -#include #ifndef CONSOLE_ONLY #include "hdr_fltk.h" #include "ui_window.h" @@ -61,17 +60,17 @@ constexpr const char *REF_FILENAME = "REFERENCE.txt"; extern int v_unload_private_font(const char *path); #endif -extern std::filesystem::path home_dir; -extern std::filesystem::path install_dir; -extern std::filesystem::path config_file; -extern std::filesystem::path options_file; -extern std::filesystem::path theme_file; -extern std::filesystem::path logging_file; -extern std::filesystem::path reference_file; +extern std::string home_dir; +extern std::string install_dir; +extern std::string config_file; +extern std::string options_file; +extern std::string theme_file; +extern std::string logging_file; +extern std::string reference_file; extern bool batch_mode; -extern std::filesystem::path batch_output_file; +extern std::string batch_output_file; extern unsigned long long next_rand_seed; @@ -155,7 +154,7 @@ extern bool did_specify_seed; extern std::string def_filename; -extern std::filesystem::path last_directory; +extern std::string last_directory; extern std::string numeric_locale; extern std::vector batch_randomize_groups; @@ -163,15 +162,15 @@ extern std::vector batch_randomize_groups; // Dialog Windows void DLG_ShowError(const char *msg, ...); -std::filesystem::path DLG_OutputFilename(const char *ext, +std::string DLG_OutputFilename(const char *ext, const char *preset = nullptr); #endif -extern std::filesystem::path default_output_path; +extern std::string default_output_path; -extern std::filesystem::path Resolve_DefaultOutputPath(); +extern std::string Resolve_DefaultOutputPath(); -extern std::filesystem::path gif_filename; +extern std::string gif_filename; extern std::string string_seed; extern std::string selected_lang; @@ -230,7 +229,7 @@ void ProgStatus(std::string_view msg, Args &&...args) { StdErrPrintf("%s\n", buffer.c_str()); #endif } -bool BackupFile(const std::filesystem::path &filename); +bool BackupFile(const std::string &filename); #if defined WIN32 && !defined CONSOLE_ONLY void Blinker(); #endif @@ -298,9 +297,9 @@ class game_interface_c { // properties are ignored. May be called during startup too. virtual void Property(std::string key, std::string value) = 0; - virtual std::filesystem::path Filename() = 0; + virtual std::string Filename() = 0; - virtual std::filesystem::path ZIP_Filename() = 0; + virtual std::string ZIP_Filename() = 0; // likely only useful for Doom, but informs the program if it needs to package // each map in its own native format (WAD, etc) @@ -312,8 +311,6 @@ extern game_interface_c *game_object; /* interface for each game format */ game_interface_c *Doom_GameObject(); -game_interface_c *Quake1_GameObject(); -game_interface_c *Quake2_GameObject(); game_interface_c *Wolf_GameObject(); #endif /* __OBSIDIAN_MAIN_H__ */ diff --git a/source_files/obsidian_main/sys_debug.cc b/source_files/obsidian_main/sys_debug.cc index 58746f4ce5..85c2f46d39 100644 --- a/source_files/obsidian_main/sys_debug.cc +++ b/source_files/obsidian_main/sys_debug.cc @@ -30,13 +30,13 @@ std::fstream log_file; std::fstream ref_file; -std::filesystem::path log_filename; -std::filesystem::path ref_filename; +std::string log_filename; +std::string ref_filename; bool debugging = false; bool terminal = false; -bool LogInit(const std::filesystem::path &filename) { +bool LogInit(const std::string &filename) { if (!filename.empty()) { log_filename = filename; @@ -57,13 +57,13 @@ bool LogInit(const std::filesystem::path &filename) { return true; } -bool RefInit(const std::filesystem::path &filename) { +bool RefInit(const std::string &filename) { if (!filename.empty()) { ref_filename = filename; // Clear previously generated reference if present - if (std::filesystem::exists(ref_filename)) { - std::filesystem::remove(ref_filename); + if (FileExists(ref_filename)) { + FileDelete(ref_filename); } ref_file.open(ref_filename, std::ios::out); diff --git a/source_files/obsidian_main/sys_debug.h b/source_files/obsidian_main/sys_debug.h index 08feeef89d..87182ffb98 100644 --- a/source_files/obsidian_main/sys_debug.h +++ b/source_files/obsidian_main/sys_debug.h @@ -23,7 +23,6 @@ #define __SYS_DEBUG_H__ #include -#include #include #include #include @@ -33,9 +32,9 @@ extern std::fstream log_file; extern std::fstream ref_file; extern std::string StringFormat(std::string_view str, ...); -bool LogInit(const std::filesystem::path &filename); // NULL for none +bool LogInit(const std::string &filename); // NULL for none void LogClose(void); -bool RefInit(const std::filesystem::path &filename); // NULL for none +bool RefInit(const std::string &filename); // NULL for none void RefClose(void); void LogEnableDebug(bool enable); diff --git a/source_files/obsidian_main/ui_map.cc b/source_files/obsidian_main/ui_map.cc index 773fba31ae..b5ed2eb205 100644 --- a/source_files/obsidian_main/ui_map.cc +++ b/source_files/obsidian_main/ui_map.cc @@ -303,10 +303,10 @@ void UI_MiniMap::DrawEntity(int x, int y, uint8_t r, uint8_t g, uint8_t b) { RawPixel(x, y + 1, r, g, b); } -void UI_MiniMap::GifStart(std::filesystem::path filename, int delay) { +void UI_MiniMap::GifStart(std::string filename, int delay) { gif_writer = new GifWriter; gif_delay = delay; - GifBegin(gif_writer, filename.generic_u8string().c_str(), map_W, map_H, gif_delay); + GifBegin(gif_writer, FileOpen(filename, "wb"), map_W, map_H, gif_delay); } void UI_MiniMap::GifFrame() { diff --git a/source_files/obsidian_main/ui_map.h b/source_files/obsidian_main/ui_map.h index ef28c27186..9c2abeff97 100644 --- a/source_files/obsidian_main/ui_map.h +++ b/source_files/obsidian_main/ui_map.h @@ -24,7 +24,6 @@ #include "FL/Fl_Box.H" #include "FL/Fl_Image.H" -#include class UI_MiniMap : public Fl_Box { private: @@ -55,7 +54,7 @@ class UI_MiniMap : public Fl_Box { void MapClear(); - void GifStart(std::filesystem::path filename, int delay); + void GifStart(std::string filename, int delay); void GifFrame(); void GifFinish(); diff --git a/source_files/slump/dump.cc b/source_files/slump/dump.cc index a060459e76..35b5a22c17 100644 --- a/source_files/slump/dump.cc +++ b/source_files/slump/dump.cc @@ -72,7 +72,7 @@ dumphandle OpenDump(config *c) answer = (dumphandle)malloc(sizeof (*answer)); #ifdef _WIN32 - answer->f = _wfopen(std::filesystem::u8path(c->outfile).c_str(), UTF8ToWString("wb").c_str()); + answer->f = _wfopen(UTF8ToWString(c->outfile).c_str(), UTF8ToWString("wb").c_str()); #else answer->f = fopen(c->outfile,"wb"); #endif diff --git a/source_files/slump/slump.cc b/source_files/slump/slump.cc index 0b434d0247..0155c32a87 100644 --- a/source_files/slump/slump.cc +++ b/source_files/slump/slump.cc @@ -1116,7 +1116,7 @@ void secretize_config(config *c) /* 3. Parse the arglist to get overrides to switches, */ /* 4. Read the config for non-switches (flats, themes, etc). */ /* 5. Do postproduction defaults and calculations and such. */ -config *get_config(std::filesystem::path filename) { +config *get_config(std::string filename) { config *answer; int i; genus *m; @@ -1125,7 +1125,7 @@ config *get_config(std::filesystem::path filename) { /* Set various defaults and stuff */ answer->cwadonly = SLUMP_FALSE; - answer->outfile = strdup(filename.generic_u8string().c_str()); + answer->outfile = strdup(filename.c_str()); ok_to_roll = SLUMP_TRUE; diff --git a/source_files/slump/slump.h b/source_files/slump/slump.h index cf44562aaf..840f5d50bf 100644 --- a/source_files/slump/slump.h +++ b/source_files/slump/slump.h @@ -29,8 +29,9 @@ * - Please do not call any derivative of this program SLIGE. */ -#include -#include +#include + +#include #include /* Slump 0.003.02 */ @@ -913,7 +914,7 @@ typedef struct s_config { /* Lots and lots and lots of functions */ /* And this isn't even all of 'em! */ -config *get_config(std::filesystem::path filename); +config *get_config(std::string filename); void NewLevel(level *l, haa *init_haa, config *c); void DumpLevel(dumphandle dh,config *c,level *l,int episode,int mission,int map); void FreeLevel(level *l); diff --git a/source_files/slump/slump_main.cc b/source_files/slump/slump_main.cc index 92838a0fbe..35c76a1e9d 100644 --- a/source_files/slump/slump_main.cc +++ b/source_files/slump/slump_main.cc @@ -34,7 +34,8 @@ #include #include #include -#include + +#include // Global variables int current_level_number = 0; @@ -57,7 +58,7 @@ void machioize(config *c,float amount) { } } - bool slump_main(std::filesystem::path filename) { + bool slump_main(std::string filename) { /* A stubby but functional main() */ diff --git a/source_files/slump/slump_main.h b/source_files/slump/slump_main.h index 7ef1728191..0a00a31604 100644 --- a/source_files/slump/slump_main.h +++ b/source_files/slump/slump_main.h @@ -1,2 +1,2 @@ // Simple hook header for Obsidian to call SLUMP; will flesh out as more things are working - Dashodanger -bool slump_main(std::filesystem::path filename); +bool slump_main(std::string filename);