diff --git a/Contrib/VPatch/Source/GenPat/PatchGenerator.cpp b/Contrib/VPatch/Source/GenPat/PatchGenerator.cpp index 172c96e8..22f1369b 100644 --- a/Contrib/VPatch/Source/GenPat/PatchGenerator.cpp +++ b/Contrib/VPatch/Source/GenPat/PatchGenerator.cpp @@ -88,7 +88,9 @@ void PatchGenerator::execute(vector& sameBlocks) { } // we need to update the memory cache of target - tout << _T("[CacheReload] File position = ") << static_cast(targetCDataBaseOffset) << _T("\n"); + if (beVerbose) { + tout << _T("[CacheReload] File position = ") << static_cast(targetCDataBaseOffset) << _T("\n"); + } target.seekg(targetCDataBaseOffset,ios::beg); target.read(reinterpret_cast(targetCData),targetCDataSize); diff --git a/Contrib/VPatch/Source/GenPat/main.cpp b/Contrib/VPatch/Source/GenPat/main.cpp index 787c5bda..03ae8c80 100644 --- a/Contrib/VPatch/Source/GenPat/main.cpp +++ b/Contrib/VPatch/Source/GenPat/main.cpp @@ -275,23 +275,24 @@ int _tmain( int argc, TCHAR * argv[] ) { *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()); + 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 bifstream tempF; 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; 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); + if (patchF.fail()) throw _T("Could not write patch file"); 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) { terr << _T("Error thrown: ") << s.c_str(); @@ -301,6 +302,10 @@ int _tmain( int argc, TCHAR * argv[] ) { terr << _T("Error thrown: ") << s; return 2; } + catch(...) { + terr << _T("Error thrown: Unknown error!\n"); + return 2; + } } else { terr << _T("There was a problem opening the files.\n"); return 2;