diff --git a/src/loadsave.cc b/src/loadsave.cc index a67d93f..4bdf654 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -41,7 +41,6 @@ #include "world_map.h" #include -#include #include #include @@ -1322,21 +1321,21 @@ int lsgPerformSaveGame() backgroundSoundPause(); sprintf(_gmpath, "%s\\%s", _patches, "SAVEGAME"); - mkdir(_gmpath); + compat_mkdir(_gmpath); sprintf(_gmpath, "%s\\%s\\%s%.2d", _patches, "SAVEGAME", "SLOT", _slot_cursor + 1); - mkdir(_gmpath); + compat_mkdir(_gmpath); strcat(_gmpath, "\\proto"); - mkdir(_gmpath); + compat_mkdir(_gmpath); char* protoBasePath = _gmpath + strlen(_gmpath); strcpy(protoBasePath, "\\critters"); - mkdir(_gmpath); + compat_mkdir(_gmpath); strcpy(protoBasePath, "\\items"); - mkdir(_gmpath); + compat_mkdir(_gmpath); if (_SaveBackup() == -1) { debugPrint("\nLOADSAVE: Warning, can't backup save file!\n"); diff --git a/src/map.cc b/src/map.cc index 21350b2..090e470 100644 --- a/src/map.cc +++ b/src/map.cc @@ -33,7 +33,6 @@ #include "window_manager.h" #include "world_map.h" -#include #include // 0x50B058 @@ -1263,10 +1262,10 @@ int _map_save() char* masterPatchesPath; if (configGetString(&gGameConfig, GAME_CONFIG_SYSTEM_KEY, GAME_CONFIG_MASTER_PATCHES_KEY, &masterPatchesPath)) { strcat(temp, masterPatchesPath); - mkdir(temp); + compat_mkdir(temp); strcat(temp, "\\MAPS"); - mkdir(temp); + compat_mkdir(temp); } int rc = -1; @@ -1451,10 +1450,10 @@ void mapMakeMapsDirectory() strcpy(path, "DATA"); } - mkdir(path); + compat_mkdir(path); strcat(path, "\\MAPS"); - mkdir(path); + compat_mkdir(path); } // 0x483ED0 diff --git a/src/platform_compat.cc b/src/platform_compat.cc index 2b9623f..34f6f9e 100644 --- a/src/platform_compat.cc +++ b/src/platform_compat.cc @@ -97,3 +97,13 @@ long compat_filelength(int fd) lseek(fd, originalOffset, SEEK_SET); return filesize; } + +int compat_mkdir(const char* path) +{ + std::error_code ec; + if (std::filesystem::create_directory(std::filesystem::path(path), ec)) { + return 0; + } + + return ec.value(); +} diff --git a/src/platform_compat.h b/src/platform_compat.h index 1b63744..759bda8 100644 --- a/src/platform_compat.h +++ b/src/platform_compat.h @@ -25,5 +25,6 @@ char* compat_itoa(int value, char* buffer, int radix); void compat_splitpath(const char* path, char* drive, char* dir, char* fname, char* ext); void compat_makepath(char* path, const char* drive, const char* dir, const char* fname, const char* ext); long compat_filelength(int fd); +int compat_mkdir(const char* path); #endif /* PLATFORM_COMPAT_H */ diff --git a/src/proto.cc b/src/proto.cc index 46bab71..d47eeb9 100644 --- a/src/proto.cc +++ b/src/proto.cc @@ -19,7 +19,6 @@ #include "stat.h" #include "trait.h" -#include #include #include @@ -1047,13 +1046,13 @@ int protoInit() sprintf(path, "%s\\proto", master_patches); len = strlen(path); - mkdir(path); + compat_mkdir(path); strcpy(path + len, "\\critters"); - mkdir(path); + compat_mkdir(path); strcpy(path + len, "\\items"); - mkdir(path); + compat_mkdir(path); // TODO: Get rid of cast. _proto_critter_init((Proto*)&gDudeProto, 0x1000000); diff --git a/src/xfile.cc b/src/xfile.cc index 3a2f6e3..d0809cf 100644 --- a/src/xfile.cc +++ b/src/xfile.cc @@ -3,7 +3,11 @@ #include "file_find.h" #include +#ifdef _WIN32 #include +#else +#include +#endif #include #include #include @@ -716,7 +720,7 @@ int xbaseMakeDirectory(const char* filePath) *pch = '\0'; if (chdir(path) != 0) { - if (mkdir(path) != 0) { + if (compat_mkdir(path) != 0) { chdir(workingDirectory); return -1; } @@ -730,7 +734,7 @@ int xbaseMakeDirectory(const char* filePath) } // Last path component. - mkdir(path); + compat_mkdir(path); chdir(workingDirectory);