From bd326ace5cd750d7752748afc3efe508919fa6ea Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 17 Dec 2015 12:39:32 +0100 Subject: [PATCH 1/4] DolphinWX: Replace GetSelectedISO hack for multiple selections --- Source/Core/DolphinWX/GameListCtrl.cpp | 69 +++++++++++--------------- Source/Core/DolphinWX/GameListCtrl.h | 5 +- 2 files changed, 32 insertions(+), 42 deletions(-) diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index 18b69e3f23..925bea1c4b 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -921,7 +921,7 @@ void CGameListCtrl::OnRightClick(wxMouseEvent& event) } } -const GameListItem * CGameListCtrl::GetSelectedISO() +const GameListItem* CGameListCtrl::GetSelectedISO() const { if (m_ISOFiles.size() == 0) { @@ -935,20 +935,21 @@ const GameListItem * CGameListCtrl::GetSelectedISO() { long item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (item == wxNOT_FOUND) - { return nullptr; - } - else - { - // Here is a little workaround for multiselections: - // when > 1 item is selected, return info on the first one - // and deselect it so the next time GetSelectedISO() is called, - // the next item's info is returned - if (GetSelectedItemCount() > 1) - SetItemState(item, 0, wxLIST_STATE_SELECTED); + return m_ISOFiles[GetItemData(item)]; + } +} - return m_ISOFiles[GetItemData(item)]; - } +std::vector CGameListCtrl::GetAllSelectedISOs() const +{ + std::vector result; + long item = -1; + while (true) + { + item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + if (item == wxNOT_FOUND) + return result; + result.push_back(m_ISOFiles[GetItemData(item)]); } } @@ -1032,32 +1033,15 @@ void CGameListCtrl::OnSetDefaultISO(wxCommandEvent& event) void CGameListCtrl::OnDeleteISO(wxCommandEvent& WXUNUSED (event)) { - if (GetSelectedItemCount() == 1) - { - const GameListItem* iso = GetSelectedISO(); - if (!iso) - return; - if (wxMessageBox(_("Are you sure you want to delete this file? It will be gone forever!"), - _("Warning"), wxYES_NO | wxICON_EXCLAMATION) == wxYES) - { - File::Delete(iso->GetFileName()); - Update(); - } - } - else - { - if (wxMessageBox(_("Are you sure you want to delete these files?\nThey will be gone forever!"), - _("Warning"), wxYES_NO | wxICON_EXCLAMATION) == wxYES) - { - int selected = GetSelectedItemCount(); + const wxString message = GetSelectedItemCount() == 1 ? + _("Are you sure you want to delete this file? It will be gone forever!") : + _("Are you sure you want to delete these files? They will be gone forever!"); - for (int i = 0; i < selected; i++) - { - const GameListItem* iso = GetSelectedISO(); - File::Delete(iso->GetFileName()); - } - Update(); - } + if (wxMessageBox(message, _("Warning"), wxYES_NO | wxICON_EXCLAMATION) == wxYES) + { + for (const GameListItem* iso : GetAllSelectedISOs()) + File::Delete(iso->GetFileName()); + Update(); } } @@ -1125,11 +1109,12 @@ void CGameListCtrl::CompressSelection(bool _compress) wxPD_SMOOTH ); + // These two variables are used when the progress dialog is updated m_currentItem = 0; m_numberItem = GetSelectedItemCount(); - for (u32 i = 0; i < m_numberItem; i++) + + for (const GameListItem* iso : GetAllSelectedISOs()) { - const GameListItem* iso = GetSelectedISO(); if (iso->GetPlatform() != DiscIO::IVolume::GAMECUBE_DISC && iso->GetPlatform() != DiscIO::IVolume::WII_DISC) continue; if (iso->GetBlobType() != DiscIO::BlobType::PLAIN && iso->GetBlobType() != DiscIO::BlobType::GCZ) @@ -1142,6 +1127,7 @@ void CGameListCtrl::CompressSelection(bool _compress) std::string FileName, FileExt; SplitPath(iso->GetFileName(), nullptr, &FileName, &FileExt); + // Update the file name in the progress dialog m_currentFilename = FileName; FileName.append(".gcz"); @@ -1167,6 +1153,7 @@ void CGameListCtrl::CompressSelection(bool _compress) { std::string FileName, FileExt; SplitPath(iso->GetFileName(), nullptr, &FileName, &FileExt); + // Update the file name in the progress dialog m_currentFilename = FileName; if (iso->GetPlatform() == DiscIO::IVolume::WII_DISC) FileName.append(".iso"); @@ -1189,6 +1176,8 @@ void CGameListCtrl::CompressSelection(bool _compress) all_good &= DiscIO::DecompressBlobToFile(iso->GetFileName().c_str(), OutputFileName.c_str(), &MultiCompressCB, &progressDialog); } + + // Update the progress in the progress dialog m_currentItem++; } } diff --git a/Source/Core/DolphinWX/GameListCtrl.h b/Source/Core/DolphinWX/GameListCtrl.h index bfc376f184..bc85468d9b 100644 --- a/Source/Core/DolphinWX/GameListCtrl.h +++ b/Source/Core/DolphinWX/GameListCtrl.h @@ -36,8 +36,9 @@ public: void Update() override; void BrowseForDirectory(); - const GameListItem *GetSelectedISO(); - const GameListItem *GetISO(size_t index) const; + const GameListItem* GetISO(size_t index) const; + const GameListItem* GetSelectedISO() const; + std::vector GetAllSelectedISOs() const; static bool IsHidingItems(); From 6a75212e7a5c7849f29eabcb47f612b2c196571c Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 17 Dec 2015 12:49:23 +0100 Subject: [PATCH 2/4] DolphinWX: Only show Wii compression warning once When compressing multiple Wii games, the warning used to be showed once for each game. Now it only appears once at the beginning. --- Source/Core/DolphinWX/GameListCtrl.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index 925bea1c4b..aa8596159a 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -1087,6 +1087,23 @@ void CGameListCtrl::OnMultiDecompressISO(wxCommandEvent& /*event*/) void CGameListCtrl::CompressSelection(bool _compress) { + const std::vector selected_items = GetAllSelectedISOs(); + + // If any Wii discs are going to be compressed, show the Wii compression warning once + if (_compress) + { + for (const GameListItem* iso : selected_items) + { + if (!iso->IsCompressed() && iso->GetPlatform() == DiscIO::IVolume::WII_DISC) + { + if (WiiCompressWarning()) + break; + else + return; + } + } + } + wxString dirHome; wxGetHomeDir(&dirHome); @@ -1113,7 +1130,7 @@ void CGameListCtrl::CompressSelection(bool _compress) m_currentItem = 0; m_numberItem = GetSelectedItemCount(); - for (const GameListItem* iso : GetAllSelectedISOs()) + for (const GameListItem* iso : selected_items) { if (iso->GetPlatform() != DiscIO::IVolume::GAMECUBE_DISC && iso->GetPlatform() != DiscIO::IVolume::WII_DISC) continue; @@ -1122,9 +1139,6 @@ void CGameListCtrl::CompressSelection(bool _compress) if (!iso->IsCompressed() && _compress) { - if (iso->GetPlatform() == DiscIO::IVolume::WII_DISC && !WiiCompressWarning()) - return; - std::string FileName, FileExt; SplitPath(iso->GetFileName(), nullptr, &FileName, &FileExt); // Update the file name in the progress dialog From 8cad70238ccb1f8c9a77946dc3d9ef09798b7d04 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 17 Dec 2015 18:50:09 +0100 Subject: [PATCH 3/4] DolphinWX: Don't store compression progress in member variables Just some extra cleanup. --- Source/Core/DolphinWX/GameListCtrl.cpp | 55 +++++++++++++++----------- Source/Core/DolphinWX/GameListCtrl.h | 3 -- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index aa8596159a..bcf1c25ca5 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -53,9 +53,19 @@ #include "DolphinWX/Main.h" #include "DolphinWX/WxUtils.h" -size_t CGameListCtrl::m_currentItem = 0; -size_t CGameListCtrl::m_numberItem = 0; -std::string CGameListCtrl::m_currentFilename; +struct CompressionProgress final +{ +public: + CompressionProgress(int items_done_, int items_total_, const std::string& current_filename_, wxProgressDialog* dialog_) + : items_done(items_done_), items_total(items_total_), current_filename(current_filename_), dialog(dialog_) + { } + + int items_done; + int items_total; + std::string current_filename; + wxProgressDialog* dialog; +}; + static bool sorted = false; static int CompareGameListItems(const GameListItem* iso1, const GameListItem* iso2, @@ -1067,12 +1077,14 @@ void CGameListCtrl::OnWiki(wxCommandEvent& WXUNUSED (event)) bool CGameListCtrl::MultiCompressCB(const std::string& text, float percent, void* arg) { - percent = (((float)m_currentItem) + percent) / (float)m_numberItem; - wxString textString(StrToWxStr(StringFromFormat("%s (%i/%i) - %s", - m_currentFilename.c_str(), (int)m_currentItem + 1, - (int)m_numberItem, text.c_str()))); + CompressionProgress* progress = static_cast(arg); - return ((wxProgressDialog*)arg)->Update((int)(percent * 1000), textString); + float total_percent = ((float)progress->items_done + percent) / (float)progress->items_total; + wxString text_string(StrToWxStr(StringFromFormat("%s (%i/%i) - %s", + progress->current_filename.c_str(), progress->items_done + 1, + progress->items_total, text.c_str()))); + + return progress->dialog->Update(total_percent * progress->dialog->GetRange(), text_string); } void CGameListCtrl::OnMultiCompressISO(wxCommandEvent& /*event*/) @@ -1118,7 +1130,7 @@ void CGameListCtrl::CompressSelection(bool _compress) wxProgressDialog progressDialog( _compress ? _("Compressing ISO") : _("Decompressing ISO"), _("Working..."), - 1000, + 1000, // Arbitrary number that's larger than the dialog's width in pixels this, wxPD_APP_MODAL | wxPD_CAN_ABORT | @@ -1126,9 +1138,7 @@ void CGameListCtrl::CompressSelection(bool _compress) wxPD_SMOOTH ); - // These two variables are used when the progress dialog is updated - m_currentItem = 0; - m_numberItem = GetSelectedItemCount(); + CompressionProgress progress(0, GetSelectedItemCount(), "", &progressDialog); for (const GameListItem* iso : selected_items) { @@ -1139,10 +1149,9 @@ void CGameListCtrl::CompressSelection(bool _compress) if (!iso->IsCompressed() && _compress) { - std::string FileName, FileExt; - SplitPath(iso->GetFileName(), nullptr, &FileName, &FileExt); - // Update the file name in the progress dialog - m_currentFilename = FileName; + std::string FileName; + SplitPath(iso->GetFileName(), nullptr, &FileName, nullptr); + progress.current_filename = FileName; FileName.append(".gcz"); std::string OutputFileName; @@ -1161,14 +1170,13 @@ void CGameListCtrl::CompressSelection(bool _compress) all_good &= DiscIO::CompressFileToBlob(iso->GetFileName(), OutputFileName, (iso->GetPlatform() == DiscIO::IVolume::WII_DISC) ? 1 : 0, - 16384, &MultiCompressCB, &progressDialog); + 16384, &MultiCompressCB, &progress); } else if (iso->IsCompressed() && !_compress) { - std::string FileName, FileExt; - SplitPath(iso->GetFileName(), nullptr, &FileName, &FileExt); - // Update the file name in the progress dialog - m_currentFilename = FileName; + std::string FileName; + SplitPath(iso->GetFileName(), nullptr, &FileName, nullptr); + progress.current_filename = FileName; if (iso->GetPlatform() == DiscIO::IVolume::WII_DISC) FileName.append(".iso"); else @@ -1188,11 +1196,10 @@ void CGameListCtrl::CompressSelection(bool _compress) continue; all_good &= DiscIO::DecompressBlobToFile(iso->GetFileName().c_str(), - OutputFileName.c_str(), &MultiCompressCB, &progressDialog); + OutputFileName.c_str(), &MultiCompressCB, &progress); } - // Update the progress in the progress dialog - m_currentItem++; + progress.items_done++; } } diff --git a/Source/Core/DolphinWX/GameListCtrl.h b/Source/Core/DolphinWX/GameListCtrl.h index bc85468d9b..dcf9d58ad3 100644 --- a/Source/Core/DolphinWX/GameListCtrl.h +++ b/Source/Core/DolphinWX/GameListCtrl.h @@ -109,9 +109,6 @@ private: void HideColumn(int column); void UnselectAll(); - static size_t m_currentItem; - static std::string m_currentFilename; - static size_t m_numberItem; static bool CompressCB(const std::string& text, float percent, void* arg); static bool MultiCompressCB(const std::string& text, float percent, void* arg); static bool WiiCompressWarning(); From 8a2e678ea745d228c94f66ba49596e3011fcda8d Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 17 Dec 2015 19:00:41 +0100 Subject: [PATCH 4/4] DolphinWX: Don't include skipped items in the compression count --- Source/Core/DolphinWX/GameListCtrl.cpp | 39 +++++++++++++------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index bcf1c25ca5..7ca7968ab8 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -1099,20 +1099,26 @@ void CGameListCtrl::OnMultiDecompressISO(wxCommandEvent& /*event*/) void CGameListCtrl::CompressSelection(bool _compress) { - const std::vector selected_items = GetAllSelectedISOs(); - - // If any Wii discs are going to be compressed, show the Wii compression warning once - if (_compress) + std::vector items_to_compress; + bool wii_compression_warning_accepted = false; + for (const GameListItem* iso : GetAllSelectedISOs()) { - for (const GameListItem* iso : selected_items) + // Don't include items that we can't do anything with + if (iso->GetPlatform() != DiscIO::IVolume::GAMECUBE_DISC && iso->GetPlatform() != DiscIO::IVolume::WII_DISC) + continue; + if (iso->GetBlobType() != DiscIO::BlobType::PLAIN && iso->GetBlobType() != DiscIO::BlobType::GCZ) + continue; + + items_to_compress.push_back(iso); + + // Show the Wii compression warning if it's relevant and it hasn't been shown already + if (!wii_compression_warning_accepted && _compress && + !iso->IsCompressed() && iso->GetPlatform() == DiscIO::IVolume::WII_DISC) { - if (!iso->IsCompressed() && iso->GetPlatform() == DiscIO::IVolume::WII_DISC) - { - if (WiiCompressWarning()) - break; - else - return; - } + if (WiiCompressWarning()) + wii_compression_warning_accepted = true; + else + return; } } @@ -1138,15 +1144,10 @@ void CGameListCtrl::CompressSelection(bool _compress) wxPD_SMOOTH ); - CompressionProgress progress(0, GetSelectedItemCount(), "", &progressDialog); + CompressionProgress progress(0, items_to_compress.size(), "", &progressDialog); - for (const GameListItem* iso : selected_items) + for (const GameListItem* iso : items_to_compress) { - if (iso->GetPlatform() != DiscIO::IVolume::GAMECUBE_DISC && iso->GetPlatform() != DiscIO::IVolume::WII_DISC) - continue; - if (iso->GetBlobType() != DiscIO::BlobType::PLAIN && iso->GetBlobType() != DiscIO::BlobType::GCZ) - continue; - if (!iso->IsCompressed() && _compress) { std::string FileName;