DolphinWX: Allow cancelling gcz compression.
This commit is contained in:
parent
f151f5ed23
commit
f2f83a0c60
|
@ -66,7 +66,7 @@ private:
|
||||||
// Factory function - examines the path to choose the right type of IBlobReader, and returns one.
|
// Factory function - examines the path to choose the right type of IBlobReader, and returns one.
|
||||||
IBlobReader* CreateBlobReader(const std::string& filename);
|
IBlobReader* CreateBlobReader(const std::string& filename);
|
||||||
|
|
||||||
typedef void (*CompressCB)(const std::string& text, float percent, void* arg);
|
typedef bool (*CompressCB)(const std::string& text, float percent, void* arg);
|
||||||
|
|
||||||
bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u32 sub_type = 0, int sector_size = 16384,
|
bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u32 sub_type = 0, int sector_size = 16384,
|
||||||
CompressCB callback = nullptr, void *arg = nullptr);
|
CompressCB callback = nullptr, void *arg = nullptr);
|
||||||
|
|
|
@ -195,6 +195,7 @@ bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u
|
||||||
int num_compressed = 0;
|
int num_compressed = 0;
|
||||||
int num_stored = 0;
|
int num_stored = 0;
|
||||||
int progress_monitor = std::max<int>(1, header.num_blocks / 1000);
|
int progress_monitor = std::max<int>(1, header.num_blocks / 1000);
|
||||||
|
bool was_cancelled = false;
|
||||||
|
|
||||||
for (u32 i = 0; i < header.num_blocks; i++)
|
for (u32 i = 0; i < header.num_blocks; i++)
|
||||||
{
|
{
|
||||||
|
@ -206,7 +207,9 @@ bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u
|
||||||
ratio = (int)(100 * position / inpos);
|
ratio = (int)(100 * position / inpos);
|
||||||
|
|
||||||
std::string temp = StringFromFormat("%i of %i blocks. Compression ratio %i%%", i, header.num_blocks, ratio);
|
std::string temp = StringFromFormat("%i of %i blocks. Compression ratio %i%%", i, header.num_blocks, ratio);
|
||||||
callback(temp, (float)i / (float)header.num_blocks, arg);
|
was_cancelled = !callback(temp, (float)i / (float)header.num_blocks, arg);
|
||||||
|
if (was_cancelled)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
offsets[i] = position;
|
offsets[i] = position;
|
||||||
|
@ -261,11 +264,20 @@ bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u
|
||||||
|
|
||||||
header.compressed_data_size = position;
|
header.compressed_data_size = position;
|
||||||
|
|
||||||
|
if (was_cancelled)
|
||||||
|
{
|
||||||
|
// Remove the incomplete output file.
|
||||||
|
f.Close();
|
||||||
|
File::Delete(outfile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Okay, go back and fill in headers
|
// Okay, go back and fill in headers
|
||||||
f.Seek(0, SEEK_SET);
|
f.Seek(0, SEEK_SET);
|
||||||
f.WriteArray(&header, 1);
|
f.WriteArray(&header, 1);
|
||||||
f.WriteArray(offsets, header.num_blocks);
|
f.WriteArray(offsets, header.num_blocks);
|
||||||
f.WriteArray(hashes, header.num_blocks);
|
f.WriteArray(hashes, header.num_blocks);
|
||||||
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
@ -301,12 +313,15 @@ bool DecompressBlobToFile(const std::string& infile, const std::string& outfile,
|
||||||
const CompressedBlobHeader &header = reader->GetHeader();
|
const CompressedBlobHeader &header = reader->GetHeader();
|
||||||
u8* buffer = new u8[header.block_size];
|
u8* buffer = new u8[header.block_size];
|
||||||
int progress_monitor = std::max<int>(1, header.num_blocks / 100);
|
int progress_monitor = std::max<int>(1, header.num_blocks / 100);
|
||||||
|
bool was_cancelled = false;
|
||||||
|
|
||||||
for (u64 i = 0; i < header.num_blocks; i++)
|
for (u64 i = 0; i < header.num_blocks; i++)
|
||||||
{
|
{
|
||||||
if (i % progress_monitor == 0)
|
if (i % progress_monitor == 0)
|
||||||
{
|
{
|
||||||
callback("Unpacking", (float)i / (float)header.num_blocks, arg);
|
was_cancelled = !callback("Unpacking", (float)i / (float)header.num_blocks, arg);
|
||||||
|
if (was_cancelled)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
reader->Read(i * header.block_size, header.block_size, buffer);
|
reader->Read(i * header.block_size, header.block_size, buffer);
|
||||||
f.WriteBytes(buffer, header.block_size);
|
f.WriteBytes(buffer, header.block_size);
|
||||||
|
@ -314,7 +329,16 @@ bool DecompressBlobToFile(const std::string& infile, const std::string& outfile,
|
||||||
|
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
|
|
||||||
|
if (was_cancelled)
|
||||||
|
{
|
||||||
|
// Remove the incomplete output file.
|
||||||
|
f.Close();
|
||||||
|
File::Delete(outfile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
f.Resize(header.data_size);
|
f.Resize(header.data_size);
|
||||||
|
}
|
||||||
|
|
||||||
delete reader;
|
delete reader;
|
||||||
|
|
||||||
|
|
|
@ -1123,14 +1123,14 @@ void CGameListCtrl::OnWiki(wxCommandEvent& WXUNUSED (event))
|
||||||
WxUtils::Launch(wikiUrl);
|
WxUtils::Launch(wikiUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGameListCtrl::MultiCompressCB(const std::string& text, float percent, void* arg)
|
bool CGameListCtrl::MultiCompressCB(const std::string& text, float percent, void* arg)
|
||||||
{
|
{
|
||||||
percent = (((float)m_currentItem) + percent) / (float)m_numberItem;
|
percent = (((float)m_currentItem) + percent) / (float)m_numberItem;
|
||||||
wxString textString(StrToWxStr(StringFromFormat("%s (%i/%i) - %s",
|
wxString textString(StrToWxStr(StringFromFormat("%s (%i/%i) - %s",
|
||||||
m_currentFilename.c_str(), (int)m_currentItem+1,
|
m_currentFilename.c_str(), (int)m_currentItem+1,
|
||||||
(int)m_numberItem, text.c_str())));
|
(int)m_numberItem, text.c_str())));
|
||||||
|
|
||||||
((wxProgressDialog*)arg)->Update((int)(percent*1000), textString);
|
return ((wxProgressDialog*)arg)->Update((int)(percent*1000), textString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGameListCtrl::OnMultiCompressISO(wxCommandEvent& /*event*/)
|
void CGameListCtrl::OnMultiCompressISO(wxCommandEvent& /*event*/)
|
||||||
|
@ -1162,6 +1162,7 @@ void CGameListCtrl::CompressSelection(bool _compress)
|
||||||
1000,
|
1000,
|
||||||
this,
|
this,
|
||||||
wxPD_APP_MODAL |
|
wxPD_APP_MODAL |
|
||||||
|
wxPD_CAN_ABORT |
|
||||||
wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME |
|
wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME |
|
||||||
wxPD_SMOOTH
|
wxPD_SMOOTH
|
||||||
);
|
);
|
||||||
|
@ -1235,9 +1236,9 @@ void CGameListCtrl::CompressSelection(bool _compress)
|
||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGameListCtrl::CompressCB(const std::string& text, float percent, void* arg)
|
bool CGameListCtrl::CompressCB(const std::string& text, float percent, void* arg)
|
||||||
{
|
{
|
||||||
((wxProgressDialog*)arg)->
|
return ((wxProgressDialog*)arg)->
|
||||||
Update((int)(percent*1000), StrToWxStr(text));
|
Update((int)(percent*1000), StrToWxStr(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1300,6 +1301,7 @@ void CGameListCtrl::OnCompressISO(wxCommandEvent& WXUNUSED (event))
|
||||||
1000,
|
1000,
|
||||||
this,
|
this,
|
||||||
wxPD_APP_MODAL |
|
wxPD_APP_MODAL |
|
||||||
|
wxPD_CAN_ABORT |
|
||||||
wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME |
|
wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME |
|
||||||
wxPD_SMOOTH
|
wxPD_SMOOTH
|
||||||
);
|
);
|
||||||
|
|
|
@ -113,6 +113,6 @@ private:
|
||||||
static size_t m_currentItem;
|
static size_t m_currentItem;
|
||||||
static std::string m_currentFilename;
|
static std::string m_currentFilename;
|
||||||
static size_t m_numberItem;
|
static size_t m_numberItem;
|
||||||
static void CompressCB(const std::string& text, float percent, void* arg);
|
static bool CompressCB(const std::string& text, float percent, void* arg);
|
||||||
static void MultiCompressCB(const std::string& text, float percent, void* arg);
|
static bool MultiCompressCB(const std::string& text, float percent, void* arg);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue