Skip to content

Commit

Permalink
applist: Create an original app.db.bkp before making other backups th…
Browse files Browse the repository at this point in the history
…at are overwritten
  • Loading branch information
Joel16 committed Apr 15, 2021
1 parent 28249c1 commit 1f80aea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ I am not responsible for anything that happens to your device after the use of t
- Sort app list alphabetically (ascending)
- Sort app list alphabetically (descending)
- Display app list after sorting is applied using ImGui's tables API.
- Backup application database before sorting is applied.
- Backup application database before sorting is applied. Note: Two backups are made. An original backup for first time use (`ux0:/data/VITAHomebrewSorter/backups/app.db.bkp`), and another backup which is overwritten everytime the sort functionality is used (`ux0:/data/VITAHomebrewSorter/backups/app.db`).
- Custom loadouts to backup/restore. (Do note: If you install a new application after you've already backed up your loadout and then attempt to restore this loadout, the new application will not appear on LiveArea and a warning message will be displayed. You can work around this by overwriting your load out backups each time an app is installed or simple re-install the VPK. Although the new application's icon will not appear on LiveArea, its data should not be lost.)

# Credits:
Expand Down
17 changes: 15 additions & 2 deletions source/applist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,14 @@ namespace AppList {
}

int Backup(void) {
const std::string backup_path = "ux0:/data/VITAHomebrewSorter/backup/app.db";
// Create an original backup for first time use.
std::string backup_path;

if (!FS::FileExists("ux0:/data/VITAHomebrewSorter/backup/app.db.bkp"))
backup_path = "ux0:/data/VITAHomebrewSorter/backup/app.db.bkp";
else
backup_path = "ux0:/data/VITAHomebrewSorter/backup/app.db";

unsigned char *data = nullptr;
SceOff size = 0;

Expand All @@ -209,11 +216,17 @@ namespace AppList {
}

int Restore(void) {
std::string restore_path;
unsigned char *data = nullptr;
SceOff size = 0;

if (!FS::FileExists("ux0:/data/VITAHomebrewSorter/backup/app.db"))
restore_path = "ux0:/data/VITAHomebrewSorter/backup/app.db.bkp";
else
restore_path = "ux0:/data/VITAHomebrewSorter/backup/app.db";

int ret = 0;
if (R_FAILED(ret = FS::ReadFile("ux0:/data/VITAHomebrewSorter/backup/app.db", &data, &size)))
if (R_FAILED(ret = FS::ReadFile(restore_path.c_str(), &data, &size)))
return ret;

if (FS::FileExists(path)) {
Expand Down
2 changes: 1 addition & 1 deletion source/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace GUI {

int RenderLoop(void) {
bool done = false;
backupExists = FS::FileExists("ux0:/data/VITAHomebrewSorter/backup/app.db");
backupExists = (FS::FileExists("ux0:/data/VITAHomebrewSorter/backup/app.db") || FS::FileExists("ux0:/data/VITAHomebrewSorter/backup/app.db.bkp"));
std::vector<AppInfoIcon> apps;
std::vector<AppInfoPage> pages;
std::vector<AppInfoFolder> folders;
Expand Down

0 comments on commit 1f80aea

Please sign in to comment.