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) { void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryType type) {
QString entry_type; const QString entry_type = [this, type] {
switch (type) {
switch (type) { case InstalledEntryType::Game:
case InstalledEntryType::Game: return tr("Contents");
entry_type = tr("Contents"); case InstalledEntryType::Update:
break; return tr("Update");
case InstalledEntryType::Update: case InstalledEntryType::AddOnContent:
entry_type = tr("Update"); return tr("DLC");
break; default:
case InstalledEntryType::AddOnContent: return QString{};
entry_type = tr("DLC"); }
break; }();
}
if (QMessageBox::question( if (QMessageBox::question(
this, tr("Remove Entry"), tr("Remove Installed Game %1?").arg(entry_type), this, tr("Remove Entry"), tr("Remove Installed Game %1?").arg(entry_type),
@ -1416,68 +1415,19 @@ void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryT
return; return;
} }
bool res;
switch (type) { switch (type) {
case InstalledEntryType::Game: case InstalledEntryType::Game:
res = Core::System::GetInstance() RemoveBaseContent(program_id, entry_type);
.GetFileSystemController()
.GetUserNANDContents()
->RemoveExistingEntry(program_id);
if (res) {
QMessageBox::information(this, tr("Successfully Removed"),
tr("Successfully removed the installed base game."));
} else {
QMessageBox::warning(
this, tr("Error Removing %1").arg(entry_type),
tr("The base game is not installed in the NAND and cannot be removed."));
}
[[fallthrough]]; [[fallthrough]];
case InstalledEntryType::Update: case InstalledEntryType::Update:
res = Core::System::GetInstance() RemoveUpdateContent(program_id, entry_type);
.GetFileSystemController()
.GetUserNANDContents()
->RemoveExistingEntry(program_id | 0x800);
if (res) {
QMessageBox::information(this, tr("Successfully Removed"),
tr("Successfully removed the installed update."));
} else {
QMessageBox::warning(this, tr("Error Removing %1").arg(entry_type),
tr("There is no update installed for this title."));
}
if (type == InstalledEntryType::Game) { if (type == InstalledEntryType::Game) {
[[fallthrough]]; [[fallthrough]];
} else { } else {
break; break;
} }
case InstalledEntryType::AddOnContent: case InstalledEntryType::AddOnContent:
u32 count{}; RemoveAddOnContent(program_id, entry_type);
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()
.GetFileSystemController()
.GetUserNANDContents()
->RemoveExistingEntry(entry.title_id);
if (res) {
++count;
}
}
}
if (count == 0) {
QMessageBox::warning(this, tr("Error Removing %1").arg(entry_type),
tr("There are no DLC installed for this title."));
break;
}
QMessageBox::information(this, tr("Successfully Removed"),
tr("Successfully removed %1 installed DLC.").arg(count));
break; break;
} }
game_list->PopulateAsync(UISettings::values.game_dirs); game_list->PopulateAsync(UISettings::values.game_dirs);
@ -1485,17 +1435,75 @@ void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryT
"game_list"); "game_list");
} }
void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target) { void GMainWindow::RemoveBaseContent(u64 program_id, const QString& entry_type) {
QString question; const auto res = Core::System::GetInstance()
.GetFileSystemController()
.GetUserNANDContents()
->RemoveExistingEntry(program_id);
switch (target) { if (res) {
case GameListRemoveTarget::ShaderCache: QMessageBox::information(this, tr("Successfully Removed"),
question = tr("Delete Transferable Shader Cache?"); tr("Successfully removed the installed base game."));
break; } else {
case GameListRemoveTarget::CustomConfiguration: QMessageBox::warning(
question = tr("Remove Custom Game Configuration?"); this, tr("Error Removing %1").arg(entry_type),
break; tr("The base game is not installed in the NAND and cannot be removed."));
} }
}
void GMainWindow::RemoveUpdateContent(u64 program_id, const QString& entry_type) {
const auto res = Core::System::GetInstance()
.GetFileSystemController()
.GetUserNANDContents()
->RemoveExistingEntry(program_id | 0x800);
if (res) {
QMessageBox::information(this, tr("Successfully Removed"),
tr("Successfully removed the installed update."));
} else {
QMessageBox::warning(this, tr("Error Removing %1").arg(entry_type),
tr("There is no update installed for this title."));
}
}
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) {
const auto res = Core::System::GetInstance()
.GetFileSystemController()
.GetUserNANDContents()
->RemoveExistingEntry(entry.title_id);
if (res) {
++count;
}
}
}
if (count == 0) {
QMessageBox::warning(this, tr("Error Removing %1").arg(entry_type),
tr("There are no DLC installed for this title."));
return;
}
QMessageBox::information(this, tr("Successfully Removed"),
tr("Successfully removed %1 installed DLC.").arg(count));
}
void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target) {
const QString question = [this, target] {
switch (target) {
case GameListRemoveTarget::ShaderCache:
return tr("Delete Transferable Shader Cache?");
case GameListRemoveTarget::CustomConfiguration:
return tr("Remove Custom Game Configuration?");
default:
return QString{};
}
}();
if (QMessageBox::question(this, tr("Remove File"), question, QMessageBox::Yes | QMessageBox::No, if (QMessageBox::question(this, tr("Remove File"), question, QMessageBox::Yes | QMessageBox::No,
QMessageBox::No) != QMessageBox::Yes) { QMessageBox::No) != QMessageBox::Yes) {
@ -1503,52 +1511,57 @@ void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget targ
} }
switch (target) { switch (target) {
case GameListRemoveTarget::ShaderCache: { case GameListRemoveTarget::ShaderCache:
const QString shader_dir = RemoveTransferableShaderCache(program_id);
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir)); break;
const QString transferable_shader_cache_folder_path = case GameListRemoveTarget::CustomConfiguration:
shader_dir + QStringLiteral("opengl") + QDir::separator() + RemoveCustomConfiguration(program_id);
QStringLiteral("transferable");
const QString transferable_shader_cache_file_path =
transferable_shader_cache_folder_path + QDir::separator() +
QString::fromStdString(fmt::format("{:016X}.bin", program_id));
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;
}
if (QFile::remove(transferable_shader_cache_file_path)) {
QMessageBox::information(this, tr("Successfully Removed"),
tr("Successfully removed the transferable shader cache."));
} else {
QMessageBox::warning(this, tr("Error Removing Transferable Shader Cache"),
tr("Failed to remove the transferable shader cache."));
}
break; break;
} }
case GameListRemoveTarget::CustomConfiguration: { }
const QString config_dir =
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir));
const QString custom_config_file_path =
config_dir + QString::fromStdString(fmt::format("{:016X}.ini", program_id));
if (!QFile::exists(custom_config_file_path)) { void GMainWindow::RemoveTransferableShaderCache(u64 program_id) {
QMessageBox::warning(this, tr("Error Removing Custom Configuration"), const QString shader_dir =
tr("A custom configuration for this title does not exist.")); QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir));
break; const QString transferable_shader_cache_folder_path =
} 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));
if (QFile::remove(custom_config_file_path)) { if (!QFile::exists(transferable_shader_cache_file_path)) {
QMessageBox::information(this, tr("Successfully Removed"), QMessageBox::warning(this, tr("Error Removing Transferable Shader Cache"),
tr("Successfully removed the custom game configuration.")); tr("A shader cache for this title does not exist."));
} else { return;
QMessageBox::warning(this, tr("Error Removing Custom Configuration"),
tr("Failed to remove the custom game configuration."));
}
break;
} }
if (QFile::remove(transferable_shader_cache_file_path)) {
QMessageBox::information(this, tr("Successfully Removed"),
tr("Successfully removed the transferable shader cache."));
} else {
QMessageBox::warning(this, tr("Error Removing Transferable Shader Cache"),
tr("Failed to remove the transferable shader cache."));
}
}
void GMainWindow::RemoveCustomConfiguration(u64 program_id) {
const QString config_dir =
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir));
const QString custom_config_file_path =
config_dir + QString::fromStdString(fmt::format("{:016X}.ini", program_id));
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."));
return;
}
if (QFile::remove(custom_config_file_path)) {
QMessageBox::information(this, tr("Successfully Removed"),
tr("Successfully removed the custom game configuration."));
} else {
QMessageBox::warning(this, tr("Error Removing Custom Configuration"),
tr("Failed to remove the custom game configuration."));
} }
} }

View file

@ -233,6 +233,11 @@ private slots:
void OnLanguageChanged(const QString& locale); void OnLanguageChanged(const QString& locale);
private: 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); std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id);
InstallResult InstallNSPXCI(const QString& filename); InstallResult InstallNSPXCI(const QString& filename);
InstallResult InstallNCA(const QString& filename); InstallResult InstallNCA(const QString& filename);