Changed: Use std::string insteaf of const char* for filenames in CPersistentDataRecord

This commit is contained in:
kervala 2015-12-15 13:35:04 +01:00
parent 573568c702
commit 68f5cb447f
29 changed files with 120 additions and 112 deletions

View file

@ -766,7 +766,7 @@ bool CProductDescriptionForClient::load(const std::string& filePath)
clear(); clear();
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromBinFile(filePath.c_str()); pdr.readFromBinFile(filePath);
apply(pdr); apply(pdr);
return true; return true;

View file

@ -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,17 +805,17 @@ 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,14 +1113,14 @@ 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
@ -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

View file

@ -407,15 +407,15 @@ public:
bool toLines(std::string& result); bool toLines(std::string& result);
// perform a toBuffer() and write the result to a binary file // perform a toBuffer() and write the result to a binary file
bool writeToBinFile(const char* fileName); bool writeToBinFile(const std::string &fileName);
// perform a toString() and write the result to a text file // perform a toString() and write the result to a text file
bool writeToTxtFile(const char* fileName,TStringFormat stringFormat=XML_STRING); bool writeToTxtFile(const std::string &fileName, TStringFormat stringFormat=XML_STRING);
// if the format is set to 'ANY_FILE' then use the extension provided in the 'fileName' argument to // if the format is set to 'ANY_FILE' then use the extension provided in the 'fileName' argument to
// determine the file type. In this case 'txt' and 'xml' have specific meanings // determine the file type. In this case 'txt' and 'xml' have specific meanings
// returns writeToTxtFile(...) or writeToBinFile(...) depending on the file format // returns writeToTxtFile(...) or writeToBinFile(...) depending on the file format
bool writeToFile(const char* fileName,TFileFormat fileFormat=ANY_FILE); bool writeToFile(const std::string &fileName, TFileFormat fileFormat=ANY_FILE);
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@ -445,14 +445,14 @@ public:
bool fromLines(const std::string& s); bool fromLines(const std::string& s);
// read from a binary file // read from a binary file
bool readFromBinFile(const char* fileName); bool readFromBinFile(const std::string &fileName);
// read from a text file // read from a text file
bool readFromTxtFile(const char* fileName); bool readFromTxtFile(const std::string &fileName);
// read a file and determine whether it's a binary or text file from it's // read a file and determine whether it's a binary or text file from it's
// content - then behave like readFromBinFile() or readFromTxtFile() // content - then behave like readFromBinFile() or readFromTxtFile()
bool readFromFile(const char* fileName); bool readFromFile(const std::string &fileName);
private: private:

View file

@ -2039,7 +2039,7 @@ bool CServerAnimationModule::doMakeAnimationSession(CAnimationSession* animSessi
{ {
string tmp = toString("r2.%04u.act%u.pdr.xml", sessionId.asInt(), first); string tmp = toString("r2.%04u.act%u.pdr.xml", sessionId.asInt(), first);
nldebug( "writing xml pdr file %s", tmp.c_str() ); nldebug( "writing xml pdr file %s", tmp.c_str() );
animSession->Pdrs[first].writeToTxtFile( tmp.c_str() ); animSession->Pdrs[first].writeToTxtFile( tmp );
} }
} }

View file

@ -52,12 +52,12 @@ void CAIActionsDataRecordPtr::clear()
void CAIActionsDataRecordPtr::readFile(const std::string &fileName) void CAIActionsDataRecordPtr::readFile(const std::string &fileName)
{ {
_PdrPtr->readFromFile(fileName.c_str()); _PdrPtr->readFromFile(fileName);
} }
void CAIActionsDataRecordPtr::writeFile(const std::string &fileName) void CAIActionsDataRecordPtr::writeFile(const std::string &fileName)
{ {
_PdrPtr->writeToFile(fileName.c_str()); _PdrPtr->writeToFile(fileName);
} }
void CAIActionsDataRecordPtr::display() void CAIActionsDataRecordPtr::display()

View file

