Fix duplicate entries and moving homebrew to folder

This commit is contained in:
XorTroll 2021-07-11 17:05:34 +02:00
parent d1b70f8171
commit 8feb63193e
5 changed files with 55 additions and 84 deletions

View file

@ -26,6 +26,23 @@ namespace cfg {
std::string name; std::string name;
std::string author; std::string author;
std::string version; std::string version;
inline bool Equals(const TitleRecord &other) {
if(this->title_type == other.title_type) {
switch(static_cast<TitleType>(this->title_type)) {
case TitleType::Installed: {
return this->app_id == other.app_id;
}
case TitleType::Homebrew: {
return std::strcmp(this->nro_target.nro_path, other.nro_target.nro_path) == 0;
}
default: {
return false;
}
}
}
return false;
}
}; };
struct TitleFolder { struct TitleFolder {

View file

@ -455,66 +455,34 @@ namespace cfg {
bool title_found = false; bool title_found = false;
TitleRecord record_copy = {}; TitleRecord record_copy = {};
std::string recjson; std::string recjson;
const auto type = static_cast<TitleType>(record.title_type);
// Search in root first // Search in root first
if(type == TitleType::Installed) { auto find = STL_FIND_IF(list.root.titles, tit, record.Equals(tit));
auto find = STL_FIND_IF(list.root.titles, tit, (tit.title_type == record.title_type) && (tit.app_id == record.app_id)); if(STL_FOUND(list.root.titles, find)) {
if(STL_FOUND(list.root.titles, find)) { // It is already on root...?
// It is already on root...? if(folder.empty()) {
if(folder.empty()) { return true;
return true;
}
recjson = STL_UNWRAP(find).json_name;
list.root.titles.erase(find);
title_found = true;
} }
} recjson = STL_UNWRAP(find).json_name;
else {
auto find = STL_FIND_IF(list.root.titles, tit, (tit.title_type == record.title_type) && (tit.nro_target.nro_path == record.nro_target.nro_path));
if(STL_FOUND(list.root.titles, find)) {
// It is already on root...?
if(folder.empty()) {
return true;
}
recjson = STL_UNWRAP(find).json_name;
list.root.titles.erase(find); list.root.titles.erase(find);
title_found = true; title_found = true;
}
} }
// If not found yet, search on all dirs if the title is present // If not found yet, search on all dirs if the title is present
if(!title_found) { if(!title_found) {
for(auto &fld: list.folders) { for(auto &fld: list.folders) {
if(type == TitleType::Installed) { auto find = STL_FIND_IF(fld.titles, tit, record.Equals(tit));
auto find = STL_FIND_IF(fld.titles, tit, (tit.title_type == record.title_type) && (tit.app_id == record.app_id)); if(STL_FOUND(fld.titles, find)) {
if(STL_FOUND(fld.titles, find)) { // It is already on that folder...?
// It is already on that folder...? if(fld.name == folder) {
if(fld.name == folder) { return true;
return true;
}
recjson = STL_UNWRAP(find).json_name;
fld.titles.erase(find);
title_found = true;
break;
} }
} recjson = STL_UNWRAP(find).json_name;
else {
auto find = STL_FIND_IF(fld.titles, tit, (tit.title_type == record.title_type) && (tit.nro_target.nro_path == record.nro_target.nro_path));
if(STL_FOUND(fld.titles, find)) {
// It is already on that folder...?
if(fld.name == folder) {
return true;
}
recjson = STL_UNWRAP(find).json_name;
fld.titles.erase(find); fld.titles.erase(find);
title_found = true; title_found = true;
break; break;
}
} }
} }
} }
@ -573,45 +541,23 @@ namespace cfg {
auto title_found = false; auto title_found = false;
TitleRecord record_copy = {}; TitleRecord record_copy = {};
std::string recjson; std::string recjson;
const auto type = static_cast<TitleType>(record.title_type);
// Search in root first // Search in root first
if(type == TitleType::Installed) { auto find = STL_FIND_IF(list.root.titles, tit, record.Equals(tit));
auto find = STL_FIND_IF(list.root.titles, tit, (tit.title_type == record.title_type) && (tit.app_id == record.app_id)); if(STL_FOUND(list.root.titles, find)) {
if(STL_FOUND(list.root.titles, find)) { if(!STL_UNWRAP(find).json_name.empty()) {
if(!STL_UNWRAP(find).json_name.empty()) { title_found = true;
title_found = true;
}
}
}
else {
auto find = STL_FIND_IF(list.root.titles, tit, (tit.title_type == record.title_type) && (tit.nro_target.nro_path == record.nro_target.nro_path));
if(STL_FOUND(list.root.titles, find)) {
if(!STL_UNWRAP(find).json_name.empty()) {
title_found = true;
}
} }
} }
// If not found yet, search on all dirs if the title is present // If not found yet, search on all dirs if the title is present
if(!title_found) { if(!title_found) {
for(auto &fld: list.folders) { for(auto &fld: list.folders) {
if(type == TitleType::Installed) { auto find = STL_FIND_IF(fld.titles, tit, record.Equals(tit));
auto find = STL_FIND_IF(fld.titles, tit, (tit.title_type == record.title_type) && (tit.app_id == record.app_id)); if(STL_FOUND(fld.titles, find)) {
if(STL_FOUND(fld.titles, find)) { if(!STL_UNWRAP(find).json_name.empty()) {
if(!STL_UNWRAP(find).json_name.empty()) { title_found = true;
title_found = true; break;
break;
}
}
}
else {
auto find = STL_FIND_IF(fld.titles, tit, (tit.title_type == record.title_type) && (tit.nro_target.nro_path == record.nro_target.nro_path));
if(STL_FOUND(fld.titles, find)) {
if(!STL_UNWRAP(find).json_name.empty()) {
title_found = true;
break;
}
} }
} }
} }

View file

@ -9,7 +9,8 @@
"menu_rename_folder_conf": "Would you like to rename this folder?", "menu_rename_folder_conf": "Would you like to rename this folder?",
"swkbd_rename_folder_guide": "Enter new folder name", "swkbd_rename_folder_guide": "Enter new folder name",
"hb_mode_entries_add": "Would you like to add all selected entries to the main menu?", "hb_mode_entries_add": "Would you like to add all selected entries to the main menu?",
"hb_mode_entries_added": "New entries were added to the main menu.", "hb_mode_entries_added": "The selected entries were added to the main menu.",
"hb_mode_entries_some_added": "Some selected entries were added in the main menu, but others already had been added.",
"menu_move_to_folder": "Would you like to move all selected entries inside a new folder or an already existing one?", "menu_move_to_folder": "Would you like to move all selected entries inside a new folder or an already existing one?",
"menu_move_new_folder": "New folder", "menu_move_new_folder": "New folder",
"menu_move_existing_folder": "Existing folder", "menu_move_existing_folder": "Existing folder",

View file

@ -10,6 +10,7 @@
"swkbd_rename_folder_guide": "新しいフォルダー名を入力してください", "swkbd_rename_folder_guide": "新しいフォルダー名を入力してください",
"hb_mode_entries_add": "選択したすべてのエントリをメインメニューに追加しますか?", "hb_mode_entries_add": "選択したすべてのエントリをメインメニューに追加しますか?",
"hb_mode_entries_added": "新しいエントリがメインメニューに追加されました。", "hb_mode_entries_added": "新しいエントリがメインメニューに追加されました。",
"hb_mode_entries_some_added": "Some selected entries were added in the main menu, but others already had been added.",
"menu_move_to_folder": "選択したすべてのエントリを新しいフォルダまたは既存のフォルダ内に移動しますか?", "menu_move_to_folder": "選択したすべてのエントリを新しいフォルダまたは既存のフォルダ内に移動しますか?",
"menu_move_new_folder": "新しいフォルダ", "menu_move_new_folder": "新しいフォルダ",
"menu_move_existing_folder": "既存のフォルダ", "menu_move_existing_folder": "既存のフォルダ",

View file

@ -316,7 +316,7 @@ namespace ui {
if(hbidx < 0) { if(hbidx < 0) {
hbidx = 0; hbidx = 0;
} }
auto any = false; auto all_added = true;
for(u32 i = 0; i < g_HomebrewRecordList.size(); i++) { for(u32 i = 0; i < g_HomebrewRecordList.size(); i++) {
auto &hb = g_HomebrewRecordList[i]; auto &hb = g_HomebrewRecordList[i];
auto idx = i + 1; auto idx = i + 1;
@ -324,14 +324,19 @@ namespace ui {
if(!cfg::ExistsRecord(g_EntryList, hb)) { if(!cfg::ExistsRecord(g_EntryList, hb)) {
cfg::SaveRecord(hb); cfg::SaveRecord(hb);
g_EntryList.root.titles.insert(g_EntryList.root.titles.begin() + hbidx, hb); g_EntryList.root.titles.insert(g_EntryList.root.titles.begin() + hbidx, hb);
any = true;
hbidx++; hbidx++;
} }
else {
all_added = false;
}
} }
} }
if(any) { if(all_added) {
g_MenuApplication->ShowNotification(GetLanguageString("hb_mode_entries_added")); g_MenuApplication->ShowNotification(GetLanguageString("hb_mode_entries_added"));
} }
else {
g_MenuApplication->ShowNotification(GetLanguageString("hb_mode_entries_some_added"));
}
this->StopMultiselect(); this->StopMultiselect();
} }
else if(sopt == 1) { else if(sopt == 1) {
@ -871,6 +876,7 @@ namespace ui {
for(u32 i = 0; i < basesz; i++) { for(u32 i = 0; i < basesz; i++) {
auto &title = g_EntryList.root.titles[i - rmvd]; auto &title = g_EntryList.root.titles[i - rmvd];
if(this->itemsMenu->IsItemMultiselected(basefsz + i)) { if(this->itemsMenu->IsItemMultiselected(basefsz + i)) {
g_MenuApplication->CreateShowDialog("A", "Moving title '" + title.name + "' to folder '" + folder + "'...", { "K" }, true);
if(cfg::MoveRecordTo(g_EntryList, title, folder)) { if(cfg::MoveRecordTo(g_EntryList, title, folder)) {
rmvd++; rmvd++;
} }