Merge branch 'fixes' into yubo

merge-requests/7/merge
Ulukyn 4 years ago
commit 222e2c5f77

@ -245,7 +245,7 @@ void CPatchManager::init(const std::vector<std::string>& patchURIs, const std::s
#endif #endif
// App name matches Domain on the SQL server // App name matches Domain on the SQL server
std::string appName = cf->getVarPtr("Application") std::string appName = cf->getVarPtr("Application")
? cf->getVar("Application").asString(0) ? cf->getVar("Application").asString(0)
: "default"; : "default";
@ -1354,7 +1354,7 @@ void CPatchManager::getServerFile (const std::string &name, bool bZipped, const
{ {
//nlwarning("EXCEPTION CATCH: getServerFile() failed - try to find an alternative: %i: %s",UsedServer,PatchServers[UsedServer].DisplayedServerPath.c_str()); //nlwarning("EXCEPTION CATCH: getServerFile() failed - try to find an alternative: %i: %s",UsedServer,PatchServers[UsedServer].DisplayedServerPath.c_str());
nlwarning("EXCEPTION CATCH: getServerFile() failed - try to find an alternative :"); nlwarning("EXCEPTION CATCH: getServerFile() failed - try to find an alternative : %s", (serverPath+srcName).c_str());
nlwarning("%i", UsedServer); nlwarning("%i", UsedServer);
if (UsedServer >= 0 && UsedServer < (int) PatchServers.size()) if (UsedServer >= 0 && UsedServer < (int) PatchServers.size())
{ {
@ -2676,6 +2676,7 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
string OutFilename; string OutFilename;
bool usePatchFile = true; bool usePatchFile = true;
bool haveAllreadyTryiedDownloadingOfFile = false;
// compute the total size of patch to download // compute the total size of patch to download
uint32 totalPatchSize = 0; uint32 totalPatchSize = 0;
@ -2743,6 +2744,7 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
{ {
// can not load the 7zip file, use normal patching // can not load the 7zip file, use normal patching
usePatchFile = true; usePatchFile = true;
haveAllreadyTryiedDownloadingOfFile = true;
break; break;
} }
@ -2754,6 +2756,7 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
{ {
// fallback to standard patch method // fallback to standard patch method
usePatchFile = true; usePatchFile = true;
haveAllreadyTryiedDownloadingOfFile = true;
break; break;
} }
} }
@ -2766,6 +2769,7 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
nlwarning("Failed to unpack lzma file %s", (pPM->ClientPatchPath+lzmaFile).c_str()); nlwarning("Failed to unpack lzma file %s", (pPM->ClientPatchPath+lzmaFile).c_str());
// fallback to standard patch method // fallback to standard patch method
usePatchFile = true; usePatchFile = true;
haveAllreadyTryiedDownloadingOfFile = true;
break; break;
} }
@ -2874,32 +2878,108 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
sTranslate = CI18N::get("uiApplyingDelta") + " " + CFile::getFilename(PatchName); sTranslate = CI18N::get("uiApplyingDelta") + " " + CFile::getFilename(PatchName);
pPM->setState(true, sTranslate); pPM->setState(true, sTranslate);
xDeltaPatch(PatchName, SourceNameXD, OutFilename); bool deltaPatchResult = xDeltaPatch(PatchName, SourceNameXD, OutFilename);
if (rFTP.LocalFileExists) if (!deltaPatchResult && !haveAllreadyTryiedDownloadingOfFile) // Patch failed, try to download and apply lzma
pPM->deleteFile(SourceName);
pPM->deleteFile(PatchName);
if (j > 0)
{ {
pPM->deleteFile(SourceNameXD, false, false); // File can exists if bad BNP loading breakable
} {
tmpSourceName = OutFilename; // compute the seven zip filename
PatchSizeProgress += rFTP.PatcheSizes[j]; string lzmaFile = rFTP.FileName+".lzma";
currentPatchedSize += rFTP.PatcheSizes[j];
}
if (tmpSourceName != DestinationName) // download the 7zip file
{ try
pPM->deleteFile(SourceName, false, false); // File can exists if bad BNP loading {
if (!_CommitPatch) // first, try in the file version subfolfer
{ try
// let the patch in the unpack directory {
pPM->renameFile(tmpSourceName, pPM->ClientPatchPath + rFTP.FileName + ".tmp"); progress.Scale = 1.f;
progress.Bias = 0.f;
if (!rFTP.Patches.empty())
{
pPM->getServerFile(toString("%05u/", rFTP.Patches.back())+lzmaFile, false, "", &progress);
}
// else -> file comes from a previous download (with .tmp extension, and is up to date)
// the remaining code will just rename it with good name and exit
}
catch (const NLMISC::EWriteError &)
{
// this is a local error, rethrow ...
throw;
}
catch(...)
{
// failed with version subfolder, try in the root patch directory
pPM->getServerFile(lzmaFile, false, "", &progress);
}
}
catch (const NLMISC::EWriteError &)
{
// this is a local error, rethrow ...
throw;
}
catch (...)
{
break;
}
OutFilename = pPM->ClientPatchPath + NLMISC::CFile::getFilename(rFTP.FileName);
// try to unpack the file
try
{
if (!unpackLZMA(pPM->ClientPatchPath+lzmaFile, OutFilename+".tmp"))
{
break;
}
}
catch (const NLMISC::EWriteError&)
{
throw;
}
catch (...)
{
nlwarning("Failed to unpack lzma file %s", (pPM->ClientPatchPath+lzmaFile).c_str());
break;
}
if (rFTP.LocalFileExists)
pPM->deleteFile(SourceName);
pPM->deleteFile(pPM->ClientPatchPath+lzmaFile); // delete the archive file
pPM->deleteFile(SourceName, false, false); // File can exists if bad BNP loading
if (_CommitPatch)
{
pPM->renameFile(OutFilename+".tmp", DestinationName);
}
}
} }
else else
{ {
pPM->renameFile(tmpSourceName, DestinationName); if (rFTP.LocalFileExists)
pPM->deleteFile(SourceName);
pPM->deleteFile(PatchName);
if (j > 0)
{
pPM->deleteFile(SourceNameXD, false, false); // File can exists if bad BNP loading
}
tmpSourceName = OutFilename;
PatchSizeProgress += rFTP.PatcheSizes[j];
currentPatchedSize += rFTP.PatcheSizes[j];
}
if (tmpSourceName != DestinationName)
{
pPM->deleteFile(SourceName, false, false); // File can exists if bad BNP loading
if (!_CommitPatch)
{
// let the patch in the unpack directory
pPM->renameFile(tmpSourceName, pPM->ClientPatchPath + rFTP.FileName + ".tmp");
}
else
{
pPM->renameFile(tmpSourceName, DestinationName);
}
} }
} }
} }
@ -2915,7 +2995,7 @@ void CPatchThread::processFile (CPatchManager::SFileToPatch &rFTP)
} }
// **************************************************************************** // ****************************************************************************
void CPatchThread::xDeltaPatch(const string &patch, const string &src, const string &out) bool CPatchThread::xDeltaPatch(const string &patch, const string &src, const string &out)
{ {
// Internal xdelta // Internal xdelta
@ -2941,12 +3021,13 @@ void CPatchThread::xDeltaPatch(const string &patch, const string &src, const str
break; break;
default: default:
{ {
std::string str = toString("Error applying %s to %s giving %s", patch.c_str(), src.c_str(), out.c_str()); nlinfo("Error applying %s to %s giving %s", patch.c_str(), src.c_str(), out.c_str());
throw Exception (str); return false;
} }
break; break;
} }
} } else
return true;
// Launching xdelta // Launching xdelta

@ -547,7 +547,7 @@ private:
void run(); void run();
void processFile (CPatchManager::SFileToPatch &rFTP); void processFile (CPatchManager::SFileToPatch &rFTP);
void xDeltaPatch(const std::string &patch, const std::string &src, const std::string &out); bool xDeltaPatch(const std::string &patch, const std::string &src, const std::string &out);
}; };
/** /**

Loading…
Cancel
Save