Changed: Allow to use a readable and writable data path for IG patch (usefull when data are read only)
This commit is contained in:
parent
c8a0d17a77
commit
b9962b01c9
2 changed files with 82 additions and 30 deletions
|
@ -207,9 +207,23 @@ CPatchManager::CPatchManager() : State("t_state"), DataScanState("t_data_scan_st
|
||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
void CPatchManager::setClientRootPath(const std::string& clientRootPath)
|
void CPatchManager::setClientRootPath(const std::string& clientRootPath)
|
||||||
{
|
{
|
||||||
ClientRootPath = clientRootPath;
|
ClientRootPath = CPath::standardizePath(clientRootPath);
|
||||||
ClientPatchPath = ClientRootPath + "unpack/";
|
ClientPatchPath = CPath::standardizePath(ClientRootPath + "unpack");
|
||||||
ClientDataPath = ClientRootPath + "data/";
|
ReadableClientDataPath = CPath::standardizePath(ClientRootPath + "data");
|
||||||
|
|
||||||
|
std::string writableTest = ReadableClientDataPath + "writableTest";
|
||||||
|
|
||||||
|
// if succeeded to create a delete a temporary file in data directory
|
||||||
|
if (CFile::createEmptyFile(writableTest) && CFile::deleteFile(writableTest))
|
||||||
|
{
|
||||||
|
// use it to patch data files
|
||||||
|
WritableClientDataPath = ReadableClientDataPath;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// use system user profile to patch data files
|
||||||
|
WritableClientDataPath = CPath::standardizePath(CPath::getApplicationDirectory("Ryzom") + "data");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
|
@ -253,7 +267,7 @@ void CPatchManager::init(const std::vector<std::string>& patchURIs, const std::s
|
||||||
DisplayedServerPath = ServerPath;
|
DisplayedServerPath = ServerPath;
|
||||||
|
|
||||||
NLMISC::CFile::createDirectory(ClientPatchPath);
|
NLMISC::CFile::createDirectory(ClientPatchPath);
|
||||||
NLMISC::CFile::createDirectory(ClientDataPath);
|
NLMISC::CFile::createDirectory(WritableClientDataPath);
|
||||||
|
|
||||||
|
|
||||||
// try to read the version file from the server (that will replace the version number)
|
// try to read the version file from the server (that will replace the version number)
|
||||||
|
@ -787,7 +801,7 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
//:TODO: handle exception?
|
// TODO: handle exception?
|
||||||
string err = toString("Error unpacking %s", rFilename.c_str());
|
string err = toString("Error unpacking %s", rFilename.c_str());
|
||||||
|
|
||||||
if (useBatchFile)
|
if (useBatchFile)
|
||||||
|
@ -913,7 +927,6 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool
|
||||||
throw NLMISC::EWriteError(UpdateBatchFilename.c_str());
|
throw NLMISC::EWriteError(UpdateBatchFilename.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
|
@ -1616,9 +1629,25 @@ void CPatchManager::getPatchFromDesc(SFileToPatch &ftpOut, const CBNPFile &fIn,
|
||||||
// Only look in data path if the file should not be unpack (otherwise it should only remains in the "unpack" directory)
|
// Only look in data path if the file should not be unpack (otherwise it should only remains in the "unpack" directory)
|
||||||
if (!needUnpack)
|
if (!needUnpack)
|
||||||
{
|
{
|
||||||
if (sFilePath.empty() && NLMISC::CFile::fileExists(ClientDataPath + rFilename)) sFilePath = ClientDataPath + rFilename;
|
if (sFilePath.empty())
|
||||||
|
{
|
||||||
|
if (NLMISC::CFile::fileExists(WritableClientDataPath + rFilename))
|
||||||
|
{
|
||||||
|
// if file exists in writable directory, use it
|
||||||
|
sFilePath = WritableClientDataPath + rFilename;
|
||||||
|
}
|
||||||
|
else if (NLMISC::CFile::fileExists(ReadableClientDataPath + rFilename))
|
||||||
|
{
|
||||||
|
// if file exists in readable directory, use it
|
||||||
|
sFilePath = ReadableClientDataPath + rFilename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sFilePath.empty() && NLMISC::CFile::fileExists(ClientPatchPath + rFilename))
|
||||||
|
{
|
||||||
|
sFilePath = ClientPatchPath + rFilename;
|
||||||
}
|
}
|
||||||
if (sFilePath.empty() && NLMISC::CFile::fileExists(ClientPatchPath + rFilename)) sFilePath = ClientPatchPath + rFilename;
|
|
||||||
|
|
||||||
// following lines removed by Sadge to ensure that the correct file is patched
|
// following lines removed by Sadge to ensure that the correct file is patched
|
||||||
// string sFilePath = CPath::lookup(rFilename, false, false);
|
// string sFilePath = CPath::lookup(rFilename, false, false);
|
||||||
|
@ -2040,6 +2069,7 @@ uint CPatchManager::applyScanDataResult()
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
uint numError= 0;
|
uint numError= 0;
|
||||||
|
|
||||||
{
|
{
|
||||||
TSyncDataScanState::CAccessor ac(&DataScanState);
|
TSyncDataScanState::CAccessor ac(&DataScanState);
|
||||||
CDataScanState &val= ac.value();
|
CDataScanState &val= ac.value();
|
||||||
|
@ -2057,7 +2087,8 @@ uint CPatchManager::applyScanDataResult()
|
||||||
// get file path
|
// get file path
|
||||||
// following lines added by Sadge to ensure that the correct file gets patched
|
// following lines added by Sadge to ensure that the correct file gets patched
|
||||||
string sFilePath;
|
string sFilePath;
|
||||||
if (NLMISC::CFile::fileExists(ClientDataPath + ftp.FileName)) sFilePath = ClientDataPath + ftp.FileName;
|
if (NLMISC::CFile::fileExists(WritableClientDataPath + ftp.FileName)) sFilePath = WritableClientDataPath + ftp.FileName;
|
||||||
|
if (sFilePath.empty() && NLMISC::CFile::fileExists(ReadableClientDataPath + ftp.FileName)) sFilePath = ReadableClientDataPath + ftp.FileName;
|
||||||
if (sFilePath.empty() && NLMISC::CFile::fileExists(ClientPatchPath + ftp.FileName)) sFilePath = ClientPatchPath + ftp.FileName;
|
if (sFilePath.empty() && NLMISC::CFile::fileExists(ClientPatchPath + ftp.FileName)) sFilePath = ClientPatchPath + ftp.FileName;
|
||||||
|
|
||||||
// following lines removed by Sadge to ensure that the correct file gets patched
|
// following lines removed by Sadge to ensure that the correct file gets patched
|
||||||
|
@ -2768,15 +2799,31 @@ public:
|
||||||
void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
|
void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
|
||||||
{
|
{
|
||||||
CPatchManager *pPM = CPatchManager::getInstance();
|
CPatchManager *pPM = CPatchManager::getInstance();
|
||||||
// Source File Name
|
|
||||||
|
// Source File Name (in writable or readable directory)
|
||||||
string SourceName;
|
string SourceName;
|
||||||
|
|
||||||
|
// Destination File Name (in writable directory)
|
||||||
|
string DestinationName;
|
||||||
|
|
||||||
if (rFTP.ExtractPath.empty())
|
if (rFTP.ExtractPath.empty())
|
||||||
{
|
{
|
||||||
|
DestinationName = pPM->WritableClientDataPath + rFTP.FileName;
|
||||||
|
|
||||||
if (rFTP.LocalFileExists)
|
if (rFTP.LocalFileExists)
|
||||||
{
|
{
|
||||||
// following lines added by Sadge to ensure that the correct file gets patched
|
// following lines added by Sadge to ensure that the correct file gets patched
|
||||||
SourceName.clear();
|
SourceName.clear();
|
||||||
if (NLMISC::CFile::fileExists(pPM->ClientDataPath + rFTP.FileName)) SourceName = pPM->ClientDataPath + rFTP.FileName;
|
|
||||||
|
if (NLMISC::CFile::fileExists(pPM->WritableClientDataPath + rFTP.FileName))
|
||||||
|
{
|
||||||
|
SourceName = pPM->WritableClientDataPath + rFTP.FileName;
|
||||||
|
}
|
||||||
|
else if (NLMISC::CFile::fileExists(pPM->ReadableClientDataPath + rFTP.FileName))
|
||||||
|
{
|
||||||
|
SourceName = pPM->ReadableClientDataPath + rFTP.FileName;
|
||||||
|
}
|
||||||
|
|
||||||
// version from previous download
|
// version from previous download
|
||||||
if (SourceName.empty()) throw Exception (std::string("ERROR: Failed to find file: ")+rFTP.FileName);
|
if (SourceName.empty()) throw Exception (std::string("ERROR: Failed to find file: ")+rFTP.FileName);
|
||||||
|
|
||||||
|
@ -2788,12 +2835,13 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
|
||||||
// note : if file was background downloaded, we have :
|
// note : if file was background downloaded, we have :
|
||||||
// rFTP.LocalFileExists = false
|
// rFTP.LocalFileExists = false
|
||||||
// rFTP.SrcFileName = "unpack/filename.bnp.tmp"
|
// rFTP.SrcFileName = "unpack/filename.bnp.tmp"
|
||||||
SourceName = pPM->ClientDataPath + rFTP.FileName;
|
SourceName = DestinationName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SourceName = pPM->ClientPatchPath + rFTP.FileName;
|
SourceName = pPM->ClientPatchPath + rFTP.FileName;
|
||||||
|
DestinationName = SourceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rFTP.LocalFileToDelete)
|
if (rFTP.LocalFileToDelete)
|
||||||
|
@ -2838,7 +2886,7 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
|
||||||
for (uint i=0; i<rFTP.PatcheSizes.size(); ++i)
|
for (uint i=0; i<rFTP.PatcheSizes.size(); ++i)
|
||||||
totalPatchSize += rFTP.PatcheSizes[i];
|
totalPatchSize += rFTP.PatcheSizes[i];
|
||||||
}
|
}
|
||||||
else
|
else if (!rFTP.PatcheSizes.empty())
|
||||||
{
|
{
|
||||||
totalPatchSize = rFTP.PatcheSizes.back();
|
totalPatchSize = rFTP.PatcheSizes.back();
|
||||||
}
|
}
|
||||||
|
@ -2930,11 +2978,11 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
|
||||||
pPM->deleteFile(SourceName, false, false); // File can exists if bad BNP loading
|
pPM->deleteFile(SourceName, false, false); // File can exists if bad BNP loading
|
||||||
if (_CommitPatch)
|
if (_CommitPatch)
|
||||||
{
|
{
|
||||||
pPM->renameFile(OutFilename+".tmp", SourceName);
|
pPM->renameFile(OutFilename+".tmp", DestinationName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (usePatchFile && !rFTP.Patches.empty())
|
if (usePatchFile)
|
||||||
{
|
{
|
||||||
uint32 currentPatchedSize = 0;
|
uint32 currentPatchedSize = 0;
|
||||||
for (uint32 j = 0; j < rFTP.Patches.size(); ++j)
|
for (uint32 j = 0; j < rFTP.Patches.size(); ++j)
|
||||||
|
@ -2987,21 +3035,14 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
|
||||||
SourceNameXD = SourceNameXD.substr(0, SourceNameXD.rfind('.'));
|
SourceNameXD = SourceNameXD.substr(0, SourceNameXD.rfind('.'));
|
||||||
SourceNameXD += "_.ref";
|
SourceNameXD += "_.ref";
|
||||||
|
|
||||||
std::string refPath;
|
if (!_CommitPatch)
|
||||||
if (_CommitPatch)
|
|
||||||
{
|
|
||||||
refPath = pPM->ClientDataPath;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// works
|
// works
|
||||||
refPath = pPM->ClientPatchPath;
|
|
||||||
std::string tmpRefFile = SourceNameXD + ".tmp";
|
std::string tmpRefFile = SourceNameXD + ".tmp";
|
||||||
if (!NLMISC::CFile::fileExists(pPM->ClientPatchPath + tmpRefFile))
|
if (!NLMISC::CFile::fileExists(pPM->ClientPatchPath + tmpRefFile))
|
||||||
{
|
{
|
||||||
// Not found in the patch directory -> version in data directory should be good, or would have been
|
// Not found in the patch directory -> version in data directory should be good, or would have been
|
||||||
// detected by the check thread else.
|
// detected by the check thread else.
|
||||||
refPath = pPM->ClientDataPath;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -3018,7 +3059,14 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
|
||||||
// if (SourceNameXDFull.empty())
|
// if (SourceNameXDFull.empty())
|
||||||
// SourceNameXDFull = pPM->ClientDataPath + SourceNameXD;
|
// SourceNameXDFull = pPM->ClientDataPath + SourceNameXD;
|
||||||
// SourceNameXD = SourceNameXDFull;
|
// SourceNameXD = SourceNameXDFull;
|
||||||
SourceNameXD = pPM->ClientDataPath + SourceNameXD;
|
if (CFile::fileExists(pPM->WritableClientDataPath + SourceNameXD))
|
||||||
|
{
|
||||||
|
SourceNameXD = pPM->WritableClientDataPath + SourceNameXD;
|
||||||
|
}
|
||||||
|
else if (CFile::fileExists(pPM->ReadableClientDataPath + SourceNameXD))
|
||||||
|
{
|
||||||
|
SourceNameXD = pPM->ReadableClientDataPath + SourceNameXD;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PatchName = pPM->ClientPatchPath + PatchName;
|
PatchName = pPM->ClientPatchPath + PatchName;
|
||||||
|
@ -3042,7 +3090,8 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
|
||||||
PatchSizeProgress += rFTP.PatcheSizes[j];
|
PatchSizeProgress += rFTP.PatcheSizes[j];
|
||||||
currentPatchedSize += rFTP.PatcheSizes[j];
|
currentPatchedSize += rFTP.PatcheSizes[j];
|
||||||
}
|
}
|
||||||
if (tmpSourceName != SourceName)
|
|
||||||
|
if (tmpSourceName != DestinationName)
|
||||||
{
|
{
|
||||||
pPM->deleteFile(SourceName, false, false); // File can exists if bad BNP loading
|
pPM->deleteFile(SourceName, false, false); // File can exists if bad BNP loading
|
||||||
if (!_CommitPatch)
|
if (!_CommitPatch)
|
||||||
|
@ -3052,7 +3101,7 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pPM->renameFile(tmpSourceName, SourceName);
|
pPM->renameFile(tmpSourceName, DestinationName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3060,9 +3109,10 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
|
||||||
{
|
{
|
||||||
PatchSizeProgress += totalPatchSize;
|
PatchSizeProgress += totalPatchSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If all patches applied with success so file size should be ok
|
// If all patches applied with success so file size should be ok
|
||||||
// We just have to change file date to match the last patch applied
|
// We just have to change file date to match the last patch applied
|
||||||
pPM->applyDate(SourceName, rFTP.LastFileDate);
|
pPM->applyDate(DestinationName, rFTP.LastFileDate);
|
||||||
//progress.progress(1.f);
|
//progress.progress(1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3413,6 +3463,7 @@ bool CPatchManager::extract(const std::string& patchPath,
|
||||||
string err = toString("Can't open file '%s' for writing: code=%d %s (error code 29)", updateBatchFilename.c_str(), errno, strerror(errno));
|
string err = toString("Can't open file '%s' for writing: code=%d %s (error code 29)", updateBatchFilename.c_str(), errno, strerror(errno));
|
||||||
throw Exception (err);
|
throw Exception (err);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(fp, "@echo off\n");
|
fprintf(fp, "@echo off\n");
|
||||||
fprintf(fp, "ping 127.0.0.1 -n 7 -w 1000 > nul\n"); // wait
|
fprintf(fp, "ping 127.0.0.1 -n 7 -w 1000 > nul\n"); // wait
|
||||||
|
|
||||||
|
|
|
@ -447,8 +447,9 @@ private:
|
||||||
std::string UpdateBatchFilename;
|
std::string UpdateBatchFilename;
|
||||||
|
|
||||||
// Where the client get all delta and desc file
|
// Where the client get all delta and desc file
|
||||||
std::string ClientPatchPath;
|
std::string ClientPatchPath; // Temporary path
|
||||||
std::string ClientDataPath;
|
std::string ReadableClientDataPath; // Where original data can be found
|
||||||
|
std::string WritableClientDataPath; // Where data can be written
|
||||||
|
|
||||||
/// Output useful information for debugging in the log file
|
/// Output useful information for debugging in the log file
|
||||||
bool VerboseLog;
|
bool VerboseLog;
|
||||||
|
|
Loading…
Reference in a new issue