void CGameListCtrl::CompressSelection(bool _compress) { std::vector<const GameListItem*> items_to_compress; bool wii_compression_warning_accepted = false; for (const GameListItem* iso : GetAllSelectedISOs()) { // 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 (WiiCompressWarning()) wii_compression_warning_accepted = true; else return; } } wxString dirHome; wxGetHomeDir(&dirHome); wxDirDialog browseDialog(this, _("Browse for output directory"), dirHome, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST); if (browseDialog.ShowModal() != wxID_OK) return; bool all_good = true; { wxProgressDialog progressDialog( _compress ? _("Compressing ISO") : _("Decompressing ISO"), _("Working..."), 1000, // Arbitrary number that's larger than the dialog's width in pixels this, wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME | wxPD_SMOOTH ); CompressionProgress progress(0, items_to_compress.size(), "", &progressDialog); for (const GameListItem* iso : items_to_compress) { if (!iso->IsCompressed() && _compress) { std::string FileName; SplitPath(iso->GetFileName(), nullptr, &FileName, nullptr); progress.current_filename = FileName; FileName.append(".gcz"); std::string OutputFileName; BuildCompleteFilename(OutputFileName, WxStrToStr(browseDialog.GetPath()), FileName); if (File::Exists(OutputFileName) && wxMessageBox( wxString::Format(_("The file %s already exists.\nDo you wish to replace it?"), StrToWxStr(OutputFileName)), _("Confirm File Overwrite"), wxYES_NO) == wxNO) continue; all_good &= DiscIO::CompressFileToBlob(iso->GetFileName(), OutputFileName, (iso->GetPlatform() == DiscIO::IVolume::WII_DISC) ? 1 : 0, 16384, &MultiCompressCB, &progress); } else if (iso->IsCompressed() && !_compress) { std::string FileName; SplitPath(iso->GetFileName(), nullptr, &FileName, nullptr); progress.current_filename = FileName; if (iso->GetPlatform() == DiscIO::IVolume::WII_DISC) FileName.append(".iso"); else FileName.append(".gcm"); std::string OutputFileName; BuildCompleteFilename(OutputFileName, WxStrToStr(browseDialog.GetPath()), FileName); if (File::Exists(OutputFileName) && wxMessageBox( wxString::Format(_("The file %s already exists.\nDo you wish to replace it?"), StrToWxStr(OutputFileName)), _("Confirm File Overwrite"), wxYES_NO) == wxNO) continue; all_good &= DiscIO::DecompressBlobToFile(iso->GetFileName().c_str(), OutputFileName.c_str(), &MultiCompressCB, &progress); } progress.items_done++; } } if (!all_good) WxUtils::ShowErrorDialog(_("Dolphin was unable to complete the requested action.")); Update(); }
void CGameListCtrl::OnCompressISO(wxCommandEvent& WXUNUSED (event)) { const GameListItem* iso = GetSelectedISO(); if (!iso) return; bool is_compressed = iso->GetBlobType() == DiscIO::BlobType::GCZ; wxString path; std::string FileName, FilePath, FileExtension; SplitPath(iso->GetFileName(), &FilePath, &FileName, &FileExtension); do { if (is_compressed) { wxString FileType; if (iso->GetPlatform() == DiscIO::IVolume::WII_DISC) FileType = _("All Wii ISO files (iso)") + "|*.iso"; else FileType = _("All GameCube GCM files (gcm)") + "|*.gcm"; path = wxFileSelector( _("Save decompressed GCM/ISO"), StrToWxStr(FilePath), StrToWxStr(FileName) + FileType.After('*'), wxEmptyString, FileType + "|" + wxGetTranslation(wxALL_FILES), wxFD_SAVE, this); } else { if (iso->GetPlatform() == DiscIO::IVolume::WII_DISC && !WiiCompressWarning()) return; path = wxFileSelector( _("Save compressed GCM/ISO"), StrToWxStr(FilePath), StrToWxStr(FileName) + ".gcz", wxEmptyString, _("All compressed GC/Wii ISO files (gcz)") + wxString::Format("|*.gcz|%s", wxGetTranslation(wxALL_FILES)), wxFD_SAVE, this); } if (!path) return; } while (wxFileExists(path) && wxMessageBox( wxString::Format(_("The file %s already exists.\nDo you wish to replace it?"), path.c_str()), _("Confirm File Overwrite"), wxYES_NO) == wxNO); bool all_good = false; { wxProgressDialog dialog( is_compressed ? _("Decompressing ISO") : _("Compressing ISO"), _("Working..."), 1000, this, wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME | wxPD_SMOOTH ); if (is_compressed) all_good = DiscIO::DecompressBlobToFile(iso->GetFileName(), WxStrToStr(path), &CompressCB, &dialog); else all_good = DiscIO::CompressFileToBlob(iso->GetFileName(), WxStrToStr(path), (iso->GetPlatform() == DiscIO::IVolume::WII_DISC) ? 1 : 0, 16384, &CompressCB, &dialog); } if (!all_good) WxUtils::ShowErrorDialog(_("Dolphin was unable to complete the requested action.")); Update(); }
void CGameListCtrl::CompressSelection(bool _compress) { wxString dirHome; wxGetHomeDir(&dirHome); wxDirDialog browseDialog(this, _("Browse for output directory"), dirHome, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST); if (browseDialog.ShowModal() != wxID_OK) return; bool all_good = true; { wxProgressDialog progressDialog( _compress ? _("Compressing ISO") : _("Decompressing ISO"), _("Working..."), 1000, this, wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME | wxPD_SMOOTH ); m_currentItem = 0; m_numberItem = GetSelectedItemCount(); for (u32 i = 0; i < m_numberItem; i++) { const GameListItem* iso = GetSelectedISO(); if (iso->GetPlatform() == DiscIO::IVolume::WII_WAD || iso->GetFileName().rfind(".wbfs") != std::string::npos) continue; if (!iso->IsCompressed() && _compress) { if (iso->GetPlatform() == DiscIO::IVolume::WII_DISC && !WiiCompressWarning()) return; std::string FileName, FileExt; SplitPath(iso->GetFileName(), nullptr, &FileName, &FileExt); m_currentFilename = FileName; FileName.append(".gcz"); std::string OutputFileName; BuildCompleteFilename(OutputFileName, WxStrToStr(browseDialog.GetPath()), FileName); if (File::Exists(OutputFileName) && wxMessageBox( wxString::Format(_("The file %s already exists.\nDo you wish to replace it?"), StrToWxStr(OutputFileName)), _("Confirm File Overwrite"), wxYES_NO) == wxNO) continue; all_good &= DiscIO::CompressFileToBlob(iso->GetFileName(), OutputFileName, (iso->GetPlatform() == DiscIO::IVolume::WII_DISC) ? 1 : 0, 16384, &MultiCompressCB, &progressDialog); } else if (iso->IsCompressed() && !_compress) { std::string FileName, FileExt; SplitPath(iso->GetFileName(), nullptr, &FileName, &FileExt); m_currentFilename = FileName; if (iso->GetPlatform() == DiscIO::IVolume::WII_DISC) FileName.append(".iso"); else FileName.append(".gcm"); std::string OutputFileName; BuildCompleteFilename(OutputFileName, WxStrToStr(browseDialog.GetPath()), FileName); if (File::Exists(OutputFileName) && wxMessageBox( wxString::Format(_("The file %s already exists.\nDo you wish to replace it?"), StrToWxStr(OutputFileName)), _("Confirm File Overwrite"), wxYES_NO) == wxNO) continue; all_good &= DiscIO::DecompressBlobToFile(iso->GetFileName().c_str(), OutputFileName.c_str(), &MultiCompressCB, &progressDialog); } m_currentItem++; } } if (!all_good) WxUtils::ShowErrorDialog(_("Dolphin was unable to complete the requested action.")); Update(); }