another patch from baby.lueshi: DiscScrubber doesn't modify original file anymore, and just returns the "real" or "free'd" buffer inline with compression - so it should be a little faster too :)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5032 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman
2010-02-08 22:46:04 +00:00
parent 98ddeadbbf
commit 5f19fb22b2
3 changed files with 66 additions and 82 deletions

View File

@ -158,6 +158,8 @@ void CompressedBlobReader::GetBlock(u64 block_num, u8 *out_ptr)
bool CompressFileToBlob(const char* infile, const char* outfile, u32 sub_type,
int block_size, CompressCB callback, void* arg)
{
bool scrubbing = false;
if (IsCompressedBlob(infile))
{
PanicAlert("%s is already compressed! Cannot compress it further.", infile);
@ -166,11 +168,13 @@ bool CompressFileToBlob(const char* infile, const char* outfile, u32 sub_type,
if (sub_type == 1)
{
if (!DiscScrubber::Scrub(infile, callback, arg))
if (!DiscScrubber::SetupScrub(infile, block_size))
{
PanicAlert("%s failed to be scrubbed. Probably the image is corrupt.", infile);
return false;
}
scrubbing = true;
}
FILE* inf = fopen(infile, "rb");
@ -230,7 +234,10 @@ bool CompressFileToBlob(const char* infile, const char* outfile, u32 sub_type,
// u64 start = i * header.block_size;
// u64 size = header.block_size;
std::fill(in_buf, in_buf + header.block_size, 0);
fread(in_buf, header.block_size, 1, inf);
if (scrubbing)
DiscScrubber::GetNextBlock(inf, in_buf);
else
fread(in_buf, header.block_size, 1, inf);
z_stream z;
memset(&z, 0, sizeof(z));
z.zalloc = Z_NULL;
@ -289,6 +296,7 @@ cleanup:
delete[] hashes;
fclose(f);
fclose(inf);
DiscScrubber::Cleanup();
callback("Done compressing disc image.", 1.0f, arg);
return true;
}