summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Morph2020-07-17 06:06:56 -0400
committerGravatar Morph2020-07-29 06:50:30 -0400
commitef02370816924156b6c3c3fd70e7e2595be19216 (patch)
tree591b4bea9fc7c79946f187cb3f047e06f8d7f8c9 /src
parentmain: Connect game list remove signals to removal functions (diff)
downloadyuzu-ef02370816924156b6c3c3fd70e7e2595be19216.tar.gz
yuzu-ef02370816924156b6c3c3fd70e7e2595be19216.tar.xz
yuzu-ef02370816924156b6c3c3fd70e7e2595be19216.zip
main: Split removal cases into their individual functions and address feedback
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/main.cpp239
-rw-r--r--src/yuzu/main.h5
2 files changed, 131 insertions, 113 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index e94785101..49c10459b 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -1396,19 +1396,18 @@ static bool RomFSRawCopy(QProgressDialog& dialog, const FileSys::VirtualDir& src
1396} 1396}
1397 1397
1398void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryType type) { 1398void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryType type) {
1399 QString entry_type; 1399 const QString entry_type = [this, type] {
1400 1400 switch (type) {
1401 switch (type) { 1401 case InstalledEntryType::Game:
1402 case InstalledEntryType::Game: 1402 return tr("Contents");
1403 entry_type = tr("Contents"); 1403 case InstalledEntryType::Update:
1404 break; 1404 return tr("Update");
1405 case InstalledEntryType::Update: 1405 case InstalledEntryType::AddOnContent:
1406 entry_type = tr("Update"); 1406 return tr("DLC");
1407 break; 1407 default:
1408 case InstalledEntryType::AddOnContent: 1408 return QString{};
1409 entry_type = tr("DLC"); 1409 }
1410 break; 1410 }();
1411 }
1412 1411
1413 if (QMessageBox::question( 1412 if (QMessageBox::question(
1414 this, tr("Remove Entry"), tr("Remove Installed Game %1?").arg(entry_type), 1413 this, tr("Remove Entry"), tr("Remove Installed Game %1?").arg(entry_type),
@@ -1416,68 +1415,19 @@ void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryT
1416 return; 1415 return;
1417 } 1416 }
1418 1417
1419 bool res;
1420
1421 switch (type) { 1418 switch (type) {
1422 case InstalledEntryType::Game: 1419 case InstalledEntryType::Game:
1423 res = Core::System::GetInstance() 1420 RemoveBaseContent(program_id, entry_type);
1424 .GetFileSystemController()
1425 .GetUserNANDContents()
1426 ->RemoveExistingEntry(program_id);
1427
1428 if (res) {
1429 QMessageBox::information(this, tr("Successfully Removed"),
1430 tr("Successfully removed the installed base game."));
1431 } else {
1432 QMessageBox::warning(
1433 this, tr("Error Removing %1").arg(entry_type),
1434 tr("The base game is not installed in the NAND and cannot be removed."));
1435 }
1436 [[fallthrough]]; 1421 [[fallthrough]];
1437 case InstalledEntryType::Update: 1422 case InstalledEntryType::Update:
1438 res = Core::System::GetInstance() 1423 RemoveUpdateContent(program_id, entry_type);
1439 .GetFileSystemController()
1440 .GetUserNANDContents()
1441 ->RemoveExistingEntry(program_id | 0x800);
1442
1443 if (res) {
1444 QMessageBox::information(this, tr("Successfully Removed"),
1445 tr("Successfully removed the installed update."));
1446 } else {
1447 QMessageBox::warning(this, tr("Error Removing %1").arg(entry_type),
1448 tr("There is no update installed for this title."));
1449 }
1450
1451 if (type == InstalledEntryType::Game) { 1424 if (type == InstalledEntryType::Game) {
1452 [[fallthrough]]; 1425 [[fallthrough]];
1453 } else { 1426 } else {
1454 break; 1427 break;
1455 } 1428 }
1456 case InstalledEntryType::AddOnContent: 1429 case InstalledEntryType::AddOnContent:
1457 u32 count{}; 1430 RemoveAddOnContent(program_id, entry_type);
1458 const auto dlc_entries = Core::System::GetInstance().GetContentProvider().ListEntriesFilter(
1459 FileSys::TitleType::AOC, FileSys::ContentRecordType::Data);
1460
1461 for (const auto& entry : dlc_entries) {
1462 if ((entry.title_id & DLC_BASE_TITLE_ID_MASK) == program_id) {
1463 res = Core::System::GetInstance()
1464 .GetFileSystemController()
1465 .GetUserNANDContents()
1466 ->RemoveExistingEntry(entry.title_id);
1467 if (res) {
1468 ++count;
1469 }
1470 }
1471 }
1472
1473 if (count == 0) {
1474 QMessageBox::warning(this, tr("Error Removing %1").arg(entry_type),
1475 tr("There are no DLC installed for this title."));
1476 break;
1477 }
1478
1479 QMessageBox::information(this, tr("Successfully Removed"),
1480 tr("Successfully removed %1 installed DLC.").arg(count));
1481 break; 1431 break;
1482 } 1432 }
1483 game_list->PopulateAsync(UISettings::values.game_dirs); 1433 game_list->PopulateAsync(UISettings::values.game_dirs);
@@ -1485,70 +1435,133 @@ void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryT
1485 "game_list"); 1435 "game_list");
1486} 1436}
1487 1437
1438void GMainWindow::RemoveBaseContent(u64 program_id, const QString& entry_type) {
1439 const auto res = Core::System::GetInstance()
1440 .GetFileSystemController()
1441 .GetUserNANDContents()
1442 ->RemoveExistingEntry(program_id);
1443
1444 if (res) {
1445 QMessageBox::information(this, tr("Successfully Removed"),
1446 tr("Successfully removed the installed base game."));
1447 } else {
1448 QMessageBox::warning(
1449 this, tr("Error Removing %1").arg(entry_type),
1450 tr("The base game is not installed in the NAND and cannot be removed."));
1451 }
1452}
1453
1454void GMainWindow::RemoveUpdateContent(u64 program_id, const QString& entry_type) {
1455 const auto res = Core::System::GetInstance()
1456 .GetFileSystemController()
1457 .GetUserNANDContents()
1458 ->RemoveExistingEntry(program_id | 0x800);
1459
1460 if (res) {
1461 QMessageBox::information(this, tr("Successfully Removed"),
1462 tr("Successfully removed the installed update."));
1463 } else {
1464 QMessageBox::warning(this, tr("Error Removing %1").arg(entry_type),
1465 tr("There is no update installed for this title."));
1466 }
1467}
1468
1469void GMainWindow::RemoveAddOnContent(u64 program_id, const QString& entry_type) {
1470 u32 count{};
1471 const auto dlc_entries = Core::System::GetInstance().GetContentProvider().ListEntriesFilter(
1472 FileSys::TitleType::AOC, FileSys::ContentRecordType::Data);
1473
1474 for (const auto& entry : dlc_entries) {
1475 if ((entry.title_id & DLC_BASE_TITLE_ID_MASK) == program_id) {
1476 const auto res = Core::System::GetInstance()
1477 .GetFileSystemController()
1478 .GetUserNANDContents()
1479 ->RemoveExistingEntry(entry.title_id);
1480 if (res) {
1481 ++count;
1482 }
1483 }
1484 }
1485
1486 if (count == 0) {
1487 QMessageBox::warning(this, tr("Error Removing %1").arg(entry_type),
1488 tr("There are no DLC installed for this title."));
1489 return;
1490 }
1491
1492 QMessageBox::information(this, tr("Successfully Removed"),
1493 tr("Successfully removed %1 installed DLC.").arg(count));
1494}
1495
1488void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target) { 1496void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target) {
1489 QString question; 1497 const QString question = [this, target] {
1498 switch (target) {
1499 case GameListRemoveTarget::ShaderCache:
1500 return tr("Delete Transferable Shader Cache?");
1501 case GameListRemoveTarget::CustomConfiguration:
1502 return tr("Remove Custom Game Configuration?");
1503 default:
1504 return QString{};
1505 }
1506 }();
1507
1508 if (QMessageBox::question(this, tr("Remove File"), question, QMessageBox::Yes | QMessageBox::No,
1509 QMessageBox::No) != QMessageBox::Yes) {
1510 return;
1511 }
1490 1512
1491 switch (target) { 1513 switch (target) {
1492 case GameListRemoveTarget::ShaderCache: 1514 case GameListRemoveTarget::ShaderCache:
1493 question = tr("Delete Transferable Shader Cache?"); 1515 RemoveTransferableShaderCache(program_id);
1494 break; 1516 break;
1495 case GameListRemoveTarget::CustomConfiguration: 1517 case GameListRemoveTarget::CustomConfiguration:
1496 question = tr("Remove Custom Game Configuration?"); 1518 RemoveCustomConfiguration(program_id);
1497 break; 1519 break;
1498 } 1520 }
1521}
1499 1522
1500 if (QMessageBox::question(this, tr("Remove File"), question, QMessageBox::Yes | QMessageBox::No, 1523void GMainWindow::RemoveTransferableShaderCache(u64 program_id) {
1501 QMessageBox::No) != QMessageBox::Yes) { 1524 const QString shader_dir =
1525 QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir));
1526 const QString transferable_shader_cache_folder_path =
1527 shader_dir + QStringLiteral("opengl") + QDir::separator() + QStringLiteral("transferable");
1528 const QString transferable_shader_cache_file_path =
1529 transferable_shader_cache_folder_path + QDir::separator() +
1530 QString::fromStdString(fmt::format("{:016X}.bin", program_id));
1531
1532 if (!QFile::exists(transferable_shader_cache_file_path)) {
1533 QMessageBox::warning(this, tr("Error Removing Transferable Shader Cache"),
1534 tr("A shader cache for this title does not exist."));
1502 return; 1535 return;
1503 } 1536 }
1504 1537
1505 switch (target) { 1538 if (QFile::remove(transferable_shader_cache_file_path)) {
1506 case GameListRemoveTarget::ShaderCache: { 1539 QMessageBox::information(this, tr("Successfully Removed"),
1507 const QString shader_dir = 1540 tr("Successfully removed the transferable shader cache."));
1508 QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir)); 1541 } else {
1509 const QString transferable_shader_cache_folder_path = 1542 QMessageBox::warning(this, tr("Error Removing Transferable Shader Cache"),
1510 shader_dir + QStringLiteral("opengl") + QDir::separator() + 1543 tr("Failed to remove the transferable shader cache."));
1511 QStringLiteral("transferable");
1512 const QString transferable_shader_cache_file_path =
1513 transferable_shader_cache_folder_path + QDir::separator() +
1514 QString::fromStdString(fmt::format("{:016X}.bin", program_id));
1515
1516 if (!QFile::exists(transferable_shader_cache_file_path)) {
1517 QMessageBox::warning(this, tr("Error Removing Transferable Shader Cache"),
1518 tr("A shader cache for this title does not exist."));
1519 break;
1520 }
1521
1522 if (QFile::remove(transferable_shader_cache_file_path)) {
1523 QMessageBox::information(this, tr("Successfully Removed"),
1524 tr("Successfully removed the transferable shader cache."));
1525 } else {
1526 QMessageBox::warning(this, tr("Error Removing Transferable Shader Cache"),
1527 tr("Failed to remove the transferable shader cache."));
1528 }
1529 break;
1530 } 1544 }
1531 case GameListRemoveTarget::CustomConfiguration: { 1545}
1532 const QString config_dir =
1533 QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir));
1534 const QString custom_config_file_path =
1535 config_dir + QString::fromStdString(fmt::format("{:016X}.ini", program_id));
1536 1546
1537 if (!QFile::exists(custom_config_file_path)) { 1547void GMainWindow::RemoveCustomConfiguration(u64 program_id) {
1538 QMessageBox::warning(this, tr("Error Removing Custom Configuration"), 1548 const QString config_dir =
1539 tr("A custom configuration for this title does not exist.")); 1549 QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir));
1540 break; 1550 const QString custom_config_file_path =
1541 } 1551 config_dir + QString::fromStdString(fmt::format("{:016X}.ini", program_id));
1542 1552
1543 if (QFile::remove(custom_config_file_path)) { 1553 if (!QFile::exists(custom_config_file_path)) {
1544 QMessageBox::information(this, tr("Successfully Removed"), 1554 QMessageBox::warning(this, tr("Error Removing Custom Configuration"),
1545 tr("Successfully removed the custom game configuration.")); 1555 tr("A custom configuration for this title does not exist."));
1546 } else { 1556 return;
1547 QMessageBox::warning(this, tr("Error Removing Custom Configuration"),
1548 tr("Failed to remove the custom game configuration."));
1549 }
1550 break;
1551 } 1557 }
1558
1559 if (QFile::remove(custom_config_file_path)) {
1560 QMessageBox::information(this, tr("Successfully Removed"),
1561 tr("Successfully removed the custom game configuration."));
1562 } else {
1563 QMessageBox::warning(this, tr("Error Removing Custom Configuration"),
1564 tr("Failed to remove the custom game configuration."));
1552 } 1565 }
1553} 1566}
1554 1567
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index bbdf7ae51..73a44a3bf 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -233,6 +233,11 @@ private slots:
233 void OnLanguageChanged(const QString& locale); 233 void OnLanguageChanged(const QString& locale);
234 234
235private: 235private:
236 void RemoveBaseContent(u64 program_id, const QString& entry_type);
237 void RemoveUpdateContent(u64 program_id, const QString& entry_type);
238 void RemoveAddOnContent(u64 program_id, const QString& entry_type);
239 void RemoveTransferableShaderCache(u64 program_id);
240 void RemoveCustomConfiguration(u64 program_id);
236 std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id); 241 std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id);
237 InstallResult InstallNSPXCI(const QString& filename); 242 InstallResult InstallNSPXCI(const QString& filename);
238 InstallResult InstallNCA(const QString& filename); 243 InstallResult InstallNCA(const QString& filename);