From 3472a614ae3b4ecf7f49516a97d387761f0f5820 Mon Sep 17 00:00:00 2001 From: aap Date: Thu, 13 Jun 2019 01:12:37 +0200 Subject: [PATCH] fixed CFileMgr somewhat; still issues when loading saves --- src/Directory.cpp | 2 +- src/FileMgr.cpp | 18 ++++++++++++------ src/FileMgr.h | 2 +- src/common.h | 2 -- src/config.h | 1 + src/re3.cpp | 11 ----------- src/skel/win/win.cpp | 7 +++++++ 7 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/Directory.cpp b/src/Directory.cpp index 553dd539..3e0d5382 100644 --- a/src/Directory.cpp +++ b/src/Directory.cpp @@ -23,7 +23,7 @@ CDirectory::ReadDirFile(const char *filename) fd = CFileMgr::OpenFile(filename, "rb"); while(CFileMgr::Read(fd, (char*)&dirinfo, sizeof(dirinfo))) AddItem(dirinfo); - return CFileMgr::CloseFile(fd); + CFileMgr::CloseFile(fd); } bool diff --git a/src/FileMgr.cpp b/src/FileMgr.cpp index 3aad9794..02c797ba 100644 --- a/src/FileMgr.cpp +++ b/src/FileMgr.cpp @@ -5,6 +5,8 @@ #include "patcher.h" #include "FileMgr.h" +const char *_psGetUserFilesFolder(); + /* * Windows FILE is BROKEN for GTA. * @@ -49,14 +51,17 @@ found: return fd; } -static void +static int myfclose(int fd) { + int ret; assert(fd < NUMFILES); if(myfiles[fd].file){ - fclose(myfiles[fd].file); + ret = fclose(myfiles[fd].file); myfiles[fd].file = nil; + return ret; } + return EOF; } static int @@ -158,7 +163,8 @@ myfseek(int fd, long offset, int whence) static int myfeof(int fd) { - return feof(myfiles[fd].file); +// return feof(myfiles[fd].file); + return ferror(myfiles[fd].file); } @@ -205,7 +211,7 @@ void CFileMgr::SetDirMyDocuments(void) { SetDir(""); // better start at the root if user directory is relative - chdir(GetUserDirectory()); + chdir(_psGetUserFilesFolder()); } int @@ -265,10 +271,10 @@ CFileMgr::ReadLine(int fd, char *buf, int len) return myfgets(buf, len, fd); } -void +int CFileMgr::CloseFile(int fd) { - myfclose(fd); + return myfclose(fd); } int diff --git a/src/FileMgr.h b/src/FileMgr.h index a77ae6fa..f67056f1 100644 --- a/src/FileMgr.h +++ b/src/FileMgr.h @@ -16,6 +16,6 @@ public: static int Write(int fd, char *buf, int len); static bool Seek(int fd, int offset, int whence); static char *ReadLine(int fd, char *buf, int len); - static void CloseFile(int fd); + static int CloseFile(int fd); static int GetErrorReadWrite(int fd); }; diff --git a/src/common.h b/src/common.h index e110e67f..4187e0c3 100644 --- a/src/common.h +++ b/src/common.h @@ -72,8 +72,6 @@ extern void **rwengine; #define SCREEN_FROM_RIGHT(a) Float(SCREEN_WIDTH - SCREEN_STRETCH_X(a)) #define SCREEN_FROM_BOTTOM(a) Float(SCREEN_HEIGHT - SCREEN_STRETCH_Y(a)) -char *GetUserDirectory(void); - struct GlobalScene { RpWorld *world; diff --git a/src/config.h b/src/config.h index 8ef51871..71689778 100644 --- a/src/config.h +++ b/src/config.h @@ -65,3 +65,4 @@ enum Config { //#define FIX_BUGS //#define NO_CDCHECK #define NO_MOVIES +//#define USE_MY_DOCUMENTS diff --git a/src/re3.cpp b/src/re3.cpp index 55ce5699..905aa992 100644 --- a/src/re3.cpp +++ b/src/re3.cpp @@ -47,17 +47,6 @@ mysrand(unsigned int seed) myrand_seed = seed; } -// platform stuff -char* -GetUserDirectory(void) -{ - static char path[MAX_PATH]; - strcpy(path, "userfiles"); - mkdir(path); - return path; -} - - int (*open_script_orig)(const char *path, const char *mode); int open_script(const char *path, const char *mode) diff --git a/src/skel/win/win.cpp b/src/skel/win/win.cpp index c26855eb..3ca4aa5d 100644 --- a/src/skel/win/win.cpp +++ b/src/skel/win/win.cpp @@ -191,6 +191,7 @@ void _psCreateFolder(LPCSTR path) */ const char *_psGetUserFilesFolder() { +#ifdef USE_MY_DOCUMENTS HKEY hKey = NULL; static CHAR szUserFiles[256]; @@ -221,6 +222,12 @@ const char *_psGetUserFilesFolder() strcpy(szUserFiles, "data"); return szUserFiles; +#else + static CHAR szUserFiles[256]; + strcpy(szUserFiles, "userfiles"); + _psCreateFolder(szUserFiles); + return szUserFiles; +#endif } /*