aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2017-08-06 18:28:29 +0200
committerShauren <shauren.trinity@gmail.com>2017-08-06 18:28:29 +0200
commit4e3f3b7d6833520a3a6ba25b3d7432088f4a2a2a (patch)
tree100124393340da3e0bea7695b64f6e85a065ce8d /src
parent3eedb3b714a474bbcfeb0a87acce98181c2d2ca2 (diff)
Tools/Extractors: Fixed mapextractor getting stuck on some files and writing them infinitely (it will now fail fast)
Diffstat (limited to 'src')
-rw-r--r--src/tools/map_extractor/System.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp
index 2399a57e1e4..b12f0cbe34e 100644
--- a/src/tools/map_extractor/System.cpp
+++ b/src/tools/map_extractor/System.cpp
@@ -1131,6 +1131,14 @@ void ExtractMaps(uint32 build)
bool ExtractFile(CASC::FileHandle const& fileInArchive, std::string const& filename)
{
+ DWORD fileSize, fileSizeHigh;
+ fileSize = CASC::GetFileSize(fileInArchive, &fileSizeHigh);
+ if (fileSize == CASC_INVALID_SIZE)
+ {
+ printf("Can't read file size of '%s'\n", filename.c_str());
+ return false;
+ }
+
FILE* output = fopen(filename.c_str(), "wb");
if (!output)
{
@@ -1139,14 +1147,28 @@ bool ExtractFile(CASC::FileHandle const& fileInArchive, std::string const& filen
}
char buffer[0x10000];
- DWORD readBytes = 1;
+ DWORD readBytes;
- while (readBytes > 0)
+ do
{
- CASC::ReadFile(fileInArchive, buffer, sizeof(buffer), &readBytes);
- if (readBytes > 0)
- fwrite(buffer, 1, readBytes, output);
- }
+ readBytes = 0;
+ if (!CASC::ReadFile(fileInArchive, buffer, std::min<DWORD>(fileSize, sizeof(buffer)), &readBytes))
+ {
+ printf("Can't read file '%s'\n", filename.c_str());
+ fclose(output);
+ boost::filesystem::remove(filename);
+ return false;
+ }
+
+ if (!readBytes)
+ break;
+
+ fwrite(buffer, 1, readBytes, output);
+ fileSize -= readBytes;
+ if (!fileSize) // now we have read entire file
+ break;
+
+ } while (true);
fclose(output);
return true;