Improved VPatch GenPat error handling
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6938 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
1330518764
commit
02843c142d
2 changed files with 16 additions and 9 deletions
|
@ -88,7 +88,9 @@ void PatchGenerator::execute(vector<SameBlock*>& sameBlocks) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to update the memory cache of target
|
// we need to update the memory cache of target
|
||||||
tout << _T("[CacheReload] File position = ") << static_cast<unsigned int>(targetCDataBaseOffset) << _T("\n");
|
if (beVerbose) {
|
||||||
|
tout << _T("[CacheReload] File position = ") << static_cast<unsigned int>(targetCDataBaseOffset) << _T("\n");
|
||||||
|
}
|
||||||
|
|
||||||
target.seekg(targetCDataBaseOffset,ios::beg);
|
target.seekg(targetCDataBaseOffset,ios::beg);
|
||||||
target.read(reinterpret_cast<char*>(targetCData),targetCDataSize);
|
target.read(reinterpret_cast<char*>(targetCData),targetCDataSize);
|
||||||
|
|
|
@ -275,23 +275,24 @@ int _tmain( int argc, TCHAR * argv[] ) {
|
||||||
*iter = NULL;
|
*iter = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
patch.close();
|
patch.close(); // Close the temporary patch file so we can open it again for reading
|
||||||
TFileOffset patchSize = POSIX::getFileSize(tempFileName.c_str());
|
TFileOffset patchSize = POSIX::getFileSize(tempFileName.c_str());
|
||||||
|
char* buf = new char[patchSize];
|
||||||
|
if (!buf) throw _T("Out of memory"); // In case we switch to nothrow_t
|
||||||
|
|
||||||
// finally: copy the temporary file to the actual patch
|
// finally: copy the temporary file to the actual patch
|
||||||
bifstream tempF;
|
bifstream tempF;
|
||||||
tempF.open(tempFileName.c_str(), std::ios_base::binary | std::ios_base::in);
|
tempF.open(tempFileName.c_str(), std::ios_base::binary | std::ios_base::in);
|
||||||
|
tempF.read(buf,patchSize);
|
||||||
|
if (tempF.fail()) throw _T("Could not read temp file");
|
||||||
|
tempF.close();
|
||||||
|
bofstream().open(tempFileName.c_str(), std::ios_base::binary | std::ios_base::out); // empty the temporary file
|
||||||
|
|
||||||
bofstream patchF;
|
bofstream patchF;
|
||||||
patchF.open(patchFileName.c_str(), std::ios_base::binary | std::ios_base::out);
|
patchF.open(patchFileName.c_str(), std::ios_base::binary | std::ios_base::out);
|
||||||
char* buf = new char[patchSize];
|
|
||||||
tempF.read(buf,patchSize);
|
|
||||||
patchF.write(buf,patchSize);
|
patchF.write(buf,patchSize);
|
||||||
|
if (patchF.fail()) throw _T("Could not write patch file");
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
tempF.close();
|
|
||||||
|
|
||||||
// now empty the temporary file
|
|
||||||
bofstream clearF;
|
|
||||||
clearF.open(tempFileName.c_str(), std::ios_base::binary | std::ios_base::out);
|
|
||||||
}
|
}
|
||||||
catch(tstring s) {
|
catch(tstring s) {
|
||||||
terr << _T("Error thrown: ") << s.c_str();
|
terr << _T("Error thrown: ") << s.c_str();
|
||||||
|
@ -301,6 +302,10 @@ int _tmain( int argc, TCHAR * argv[] ) {
|
||||||
terr << _T("Error thrown: ") << s;
|
terr << _T("Error thrown: ") << s;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
catch(...) {
|
||||||
|
terr << _T("Error thrown: Unknown error!\n");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
terr << _T("There was a problem opening the files.\n");
|
terr << _T("There was a problem opening the files.\n");
|
||||||
return 2;
|
return 2;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue