mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-02-07 07:21:01 +00:00
Moved FConfigFile over to FileReader/FileWriter
Don't use new operator, use value instead
This commit is contained in:
parent
050d72724f
commit
c8e55fed46
4 changed files with 18 additions and 17 deletions
|
@ -38,6 +38,7 @@
|
||||||
|
|
||||||
#include "doomtype.h"
|
#include "doomtype.h"
|
||||||
#include "configfile.h"
|
#include "configfile.h"
|
||||||
|
#include "files.h"
|
||||||
#include "m_random.h"
|
#include "m_random.h"
|
||||||
|
|
||||||
#define READBUFFERSIZE 256
|
#define READBUFFERSIZE 256
|
||||||
|
@ -601,17 +602,16 @@ FConfigFile::FConfigEntry *FConfigFile::NewConfigEntry (
|
||||||
|
|
||||||
void FConfigFile::LoadConfigFile ()
|
void FConfigFile::LoadConfigFile ()
|
||||||
{
|
{
|
||||||
FILE *file = fopen (PathName, "r");
|
FileReader file;
|
||||||
bool succ;
|
bool succ;
|
||||||
|
|
||||||
FileExisted = false;
|
FileExisted = false;
|
||||||
if (file == NULL)
|
if (!file.OpenFile (PathName))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
succ = ReadConfig (file);
|
succ = ReadConfig (&file);
|
||||||
fclose (file);
|
|
||||||
FileExisted = succ;
|
FileExisted = succ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -787,7 +787,7 @@ FConfigFile::FConfigEntry *FConfigFile::ReadMultiLineValue(void *file, FConfigSe
|
||||||
|
|
||||||
char *FConfigFile::ReadLine (char *string, int n, void *file) const
|
char *FConfigFile::ReadLine (char *string, int n, void *file) const
|
||||||
{
|
{
|
||||||
return fgets (string, n, (FILE *)file);
|
return ((FileReader *)file)->Gets (string, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
//====================================================================
|
//====================================================================
|
||||||
|
@ -805,7 +805,7 @@ bool FConfigFile::WriteConfigFile () const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *file = fopen (PathName, "w");
|
FileWriter *file = FileWriter::Open (PathName);
|
||||||
FConfigSection *section;
|
FConfigSection *section;
|
||||||
FConfigEntry *entry;
|
FConfigEntry *entry;
|
||||||
|
|
||||||
|
@ -820,27 +820,27 @@ bool FConfigFile::WriteConfigFile () const
|
||||||
entry = section->RootEntry;
|
entry = section->RootEntry;
|
||||||
if (section->Note.IsNotEmpty())
|
if (section->Note.IsNotEmpty())
|
||||||
{
|
{
|
||||||
fputs (section->Note.GetChars(), file);
|
file->Write (section->Note.GetChars(), section->Note.Len());
|
||||||
}
|
}
|
||||||
fprintf (file, "[%s]\n", section->SectionName.GetChars());
|
file->Printf ("[%s]\n", section->SectionName.GetChars());
|
||||||
while (entry != NULL)
|
while (entry != NULL)
|
||||||
{
|
{
|
||||||
if (strpbrk(entry->Value, "\r\n") == NULL)
|
if (strpbrk(entry->Value, "\r\n") == NULL)
|
||||||
{ // Single-line value
|
{ // Single-line value
|
||||||
fprintf (file, "%s=%s\n", entry->Key, entry->Value);
|
file->Printf ("%s=%s\n", entry->Key, entry->Value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Multi-line value
|
{ // Multi-line value
|
||||||
const char *endtag = GenerateEndTag(entry->Value);
|
const char *endtag = GenerateEndTag(entry->Value);
|
||||||
fprintf (file, "%s=<<<%s\n%s\n>>>%s\n", entry->Key,
|
file->Printf ("%s=<<<%s\n%s\n>>>%s\n", entry->Key,
|
||||||
endtag, entry->Value, endtag);
|
endtag, entry->Value, endtag);
|
||||||
}
|
}
|
||||||
entry = entry->Next;
|
entry = entry->Next;
|
||||||
}
|
}
|
||||||
section = section->Next;
|
section = section->Next;
|
||||||
fputs ("\n", file);
|
file->Write ("\n", 1);
|
||||||
}
|
}
|
||||||
fclose (file);
|
delete file;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -890,7 +890,7 @@ const char *FConfigFile::GenerateEndTag(const char *value)
|
||||||
//
|
//
|
||||||
//====================================================================
|
//====================================================================
|
||||||
|
|
||||||
void FConfigFile::WriteCommentHeader (FILE *file) const
|
void FConfigFile::WriteCommentHeader (FileWriter *file) const
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#define __CONFIGFILE_H__
|
#define __CONFIGFILE_H__
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "files.h"
|
||||||
#include "zstring.h"
|
#include "zstring.h"
|
||||||
|
|
||||||
class FConfigFile
|
class FConfigFile
|
||||||
|
@ -73,7 +74,7 @@ public:
|
||||||
bool WriteConfigFile () const;
|
bool WriteConfigFile () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void WriteCommentHeader (FILE *file) const;
|
virtual void WriteCommentHeader (FileWriter *file) const;
|
||||||
|
|
||||||
virtual char *ReadLine (char *string, int n, void *file) const;
|
virtual char *ReadLine (char *string, int n, void *file) const;
|
||||||
bool ReadConfig (void *file);
|
bool ReadConfig (void *file);
|
||||||
|
|
|
@ -167,9 +167,9 @@ FGameConfigFile::~FGameConfigFile ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGameConfigFile::WriteCommentHeader (FILE *file) const
|
void FGameConfigFile::WriteCommentHeader (FileWriter *file) const
|
||||||
{
|
{
|
||||||
fprintf (file, "# This file was generated by " GAMENAME " %s on %s\n", GetVersionString(), myasctime());
|
file->Printf ("# This file was generated by " GAMENAME " %s on %s\n", GetVersionString(), myasctime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGameConfigFile::DoAutoloadSetup (FIWadManager *iwad_man)
|
void FGameConfigFile::DoAutoloadSetup (FIWadManager *iwad_man)
|
||||||
|
|
|
@ -58,7 +58,7 @@ public:
|
||||||
void ReadNetVars ();
|
void ReadNetVars ();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void WriteCommentHeader (FILE *file) const;
|
void WriteCommentHeader (FileWriter *file) const;
|
||||||
void CreateStandardAutoExec (const char *section, bool start);
|
void CreateStandardAutoExec (const char *section, bool start);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue