added support for multi selection to compress/decompress multiple files at once (btw: it sux that we have to kick the garbage with another tool:))

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@759 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
fires.gc 2008-10-03 21:48:18 +00:00
parent d162fa6ade
commit 8997f9cb3e
4 changed files with 168 additions and 36 deletions

View File

@ -154,7 +154,7 @@ CFrame::CFrame(wxFrame* parent,
m_GameListCtrl = new CGameListCtrl(m_Panel, LIST_CTRL, m_GameListCtrl = new CGameListCtrl(m_Panel, LIST_CTRL,
wxDefaultPosition, wxDefaultSize, wxDefaultPosition, wxDefaultSize,
wxLC_REPORT | wxSUNKEN_BORDER | wxLC_ALIGN_LEFT | wxLC_SINGLE_SEL); wxLC_REPORT | wxSUNKEN_BORDER | wxLC_ALIGN_LEFT);
wxBoxSizer* sizerPanel = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer* sizerPanel = new wxBoxSizer(wxHORIZONTAL);
sizerPanel->Add(m_GameListCtrl, 2, wxEXPAND | wxALL); sizerPanel->Add(m_GameListCtrl, 2, wxEXPAND | wxALL);

View File

@ -37,8 +37,12 @@
#include "../resources/Flag_USA.xpm" #include "../resources/Flag_USA.xpm"
#endif // USE_XPM_BITMAPS #endif // USE_XPM_BITMAPS
static int currentColumn = 0; size_t CGameListCtrl::m_currentItem = 0;
size_t CGameListCtrl::m_numberItem = 0;
std::string CGameListCtrl::m_currentFilename;
static int currentColumn = 0;
bool operator < (const GameListItem &one, const GameListItem &other) bool operator < (const GameListItem &one, const GameListItem &other)
{ {
switch(currentColumn) switch(currentColumn)
@ -66,6 +70,8 @@ EVT_MENU(IDM_OPENCONTAININGFOLDER, CGameListCtrl::OnOpenContainingFolder)
EVT_MENU(IDM_SETDEFAULTGCM, CGameListCtrl::OnSetDefaultGCM) EVT_MENU(IDM_SETDEFAULTGCM, CGameListCtrl::OnSetDefaultGCM)
EVT_MENU(IDM_FILESYSTEMVIEWER, CGameListCtrl::OnFilesystemViewer) EVT_MENU(IDM_FILESYSTEMVIEWER, CGameListCtrl::OnFilesystemViewer)
EVT_MENU(IDM_COMPRESSGCM, CGameListCtrl::OnCompressGCM) EVT_MENU(IDM_COMPRESSGCM, CGameListCtrl::OnCompressGCM)
EVT_MENU(IDM_MULTICOMPRESSGCM, CGameListCtrl::OnMultiCompressGCM)
EVT_MENU(IDM_MULTIDECOMPRESSGCM, CGameListCtrl::OnMultiDecompressGCM)
EVT_MENU(IDM_DELETEGCM, CGameListCtrl::OnDeleteGCM) EVT_MENU(IDM_DELETEGCM, CGameListCtrl::OnDeleteGCM)
END_EVENT_TABLE() END_EVENT_TABLE()
@ -388,7 +394,6 @@ void CGameListCtrl::ScanForISOs()
_T("Scanning..."), _T("Scanning..."),
rFilenames.size(), // range rFilenames.size(), // range
this, // parent this, // parent
wxPD_CAN_ABORT |
wxPD_APP_MODAL | wxPD_APP_MODAL |
// wxPD_AUTO_HIDE | -- try this as well // wxPD_AUTO_HIDE | -- try this as well
wxPD_ELAPSED_TIME | wxPD_ELAPSED_TIME |
@ -511,31 +516,47 @@ void CGameListCtrl::OnRightClick(wxMouseEvent& event)
// Focus the clicked item. // Focus the clicked item.
int flags; int flags;
long item = HitTest(event.GetPosition(), flags); long item = HitTest(event.GetPosition(), flags);
if (item != wxNOT_FOUND) { if (item != wxNOT_FOUND)
SetItemState(item, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, {
wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED); if (GetItemState(item, wxLIST_STATE_SELECTED) != wxLIST_STATE_SELECTED)
} {
const GameListItem *selected_iso = GetSelectedISO(); UnselectAll();
if (selected_iso) SetItemState(item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
}
SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
}
if (GetSelectedItemCount() == 1)
{
const GameListItem *selected_iso = GetSelectedISO();
if (selected_iso)
{
std::string unique_id = selected_iso->GetUniqueID();
wxMenu popupMenu;
std::string menu_text = StringFromFormat("Edit &patch file: %s.ini", unique_id.c_str());
popupMenu.Append(IDM_EDITPATCHFILE, wxString::FromAscii(menu_text.c_str())); //Pretty much everything in wxwidgets is a wxString, try to convert to those first!
popupMenu.Append(IDM_OPENCONTAININGFOLDER, wxString::FromAscii("Open &containing folder"));
popupMenu.Append(IDM_FILESYSTEMVIEWER, wxString::FromAscii("Open in ISO viewer/dumper"));
popupMenu.AppendCheckItem(IDM_SETDEFAULTGCM, wxString::FromAscii("Set as &default ISO"));
if(selected_iso->GetFileName() == SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDefaultGCM)
popupMenu.FindItemByPosition(3)->Check();
popupMenu.AppendSeparator();
popupMenu.Append(IDM_DELETEGCM, wxString::FromAscii("&Delete ISO..."));
if (selected_iso->IsCompressed())
popupMenu.Append(IDM_COMPRESSGCM, wxString::FromAscii("Decompress ISO... (UNTESTED)"));
else
popupMenu.Append(IDM_COMPRESSGCM, wxString::FromAscii("Compress ISO... (UNTESTED)"));
PopupMenu(&popupMenu);
}
}
else if (GetSelectedItemCount() > 1)
{ {
std::string unique_id = selected_iso->GetUniqueID();
wxMenu popupMenu; wxMenu popupMenu;
std::string menu_text = StringFromFormat("Edit &patch file: %s.ini", unique_id.c_str()); popupMenu.Append(IDM_MULTICOMPRESSGCM, wxString::FromAscii("Compress selected ISOs..."));
popupMenu.Append(IDM_EDITPATCHFILE, wxString::FromAscii(menu_text.c_str())); //Pretty much everything in wxwidgets is a wxString, try to convert to those first! popupMenu.Append(IDM_MULTIDECOMPRESSGCM, wxString::FromAscii("Decompress selected ISOs..."));
popupMenu.Append(IDM_OPENCONTAININGFOLDER, wxString::FromAscii("Open &containing folder"));
popupMenu.Append(IDM_FILESYSTEMVIEWER, wxString::FromAscii("Open in ISO viewer/dumper"));
popupMenu.AppendCheckItem(IDM_SETDEFAULTGCM, wxString::FromAscii("Set as &default ISO"));
if(selected_iso->GetFileName() == SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDefaultGCM)
popupMenu.FindItemByPosition(3)->Check();
popupMenu.AppendSeparator();
popupMenu.Append(IDM_DELETEGCM, wxString::FromAscii("&Delete ISO..."));
if (selected_iso->IsCompressed())
popupMenu.Append(IDM_COMPRESSGCM, wxString::FromAscii("Decompress ISO... (UNTESTED)"));
else
popupMenu.Append(IDM_COMPRESSGCM, wxString::FromAscii("Compress ISO... (UNTESTED)"));
PopupMenu(&popupMenu); PopupMenu(&popupMenu);
} }
} }
@ -566,7 +587,8 @@ const GameListItem * CGameListCtrl::GetSelectedISO() const
return &m_ISOFiles[GetItemData(item)]; return &m_ISOFiles[GetItemData(item)];
} }
void CGameListCtrl::OnOpenContainingFolder(wxCommandEvent& WXUNUSED (event)) { void CGameListCtrl::OnOpenContainingFolder(wxCommandEvent& WXUNUSED (event))
{
const GameListItem *iso = GetSelectedISO(); const GameListItem *iso = GetSelectedISO();
if (!iso) if (!iso)
return; return;
@ -575,7 +597,8 @@ void CGameListCtrl::OnOpenContainingFolder(wxCommandEvent& WXUNUSED (event)) {
File::Explore(path.c_str()); File::Explore(path.c_str());
} }
void CGameListCtrl::OnSetDefaultGCM(wxCommandEvent& WXUNUSED (event)) { void CGameListCtrl::OnSetDefaultGCM(wxCommandEvent& WXUNUSED (event))
{
const GameListItem *iso = GetSelectedISO(); const GameListItem *iso = GetSelectedISO();
if (!iso) if (!iso)
return; return;
@ -583,7 +606,8 @@ void CGameListCtrl::OnSetDefaultGCM(wxCommandEvent& WXUNUSED (event)) {
SConfig::GetInstance().SaveSettings(); SConfig::GetInstance().SaveSettings();
} }
void CGameListCtrl::OnDeleteGCM(wxCommandEvent& WXUNUSED (event)) { void CGameListCtrl::OnDeleteGCM(wxCommandEvent& WXUNUSED (event))
{
const GameListItem *iso = GetSelectedISO(); const GameListItem *iso = GetSelectedISO();
if (!iso) if (!iso)
return; return;
@ -594,7 +618,8 @@ void CGameListCtrl::OnDeleteGCM(wxCommandEvent& WXUNUSED (event)) {
Update(); Update();
} }
void CGameListCtrl::OnFilesystemViewer(wxCommandEvent& WXUNUSED (event)) { void CGameListCtrl::OnFilesystemViewer(wxCommandEvent& WXUNUSED (event))
{
const GameListItem *iso = GetSelectedISO(); const GameListItem *iso = GetSelectedISO();
if (!iso) if (!iso)
return; return;
@ -602,13 +627,95 @@ void CGameListCtrl::OnFilesystemViewer(wxCommandEvent& WXUNUSED (event)) {
FSViewer.ShowModal(); FSViewer.ShowModal();
} }
void CGameListCtrl::MultiCompressCB(const char* text, float percent, void* arg)
{
wxString textString(wxString::Format("%s (%i/%i) - %s", m_currentFilename.c_str(), m_currentItem+1, m_numberItem, text));
percent = (((float)m_currentItem) + percent) / (float)m_numberItem;
wxProgressDialog* pDialog = (wxProgressDialog*)arg;
pDialog->Update((int)(percent*1000), textString);
}
void CGameListCtrl::OnMultiCompressGCM(wxCommandEvent& /*event*/)
{
CompressSelection(true);
}
void CGameListCtrl::OnMultiDecompressGCM(wxCommandEvent& /*event*/)
{
CompressSelection(false);
}
void CGameListCtrl::CompressSelection(bool _compress)
{
wxString dirHome;
wxGetHomeDir(&dirHome);
wxDirDialog browseDialog(this, _T("Browse for output directory"), dirHome, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
if (browseDialog.ShowModal() != wxID_OK)
return;
wxProgressDialog progressDialog(_compress ? _T("Compressing ISO") : _T("Decompressing ISO"),
_T("Working..."),
1000, // range
this, // parent
wxPD_APP_MODAL |
// wxPD_AUTO_HIDE | -- try this as well
wxPD_ELAPSED_TIME |
wxPD_ESTIMATED_TIME |
wxPD_REMAINING_TIME |
wxPD_SMOOTH // - makes indeterminate mode bar on WinXP very small
);
progressDialog.SetSize(wxSize(600, 180));
progressDialog.CenterOnParent();
m_currentItem = 0;
m_numberItem = GetSelectedItemCount();
for (size_t i=0; i<GetItemCount(); i++)
{
const GameListItem& rISOFile = m_ISOFiles[i];
if (GetItemState(i, wxLIST_STATE_SELECTED) == wxLIST_STATE_SELECTED)
{
if (!rISOFile.IsCompressed() && _compress)
{
std::string FileName;
SplitPath(rISOFile.GetFileName(), NULL, &FileName, NULL);
m_currentFilename = FileName;
FileName.append(".gcz");
std::string OutputFileName;
BuildCompleteFilename(OutputFileName, browseDialog.GetPath().ToAscii(), FileName);
DiscIO::CompressFileToBlob(rISOFile.GetFileName().c_str(), OutputFileName.c_str(), 0, 16384, &MultiCompressCB, &progressDialog);
}
else if (rISOFile.IsCompressed() && !_compress)
{
std::string FileName;
SplitPath(rISOFile.GetFileName(), NULL, &FileName, NULL);
m_currentFilename = FileName;
FileName.append(".gcm");
std::string OutputFileName;
BuildCompleteFilename(OutputFileName, browseDialog.GetPath().ToAscii(), FileName);
DiscIO::DecompressBlobToFile(rISOFile.GetFileName().c_str(), OutputFileName.c_str(), &MultiCompressCB, &progressDialog);
}
m_currentItem++;
}
}
Update();
}
void CGameListCtrl::CompressCB(const char* text, float percent, void* arg) void CGameListCtrl::CompressCB(const char* text, float percent, void* arg)
{ {
wxProgressDialog* pDialog = (wxProgressDialog*)arg; wxProgressDialog* pDialog = (wxProgressDialog*)arg;
pDialog->Update((int)(percent*1000), wxString::FromAscii(text)); pDialog->Update((int)(percent*1000), wxString::FromAscii(text));
} }
void CGameListCtrl::OnCompressGCM(wxCommandEvent& WXUNUSED (event)) { void CGameListCtrl::OnCompressGCM(wxCommandEvent& WXUNUSED (event))
{
const GameListItem *iso = GetSelectedISO(); const GameListItem *iso = GetSelectedISO();
if (!iso) if (!iso)
return; return;
@ -669,8 +776,8 @@ void CGameListCtrl::OnCompressGCM(wxCommandEvent& WXUNUSED (event)) {
wxPD_SMOOTH // - makes indeterminate mode bar on WinXP very small wxPD_SMOOTH // - makes indeterminate mode bar on WinXP very small
); );
dialog.CenterOnParent();
dialog.SetSize(wxSize(280, 180)); dialog.SetSize(wxSize(280, 180));
dialog.CenterOnParent();
if (iso->IsCompressed()) if (iso->IsCompressed())
DiscIO::DecompressBlobToFile(iso->GetFileName().c_str(), path.char_str(), &CompressCB, &dialog); DiscIO::DecompressBlobToFile(iso->GetFileName().c_str(), path.char_str(), &CompressCB, &dialog);
@ -685,9 +792,12 @@ void CGameListCtrl::OnEditPatchFile(wxCommandEvent& WXUNUSED (event))
const GameListItem *iso = GetSelectedISO(); const GameListItem *iso = GetSelectedISO();
if (!iso) if (!iso)
return; return;
std::string filename = "GameIni/" + iso->GetUniqueID() + ".ini"; std::string filename = "GameIni/" + iso->GetUniqueID() + ".ini";
if (!File::Exists(filename.c_str())) { if (!File::Exists(filename.c_str()))
if (AskYesNo("%s.ini does not exist. Do you want to create it?", iso->GetUniqueID().c_str())) { {
if (AskYesNo("%s.ini does not exist. Do you want to create it?", iso->GetUniqueID().c_str()))
{
FILE *f = fopen(filename.c_str(), "w"); FILE *f = fopen(filename.c_str(), "w");
fprintf(f, "# %s - %s\r\n\r\n", iso->GetUniqueID().c_str(), iso->GetName().c_str()); fprintf(f, "# %s - %s\r\n\r\n", iso->GetUniqueID().c_str(), iso->GetName().c_str());
fprintf(f, "[EmuState]\n#The Emulation State.\n"); fprintf(f, "[EmuState]\n#The Emulation State.\n");
@ -695,7 +805,9 @@ void CGameListCtrl::OnEditPatchFile(wxCommandEvent& WXUNUSED (event))
fprintf(f, "[OnFrame]\r\n#Add memory patches here.\r\n\r\n"); fprintf(f, "[OnFrame]\r\n#Add memory patches here.\r\n\r\n");
fprintf(f, "[ActionReplay]\r\n#Add decrypted action replay cheats here.\r\n"); fprintf(f, "[ActionReplay]\r\n#Add decrypted action replay cheats here.\r\n");
fclose(f); fclose(f);
} else { }
else
{
return; return;
} }
} }
@ -731,3 +843,13 @@ void CGameListCtrl::AutomaticColumnWidth()
SetColumnWidth(COLUMN_NOTES, wxMax(0.5*resizable, 100)); SetColumnWidth(COLUMN_NOTES, wxMax(0.5*resizable, 100));
} }
} }
void CGameListCtrl::UnselectAll()
{
for (size_t i=0; i<GetItemCount(); i++)
{
SetItemState(i, 0, wxLIST_STATE_SELECTED);
}
}

View File

@ -76,13 +76,21 @@ private:
void OnSetDefaultGCM(wxCommandEvent& event); void OnSetDefaultGCM(wxCommandEvent& event);
void OnDeleteGCM(wxCommandEvent& event); void OnDeleteGCM(wxCommandEvent& event);
void OnCompressGCM(wxCommandEvent& event); void OnCompressGCM(wxCommandEvent& event);
void OnMultiCompressGCM(wxCommandEvent& event);
void OnMultiDecompressGCM(wxCommandEvent& event);
void OnFilesystemViewer(wxCommandEvent& event); void OnFilesystemViewer(wxCommandEvent& event);
virtual bool MSWDrawSubItem(wxPaintDC& rPaintDC, int item, int subitem); virtual bool MSWDrawSubItem(wxPaintDC& rPaintDC, int item, int subitem);
void CompressSelection(bool _compress);
void AutomaticColumnWidth(); void AutomaticColumnWidth();
void UnselectAll();
static size_t m_currentItem;
static std::string m_currentFilename;
static size_t m_numberItem;
static void CompressCB(const char* text, float percent, void* arg); static void CompressCB(const char* text, float percent, void* arg);
static void MultiCompressCB(const char* text, float percent, void* arg);
}; };

View File

@ -52,6 +52,8 @@ enum
IDM_DELETEGCM, IDM_DELETEGCM,
IDM_FILESYSTEMVIEWER, IDM_FILESYSTEMVIEWER,
IDM_COMPRESSGCM, IDM_COMPRESSGCM,
IDM_MULTICOMPRESSGCM,
IDM_MULTIDECOMPRESSGCM,
IDM_CONFIG_MAIN, IDM_CONFIG_MAIN,
IDM_CONFIG_GFX_PLUGIN, IDM_CONFIG_GFX_PLUGIN,
IDM_CONFIG_DSP_PLUGIN, IDM_CONFIG_DSP_PLUGIN,