Workaround '0' unpack directory bug, and don't choke on 0 size files when unpacking bnp files

--HG--
branch : feature-streamed-package
hg/feature/streamed-package
kaetemi 10 years ago
parent 20b4fc8a87
commit 4ba6b6c4bf

@ -330,13 +330,16 @@ void unpack (const string &dirName)
if (out != NULL)
{
nlfseek64 (bnp, rBNPFile.Pos, SEEK_SET);
uint8 *ptr = new uint8[rBNPFile.Size];
if (fread (ptr, rBNPFile.Size, 1, bnp) != 1)
nlwarning("%s read error", filename.c_str());
if (fwrite (ptr, rBNPFile.Size, 1, out) != 1)
nlwarning("%s write error", filename.c_str());
if (rBNPFile.Size)
{
uint8 *ptr = new uint8[rBNPFile.Size];
if (fread (ptr, rBNPFile.Size, 1, bnp) != 1)
nlwarning("%s read error", filename.c_str());
if (fwrite (ptr, rBNPFile.Size, 1, out) != 1)
nlwarning("%s write error", filename.c_str());
delete [] ptr;
}
fclose (out);
delete [] ptr;
}
}
fclose (bnp);

@ -1176,13 +1176,35 @@ void CPatchManager::readDescFile(sint32 nVersion)
std::string unpackTo = category.getUnpackTo();
if (unpackTo.substr(0, 2) == "./")
if (unpackTo == "0")
{
nlwarning("BUG: unpackTo == '0'");
unpackTo = ClientRootPath;
category.setUnpackTo(unpackTo);
}
else if (unpackTo.substr(0, 2) == "./")
{
unpackTo = ClientRootPath + unpackTo.substr(2);
category.setUnpackTo(unpackTo);
}
}
}
else
{
for (cat = 0; cat < DescFile.getCategories().categoryCount(); ++cat)
{
CBNPCategory &category = const_cast<CBNPCategory &>(DescFile.getCategories().getCategory(cat));
std::string unpackTo = category.getUnpackTo();
if (unpackTo == "0")
{
nlwarning("BUG: unpackTo == '0'");
unpackTo = "./";
category.setUnpackTo(unpackTo);
}
}
}
// tmp for debug : flag some categories as 'Mainland'
for (cat = 0; cat < DescFile.getCategories().categoryCount(); ++cat)
@ -1884,29 +1906,36 @@ bool CPatchManager::bnpUnpack(const string &srcBigfile, const string &dstPath, v
if (out != NULL)
{
nlfseek64 (bnp, rBNPFile.Pos, SEEK_SET);
uint8 *ptr = new uint8[rBNPFile.Size];
if (fread (ptr, rBNPFile.Size, 1, bnp) != 1)
if (rBNPFile.Size)
{
fclose(out);
return false;
}
uint8 *ptr = new uint8[rBNPFile.Size];
bool writeError = fwrite (ptr, rBNPFile.Size, 1, out) != 1;
if (writeError)
{
nlwarning("errno = %d", errno);
}
bool diskFull = ferror(out) && errno == 28 /* ENOSPC*/;
fclose (out);
delete [] ptr;
if (diskFull)
{
throw NLMISC::EDiskFullError(filename);
if (fread (ptr, rBNPFile.Size, 1, bnp) != 1)
{
fclose(out);
return false;
}
bool writeError = fwrite (ptr, rBNPFile.Size, 1, out) != 1;
if (writeError)
{
nlwarning("errno = %d", errno);
}
bool diskFull = ferror(out) && errno == 28 /* ENOSPC*/;
fclose (out);
delete [] ptr;
if (diskFull)
{
throw NLMISC::EDiskFullError(filename);
}
if (writeError)
{
throw NLMISC::EWriteError(filename);
}
}
if (writeError)
else
{
throw NLMISC::EWriteError(filename);
fclose (out);
}
}
}

Loading…
Cancel
Save