main: Split removal cases into their individual functions and address feedback

This commit is contained in:
Morph 2020-07-17 06:06:56 -04:00
parent 85e1facfe6
commit ef02370816
2 changed files with 133 additions and 115 deletions

View file

@ -1396,19 +1396,18 @@ static bool RomFSRawCopy(QProgressDialog& dialog, const FileSys::VirtualDir& src
}
void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryType type) {
QString entry_type;
const QString entry_type = [this, type] {
switch (type) {
case InstalledEntryType::Game:
entry_type = tr("Contents");
break;
return tr("Contents");
case InstalledEntryType::Update:
entry_type = tr("Update");
break;
return tr("Update");
case InstalledEntryType::AddOnContent:
entry_type = tr("DLC");
break;
return tr("DLC");
default:
return QString{};
}
}();
if (QMessageBox::question(
this, tr("Remove Entry"), tr("Remove Installed Game %1?").arg(entry_type),
@ -1416,11 +1415,28 @@ void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryT
return;
}
bool res;
switch (type) {
case InstalledEntryType::Game:
res = Core::System::GetInstance()
RemoveBaseContent(program_id, entry_type);
[[fallthrough]];
case InstalledEntryType::Update:
RemoveUpdateContent(program_id, entry_type);
if (type == InstalledEntryType::Game) {
[[fallthrough]];
} else {
break;
}
case InstalledEntryType::AddOnContent:
RemoveAddOnContent(program_id, entry_type);
break;
}
game_list->PopulateAsync(UISettings::values.game_dirs);
FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP +
"game_list");
}
void GMainWindow::RemoveBaseContent(u64 program_id, const QString& entry_type) {
const auto res = Core::System::GetInstance()
.GetFileSystemController()
.GetUserNANDContents()
->RemoveExistingEntry(program_id);
@ -1433,9 +1449,10 @@ void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryT
this, tr("Error Removing %1").arg(entry_type),
tr("The base game is not installed in the NAND and cannot be removed."));
}
[[fallthrough]];
case InstalledEntryType::Update:
res = Core::System::GetInstance()
}
void GMainWindow::RemoveUpdateContent(u64 program_id, const QString& entry_type) {
const auto res = Core::System::GetInstance()
.GetFileSystemController()
.GetUserNANDContents()
->RemoveExistingEntry(program_id | 0x800);
@ -1447,20 +1464,16 @@ void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryT
QMessageBox::warning(this, tr("Error Removing %1").arg(entry_type),
tr("There is no update installed for this title."));
}
}
if (type == InstalledEntryType::Game) {
[[fallthrough]];
} else {
break;
}
case InstalledEntryType::AddOnContent:
void GMainWindow::RemoveAddOnContent(u64 program_id, const QString& entry_type) {
u32 count{};
const auto dlc_entries = Core::System::GetInstance().GetContentProvider().ListEntriesFilter(
FileSys::TitleType::AOC, FileSys::ContentRecordType::Data);
for (const auto& entry : dlc_entries) {
if ((entry.title_id & DLC_BASE_TITLE_ID_MASK) == program_id) {
res = Core::System::GetInstance()
const auto res = Core::System::GetInstance()
.GetFileSystemController()
.GetUserNANDContents()
->RemoveExistingEntry(entry.title_id);
@ -1473,29 +1486,24 @@ void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryT
if (count == 0) {
QMessageBox::warning(this, tr("Error Removing %1").arg(entry_type),
tr("There are no DLC installed for this title."));
break;
return;
}
QMessageBox::information(this, tr("Successfully Removed"),
tr("Successfully removed %1 installed DLC.").arg(count));
break;
}
game_list->PopulateAsync(UISettings::values.game_dirs);
FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP +
"game_list");
}
void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target) {
QString question;
const QString question = [this, target] {
switch (target) {
case GameListRemoveTarget::ShaderCache:
question = tr("Delete Transferable Shader Cache?");
break;
return tr("Delete Transferable Shader Cache?");
case GameListRemoveTarget::CustomConfiguration:
question = tr("Remove Custom Game Configuration?");
break;
return tr("Remove Custom Game Configuration?");
default:
return QString{};
}
}();
if (QMessageBox::question(this, tr("Remove File"), question, QMessageBox::Yes | QMessageBox::No,
QMessageBox::No) != QMessageBox::Yes) {
@ -1503,12 +1511,20 @@ void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget targ
}
switch (target) {
case GameListRemoveTarget::ShaderCache: {
case GameListRemoveTarget::ShaderCache:
RemoveTransferableShaderCache(program_id);
break;
case GameListRemoveTarget::CustomConfiguration:
RemoveCustomConfiguration(program_id);
break;
}
}
void GMainWindow::RemoveTransferableShaderCache(u64 program_id) {
const QString shader_dir =
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir));
const QString transferable_shader_cache_folder_path =
shader_dir + QStringLiteral("opengl") + QDir::separator() +
QStringLiteral("transferable");
shader_dir + QStringLiteral("opengl") + QDir::separator() + QStringLiteral("transferable");
const QString transferable_shader_cache_file_path =
transferable_shader_cache_folder_path + QDir::separator() +
QString::fromStdString(fmt::format("{:016X}.bin", program_id));
@ -1516,7 +1532,7 @@ void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget targ
if (!QFile::exists(transferable_shader_cache_file_path)) {
QMessageBox::warning(this, tr("Error Removing Transferable Shader Cache"),
tr("A shader cache for this title does not exist."));
break;
return;
}
if (QFile::remove(transferable_shader_cache_file_path)) {
@ -1526,9 +1542,9 @@ void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget targ
QMessageBox::warning(this, tr("Error Removing Transferable Shader Cache"),
tr("Failed to remove the transferable shader cache."));
}
break;
}
case GameListRemoveTarget::CustomConfiguration: {
}
void GMainWindow::RemoveCustomConfiguration(u64 program_id) {
const QString config_dir =
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir));
const QString custom_config_file_path =
@ -1537,7 +1553,7 @@ void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget targ
if (!QFile::exists(custom_config_file_path)) {
QMessageBox::warning(this, tr("Error Removing Custom Configuration"),
tr("A custom configuration for this title does not exist."));
break;
return;
}
if (QFile::remove(custom_config_file_path)) {
@ -1547,9 +1563,6 @@ void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget targ
QMessageBox::warning(this, tr("Error Removing Custom Configuration"),
tr("Failed to remove the custom game configuration."));
}
break;
}
}
}
void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_path) {

View file

@ -233,6 +233,11 @@ private slots:
void OnLanguageChanged(const QString& locale);
private:
void RemoveBaseContent(u64 program_id, const QString& entry_type);
void RemoveUpdateContent(u64 program_id, const QString& entry_type);
void RemoveAddOnContent(u64 program_id, const QString& entry_type);
void RemoveTransferableShaderCache(u64 program_id);
void RemoveCustomConfiguration(u64 program_id);
std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id);
InstallResult InstallNSPXCI(const QString& filename);
InstallResult InstallNCA(const QString& filename);