diff --git a/src/engine/config.cpp b/src/engine/config.cpp index fe817ed2c..af4322685 100644 --- a/src/engine/config.cpp +++ b/src/engine/config.cpp @@ -58,6 +58,9 @@ bool DivConfig::save(const char* path, bool redundancy) { reportError(fmt::sprintf("could not write config file! %s",strerror(errno))); return false; } + if (redundancy) { + fputs("!DIV_CONFIG_START!\n",f); + } for (auto& i: conf) { String toWrite=fmt::sprintf("%s=%s\n",i.first,i.second); if (fwrite(toWrite.c_str(),1,toWrite.size(),f)!=toWrite.size()) { @@ -69,6 +72,9 @@ bool DivConfig::save(const char* path, bool redundancy) { return false; } } + if (redundancy) { + fputs("~DIV_CONFIG_END~\n",f); + } fclose(f); logD("config file written successfully."); return true; @@ -124,8 +130,12 @@ bool DivConfig::loadFromFile(const char* path, bool createOnFail, bool redundanc if (redundancy) { unsigned char* readBuf=new unsigned char[CHECK_BUF_SIZE]; size_t readBufLen=0; + bool weRescued=false; for (int i=0; i0) { snprintf(line,4095,"%s.%d",path,i); } else { @@ -143,15 +153,27 @@ bool DivConfig::loadFromFile(const char* path, bool createOnFail, bool redundanc // check whether there's something while (!feof(f)) { + bool willBreak=false; readBufLen=fread(readBuf,1,CHECK_BUF_SIZE,f); if (ferror(f)) { logV("fread(): %s",strerror(errno)); break; } + if (startCheck) { + if (readBufLen>=19) { + if (memcmp(readBuf,"!DIV_CONFIG_START!\n",19)==0) { + hasStartMarker=true; + logV("start marker found"); + } + } + startCheck=false; + } + for (size_t j=0; j=18) { + memcpy(endMarker,&readBuf[readBufLen-18],18); + } else if (readBufLen>0) { + // shift buffer left + for (size_t j=0, k=readBufLen; j