fixed CFileMgr somewhat; still issues when loading saves

This commit is contained in:
aap 2019-06-13 01:12:37 +02:00
parent 9703ef9b59
commit 3472a614ae
7 changed files with 22 additions and 21 deletions

View file

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

View file

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

View file

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

View file

@ -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;

View file

@ -65,3 +65,4 @@ enum Config {
//#define FIX_BUGS
//#define NO_CDCHECK
#define NO_MOVIES
//#define USE_MY_DOCUMENTS

View file

@ -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)

View file

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