|
|
@ -737,7 +737,7 @@ bool CPersistentDataRecord::toLines(std::string& result)
|
|
|
|
return pdt.readFromPdr(*this) && pdt.writeToBuffer(reinterpret_cast<NLMISC::CSString&>(result));
|
|
|
|
return pdt.readFromPdr(*this) && pdt.writeToBuffer(reinterpret_cast<NLMISC::CSString&>(result));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CPersistentDataRecord::writeToBinFile(const char* fileName)
|
|
|
|
bool CPersistentDataRecord::writeToBinFile(const std::string &fileName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
H_AUTO(CPersistentDataRecordWriteToBinFile);
|
|
|
|
H_AUTO(CPersistentDataRecordWriteToBinFile);
|
|
|
|
|
|
|
|
|
|
|
@ -750,7 +750,7 @@ bool CPersistentDataRecord::writeToBinFile(const char* fileName)
|
|
|
|
// write the buffer to a file
|
|
|
|
// write the buffer to a file
|
|
|
|
COFile f;
|
|
|
|
COFile f;
|
|
|
|
bool open = f.open(fileName);
|
|
|
|
bool open = f.open(fileName);
|
|
|
|
DROP_IF(!open,NLMISC::toString("Failed to open output file %s",fileName).c_str(),return false);
|
|
|
|
DROP_IF(!open, NLMISC::toString("Failed to open output file %s", fileName.c_str()).c_str(),return false);
|
|
|
|
|
|
|
|
|
|
|
|
// write the binary data to file
|
|
|
|
// write the binary data to file
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -759,7 +759,7 @@ bool CPersistentDataRecord::writeToBinFile(const char* fileName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DROP(NLMISC::toString("Failed to write output file: %s",fileName),return false);
|
|
|
|
DROP(NLMISC::toString("Failed to write output file: %s", fileName.c_str()),return false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// rewind the read pointer 'cos it's at the end of file
|
|
|
|
// rewind the read pointer 'cos it's at the end of file
|
|
|
@ -768,7 +768,7 @@ bool CPersistentDataRecord::writeToBinFile(const char* fileName)
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CPersistentDataRecord::writeToTxtFile(const char* fileName,TStringFormat stringFormat)
|
|
|
|
bool CPersistentDataRecord::writeToTxtFile(const std::string &fileName,TStringFormat stringFormat)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
H_AUTO(CPersistentDataRecordWriteToTxtFile);
|
|
|
|
H_AUTO(CPersistentDataRecordWriteToTxtFile);
|
|
|
|
|
|
|
|
|
|
|
@ -779,7 +779,7 @@ bool CPersistentDataRecord::writeToTxtFile(const char* fileName,TStringFormat st
|
|
|
|
// write the text buffer to a file
|
|
|
|
// write the text buffer to a file
|
|
|
|
COFile f;
|
|
|
|
COFile f;
|
|
|
|
bool open = f.open(fileName);
|
|
|
|
bool open = f.open(fileName);
|
|
|
|
DROP_IF(!open,NLMISC::toString("Failed to open output file %s",fileName).c_str(),return false);
|
|
|
|
DROP_IF(!open,NLMISC::toString("Failed to open output file %s", fileName.c_str()).c_str(), return false);
|
|
|
|
|
|
|
|
|
|
|
|
// write the binary data to file
|
|
|
|
// write the binary data to file
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -788,7 +788,7 @@ bool CPersistentDataRecord::writeToTxtFile(const char* fileName,TStringFormat st
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DROP(NLMISC::toString("Failed to write output file: %s",fileName),return false);
|
|
|
|
DROP(NLMISC::toString("Failed to write output file: %s", fileName.c_str()), return false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// rewind the read pointer 'cos it's at the end of file
|
|
|
|
// rewind the read pointer 'cos it's at the end of file
|
|
|
@ -797,7 +797,7 @@ bool CPersistentDataRecord::writeToTxtFile(const char* fileName,TStringFormat st
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CPersistentDataRecord::writeToFile(const char* fileName,TFileFormat fileFormat)
|
|
|
|
bool CPersistentDataRecord::writeToFile(const std::string &fileName, TFileFormat fileFormat)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
H_AUTO(CPersistentDataRecordWriteToFile);
|
|
|
|
H_AUTO(CPersistentDataRecordWriteToFile);
|
|
|
|
|
|
|
|
|
|
|
@ -805,18 +805,18 @@ bool CPersistentDataRecord::writeToFile(const char* fileName,TFileFormat fileFor
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case BINARY_FILE:
|
|
|
|
case BINARY_FILE:
|
|
|
|
binary_file:
|
|
|
|
binary_file:
|
|
|
|
nlinfo("saving binary file: %s",fileName);
|
|
|
|
nlinfo("saving binary file: %s", fileName.c_str());
|
|
|
|
return writeToBinFile(fileName);
|
|
|
|
return writeToBinFile(fileName);
|
|
|
|
|
|
|
|
|
|
|
|
case XML_FILE:
|
|
|
|
case XML_FILE:
|
|
|
|
xml_file:
|
|
|
|
xml_file:
|
|
|
|
nlinfo("saving xml file: %s",fileName);
|
|
|
|
nlinfo("saving xml file: %s", fileName.c_str());
|
|
|
|
return writeToTxtFile(fileName,XML_STRING);
|
|
|
|
return writeToTxtFile(fileName, XML_STRING);
|
|
|
|
|
|
|
|
|
|
|
|
case LINES_FILE:
|
|
|
|
case LINES_FILE:
|
|
|
|
lines_file:
|
|
|
|
lines_file:
|
|
|
|
nlinfo("saving line-based txt file: %s",fileName);
|
|
|
|
nlinfo("saving line-based txt file: %s", fileName.c_str());
|
|
|
|
return writeToTxtFile(fileName,LINES_STRING);
|
|
|
|
return writeToTxtFile(fileName, LINES_STRING);
|
|
|
|
|
|
|
|
|
|
|
|
case ANY_FILE:
|
|
|
|
case ANY_FILE:
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1113,15 +1113,15 @@ bool CPersistentDataRecord::fromBuffer(NLMISC::IStream& stream)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CPersistentDataRecord::readFromFile(const char* fileName)
|
|
|
|
bool CPersistentDataRecord::readFromFile(const std::string &fileName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
H_AUTO(pdrReadFromFile)
|
|
|
|
H_AUTO(pdrReadFromFile)
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
|
|
|
|
|
|
|
|
// open the file
|
|
|
|
// open the file
|
|
|
|
FILE* inf= fopen(fileName,"rb");
|
|
|
|
FILE* inf= fopen(fileName.c_str(), "rb");
|
|
|
|
DROP_IF( inf==NULL, "Failed to open input file "<<fileName, return false);
|
|
|
|
DROP_IF( inf==NULL, "Failed to open input file " << fileName, return false);
|
|
|
|
|
|
|
|
|
|
|
|
// get the file size
|
|
|
|
// get the file size
|
|
|
|
uint32 length= filelength(fileno(inf));
|
|
|
|
uint32 length= filelength(fileno(inf));
|
|
|
@ -1166,14 +1166,14 @@ bool CPersistentDataRecord::readFromFile(const char* fileName)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CPersistentDataRecord::readFromBinFile(const char* fileName)
|
|
|
|
bool CPersistentDataRecord::readFromBinFile(const std::string &fileName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
H_AUTO(CPersistentDataRecordReadFromBinFile);
|
|
|
|
H_AUTO(CPersistentDataRecordReadFromBinFile);
|
|
|
|
|
|
|
|
|
|
|
|
// open the file
|
|
|
|
// open the file
|
|
|
|
CIFile f;
|
|
|
|
CIFile f;
|
|
|
|
bool open = f.open(fileName);
|
|
|
|
bool open = f.open(fileName);
|
|
|
|
DROP_IF(!open,NLMISC::toString("Failed to open input file %s",fileName).c_str(),return false)
|
|
|
|
DROP_IF(!open, NLMISC::toString("Failed to open input file %s", fileName.c_str()), return false)
|
|
|
|
|
|
|
|
|
|
|
|
// get the file size
|
|
|
|
// get the file size
|
|
|
|
uint32 len=CFile::getFileSize(fileName);
|
|
|
|
uint32 len=CFile::getFileSize(fileName);
|
|
|
@ -1189,7 +1189,7 @@ bool CPersistentDataRecord::readFromBinFile(const char* fileName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DROP(NLMISC::toString("Failed to read input file: %s",fileName),return false);
|
|
|
|
DROP(NLMISC::toString("Failed to read input file: %s", fileName.c_str()), return false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// parse the buffer contents to re-generate the data
|
|
|
|
// parse the buffer contents to re-generate the data
|
|
|
@ -1199,14 +1199,14 @@ bool CPersistentDataRecord::readFromBinFile(const char* fileName)
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CPersistentDataRecord::readFromTxtFile(const char* fileName)
|
|
|
|
bool CPersistentDataRecord::readFromTxtFile(const std::string &fileName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
H_AUTO(CPersistentDataRecordReadFromTxtFile);
|
|
|
|
H_AUTO(CPersistentDataRecordReadFromTxtFile);
|
|
|
|
|
|
|
|
|
|
|
|
// open the file
|
|
|
|
// open the file
|
|
|
|
CIFile f;
|
|
|
|
CIFile f;
|
|
|
|
bool open = f.open(fileName);
|
|
|
|
bool open = f.open(fileName);
|
|
|
|
DROP_IF(!open,NLMISC::toString("Failed to open input file %s",fileName).c_str(),return false)
|
|
|
|
DROP_IF(!open, NLMISC::toString("Failed to open input file %s", fileName.c_str()), return false)
|
|
|
|
|
|
|
|
|
|
|
|
// get the file size
|
|
|
|
// get the file size
|
|
|
|
uint32 len=CFile::getFileSize(fileName);
|
|
|
|
uint32 len=CFile::getFileSize(fileName);
|
|
|
@ -1222,7 +1222,7 @@ bool CPersistentDataRecord::readFromTxtFile(const char* fileName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DROP(NLMISC::toString("Failed to read input file: %s",fileName),return false);
|
|
|
|
DROP(NLMISC::toString("Failed to read input file: %s", fileName.c_str()), return false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// parse the buffer contents to re-generate the data
|
|
|
|
// parse the buffer contents to re-generate the data
|
|
|
|