@ -121,7 +121,7 @@ NLMISC_COMMAND ( dumpCharacterFile, "dump the content of the save file for a cha
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
if (!pdr.readFromBinFile(fileName.c_str())) if (!pdr.readFromBinFile(fileName))
{ {
log.displayNL("Error while reading file '%s'", fileName.c_str()); log.displayNL("Error while reading file '%s'", fileName.c_str());
return true; return true;

View file

@ -2199,7 +2199,7 @@ NLMISC_CATEGORISED_COMMAND(pdr,saveToXML,"save a character to an XML file","<eid
static CPersistentDataRecordRyzomStore pdr; static CPersistentDataRecordRyzomStore pdr;
pdr.clear(); pdr.clear();
c->store(pdr); c->store(pdr);
pdr.writeToTxtFile((fileName+".xml").c_str()); pdr.writeToTxtFile(fileName+".xml");
return true; return true;
} }
@ -2225,7 +2225,7 @@ NLMISC_CATEGORISED_COMMAND(pdr,loadFromXML,"load a character from an XML file","
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromTxtFile((fileName+".xml").c_str()); pdr.readFromTxtFile(fileName+".xml");
c->apply(pdr); c->apply(pdr);
c->setName(name); c->setName(name);
c->setGuildId(guildId); c->setGuildId(guildId);
@ -2256,7 +2256,7 @@ NLMISC_CATEGORISED_COMMAND(pdr,saveToPDR,"save a character to a binary PDR file"
static CPersistentDataRecordRyzomStore pdr; static CPersistentDataRecordRyzomStore pdr;
pdr.clear(); pdr.clear();
c->store(pdr); c->store(pdr);
pdr.writeToBinFile((fileName+".pdr").c_str()); pdr.writeToBinFile(fileName+".pdr");
return true; return true;
} }
@ -2282,7 +2282,7 @@ NLMISC_CATEGORISED_COMMAND(pdr,loadFromPDR,"load a character from a binary PDR f
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromBinFile((fileName+".pdr").c_str()); pdr.readFromBinFile(fileName+".pdr");
c->apply(pdr); c->apply(pdr);
c->setName(name); c->setName(name);

View file

@ -1720,7 +1720,7 @@ NLMISC_COMMAND(loadCharacterNames,"load all character save games and extract nam
pdr.clear(); pdr.clear();
{ {
H_AUTO(LoadCharacterNamesLoadFile); H_AUTO(LoadCharacterNamesLoadFile);
pdr.readFromFile((*it).second.FileName.c_str()); pdr.readFromFile((*it).second.FileName);
} }
CCharacterNameExtraction nameExtractor; CCharacterNameExtraction nameExtractor;
{ {
@ -1760,25 +1760,25 @@ NLMISC_COMMAND(loadCharacterNames,"load all character save games and extract nam
// // std read tst // // std read tst
// static CPersistentDataRecord pdrRead(""); // static CPersistentDataRecord pdrRead("");
// pdrRead.clear(); // pdrRead.clear();
// pdrRead.readFromBinFile(files[i].c_str()); // pdrRead.readFromBinFile(files[i]);
// pdrRead.writeToTxtFile((saveDir + "test/txt_read/" + CFile::getFilenameWithoutExtension(file) + ".txt").c_str(), CPersistentDataRecord::LINES_STRING); // pdrRead.writeToTxtFile(saveDir + "test/txt_read/" + CFile::getFilenameWithoutExtension(file) + ".txt", CPersistentDataRecord::LINES_STRING);
// //
// // read write tst (even with a bad used RyzomStore class) // // read write tst (even with a bad used RyzomStore class)
// static CPersistentDataRecordRyzomStore pdr; // static CPersistentDataRecordRyzomStore pdr;
// pdr.clear(); // pdr.clear();
// pdr.readFromBinFile(files[i].c_str()); // pdr.readFromBinFile(files[i]);
// TTime t0= CTime::getLocalTime(); // TTime t0= CTime::getLocalTime();
// pdr.writeToBinFile((saveDir + "test/bin_new/" + file).c_str()); // pdr.writeToBinFile(saveDir + "test/bin_new/" + file);
// TTime t1= CTime::getLocalTime(); // TTime t1= CTime::getLocalTime();
// nlinfo("resaved %s in %d ms", file.c_str(), uint32(t1-t0)); // nlinfo("resaved %s in %d ms", file.c_str(), uint32(t1-t0));
// pdr.writeToTxtFile((saveDir + "test/txt_before/" + CFile::getFilenameWithoutExtension(file) + ".txt").c_str(), CPersistentDataRecord::LINES_STRING); // pdr.writeToTxtFile(saveDir + "test/txt_before/" + CFile::getFilenameWithoutExtension(file) + ".txt", CPersistentDataRecord::LINES_STRING);
// } // }
// // ReLoad // // ReLoad
// { // {
// static CPersistentDataRecordRyzomStore pdr; // static CPersistentDataRecordRyzomStore pdr;
// pdr.clear(); // pdr.clear();
// pdr.readFromBinFile((saveDir + "test/bin_new/" + file).c_str()); // pdr.readFromBinFile(saveDir + "test/bin_new/" + file);
// pdr.writeToTxtFile((saveDir + "test/txt_after/" + CFile::getFilenameWithoutExtension(file) + ".txt").c_str(), CPersistentDataRecord::LINES_STRING); // pdr.writeToTxtFile(saveDir + "test/txt_after/" + CFile::getFilenameWithoutExtension(file) + ".txt", CPersistentDataRecord::LINES_STRING);
// } // }
// } // }
// } // }
@ -1813,10 +1813,10 @@ NLMISC_COMMAND(loadCharacterNames,"load all character save games and extract nam
// { // {
// static CPersistentDataRecord pdr; // static CPersistentDataRecord pdr;
// pdr.clear(); // pdr.clear();
// pdr.readFromFile(files[i].c_str()); // pdr.readFromFile(files[i]);
// string txtFile= files[i]; // string txtFile= files[i];
// strFindReplace(txtFile, ".bin", ".txt"); // strFindReplace(txtFile, ".bin", ".txt");
// pdr.writeToTxtFile(txtFile.c_str(), CPersistentDataRecord::LINES_STRING); // pdr.writeToTxtFile(txtFile, CPersistentDataRecord::LINES_STRING);
// } // }
// } // }
// } // }

View file

@ -66,7 +66,7 @@ void CGameEventManager::init()
{ {
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromTxtFile(sFilename.c_str()); pdr.readFromTxtFile(sFilename);
apply(pdr); apply(pdr);
createEventChannel(); createEventChannel();
} }
@ -308,7 +308,7 @@ void CGameEventManager::saveGameEventFile()
static CPersistentDataRecordRyzomStore pdr; static CPersistentDataRecordRyzomStore pdr;
pdr.clear(); pdr.clear();
store(pdr); store(pdr);
pdr.writeToTxtFile(sFilename.c_str()); pdr.writeToTxtFile(sFilename);
} }
} }

View file

@ -510,7 +510,7 @@ NLMISC_COMMAND( importGuildFile, "Import a guild file into the server", "<filena
if ( id > 0) if ( id > 0)
{ {
// this is a guild file. We can load it // this is a guild file. We can load it
pdr.readFromBinFile(args[0].c_str()); pdr.readFromBinFile(args[0]);
guildId = id; guildId = id;
} }
@ -540,7 +540,7 @@ NLMISC_COMMAND( importGuildFile, "Import a guild file into the server", "<filena
if ( id > 0) if ( id > 0)
{ {
// this is a guild file. We can load it // this is a guild file. We can load it
pdr.readFromTxtFile(args[0].c_str()); pdr.readFromTxtFile(args[0]);
guildId = id; guildId = id;
} }
else else

View file

@ -328,7 +328,7 @@ void CGuildManager::saveGuild( CGuild* guild )
{ {
H_AUTO( CGuildManagerUpdate_PDR_WRITE_TEXT ) H_AUTO( CGuildManagerUpdate_PDR_WRITE_TEXT )
string fileName = Bsi.getLocalPath()+NLMISC::toString("guilds/guild_%05u.txt", id & 0x000fffff); string fileName = Bsi.getLocalPath()+NLMISC::toString("guilds/guild_%05u.txt", id & 0x000fffff);
pdr.writeToTxtFile(fileName.c_str()); pdr.writeToTxtFile(fileName);
} }
else else
{ {
@ -360,7 +360,7 @@ void CGuildManager::saveGuild( CGuild* guild )
else else
{ {
H_AUTO( CGuildManagerUpdatePDR_WRITE_BIN_NO_PDS ) H_AUTO( CGuildManagerUpdatePDR_WRITE_BIN_NO_PDS )
pdr.writeToBinFile((Bsi.getLocalPath() + fileName).c_str()); pdr.writeToBinFile(Bsi.getLocalPath() + fileName);
} }
} }

View file

@ -55,7 +55,7 @@ void CMissionQueueManager::init()
{ {
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromTxtFile(sFilename.c_str()); pdr.readFromTxtFile(sFilename);
apply(pdr); apply(pdr);
} }
_InitOk = true; _InitOk = true;

View file

@ -430,7 +430,7 @@ void COutpostManager::loadOutpostSaveFiles()
// // load dynamic data // // load dynamic data
// static CPersistentDataRecord pdr; // static CPersistentDataRecord pdr;
// pdr.clear(); // pdr.clear();
// pdr.readFromBinFile(files[i].c_str()); // pdr.readFromBinFile(files[i]);
// outpost->apply( pdr ); // outpost->apply( pdr );
// loadedOutposts.push_back( outpost ); // loadedOutposts.push_back( outpost );
// } // }
@ -808,7 +808,7 @@ void COutpostManager::saveOutpost(NLMISC::CSmartPtr<COutpost> outpost)
else else
{ {
H_AUTO( COutpostManagerSTORE_NO_BS ) H_AUTO( COutpostManagerSTORE_NO_BS )
pdr.writeToBinFile((Bsi.getLocalPath() + fileName).c_str()); pdr.writeToBinFile(Bsi.getLocalPath() + fileName);
} }
} }

View file

@ -831,7 +831,7 @@ void CPlayer::loadAllCharacters()
bool isOK; bool isOK;
{ {
H_AUTO(LoadAllCharactersPdrBinReadFile); H_AUTO(LoadAllCharactersPdrBinReadFile);
isOK= pdr.readFromBinFile(pdrBinFileName.c_str()); isOK= pdr.readFromBinFile(pdrBinFileName);
} }
if (!isOK) if (!isOK)
break; break;
@ -854,7 +854,7 @@ void CPlayer::loadAllCharacters()
bool isOK; bool isOK;
{ {
H_AUTO(LoadAllCharactersPdrXmlReadFile); H_AUTO(LoadAllCharactersPdrXmlReadFile);
isOK= pdr.readFromTxtFile(pdrXmlFileName.c_str()); isOK= pdr.readFromTxtFile(pdrXmlFileName);
} }
if (!isOK) if (!isOK)
break; break;
@ -975,7 +975,7 @@ void CPlayer::loadAllCharactersPdr()
// try loading the save data from disk // try loading the save data from disk
try try
{ {
bool isOK= pdr.readFromFile(fileName.c_str()); bool isOK= pdr.readFromFile(fileName);
if (!isOK) if (!isOK)
continue; continue;
} }
@ -1478,11 +1478,11 @@ NLMISC_CATEGORISED_COMMAND(egs, convertToPdr, "Load all possible characters from
bool writeSuccess = false; bool writeSuccess = false;
if (xml) if (xml)
{ {
writeSuccess = pdr.writeToTxtFile(dstFile.c_str()); writeSuccess = pdr.writeToTxtFile(dstFile);
} }
else else
{ {
writeSuccess = pdr.writeToBinFile(dstFile.c_str()); writeSuccess = pdr.writeToBinFile(dstFile);
} }
// check file can be read back // check file can be read back
@ -1491,7 +1491,7 @@ NLMISC_CATEGORISED_COMMAND(egs, convertToPdr, "Load all possible characters from
static CPersistentDataRecord pdrTest; static CPersistentDataRecord pdrTest;
pdrTest.clear(); pdrTest.clear();
if (pdrTest.readFromFile(dstFile.c_str())) if (pdrTest.readFromFile(dstFile))
{ {
CCharacter* characterTest = new CCharacter(); CCharacter* characterTest = new CCharacter();
characterTest->setId( PlayerManager.createCharacterId( UserId, CharId ) ); characterTest->setId( PlayerManager.createCharacterId( UserId, CharId ) );

View file

@ -846,7 +846,7 @@ void CPlayerManager::savePlayerCharRecurs( uint32 userId, sint32 idx, std::set<C
} }
{ {
H_AUTO(SavePlayerPDRSave); H_AUTO(SavePlayerPDRSave);
pdr.writeToFile(pdrPathFileName.c_str()); pdr.writeToFile(pdrPathFileName);
} }
} }
catch(const Exception &) catch(const Exception &)

View file

@ -236,7 +236,7 @@ void CPVPFactionRewardManager::_totemFileCallback(const CFileDescription& fileDe
static CPersistentDataRecordRyzomStore pdr; static CPersistentDataRecordRyzomStore pdr;
pdr.clear(); pdr.clear();
pdr.fromBuffer(dataStream); pdr.fromBuffer(dataStream);
// pdr.readFromFile( sFilePath.c_str() ); // pdr.readFromFile( sFilePath );
apply( pdr ); apply( pdr );
} }
@ -261,7 +261,7 @@ bool CPVPFactionRewardManager::_LoadFromPDR()
// //
// static CPersistentDataRecordRyzomStore pdr; // static CPersistentDataRecordRyzomStore pdr;
// pdr.clear(); // pdr.clear();
// pdr.readFromFile( sFilePath.c_str() ); // pdr.readFromFile( sFilePath );
// //
// if ( pdr.isEndOfData() ) // if ( pdr.isEndOfData() )
// { // {

View file

@ -332,7 +332,7 @@ void CTotemBase::totemFileCallback(const CFileDescription& fileDescription, NLMI
static CPersistentDataRecordRyzomStore pdr; static CPersistentDataRecordRyzomStore pdr;
pdr.clear(); pdr.clear();
pdr.fromBuffer(dataStream); pdr.fromBuffer(dataStream);
// pdr.readFromFile( sFilePath.c_str() ); // pdr.readFromFile( sFilePath );
apply( pdr ); apply( pdr );
} }
@ -352,7 +352,7 @@ void CTotemBase::loadFromPDR()
// static CPersistentDataRecordRyzomStore pdr; // static CPersistentDataRecordRyzomStore pdr;
// pdr.clear(); // pdr.clear();
// pdr.readFromFile( sFilePath.c_str() ); // pdr.readFromFile( sFilePath );
// //
// apply( pdr ); // apply( pdr );
} }

View file

@ -262,7 +262,7 @@ void CDynamicItems::init()
// static CPersistentDataRecord pdr; // static CPersistentDataRecord pdr;
// pdr.clear(); // pdr.clear();
// //
// pdr.readFromFile(fileName.c_str()); // pdr.readFromFile(fileName);
// apply(pdr, i); // apply(pdr, i);
// //
// for( uint32 j = 0; j < subVec.size(); ++j ) // for( uint32 j = 0; j < subVec.size(); ++j )

View file

@ -68,7 +68,7 @@ void CNamedItems::loadNamedItemsFromFile(const std::string & fileName)
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromTxtFile(path.c_str()); pdr.readFromTxtFile(path);
CInventoryPtr inv = loadFromPdr(pdr); CInventoryPtr inv = loadFromPdr(pdr);
if (inv == NULL) if (inv == NULL)
{ {

View file

@ -728,7 +728,7 @@ void CStatDB::valueLeaveFileCallback(const CFileDescription& fileDescription, N
CStatDBValueLeavesPD valueLeavesPD; CStatDBValueLeavesPD valueLeavesPD;
pdr.fromBuffer(dataStream); pdr.fromBuffer(dataStream);
// pdr.readFromFile(sFilePath.c_str()); // pdr.readFromFile(sFilePath);
valueLeavesPD.apply(pdr); valueLeavesPD.apply(pdr);
nTotalLoaded += fileDescription.FileSize; nTotalLoaded += fileDescription.FileSize;
@ -791,7 +791,7 @@ void CStatDB::tableLeaveFileCallback(const CFileDescription& fileDescription, N
CStatDBTableLeafPD tableLeafPD; CStatDBTableLeafPD tableLeafPD;
pdr.fromBuffer(dataStream); pdr.fromBuffer(dataStream);
// pdr.readFromFile(fileName.c_str()); // pdr.readFromFile(fileName);
tableLeafPD.apply(pdr); tableLeafPD.apply(pdr);
nTotalLoaded += CFile::getFileSize(fileName); nTotalLoaded += CFile::getFileSize(fileName);
@ -854,7 +854,7 @@ void CStatDB::load()
// pdr.clear(); // pdr.clear();
// CStatDBValueLeavesPD valueLeavesPD; // CStatDBValueLeavesPD valueLeavesPD;
// //
// pdr.readFromFile(sFilePath.c_str()); // pdr.readFromFile(sFilePath);
// valueLeavesPD.apply(pdr); // valueLeavesPD.apply(pdr);
// nTotalLoaded += CFile::getFileSize(sFilePath); // nTotalLoaded += CFile::getFileSize(sFilePath);
// //
@ -910,7 +910,7 @@ void CStatDB::load()
// pdr.clear(); // pdr.clear();
// CStatDBTableLeafPD tableLeafPD; // CStatDBTableLeafPD tableLeafPD;
// //
// pdr.readFromFile(fileName.c_str()); // pdr.readFromFile(fileName);
// tableLeafPD.apply(pdr); // tableLeafPD.apply(pdr);
// nTotalLoaded += CFile::getFileSize(fileName); // nTotalLoaded += CFile::getFileSize(fileName);
// //

View file

@ -141,7 +141,7 @@ NLMISC_CATEGORISED_COMMAND(Stats,listCharNames,"display the names of the charact
{ {
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromFile(files[i].c_str()); pdr.readFromFile(files[i]);
CStatsScanCharacter c; CStatsScanCharacter c;
c.apply(pdr); c.apply(pdr);

View file

@ -286,7 +286,7 @@ bool CCharacterScanJob::runForFile(const std::string& fileName)
// load the file into a pdr record // load the file into a pdr record
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromFile(fileName.c_str()); pdr.readFromFile(fileName);
// create a character representation and apply the pdr // create a character representation and apply the pdr
CStatsScanCharacter c; CStatsScanCharacter c;

View file

@ -310,7 +310,7 @@ NLMISC_CATEGORISED_COMMAND(Stats,listCharNames,"display the names of the charact
{ {
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromFile(files[i].c_str()); pdr.readFromFile(files[i]);
CStatsScanCharacter c; CStatsScanCharacter c;
c.apply(pdr); c.apply(pdr);

View file

@ -286,7 +286,7 @@ bool CCharacterScanJob::runForFile(const std::string& fileName)
// load the file into a pdr record // load the file into a pdr record
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromFile(fileName.c_str()); pdr.readFromFile(fileName);
// create a character representation and apply the pdr // create a character representation and apply the pdr
CStatsScanCharacter c; CStatsScanCharacter c;

View file

@ -91,8 +91,8 @@ NLMISC_CATEGORISED_COMMAND(utils,pdrBin2xml,"convert a binary pdr file to xml","
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromBinFile(args[0].c_str()); pdr.readFromBinFile(args[0]);
pdr.writeToTxtFile(args[1].c_str()); pdr.writeToTxtFile(args[1]);
return true; return true;
} }
@ -108,8 +108,8 @@ NLMISC_CATEGORISED_COMMAND(utils,pdrXml2bin,"convert a text pdr file to binary",
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromTxtFile(args[0].c_str()); pdr.readFromTxtFile(args[0]);
pdr.writeToBinFile(args[1].c_str()); pdr.writeToBinFile(args[1]);
return true; return true;
} }
@ -138,8 +138,8 @@ NLMISC_CATEGORISED_COMMAND(utils,pdr2xml,"convert one or more sets of pdr files
log.displayNL("Converting to XML : %s => %s",fd.FileName.c_str(),outputFileName.c_str()); log.displayNL("Converting to XML : %s => %s",fd.FileName.c_str(),outputFileName.c_str());
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromFile(fd.FileName.c_str()); pdr.readFromFile(fd.FileName);
pdr.writeToFile(outputFileName.c_str()); pdr.writeToFile(outputFileName);
} }
} }
@ -170,8 +170,8 @@ NLMISC_CATEGORISED_COMMAND(utils,pdr2bin,"convert one or more sets of pdr files
log.displayNL("Converting to Binary : %s => %s",fd.FileName.c_str(),outputFileName.c_str()); log.displayNL("Converting to Binary : %s => %s",fd.FileName.c_str(),outputFileName.c_str());
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromFile(fd.FileName.c_str()); pdr.readFromFile(fd.FileName);
pdr.writeToFile(outputFileName.c_str()); pdr.writeToFile(outputFileName);
} }
} }
@ -202,8 +202,8 @@ NLMISC_CATEGORISED_COMMAND(utils,pdr2txt,"convert one or more sets of pdr files
log.displayNL("Converting to TXT : %s => %s",fd.FileName.c_str(),outputFileName.c_str()); log.displayNL("Converting to TXT : %s => %s",fd.FileName.c_str(),outputFileName.c_str());
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromFile(fd.FileName.c_str()); pdr.readFromFile(fd.FileName);
pdr.writeToFile(outputFileName.c_str()); pdr.writeToFile(outputFileName);
} }
} }
@ -218,10 +218,10 @@ NLMISC_CATEGORISED_COMMAND(utils,pdrFileCompare,"Compare 2 pdr files","<first fi
return false; return false;
CPersistentDataRecord pdr0; CPersistentDataRecord pdr0;
pdr0.readFromFile(args[0].c_str()); pdr0.readFromFile(args[0]);
CPersistentDataRecord pdr1; CPersistentDataRecord pdr1;
pdr1.readFromFile(args[1].c_str()); pdr1.readFromFile(args[1]);
log.displayNL("%s : %s / %s", (pdr0==pdr1)?"Files MATCH":"Files DON'T match", args[0].c_str(), args[1].c_str()); log.displayNL("%s : %s / %s", (pdr0==pdr1)?"Files MATCH":"Files DON'T match", args[0].c_str(), args[1].c_str());
@ -272,7 +272,7 @@ NLMISC_CATEGORISED_COMMAND(utils,pdrInfo,"Extract info from pdr file(s)","<input
{ {
H_AUTO(pdrInfo_readFromFile) H_AUTO(pdrInfo_readFromFile)
pdr.readFromFile(fd.FileName.c_str()); pdr.readFromFile(fd.FileName);
} }
log.displayNL("%s",pdr.getInfo().c_str()); log.displayNL("%s",pdr.getInfo().c_str());

View file

@ -189,7 +189,7 @@ void CPackageDescription::setup(const std::string& packageName)
// read new contents from input file // read new contents from input file
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromTxtFile(packageName.c_str()); pdr.readFromTxtFile(packageName);
apply(pdr); apply(pdr);
// root directory // root directory
@ -229,30 +229,34 @@ void CPackageDescription::storeToPdr(CPersistentDataRecord& pdr) const
void CPackageDescription::readIndex(CBNPFileSet& packageIndex) const void CPackageDescription::readIndex(CBNPFileSet& packageIndex) const
{ {
nlinfo("Reading history file: %s ...",(_RootDirectory+_IndexFileName).c_str()); std::string indexPath = _RootDirectory + _IndexFileName;
nlinfo("Reading history file: %s ...", indexPath.c_str());
// clear out old contents before reading from input file // clear out old contents before reading from input file
packageIndex.clear(); packageIndex.clear();
// read new contents from input file // read new contents from input file
if (NLMISC::CFile::fileExists(_RootDirectory+_IndexFileName)) if (NLMISC::CFile::fileExists(indexPath))
{ {
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromTxtFile((_RootDirectory+_IndexFileName).c_str()); pdr.readFromTxtFile(indexPath);
packageIndex.apply(pdr); packageIndex.apply(pdr);
} }
} }
void CPackageDescription::writeIndex(const CBNPFileSet& packageIndex) const void CPackageDescription::writeIndex(const CBNPFileSet& packageIndex) const
{ {
nlinfo("Writing history file: %s ...",(_RootDirectory+_IndexFileName).c_str()); std::string indexPath = _RootDirectory + _IndexFileName;
nlinfo("Writing history file: %s ...", indexPath.c_str());
// write contents to output file // write contents to output file
static CPersistentDataRecordRyzomStore pdr; static CPersistentDataRecordRyzomStore pdr;
pdr.clear(); pdr.clear();
packageIndex.store(pdr); packageIndex.store(pdr);
pdr.writeToTxtFile((_RootDirectory+_IndexFileName).c_str()); pdr.writeToTxtFile(indexPath);
} }
void CPackageDescription::getCategories(CPersistentDataRecord &pdr) const void CPackageDescription::getCategories(CPersistentDataRecord &pdr) const
@ -287,10 +291,14 @@ void CPackageDescription::updateIndexFileList(CBNPFileSet& packageIndex) const
void CPackageDescription::generateClientIndex(CProductDescriptionForClient& theClientPackage, const CBNPFileSet& packageIndex) const void CPackageDescription::generateClientIndex(CProductDescriptionForClient& theClientPackage, const CBNPFileSet& packageIndex) const
{ {
nlinfo("Generating client index: %s ...",(_PatchDirectory+toString("%05u/", packageIndex.getVersionNumber())+_ClientIndexFileName).c_str()); std::string patchNumber = toString("%05u", packageIndex.getVersionNumber());
std::string patchDirectory = _PatchDirectory + patchNumber;
std::string patchFile = patchDirectory + "/" + _ClientIndexFileName;
nlinfo("Generating client index: %s...", patchFile.c_str());
// make sure the version sub directory exist // make sure the version sub directory exist
CFile::createDirectory(_PatchDirectory+toString("%05u/", packageIndex.getVersionNumber())); CFile::createDirectory(patchDirectory);
// clear out the client package before we start // clear out the client package before we start
theClientPackage.clear(); theClientPackage.clear();
@ -310,11 +318,10 @@ void CPackageDescription::generateClientIndex(CProductDescriptionForClient& theC
pdr.clear(); pdr.clear();
theClientPackage.store(pdr); theClientPackage.store(pdr);
std::string newName = _PatchDirectory + toString("%05u/", packageIndex.getVersionNumber()) + NLMISC::CFile::getFilenameWithoutExtension(_ClientIndexFileName); std::string newName = patchDirectory + "/" + NLMISC::CFile::getFilenameWithoutExtension(_ClientIndexFileName) + "_" + patchNumber;
newName += NLMISC::toString("_%05u", packageIndex.getVersionNumber());
pdr.writeToBinFile((newName+".idx").c_str()); pdr.writeToBinFile(newName + ".idx");
pdr.writeToTxtFile((newName+"_debug.xml").c_str()); pdr.writeToTxtFile(newName + "_debug.xml");
} }
void CPackageDescription::addVersion(CBNPFileSet& packageIndex) void CPackageDescription::addVersion(CBNPFileSet& packageIndex)
@ -548,12 +555,13 @@ static bool createNewProduct(std::string fileName)
static CPersistentDataRecordRyzomStore pdr; static CPersistentDataRecordRyzomStore pdr;
pdr.clear(); pdr.clear();
package.storeToPdr(pdr); package.storeToPdr(pdr);
pdr.writeToTxtFile(fileName.c_str()); pdr.writeToTxtFile(fileName);
package.setup(fileName); package.setup(fileName);
package.createDirectories(); package.createDirectories();
package.buildDefaultFileList(); package.buildDefaultFileList();
package.storeToPdr(pdr); package.storeToPdr(pdr);
pdr.writeToTxtFile(fileName.c_str()); pdr.writeToTxtFile(fileName);
BOMB_IF(!NLMISC::CFile::fileExists(fileName),("Failed to create new package file: "+fileName).c_str(),return false); BOMB_IF(!NLMISC::CFile::fileExists(fileName),("Failed to create new package file: "+fileName).c_str(),return false);
nlinfo("New package description file created successfully: %s",fileName.c_str()); nlinfo("New package description file created successfully: %s",fileName.c_str());

View file

@ -258,25 +258,25 @@ int main(int argc, char *argv[])
} }
else else
printf("Converting '%s' (XML) to '%s' (BINARY)\n", fileName.c_str(), outputFileName.c_str() ); printf("Converting '%s' (XML) to '%s' (BINARY)\n", fileName.c_str(), outputFileName.c_str() );
if (!pdr.readFromTxtFile(fileName.c_str())) if (!pdr.readFromTxtFile(fileName))
goto failureRead; goto failureRead;
if (!pdr.writeToBinFile(outputFileName.c_str())) if (!pdr.writeToBinFile(outputFileName))
goto failureWrite; goto failureWrite;
break; break;
case cm_to_xml: case cm_to_xml:
printf("Converting '%s' (BINARY) to '%s' (XML)\n", fileName.c_str(), outputFileName.c_str() ); printf("Converting '%s' (BINARY) to '%s' (XML)\n", fileName.c_str(), outputFileName.c_str() );
if (!pdr.readFromBinFile(fileName.c_str())) if (!pdr.readFromBinFile(fileName))
goto failureRead; goto failureRead;
if (!pdr.writeToTxtFile(outputFileName.c_str(), CPersistentDataRecord::XML_STRING)) if (!pdr.writeToTxtFile(outputFileName, CPersistentDataRecord::XML_STRING))
goto failureWrite; goto failureWrite;
break; break;
case cm_to_txt: case cm_to_txt:
printf("Converting '%s' (BINARY) to '%s' (TXT)\n", fileName.c_str(), outputFileName.c_str() ); printf("Converting '%s' (BINARY) to '%s' (TXT)\n", fileName.c_str(), outputFileName.c_str() );
if (!pdr.readFromBinFile(fileName.c_str())) if (!pdr.readFromBinFile(fileName))
goto failureRead; goto failureRead;
if (!pdr.writeToTxtFile(outputFileName.c_str(), CPersistentDataRecord::LINES_STRING)) if (!pdr.writeToTxtFile(outputFileName, CPersistentDataRecord::LINES_STRING))
goto failureWrite; goto failureWrite;
break; break;
default: default:

View file

@ -142,7 +142,7 @@ NLMISC_COMMAND(listCharNames,"display the names of the characters int he listed
{ {
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromFile(files[i].c_str()); pdr.readFromFile(files[i]);
CStatsScanCharacter c; CStatsScanCharacter c;
c.apply(pdr); c.apply(pdr);

View file

@ -99,7 +99,7 @@ void CCharacterScanJob::update()
// load the file into a pdr record // load the file into a pdr record
static CPersistentDataRecord pdr; static CPersistentDataRecord pdr;
pdr.clear(); pdr.clear();
pdr.readFromFile(_Files[_NextFile].c_str()); pdr.readFromFile(_Files[_NextFile]);
++_NextFile; ++_NextFile;
// create a character representation and apply the pdr // create a character representation and apply the pdr