Fixed: Homogenize CFile::moveFile with other methods (use std::string instead of const char*)

This commit is contained in:
kervala 2015-12-13 13:03:16 +01:00
parent 4c122318f4
commit bf73907da1
26 changed files with 51 additions and 51 deletions

View file

@ -701,7 +701,7 @@ struct CFile
/** Move a file
* NB this keeps file attributes
*/
static bool moveFile(const char *dest, const char *src);
static bool moveFile(const std::string &dest, const std::string &src);
/** Create a directory
* \return true if success

View file

@ -579,7 +579,7 @@ namespace NLGUI
string finalUrl;
if (it->type == ImgType)
{
CFile::moveFile(it->dest.c_str(), tmpfile.c_str());
CFile::moveFile(it->dest, tmpfile);
//if (lookupLocalFile (finalUrl, file.c_str(), false))
{
for(uint i = 0; i < it->imgs.size(); i++)
@ -591,7 +591,7 @@ namespace NLGUI
}
else
{
CFile::moveFile(it->dest.c_str(), tmpfile.c_str());
CFile::moveFile(it->dest, tmpfile);
//if (lookupLocalFile (finalUrl, file.c_str(), false))
{
CLuaManager::getInstance().executeLuaScript( it->luaScript, true );

View file

@ -356,7 +356,7 @@ namespace NLGUI
string backup = nextFileName+".backup";
if (CFile::fileExists(backup))
CFile::deleteFile(backup);
CFile::moveFile(backup.c_str(), nextFileName.c_str());
CFile::moveFile(backup, nextFileName);
}
return false;
}

View file

@ -627,7 +627,7 @@ void COFile::internalClose(bool success)
if (CFile::fileExists(_FileName))
CFile::deleteFile (_FileName);
if (CFile::moveFile (_FileName.c_str(), _TempFileName.c_str()))
if (CFile::moveFile(_FileName, _TempFileName))
break;
nlSleep (0);
}

View file

@ -2451,7 +2451,7 @@ bool CFile::thoroughFileCompare(const std::string &fileName0, const std::string
return true;
}
bool CFile::moveFile(const char *dest,const char *src)
bool CFile::moveFile(const std::string &dest, const std::string &src)
{
return CopyMoveFile(dest, src, false);
}

View file

@ -563,7 +563,7 @@ static bool CheckIfNeedRebuildColoredVersionForOneBitmap(const CBuildInfo &bi, c
return true;
// ok, can move the cache
if (!NLMISC::CFile::moveFile(outputHLSInfo.c_str(), cacheHLSInfo.c_str()))
if (!NLMISC::CFile::moveFile(outputHLSInfo, cacheHLSInfo))
{
nlwarning(("Couldn't move " + cacheHLSInfo + " to " + outputHLSInfo).c_str());
return true;
@ -595,7 +595,7 @@ static bool CheckIfNeedRebuildColoredVersionForOneBitmap(const CBuildInfo &bi, c
// get version that is in the cache
std::string cacheDest = bi.OutputPath + outputFileName + bi.OutputFormat;
if (!NLMISC::CFile::moveFile(cacheDest.c_str(), searchName.c_str()))
if (!NLMISC::CFile::moveFile(cacheDest, searchName))
{
nlwarning(("Couldn't move " + searchName + " to " + cacheDest).c_str());
return true;

View file

@ -127,7 +127,7 @@ private:
fclose(fp);
fp = NULL;
NLMISC::CFile::moveFile(_DstFile.c_str(), _SrcFile.c_str());
NLMISC::CFile::moveFile(_DstFile, _SrcFile);
// verify the resulting file
fp = fopen(_SrcFile.c_str(), "rb");

View file

@ -1744,7 +1744,7 @@ bool CInterfaceManager::loadConfig (const string &filename)
string sFileNameBackup = sFileName+"backup";
if (CFile::fileExists(sFileNameBackup))
CFile::deleteFile(sFileNameBackup);
CFile::moveFile(sFileNameBackup.c_str(), sFileName.c_str());
CFile::moveFile(sFileNameBackup, sFileName);
nlwarning("Config loading failed : restore default");
vector<string> v;
if (!ClientCfg.R2EDEnabled)

View file

@ -854,7 +854,7 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool
else
{
deleteFile(DstName);
CFile::moveFile(DstName.c_str(), SrcName.c_str());
CFile::moveFile(DstName, SrcName);
}
nblab++;
@ -1128,7 +1128,7 @@ void CPatchManager::renameFile (const string &src, const string &dst)
ucstring s = CI18N::get("uiRenameFile") + " " + NLMISC::CFile::getFilename(src);
setState(true, s);
if (!NLMISC::CFile::moveFile(dst.c_str(), src.c_str()))
if (!NLMISC::CFile::moveFile(dst, src))
{
s = CI18N::get("uiRenameErr") + " " + src + " -> " + dst + " (" + toString(errno) + "," + strerror(errno) + ")";
setState(true, s);
@ -3677,7 +3677,7 @@ void CDownloadThread::run()
try
{
pPM->getServerFile(patchName, false, tmpFile);
NLMISC::CFile::moveFile(finalFile.c_str(), tmpFile.c_str());
NLMISC::CFile::moveFile(finalFile, tmpFile);
pPM->applyDate(finalFile, _Entries[first].Timestamp);
}

View file

@ -4734,7 +4734,7 @@ void CEditor::autoSave()
{
CFile::deleteFile(next);
}
CFile::moveFile(next.c_str(), current.c_str());
CFile::moveFile(next, current);
}
}

View file

@ -478,7 +478,7 @@ IFileAccess::TReturnCode CDeleteFile::execute(CFileAccessManager& manager)
}
while (i <= 10000 && NLMISC::CFile::fileExists(backup));
fileBackuped = (i <= 10000 && NLMISC::CFile::moveFile(backup.c_str(), (getBackupFileName(Filename)).c_str()));
fileBackuped = (i <= 10000 && NLMISC::CFile::moveFile(backup, getBackupFileName(Filename)));
}
catch (...)
{

View file

@ -3244,8 +3244,8 @@ NLMISC_COMMAND(moveCharAndOfflineCmdToHashTable, "Move all character and offline
CFile::createDirectory(PlayerManager.getCharacterPath(userId, false));
// move the file
CFile::moveFile(
(PlayerManager.getCharacterPath(userId, false)+CFile::getFilename(allChars[i])).c_str(),
allChars[i].c_str()
PlayerManager.getCharacterPath(userId, false)+CFile::getFilename(allChars[i]),
allChars[i]
);
}
}
@ -3271,8 +3271,8 @@ NLMISC_COMMAND(moveCharAndOfflineCmdToHashTable, "Move all character and offline
CFile::createDirectory(PlayerManager.getOfflineCommandPath(userId, false));
// move the file
CFile::moveFile(
(PlayerManager.getOfflineCommandPath(userId, false)+CFile::getFilename(allCommands[i])).c_str(),
allCommands[i].c_str()
PlayerManager.getOfflineCommandPath(userId, false)+CFile::getFilename(allCommands[i]),
allCommands[i]
);
}
}

View file

@ -127,7 +127,7 @@ void CPlayer::checkCrashMarker()
wipeAndRestore(NLMISC::toString("%s/account_%u_%d_pdr.bin", PlayerManager.getCharacterPath(userId, false).c_str(), userId, charId));
// string fileName = makeCharacterFileName(lastBad[0], lastBad[1]);
// CFile::moveFile((fileName+".wiped").c_str(), fileName.c_str());
// CFile::moveFile(fileName+".wiped", fileName);
//
// // try to restore a backup
// if (CFile::isExists(fileName+".last_good"))
@ -166,9 +166,9 @@ bool wipeAndRestore(const std::string &fileName)
return false;
}
// move the last wiped file
CFile::moveFile(incFn.c_str(), newfn.c_str());
CFile::moveFile(incFn, newfn);
}
CFile::moveFile(newfn.c_str(), fileName.c_str());
CFile::moveFile(newfn, fileName);
// // try to restore a backup
//if (CFile::isExists(fileName+".last_good"))
@ -811,13 +811,13 @@ void CPlayer::loadAllCharacters()
{
nlwarning("Failed to load '%s': %s", serialBinFileName.c_str(), e.what());
string newfn = serialBinFileName+".wiped";
CFile::moveFile(newfn.c_str(), serialBinFileName.c_str());
CFile::moveFile(newfn, serialBinFileName);
}
catch(...)
{
nlwarning("Failed to load '%s': low level exception", serialBinFileName.c_str());
string newfn = serialBinFileName+".wiped";
CFile::moveFile(newfn.c_str(), serialBinFileName.c_str());
CFile::moveFile(newfn, serialBinFileName);
}
}
break;
@ -910,13 +910,13 @@ void CPlayer::loadAllCharacters()
{
nlwarning("Failed to load '%s': %s", fileName.c_str(), e.what());
string newfn = fileName+".wiped";
CFile::moveFile(newfn.c_str(), fileName.c_str());
CFile::moveFile(newfn, fileName);
}
catch(...)
{
nlwarning("Failed to load '%s': low level exception", fileName.c_str());
string newfn = fileName+".wiped";
CFile::moveFile(newfn.c_str(), fileName.c_str());
CFile::moveFile(newfn, fileName);
}
}
else
@ -937,13 +937,13 @@ void CPlayer::loadAllCharacters()
{
nlwarning("Failed to load '%s': %s", fileName.c_str(), e.what());
string newfn = fileName+".wiped";
CFile::moveFile(newfn.c_str(), fileName.c_str());
CFile::moveFile(newfn, fileName);
}
catch(...)
{
nlwarning("Failed to load '%s': low level exception", fileName.c_str());
string newfn = fileName+".wiped";
CFile::moveFile(newfn.c_str(), fileName.c_str());
CFile::moveFile(newfn, fileName);
}
}
}
@ -983,14 +983,14 @@ void CPlayer::loadAllCharactersPdr()
{
nlwarning("Failed to load '%s': %s", fileName.c_str(), e.what());
string newfn = fileName+".wiped";
CFile::moveFile(newfn.c_str(), fileName.c_str());
CFile::moveFile(newfn, fileName);
continue;
}
catch(...)
{
nlwarning("Failed to load '%s': low level exception", fileName.c_str());
string newfn = fileName+".wiped";
CFile::moveFile(newfn.c_str(), fileName.c_str());
CFile::moveFile(newfn, fileName);
continue;
}

View file

@ -477,7 +477,7 @@ void CRepositoryReceiver::fileEnd(NLNET::IModuleProxy *sender, const std::string
// rename the temp file
// note that the _receiveBeginFile() method will have removed any file that could be in the way...
bool renameOk= NLMISC::CFile::moveFile((_TargetDirectory+awaitedFileName).c_str(),rrTempFileName(_TargetDirectory,_EmitterName).c_str());
bool renameOk= NLMISC::CFile::moveFile(_TargetDirectory+awaitedFileName, rrTempFileName(_TargetDirectory,_EmitterName));
DROP_IF(!renameOk,"Failed to move tmp file ('"+rrTempFileName(_TargetDirectory,_EmitterName)+"') to : '"+fileNameRec+"'",return);
// setup the index entry for this file and force an index file write

View file

@ -318,7 +318,7 @@ namespace SAVES
// do the moving
nlinfo("Treating request to move file: %s => %s",srcPath.c_str(),dstPath.c_str());
CFile::moveFile((_Path+dstPath).c_str(),(_Path+srcPath).c_str());
CFile::moveFile(_Path+dstPath, _Path+srcPath);
// make sure the src file no longer exists and that a destination file now exists
if (CFile::fileExists(_Path+srcPath) && !CFile::fileExists(_Path+dstPath))

View file

@ -138,7 +138,7 @@ bool finalisePatch(const NLMISC::CSString& installDir,const NLMISC::CSString& fi
// rename the final patched file
nldebug("SPA RENAME: %s => %s",srcFile.c_str(),destFile.c_str());
NLMISC::CFile::moveFile(destFile.c_str(),srcFile.c_str());
NLMISC::CFile::moveFile(destFile, srcFile);
// delete the temp file used in patch generation (if there was one)
if (NLMISC::CFile::fileExists(oldFile))

View file

@ -98,7 +98,7 @@ public:
// rename the created file...
DROP_IF(!NLMISC::CFile::fileExists(_TmpFileName),"No output file created: "+_TmpFileName,return);
DROP_IF(NLMISC::CFile::fileExists(_FileName),"Cannot rename output file '"+_TmpFileName+"' because another file is in the way: "+_FileName,return);
NLMISC::CFile::moveFile(_FileName.c_str(),_TmpFileName.c_str());
NLMISC::CFile::moveFile(_FileName, _TmpFileName);
DROP_IF(!NLMISC::CFile::fileExists(_FileName),"Failed to create final output file: '"+_FileName+"' from tmp file: '"+_TmpFileName+"'",return);
}

View file

@ -246,7 +246,7 @@ public:
of.serial(*this);
}
// rename the 'tmp" into finale output file
NLMISC::CFile::moveFile(fileName.c_str(), (fileName+".tmp").c_str());
NLMISC::CFile::moveFile(fileName, fileName+".tmp");
}

View file

@ -274,7 +274,7 @@ void CMailForumService::changeUserName(uint32 shardid, const string& oldName, co
uint i;
for (i=0; i<files.size(); ++i)
CFile::moveFile((newdir+CFile::getFilename(files[i])).c_str(), files[i].c_str());
CFile::moveFile(newdir+CFile::getFilename(files[i]), files[i]);
}
@ -373,7 +373,7 @@ void CMailForumService::removeUser( uint32 shardid, string username )
}
while (CFile::isExists(userDelDir));
CFile::moveFile(userDelDir.c_str(), userDir.c_str());
CFile::moveFile(userDelDir, userDir);
}
// ****************************************************************************
@ -392,7 +392,7 @@ void CMailForumService::removeGuild( uint32 shardid, string guildname )
}
while (CFile::isExists(guildDelDir));
CFile::moveFile(guildDelDir.c_str(), guildDir.c_str());
CFile::moveFile(guildDelDir, guildDir);
}

View file

@ -677,7 +677,7 @@ namespace PATCHMAN
}
// write succeeded so rename the tmp file to the correct file name
bool ok= NLMISC::CFile::moveFile(fileName.c_str(),tmpFileName.c_str());
bool ok= NLMISC::CFile::moveFile(fileName, tmpFileName);
DROP_IF(!ok,"Failed to save file '"+fileName+"' because failed to rename tmp file: '"+tmpFileName+"'",return false);
return true;

View file

@ -493,7 +493,7 @@ void CRepositoryReceiver::fileList(NLNET::IModuleProxy *sender, uint32 version,
//
// // rename the temp file
// // note that the _receiveBeginFile() method will have removed any file that could be in the way...
// bool renameOk= NLMISC::CFile::moveFile((_TargetDirectories.patchDirectoryName()+awaitedFileName).c_str(),rrTempFileName(_TargetDirectories.patchDirectoryName(),_EmitterName).c_str());
// bool renameOk= NLMISC::CFile::moveFile(_TargetDirectories.patchDirectoryName()+awaitedFileName, rrTempFileName(_TargetDirectories.patchDirectoryName(),_EmitterName));
// DROP_IF(!renameOk,"Failed to move tmp file ('"+rrTempFileName(_TargetDirectories.patchDirectoryName(),_EmitterName)+"') to : '"+fileNameRec+"'",return);
//
// // If we're all done then we need to set the new version number

View file

@ -290,7 +290,7 @@ void CServerPatchTerminal::onModuleUpdate()
{
// move the command file to a tmp file...
CSString tmpFileName= _CommandFileName+"__patchman__spt__.tmp";
bool ok= NLMISC::CFile::moveFile(tmpFileName.c_str(),_CommandFileName.c_str());
bool ok= NLMISC::CFile::moveFile(tmpFileName,_CommandFileName);
DROP_IF(!ok,"Attempt to move file '"+_CommandFileName+"' to '"+tmpFileName+"' FAILED",return);
// read the tmp file and delete it

View file

@ -1409,7 +1409,7 @@ bool CDatabase::isReferenceUpToDate()
{
if (timestamp > _State.EndTimestamp)
{
CFile::moveFile((files[i]+".disabled").c_str(), files[i].c_str());
CFile::moveFile(files[i]+".disabled", files[i]);
continue;
}

View file

@ -369,7 +369,7 @@ void CPackageDescription::generatePatches(CBNPFileSet& packageIndex) const
// process cannot terminate)
GenerateLZMA(bnpFileName, lzmaFile+".tmp");
// rename the tmp file
CFile::moveFile(lzmaFile.c_str(), (lzmaFile+".tmp").c_str());
CFile::moveFile(lzmaFile, lzmaFile+".tmp");
}
// store the lzma file size in the descriptor

View file

@ -408,7 +408,7 @@ bool mergeStringDiff(vector<TStringInfo> &strings, const string &language, const
if (archiveDiff)
{
// move the diff file in the history dir
CFile::moveFile((historyDir+CFile::getFilename(diffs[i])).c_str(), diffs[i].c_str());
CFile::moveFile(historyDir+CFile::getFilename(diffs[i]), diffs[i]);
}
}
@ -801,7 +801,7 @@ int mergeStringDiff(int argc, char *argv[])
ucstring old;
CI18N::readTextFile(filename, old, false, true, false, CI18N::LINE_FMT_CRLF);
if (old != str)
CFile::moveFile((historyDir+CFile::getFilenameWithoutExtension(filename)+"_"+diffVersion+"."+CFile::getExtension(filename)).c_str(), filename.c_str());
CFile::moveFile(historyDir+CFile::getFilenameWithoutExtension(filename)+"_"+diffVersion+"."+CFile::getExtension(filename), filename);
}
CI18N::writeTextFile(filename, str);
@ -909,7 +909,7 @@ bool mergePhraseDiff(vector<TPhrase> &phrases, const string &language, bool only
if (archiveDiff)
{
// move the diff file in the history dir
CFile::moveFile((historyDir+CFile::getFilename(diffs[i])).c_str(), diffs[i].c_str());
CFile::moveFile(historyDir+CFile::getFilename(diffs[i]), diffs[i]);
}
}
@ -1165,7 +1165,7 @@ int mergePhraseDiff(int argc, char *argv[], int version)
ucstring old;
CI18N::readTextFile(filename, old, false, true, false, CI18N::LINE_FMT_CRLF);
if (old != str)
CFile::moveFile((historyDir+CFile::getFilenameWithoutExtension(filename)+"_"+diffVersion+"."+CFile::getExtension(filename)).c_str(), filename.c_str());
CFile::moveFile(historyDir+CFile::getFilenameWithoutExtension(filename)+"_"+diffVersion+"."+CFile::getExtension(filename), filename);
}
CI18N::writeTextFile(transDir+basename+".txt", str);
@ -1334,7 +1334,7 @@ int mergeClauseDiff(int argc, char *argv[])
ucstring old;
CI18N::readTextFile(filename, old, false, true, false, CI18N::LINE_FMT_CRLF);
if (old != str)
CFile::moveFile((historyDir+CFile::getFilenameWithoutExtension(filename)+"_"+diffVersion+"."+CFile::getExtension(filename)).c_str(), filename.c_str());
CFile::moveFile(historyDir+CFile::getFilenameWithoutExtension(filename)+"_"+diffVersion+"."+CFile::getExtension(filename), filename);
}
CI18N::writeTextFile(filename, str);
@ -1449,7 +1449,7 @@ bool mergeWorksheetDiff(const std::string filename, TWorksheet &sheet, bool only
if (archiveDiff)
{
// move the diff file in the history dir
CFile::moveFile((historyDir+CFile::getFilename(fileList[i])).c_str(), fileList[i].c_str());
CFile::moveFile(historyDir+CFile::getFilename(fileList[i]), fileList[i]);
}
}

View file

@ -245,7 +245,7 @@ void BNPFileHandle::addFiles( const vector<string> &filePathes)
if (CFile::fileExists( m_openedBNPFile ))
CFile::deleteFile( m_openedBNPFile );
string src = m_openedBNPFile + ".tmp";
CFile::moveFile( m_openedBNPFile.c_str(), src.c_str() );
CFile::moveFile(m_openedBNPFile, src);
}
// ***************************************************************************
void BNPFileHandle::deleteFiles( const vector<string>& fileNames)
@ -281,7 +281,7 @@ void BNPFileHandle::deleteFiles( const vector<string>& fileNames)
CFile::deleteFile( m_openedBNPFile );
string src = m_openedBNPFile + ".tmp";
CFile::moveFile( m_openedBNPFile.c_str(), src.c_str() );
CFile::moveFile(m_openedBNPFile, src);
}
// ***************************************************************************
void BNPFileHandle::append(const string &destination, const PackedFile &source)