mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-09-22 22:48:08 +03:00
Fix fileCheckExist
This fixes https://github.com/kichikuou/xsystem35-sdl2/issues/55.
This commit is contained in:
+18
-3
@@ -42,11 +42,14 @@
|
||||
#include "ald_manager.h"
|
||||
#include "LittleEndian.h"
|
||||
#include "hacks.h"
|
||||
#include "filecheck.h"
|
||||
|
||||
/* 選択 Window OPEN 時 callback */
|
||||
static int cb_sel_init_page = 0;
|
||||
static int cb_sel_init_address = 0;
|
||||
|
||||
static const char REGREADSTRING_RESULT[] = "*regReadString*";
|
||||
|
||||
extern INPUTSTRING_PARAM mi_param;
|
||||
|
||||
extern void commandH();
|
||||
@@ -1441,7 +1444,10 @@ void commands2F87() {
|
||||
int eBaneStrNum = getCaliValue();
|
||||
int eResultStrNum = getCaliValue();
|
||||
int *vResult = getCaliVariable();
|
||||
|
||||
|
||||
// This command is used to check if the game is installed, so we always
|
||||
// return 1 with the dummy string REGREADSTRING_RESULT.
|
||||
svar_set(eResultStrNum, REGREADSTRING_RESULT);
|
||||
*vResult = 1;
|
||||
|
||||
DEBUG_COMMAND("regReadString %d,%d,%d,%d:",
|
||||
@@ -1451,8 +1457,17 @@ void commands2F87() {
|
||||
void commands2F88() {
|
||||
int eFileNameStrNum = getCaliValue();
|
||||
int *vResult = getCaliVariable();
|
||||
|
||||
*vResult = 1;
|
||||
|
||||
const char *fname = svar_get(eFileNameStrNum);
|
||||
if (strcmp(fname, REGREADSTRING_RESULT) == 0) {
|
||||
// If this command is called with the result of regReadString, the game
|
||||
// is checking if the game CD is inserted. We return 1 in this case.
|
||||
*vResult = 1;
|
||||
} else {
|
||||
char *fname_utf8 = sjis2utf(fname);
|
||||
*vResult = fc_exists(fname_utf8) ? 1 : 0;
|
||||
free(fname_utf8);
|
||||
}
|
||||
|
||||
DEBUG_COMMAND("fileCheckExist %d,%d:", eFileNameStrNum, *vResult);
|
||||
}
|
||||
|
||||
+21
-2
@@ -29,11 +29,10 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#include <windows.h>
|
||||
#undef min
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#include "filecheck.h"
|
||||
@@ -126,6 +125,18 @@ char *fc_get_path(const char *fname_utf8) {
|
||||
return get_fullpath(saveDataPath, fname_utf8);
|
||||
}
|
||||
|
||||
bool fc_exists(const char *fname_utf8)
|
||||
{
|
||||
char *path = fc_get_path(fname_utf8);
|
||||
wchar_t wpath[PATH_MAX + 1];
|
||||
bool result = false;
|
||||
if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path, -1, wpath, PATH_MAX + 1)) {
|
||||
result = _waccess(wpath, F_OK) != -1;
|
||||
}
|
||||
free(path);
|
||||
return result;
|
||||
}
|
||||
|
||||
FILE *fc_open(const char *fname_utf8, char type) {
|
||||
char *path = fc_get_path(fname_utf8);
|
||||
FILE *fp = fopen_utf8(path, type);
|
||||
@@ -162,6 +173,14 @@ char *fc_get_path(const char *fname_utf8) {
|
||||
return get_fullpath(saveDataPath, fname_utf8);
|
||||
}
|
||||
|
||||
bool fc_exists(const char *fname_utf8)
|
||||
{
|
||||
char *path = fc_get_path(fname_utf8);
|
||||
bool result = access(path, F_OK) != -1;
|
||||
free(path);
|
||||
return result;
|
||||
}
|
||||
|
||||
FILE *fc_open(const char *fname_utf8, char type) {
|
||||
char *fullpath = fc_search(fname_utf8, saveDataPath);
|
||||
if (!fullpath) {
|
||||
|
||||
+7
-4
@@ -24,9 +24,12 @@
|
||||
#ifndef __FILECHECK_H__
|
||||
#define __FILECHECK_H__
|
||||
|
||||
extern void fc_init(const char *name);
|
||||
extern char *fc_get_path(const char *fname_utf8);
|
||||
extern FILE *fc_open(const char *fname_utf8, char type);
|
||||
extern void fc_backup_oldfile(const char *filename);
|
||||
#include <stdbool.h>
|
||||
|
||||
void fc_init(const char *name);
|
||||
char *fc_get_path(const char *fname_utf8);
|
||||
bool fc_exists(const char *fname_utf8);
|
||||
FILE *fc_open(const char *fname_utf8, char type);
|
||||
void fc_backup_oldfile(const char *filename);
|
||||
|
||||
#endif /* !__FILECHECK_H__ */
|
||||
|
||||
Reference in New Issue
Block a user