Provide mkdir compatibility layer

See #17, #24
This commit is contained in:
Alexander Batalov 2022-05-29 18:08:55 +03:00
parent e75349c98b
commit 3d477ed235
6 changed files with 29 additions and 17 deletions

View File

@ -41,7 +41,6 @@
#include "world_map.h"
#include <assert.h>
#include <direct.h>
#include <stdio.h>
#include <time.h>
@ -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");

View File

@ -33,7 +33,6 @@
#include "window_manager.h"
#include "world_map.h"
#include <direct.h>
#include <stdio.h>
// 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

View File

@ -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();
}

View File

@ -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 */

View File

@ -19,7 +19,6 @@
#include "stat.h"
#include "trait.h"
#include <direct.h>
#include <stdio.h>
#include <string.h>
@ -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);

View File

@ -3,7 +3,11 @@
#include "file_find.h"
#include <assert.h>
#ifdef _WIN32
#include <direct.h>
#else
#include <unistd.h>
#endif
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
@ -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);