diff --git a/source/common/utility/configfile.cpp b/source/common/utility/configfile.cpp index cf7f44312..52bb4bcae 100644 --- a/source/common/utility/configfile.cpp +++ b/source/common/utility/configfile.cpp @@ -617,15 +617,15 @@ void FConfigFile::LoadConfigFile () // //==================================================================== -bool FConfigFile::ReadConfig (void *file) +bool FConfigFile::ReadConfig (FileReader *file) { - uint8_t readbuf[READBUFFERSIZE]; + TArray readbuf; FConfigSection *section = NULL; ClearConfig (); - while (ReadLine ((char*)readbuf, READBUFFERSIZE, file) != NULL) + while (ReadLine (readbuf, file) != NULL) { - uint8_t *start = readbuf; + uint8_t *start = readbuf.Data(); uint8_t *equalpt; uint8_t *endpt; @@ -639,25 +639,17 @@ bool FConfigFile::ReadConfig (void *file) { continue; } - // Do not process tail of long line - const bool longline = (READBUFFERSIZE - 1) == strlen((char*)readbuf) && '\n' != readbuf[READBUFFERSIZE - 2]; - if (longline) + + // Remove white space at end of line + endpt = start + strlen ((char*)start) - 1; + while (endpt > start && *endpt <= ' ') { - endpt = start + READBUFFERSIZE - 2; - } - else - { - // Remove white space at end of line - endpt = start + strlen ((char*)start) - 1; - while (endpt > start && *endpt <= ' ') - { - endpt--; - } - // Remove line feed '\n' character - endpt[1] = 0; - if (endpt <= start) - continue; // Nothing here + endpt--; } + // Remove line feed '\n' character + endpt[1] = 0; + if (endpt <= start) + continue; // Nothing here if (*start == '[') { // Section header @@ -693,31 +685,6 @@ bool FConfigFile::ReadConfig (void *file) { ReadMultiLineValue (file, section, (char*)start, (char*)whiteprobe + 3); } - else if (longline) - { - const FString key = (char*)start; - FString value = (char*)whiteprobe; - - while (ReadLine ((char*)readbuf, READBUFFERSIZE, file) != NULL) - { - const size_t endpos = (0 == readbuf[0]) ? 0 : (strlen((char*)readbuf) - 1); - const bool endofline = '\n' == readbuf[endpos]; - - if (endofline) - { - readbuf[endpos] = 0; - } - - value += (char*)readbuf; - - if (endofline) - { - break; - } - } - - NewConfigEntry (section, key.GetChars(), value.GetChars()); - } else { NewConfigEntry (section, (char*)start, (char*)whiteprobe); @@ -742,18 +709,18 @@ bool FConfigFile::ReadConfig (void *file) // //==================================================================== -FConfigFile::FConfigEntry *FConfigFile::ReadMultiLineValue(void *file, FConfigSection *section, const char *key, const char *endtag) +FConfigFile::FConfigEntry *FConfigFile::ReadMultiLineValue(FileReader *file, FConfigSection *section, const char *key, const char *endtag) { - char readbuf[READBUFFERSIZE]; + TArray readbuf; FString value; size_t endlen = strlen(endtag); // Keep on reading lines until we reach a line that matches >>>endtag - while (ReadLine(readbuf, READBUFFERSIZE, file) != NULL) + while (ReadLine(readbuf, file) != NULL) { // Does the start of this line match the endtag? if (readbuf[0] == '>' && readbuf[1] == '>' && readbuf[2] == '>' && - strncmp(readbuf + 3, endtag, endlen) == 0) + strncmp((char*)readbuf.Data() + 3, endtag, endlen) == 0) { // Is there nothing but line break characters after the match? size_t i; for (i = endlen + 3; readbuf[i] != '\0'; ++i) @@ -781,9 +748,28 @@ FConfigFile::FConfigEntry *FConfigFile::ReadMultiLineValue(void *file, FConfigSe // //==================================================================== -char *FConfigFile::ReadLine (char *string, int n, void *file) const +uint8_t *FConfigFile::ReadLine(TArray& string, FileReader* file) const { - return ((FileReader *)file)->Gets (string, n); + uint8_t byte; + string.Clear(); + while (file->Read(&byte, 1)) + { + if (byte == 0) + { + break; + } + if (byte != '\r') + { + string.Push(byte); + if (byte == '\n') + { + break; + } + } + } + if (string.Size() == 0) return nullptr; + string.Push(0); + return string.Data(); } //==================================================================== diff --git a/source/common/utility/configfile.h b/source/common/utility/configfile.h index 1e7bdc158..cc484a3c2 100644 --- a/source/common/utility/configfile.h +++ b/source/common/utility/configfile.h @@ -76,8 +76,8 @@ public: protected: virtual void WriteCommentHeader (FileWriter *file) const; - virtual char *ReadLine (char *string, int n, void *file) const; - bool ReadConfig (void *file); + uint8_t *ReadLine (TArray &string, FileReader *file) const; + bool ReadConfig (FileReader *file); static const char *GenerateEndTag(const char *value); void RenameSection(const char *oldname, const char *newname) const; @@ -113,7 +113,7 @@ private: FConfigEntry *FindEntry (FConfigSection *section, const char *key) const; FConfigSection *NewConfigSection (const char *name); FConfigEntry *NewConfigEntry (FConfigSection *section, const char *key, const char *value); - FConfigEntry *ReadMultiLineValue (void *file, FConfigSection *section, const char *key, const char *terminator); + FConfigEntry *ReadMultiLineValue (FileReader *file, FConfigSection *section, const char *key, const char *terminator); void SetSectionNote (FConfigSection *section, const char *note); public: