applist: Properly handle folders with no names and pageIds that are not in sequential order

This commit is contained in:
Joel16 2021-04-18 12:19:19 -04:00
parent 6df3a43543
commit 8800c096d9
3 changed files with 37 additions and 23 deletions

View File

@ -8,7 +8,7 @@ typedef struct AppInfoIcon {
int pageId = 0;
int pageNo = 0;
int pos = 0;
std::string title;
char title[128];
char titleId[16];
int reserved01 = 0;
bool folder = false;

View File

@ -36,7 +36,7 @@ namespace AppList {
entry.pageId = std::stoi(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)));
entry.pageNo = sqlite3_column_int(stmt, 1);
entry.pos = sqlite3_column_int(stmt, 2);
entry.title = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3));
std::snprintf(entry.title, 128, "%s", reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3)));
std::snprintf(entry.titleId, 16, "%s", sqlite3_column_text(stmt, 4));
if (std::string(entry.titleId) == "(null)")
entry.reserved01 = (std::stoi(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 5))));
@ -62,14 +62,16 @@ namespace AppList {
ret = sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr);
while ((ret = sqlite3_step(stmt)) == SQLITE_ROW) {
AppInfoPage entry;
entry.pageId = sqlite3_column_int(stmt, 0);
entry.pageNo = sqlite3_column_int(stmt, 1);
pages.push_back(entry);
AppInfoPage page;
AppInfoFolder folder;
int pageNo = sqlite3_column_int(stmt, 1);
if (entry.pageNo < 0) {
if (pageNo >= 0) {
page.pageId = sqlite3_column_int(stmt, 0);
page.pageNo = pageNo;
pages.push_back(page);
}
else if (pageNo < 0) {
folder.pageId = sqlite3_column_int(stmt, 0);
folders.push_back(folder);
}
@ -80,7 +82,7 @@ namespace AppList {
sqlite3_close(db);
return ret;
}
sqlite3_finalize(stmt);
sqlite3_close(db);
return 0;
@ -95,13 +97,19 @@ namespace AppList {
// Hacky workaround to avoid SQL's unique constraints. Please look away!
for (int i = 0, counter = 10; i < entries.size(); i++, counter++) {
std::string title = entries[i].title;
std::string titleId = entries[i].titleId;
std::string query =
std::string("UPDATE tbl_appinfo_icon ")
+ "SET pageId = " + std::to_string(entries[i].pageId) + ", pos = " + std::to_string(counter) + " "
+ "WHERE "
+ (titleId == "(null)"? "title = '" + entries[i].title + "'" : "titleId = '" + titleId + "'")
+ (entries[i].folder == true? " AND reserved01 = " + std::to_string(entries[i].reserved01) + ";" : ";");
+ "WHERE ";
if ((title == "(null)") && (titleId == "(null)"))
query.append("reserved01 = " + std::to_string(entries[i].reserved01) + ";");
else {
query.append((titleId == "(null)"? "title = '" + title + "'" : "titleId = '" + titleId + "'")
+ (entries[i].folder == true? " AND reserved01 = " + std::to_string(entries[i].reserved01) + ";" : ";"));
}
char *error;
ret = sqlite3_exec(db, query.c_str(), nullptr, nullptr, &error);
@ -118,14 +126,20 @@ namespace AppList {
}
for (int i = 0; i < entries.size(); i++) {
std::string title = entries[i].title;
std::string titleId = entries[i].titleId;
std::string query =
std::string("UPDATE tbl_appinfo_icon ")
+ "SET pageId = " + std::to_string(entries[i].pageId) + ", pos = " + std::to_string(entries[i].pos) + " "
+ "WHERE "
+ (titleId == "(null)"? "title = '" + entries[i].title + "'" : "titleId = '" + titleId + "'")
+ (entries[i].folder == true? " AND reserved01 = " + std::to_string(entries[i].reserved01) + ";" : ";");
+ "WHERE ";
if ((title == "(null)") && (titleId == "(null)"))
query.append("reserved01 = " + std::to_string(entries[i].reserved01) + ";");
else {
query.append((titleId == "(null)"? "title = '" + title + "'" : "titleId = '" + titleId + "'")
+ (entries[i].folder == true? " AND reserved01 = " + std::to_string(entries[i].reserved01) + ";" : ";"));
}
char *error;
ret = sqlite3_exec(db, query.c_str(), nullptr, nullptr, &error);

View File

@ -232,7 +232,7 @@ namespace GUI {
ret = FS::GetDirList("ux0:data/VITAHomebrewSorter/loadouts", loadouts);
int date_format = Utils::GetDateFormat();
std::string loadout_name;
enum SortMode {
SortDefault,
SortAsc,
@ -314,7 +314,7 @@ namespace GUI {
ImGui::Image(reinterpret_cast<ImTextureID>(apps[i].folder? icons[Folder].id : icons[App].id), ImVec2(20, 20));
ImGui::TableNextColumn();
ImGui::Selectable(apps[i].title.c_str(), false, ImGuiSelectableFlags_SpanAllColumns);
ImGui::Selectable(apps[i].title, false, ImGuiSelectableFlags_SpanAllColumns);
ImGui::TableNextColumn();
ImGui::Text("%d", apps[i].pageId);
@ -345,15 +345,15 @@ namespace GUI {
ImGui::Dummy(ImVec2(0.0f, 5.0f)); // Spacing
if (ImGui::BeginTable("LoadoutList", 3, tableFlags)) {
ImGui::TableSetupColumn("");
ImGui::TableSetupColumn("Title");
ImGui::TableSetupColumn("Date");
ImGui::TableHeadersRow();
if (loadouts.empty()) {
ImGui::Text("No loadouts found");
}
else {
ImGui::TableSetupColumn("");
ImGui::TableSetupColumn("Title");
ImGui::TableSetupColumn("Date");
ImGui::TableHeadersRow();
for (int i = 0; i < loadouts.size(); i++) {
ImGui::TableNextRow();