mirror of
https://github.com/joel16/VITA-Homebrew-Sorter.git
synced 2024-11-23 11:29:50 +00:00
gui: Cleanup prompts and display warning message if loadout is outdated
This commit is contained in:
parent
32e8a9c5a3
commit
7fad0f5a86
@ -31,6 +31,7 @@ namespace AppList {
|
||||
void Sort(std::vector<AppInfoIcon> &entries, std::vector<AppInfoPage> &pages, std::vector<AppInfoFolder> &folders);
|
||||
int Backup(void);
|
||||
int Restore(void);
|
||||
bool Compare(const char *db_name);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -226,4 +226,64 @@ namespace AppList {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Compare(const char *db_name) {
|
||||
std::vector<std::string> app_entries;
|
||||
std::vector<std::string> loadout_entries;
|
||||
std::vector<std::string> diff_entries;
|
||||
|
||||
sqlite3 *db;
|
||||
int ret = sqlite3_open_v2(path, &db, SQLITE_OPEN_READWRITE, nullptr);
|
||||
|
||||
if (ret)
|
||||
return false;
|
||||
|
||||
std::string query = "SELECT title FROM tbl_appinfo_icon;";
|
||||
|
||||
sqlite3_stmt *stmt;
|
||||
ret = sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr);
|
||||
|
||||
while ((ret = sqlite3_step(stmt)) == SQLITE_ROW) {
|
||||
std::string entry = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
|
||||
app_entries.push_back(entry);
|
||||
}
|
||||
|
||||
if (ret != SQLITE_DONE) {
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_close(db);
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_close(db);
|
||||
|
||||
std::string db_path = "ux0:data/VITAHomebrewSorter/loadouts/" + std::string(db_name);
|
||||
ret = sqlite3_open_v2(db_path.c_str(), &db, SQLITE_OPEN_READWRITE, nullptr);
|
||||
|
||||
if (ret)
|
||||
return false;
|
||||
|
||||
ret = sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr);
|
||||
|
||||
while ((ret = sqlite3_step(stmt)) == SQLITE_ROW) {
|
||||
std::string entry = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
|
||||
loadout_entries.push_back(entry);
|
||||
}
|
||||
|
||||
if (ret != SQLITE_DONE) {
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_close(db);
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_close(db);
|
||||
|
||||
if (app_entries.empty() || loadout_entries.empty())
|
||||
return false;
|
||||
|
||||
std::set_difference(app_entries.begin(), app_entries.end(), loadout_entries.begin(), loadout_entries.end(),
|
||||
std::inserter(diff_entries, diff_entries.begin()));
|
||||
return (diff_entries.size() > 0);
|
||||
}
|
||||
}
|
||||
|
161
source/gui.cpp
161
source/gui.cpp
@ -32,6 +32,7 @@ namespace GUI {
|
||||
StateConfirm,
|
||||
StateRestore,
|
||||
StateLoadoutRestore,
|
||||
StateWarning,
|
||||
StateDone
|
||||
};
|
||||
|
||||
@ -100,49 +101,98 @@ namespace GUI {
|
||||
}
|
||||
}
|
||||
|
||||
static void ConfirmRestorePopup(State *state, std::vector<AppInfoIcon> &entries, const char *name) {
|
||||
ImGui::OpenPopup(*state == StateConfirm? "Confirmation" : "Restoration");
|
||||
static void Prompt(State *state, std::vector<AppInfoIcon> &entries, const char *name) {
|
||||
if (*state == StateNone)
|
||||
return;
|
||||
|
||||
std::string title, prompt;
|
||||
|
||||
switch (*state) {
|
||||
case StateConfirm:
|
||||
title = "Confirm";
|
||||
prompt = "Are you sure you want to apply this sorting method?";
|
||||
break;
|
||||
|
||||
case StateRestore:
|
||||
title = "Restore Backup";
|
||||
prompt = "Are you sure you want to restore this backup?";
|
||||
break;
|
||||
|
||||
case StateLoadoutRestore:
|
||||
title = "Restore Loadout";
|
||||
prompt = "Are you sure you want to apply this loadout?";
|
||||
break;
|
||||
|
||||
case StateWarning:
|
||||
title = "Warning";
|
||||
prompt = "This loadout is outdated and may not include some newly installed apps.";
|
||||
break;
|
||||
|
||||
case StateDone:
|
||||
title = "Restart";
|
||||
prompt = "Do you wish to restart your device?";
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ImGui::OpenPopup(title.c_str());
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 20));
|
||||
ImGui::SetNextWindowPos(ImVec2(480.0f, 272.0f), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||
|
||||
if (ImGui::BeginPopupModal(*state == StateConfirm? "Confirmation" : "Restoration", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
switch (*state) {
|
||||
case StateConfirm:
|
||||
ImGui::Text("Are you sure you want to apply this sorting method?");
|
||||
break;
|
||||
if (ImGui::BeginPopupModal(title.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::Text(prompt.c_str());
|
||||
|
||||
case StateRestore:
|
||||
ImGui::Text("Are you sure you want to restore this backup?");
|
||||
break;
|
||||
|
||||
case StateLoadoutRestore:
|
||||
ImGui::Text("Are you sure you want to apply this loadout?");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
if ((*state == StateConfirm) || (*state == StateRestore) || (*state == StateLoadoutRestore)) {
|
||||
ImGui::Dummy(ImVec2(0.0f, 5.0f));
|
||||
ImGui::Text("You must reboot your device for the changes to take effect.");
|
||||
}
|
||||
else if (*state == StateWarning) {
|
||||
ImGui::Dummy(ImVec2(0.0f, 5.0f));
|
||||
ImGui::Text("Do you still wish to continue restoring this loadout?");
|
||||
}
|
||||
|
||||
ImGui::Dummy(ImVec2(0.0f, 5.0f));
|
||||
ImGui::Text("You must reboot your device for the changes to take effect.");
|
||||
ImGui::Dummy(ImVec2(0.0f, 5.0f));
|
||||
|
||||
if (ImGui::Button("Ok", ImVec2(120, 0))) {
|
||||
if (*state == StateConfirm) {
|
||||
AppList::Backup();
|
||||
|
||||
if (!backupExists)
|
||||
switch (*state) {
|
||||
case StateConfirm:
|
||||
AppList::Backup();
|
||||
backupExists = true;
|
||||
|
||||
AppList::Save(entries);
|
||||
AppList::Save(entries);
|
||||
*state = StateDone;
|
||||
break;
|
||||
|
||||
case StateRestore:
|
||||
AppList::Restore();
|
||||
*state = StateDone;
|
||||
break;
|
||||
|
||||
case StateLoadoutRestore:
|
||||
if (AppList::Compare(name)) {
|
||||
*state = StateWarning;
|
||||
}
|
||||
else {
|
||||
Loadouts::Restore(name);
|
||||
*state = StateDone;
|
||||
}
|
||||
break;
|
||||
|
||||
case StateWarning:
|
||||
Loadouts::Restore(name);
|
||||
*state = StateDone;
|
||||
break;
|
||||
|
||||
case StateDone:
|
||||
scePowerRequestColdReset();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
else if (*state == StateRestore)
|
||||
AppList::Restore();
|
||||
else if (*state == StateLoadoutRestore)
|
||||
Loadouts::Restore(name);
|
||||
|
||||
|
||||
ImGui::CloseCurrentPopup();
|
||||
*state = StateDone;
|
||||
}
|
||||
|
||||
ImGui::SameLine(0.0f, 15.0f);
|
||||
@ -158,31 +208,6 @@ namespace GUI {
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
static void RestartPopup(State *state) {
|
||||
ImGui::OpenPopup("Restart");
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 20));
|
||||
ImGui::SetNextWindowPos(ImVec2(480.0f, 272.0f), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||
|
||||
if (ImGui::BeginPopupModal("Restart", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::Text("Do you wish to restart your device?");
|
||||
ImGui::Dummy(ImVec2(0.0f, 5.0f));
|
||||
|
||||
if (ImGui::Button("Ok", ImVec2(120, 0)))
|
||||
scePowerRequestColdReset();
|
||||
|
||||
ImGui::SameLine(0.0f, 15.0f);
|
||||
|
||||
if (ImGui::Button("Cancel", ImVec2(120, 0))) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
*state = StateNone;
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
int RenderLoop(void) {
|
||||
bool done = false;
|
||||
backupExists = FS::FileExists("ux0:/data/VITAHomebrewSorter/backup/app.db");
|
||||
@ -346,29 +371,7 @@ namespace GUI {
|
||||
}
|
||||
|
||||
GUI::ExitWindow();
|
||||
|
||||
switch(state) {
|
||||
case StateNone:
|
||||
break;
|
||||
|
||||
case StateConfirm:
|
||||
GUI::ConfirmRestorePopup(&state, apps, loadout_name.c_str());
|
||||
break;
|
||||
|
||||
case StateRestore:
|
||||
GUI::ConfirmRestorePopup(&state, apps, loadout_name.c_str());
|
||||
break;
|
||||
|
||||
case StateLoadoutRestore:
|
||||
GUI::ConfirmRestorePopup(&state, apps, loadout_name.c_str());
|
||||
break;
|
||||
|
||||
case StateDone:
|
||||
GUI::RestartPopup(&state);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
GUI::Prompt(&state, apps, loadout_name.c_str());
|
||||
Renderer::End(ImVec4(0.45f, 0.55f, 0.60f, 1.00f));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user