Core: Create game-related paths if they don't exist (fixes #1446)

This commit is contained in:
Vicki Pfau 2019-06-17 12:57:45 -07:00
parent 34ddae8e4d
commit 918caf87c4
7 changed files with 46 additions and 0 deletions

View File

@ -53,6 +53,7 @@ Misc:
- Qt: Make mute menu option also toggle fast-forward mute (fixes mgba.io/i/1424)
- Vita: L2/R2 and L3/R3 can now be mapped on PSTV (fixes mgba.io/i/1292)
- mGUI: Remember name and position of last loaded game
- Core: Create game-related paths if they don't exist (fixes mgba.io/i/1446)
0.7.2: (2019-05-25)
Emulation fixes:

View File

@ -91,6 +91,8 @@ struct VDir* VDirOpen7z(const char* path, int flags);
struct VDir* VDeviceList(void);
#endif
bool VDirCreate(const char* path);
#ifdef USE_VFS_FILE
struct VFile* VFileFOpen(const char* path, const char* mode);
struct VFile* VFileFromFILE(FILE* file);

View File

@ -173,6 +173,9 @@ struct VFile* mDirectorySetOpenSuffix(struct mDirectorySet* dirs, struct VDir* d
void mDirectorySetMapOptions(struct mDirectorySet* dirs, const struct mCoreOptions* opts) {
if (opts->savegamePath) {
struct VDir* dir = VDirOpen(opts->savegamePath);
if (!dir && VDirCreate(opts->savegamePath)) {
dir = VDirOpen(opts->savegamePath);
}
if (dir) {
if (dirs->save && dirs->save != dirs->base) {
dirs->save->close(dirs->save);
@ -183,6 +186,9 @@ void mDirectorySetMapOptions(struct mDirectorySet* dirs, const struct mCoreOptio
if (opts->savestatePath) {
struct VDir* dir = VDirOpen(opts->savestatePath);
if (!dir && VDirCreate(opts->savestatePath)) {
dir = VDirOpen(opts->savestatePath);
}
if (dir) {
if (dirs->state && dirs->state != dirs->base) {
dirs->state->close(dirs->state);
@ -193,6 +199,9 @@ void mDirectorySetMapOptions(struct mDirectorySet* dirs, const struct mCoreOptio
if (opts->screenshotPath) {
struct VDir* dir = VDirOpen(opts->screenshotPath);
if (!dir && VDirCreate(opts->screenshotPath)) {
dir = VDirOpen(opts->screenshotPath);
}
if (dir) {
if (dirs->screenshot && dirs->screenshot != dirs->base) {
dirs->screenshot->close(dirs->screenshot);
@ -203,6 +212,9 @@ void mDirectorySetMapOptions(struct mDirectorySet* dirs, const struct mCoreOptio
if (opts->patchPath) {
struct VDir* dir = VDirOpen(opts->patchPath);
if (!dir && VDirCreate(opts->patchPath)) {
dir = VDirOpen(opts->patchPath);
}
if (dir) {
if (dirs->patch && dirs->patch != dirs->base) {
dirs->patch->close(dirs->patch);
@ -213,6 +225,9 @@ void mDirectorySetMapOptions(struct mDirectorySet* dirs, const struct mCoreOptio
if (opts->cheatsPath) {
struct VDir* dir = VDirOpen(opts->cheatsPath);
if (!dir && VDirCreate(opts->cheatsPath)) {
dir = VDirOpen(opts->cheatsPath);
}
if (dir) {
if (dirs->cheats && dirs->cheats != dirs->base) {
dirs->cheats->close(dirs->cheats);

View File

@ -310,4 +310,9 @@ static enum VFSType _vd3deType(struct VDirEntry* vde) {
}
return VFS_FILE;
}
bool VDirCreate(const char* path) {
Result rc = FSUSER_CreateDirectory(sdmcArchive, fsMakePath(PATH_ASCII, path), 0);
return R_SUCCEEDED(rc) || rc == 0xC82044BE;
}
#endif

View File

@ -357,3 +357,9 @@ static enum VFSType _vdlesceType(struct VDirEntry* vde) {
UNUSED(vde);
return VFS_DIRECTORY;
}
bool VDirCreate(const char* path) {
// TODO: Verify vitasdk explanation of return values
sceIoMkdir(path, 0777);
return true;
}

View File

@ -172,3 +172,15 @@ static enum VFSType _vdweType(struct VDirEntry* vde) {
}
return VFS_FILE;
}
bool VDirCreate(const char* path) {
wchar_t wpath[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_PATH);
if (CreateDirectoryW(wpath, NULL)) {
return true;
}
if (GetLastError() == ERROR_ALREADY_EXISTS) {
return true;
}
return false;
}

View File

@ -8,6 +8,7 @@
#include <mgba-util/string.h>
#include <dirent.h>
#include <errno.h>
#include <sys/stat.h>
static bool _vdClose(struct VDir* vd);
@ -166,3 +167,7 @@ static enum VFSType _vdeType(struct VDirEntry* vde) {
return VFS_FILE;
#endif
}
bool VDirCreate(const char* path) {
return mkdir(path, 0777) == 0 || errno == EEXIST;
}