From c8e55fed4628eeb0bf0010ce0cc9496a2b18adee Mon Sep 17 00:00:00 2001 From: ZippeyKeys12 Date: Thu, 30 Aug 2018 16:39:11 -0500 Subject: [PATCH] Moved FConfigFile over to FileReader/FileWriter Don't use new operator, use value instead --- src/configfile.cpp | 26 +++++++++++++------------- src/configfile.h | 3 ++- src/gameconfigfile.cpp | 4 ++-- src/gameconfigfile.h | 2 +- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/configfile.cpp b/src/configfile.cpp index 2319f28226..b841e8d3da 100644 --- a/src/configfile.cpp +++ b/src/configfile.cpp @@ -38,6 +38,7 @@ #include "doomtype.h" #include "configfile.h" +#include "files.h" #include "m_random.h" #define READBUFFERSIZE 256 @@ -601,17 +602,16 @@ FConfigFile::FConfigEntry *FConfigFile::NewConfigEntry ( void FConfigFile::LoadConfigFile () { - FILE *file = fopen (PathName, "r"); + FileReader file; bool succ; FileExisted = false; - if (file == NULL) + if (!file.OpenFile (PathName)) { return; } - succ = ReadConfig (file); - fclose (file); + succ = ReadConfig (&file); FileExisted = succ; } @@ -787,7 +787,7 @@ FConfigFile::FConfigEntry *FConfigFile::ReadMultiLineValue(void *file, FConfigSe 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; } - FILE *file = fopen (PathName, "w"); + FileWriter *file = FileWriter::Open (PathName); FConfigSection *section; FConfigEntry *entry; @@ -820,27 +820,27 @@ bool FConfigFile::WriteConfigFile () const entry = section->RootEntry; 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) { if (strpbrk(entry->Value, "\r\n") == NULL) { // Single-line value - fprintf (file, "%s=%s\n", entry->Key, entry->Value); + file->Printf ("%s=%s\n", entry->Key, entry->Value); } else { // Multi-line 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); } entry = entry->Next; } section = section->Next; - fputs ("\n", file); + file->Write ("\n", 1); } - fclose (file); + delete file; 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 { } diff --git a/src/configfile.h b/src/configfile.h index a48ddfad61..ab68664306 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -35,6 +35,7 @@ #define __CONFIGFILE_H__ #include +#include "files.h" #include "zstring.h" class FConfigFile @@ -73,7 +74,7 @@ public: bool WriteConfigFile () const; protected: - virtual void WriteCommentHeader (FILE *file) const; + virtual void WriteCommentHeader (FileWriter *file) const; virtual char *ReadLine (char *string, int n, void *file) const; bool ReadConfig (void *file); diff --git a/src/gameconfigfile.cpp b/src/gameconfigfile.cpp index cb47c3597f..37abce9d7f 100644 --- a/src/gameconfigfile.cpp +++ b/src/gameconfigfile.cpp @@ -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) diff --git a/src/gameconfigfile.h b/src/gameconfigfile.h index 1ba066d058..9ef4684898 100644 --- a/src/gameconfigfile.h +++ b/src/gameconfigfile.h @@ -58,7 +58,7 @@ public: void ReadNetVars (); protected: - void WriteCommentHeader (FILE *file) const; + void WriteCommentHeader (FileWriter *file) const; void CreateStandardAutoExec (const char *section, bool start); private: