mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-12-01 08:31:45 +00:00
- got rid of M_ReadFile(Malloc) which werew each used only once in the entire code. These were still using the low level POSIX-style file interface which shouldn't really be used anymore.
- let FScanner::OpenFile return an error instead of throwing an exception. The exception was never used anyway aside from being caught right away to be ignored.
This commit is contained in:
parent
e15b23f132
commit
838e52001c
8 changed files with 39 additions and 81 deletions
|
@ -532,13 +532,9 @@ bool FCajunMaster::LoadBots ()
|
|||
DPrintf (DMSG_ERROR, "No " BOTFILENAME ", so no bots\n");
|
||||
return false;
|
||||
}
|
||||
try
|
||||
if (!sc.OpenFile(tmp))
|
||||
{
|
||||
sc.OpenFile(tmp);
|
||||
}
|
||||
catch (CRecoverableError &err)
|
||||
{
|
||||
Printf("%s. So no bots\n", err.GetMessage());
|
||||
Printf("Unable to open %s. So no bots\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -2798,7 +2798,17 @@ void G_DoPlayDemo (void)
|
|||
{
|
||||
FixPathSeperator (defdemoname);
|
||||
DefaultExtension (defdemoname, ".lmp");
|
||||
M_ReadFileMalloc (defdemoname, &demobuffer);
|
||||
FileReader fr;
|
||||
if (!fr.Open(defdemoname))
|
||||
{
|
||||
I_Error("Unable to open demo '%s'", defdemoname.GetChars());
|
||||
}
|
||||
auto len = fr.GetLength();
|
||||
demobuffer = (uint8_t*)M_Malloc(len);
|
||||
if (fr.Read(demobuffer, len) != len)
|
||||
{
|
||||
I_Error("Unable to read demo '%s'", defdemoname.GetChars());
|
||||
}
|
||||
}
|
||||
demo_p = demobuffer;
|
||||
|
||||
|
|
|
@ -115,60 +115,6 @@ bool M_WriteFile (char const *name, void *source, int length)
|
|||
}
|
||||
|
||||
|
||||
//
|
||||
// M_ReadFile
|
||||
//
|
||||
int M_ReadFile (char const *name, uint8_t **buffer)
|
||||
{
|
||||
int handle, count, length;
|
||||
struct stat fileinfo;
|
||||
uint8_t *buf;
|
||||
|
||||
handle = open (name, O_RDONLY | O_BINARY, 0666);
|
||||
if (handle == -1)
|
||||
I_Error ("Couldn't read file %s", name);
|
||||
// [BL] Use stat instead of fstat for v140_xp hack
|
||||
if (stat (name,&fileinfo) == -1)
|
||||
I_Error ("Couldn't read file %s", name);
|
||||
length = fileinfo.st_size;
|
||||
buf = new uint8_t[length];
|
||||
count = read (handle, buf, length);
|
||||
close (handle);
|
||||
|
||||
if (count < length)
|
||||
I_Error ("Couldn't read file %s", name);
|
||||
|
||||
*buffer = buf;
|
||||
return length;
|
||||
}
|
||||
|
||||
//
|
||||
// M_ReadFile (same as above but use malloc instead of new to allocate the buffer.)
|
||||
//
|
||||
int M_ReadFileMalloc (char const *name, uint8_t **buffer)
|
||||
{
|
||||
int handle, count, length;
|
||||
struct stat fileinfo;
|
||||
uint8_t *buf;
|
||||
|
||||
handle = open (name, O_RDONLY | O_BINARY, 0666);
|
||||
if (handle == -1)
|
||||
I_Error ("Couldn't read file %s", name);
|
||||
// [BL] Use stat instead of fstat for v140_xp hack
|
||||
if (stat (name,&fileinfo) == -1)
|
||||
I_Error ("Couldn't read file %s", name);
|
||||
length = fileinfo.st_size;
|
||||
buf = (uint8_t*)M_Malloc(length);
|
||||
count = read (handle, buf, length);
|
||||
close (handle);
|
||||
|
||||
if (count < length)
|
||||
I_Error ("Couldn't read file %s", name);
|
||||
|
||||
*buffer = buf;
|
||||
return length;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// PROC M_FindResponseFile
|
||||
|
|
|
@ -34,8 +34,6 @@ class FIWadManager;
|
|||
extern FGameConfigFile *GameConfig;
|
||||
|
||||
bool M_WriteFile (char const *name, void *source, int length);
|
||||
int M_ReadFile (char const *name, uint8_t **buffer);
|
||||
int M_ReadFileMalloc (char const *name, uint8_t **buffer);
|
||||
void M_FindResponseFile (void);
|
||||
|
||||
// [RH] M_ScreenShot now accepts a filename parameter.
|
||||
|
|
|
@ -122,17 +122,18 @@ static TArray<FString> ParseSteamRegistry(const char* path)
|
|||
|
||||
// Read registry data
|
||||
FScanner sc;
|
||||
sc.OpenFile(path);
|
||||
if (sc.OpenFile(path))
|
||||
{
|
||||
sc.SetCMode(true);
|
||||
|
||||
// Find the SteamApps listing
|
||||
if(PSR_FindAndEnterBlock(sc, "InstallConfigStore"))
|
||||
if (PSR_FindAndEnterBlock(sc, "InstallConfigStore"))
|
||||
{
|
||||
if(PSR_FindAndEnterBlock(sc, "Software"))
|
||||
if (PSR_FindAndEnterBlock(sc, "Software"))
|
||||
{
|
||||
if(PSR_FindAndEnterBlock(sc, "Valve"))
|
||||
if (PSR_FindAndEnterBlock(sc, "Valve"))
|
||||
{
|
||||
if(PSR_FindAndEnterBlock(sc, "Steam"))
|
||||
if (PSR_FindAndEnterBlock(sc, "Steam"))
|
||||
{
|
||||
dirs = PSR_ReadBaseInstalls(sc);
|
||||
}
|
||||
|
@ -142,7 +143,7 @@ static TArray<FString> ParseSteamRegistry(const char* path)
|
|||
}
|
||||
PSR_FindEndBlock(sc);
|
||||
}
|
||||
|
||||
}
|
||||
return dirs;
|
||||
}
|
||||
|
||||
|
|
|
@ -244,18 +244,25 @@ void FScanner::Open (const char *name)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void FScanner::OpenFile (const char *name)
|
||||
bool FScanner::OpenFile (const char *name)
|
||||
{
|
||||
uint8_t *filebuf;
|
||||
int filesize;
|
||||
|
||||
Close ();
|
||||
filesize = M_ReadFile (name, &filebuf);
|
||||
|
||||
FileReader fr(name);
|
||||
if (!fr.Open(name)) return false;
|
||||
auto filesize = fr.GetLength();
|
||||
auto filebuf = new uint8_t[filesize];
|
||||
if (fr.Read(filebuf, filesize) != filesize)
|
||||
{
|
||||
delete[] filebuf;
|
||||
return false;
|
||||
}
|
||||
ScriptBuffer = FString((const char *)filebuf, filesize);
|
||||
delete[] filebuf;
|
||||
ScriptName = name; // This is used for error messages so the full file name is preferable
|
||||
LumpNum = -1;
|
||||
PrepareScript ();
|
||||
return true;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
FScanner &operator=(const FScanner &other);
|
||||
|
||||
void Open(const char *lumpname);
|
||||
void OpenFile(const char *filename);
|
||||
bool OpenFile(const char *filename);
|
||||
void OpenMem(const char *name, const char *buffer, int size);
|
||||
void OpenString(const char *name, FString buffer);
|
||||
void OpenLumpNum(int lump);
|
||||
|
|
|
@ -137,7 +137,7 @@ static void ParseStatistics(const char *fn, TArray<FStatistics> &statlist)
|
|||
try
|
||||
{
|
||||
FScanner sc;
|
||||
sc.OpenFile(fn);
|
||||
if (!sc.OpenFile(fn)) return;
|
||||
|
||||
while (sc.GetString())
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue