Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #21 from TheLogicMaster/hide-installed-titles
Browse files Browse the repository at this point in the history
Installed title hiding selection fix and simplification, thx @TheLogicMaster
  • Loading branch information
dezem committed Jan 27, 2022
2 parents 7e58e7b + 16aacbc commit b606534
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 72 deletions.
1 change: 1 addition & 0 deletions include/ui/netInstPage.hpp
Expand Up @@ -22,6 +22,7 @@ namespace inst::ui {
std::vector<std::string> selectedUrls;
std::vector<std::string> alternativeNames;
std::vector<std::pair<u64, u32>> installedTitles;
std::vector<long unsigned int> menuIndices;
TextBlock::Ref butText;
Rectangle::Ref topRect;
Rectangle::Ref infoRect;
Expand Down
1 change: 1 addition & 0 deletions include/ui/sdInstPage.hpp
Expand Up @@ -24,6 +24,7 @@ namespace inst::ui {
std::vector<std::filesystem::path> ourFiles;
std::vector<std::filesystem::path> selectedTitles;
std::vector<std::pair<u64, u32>> installedTitles;
std::vector<long unsigned int> menuIndices;
std::filesystem::path currentDir;
TextBlock::Ref butText;
Rectangle::Ref topRect;
Expand Down
1 change: 1 addition & 0 deletions include/ui/usbHDDInstPage.hpp
Expand Up @@ -24,6 +24,7 @@ namespace inst::ui {
std::vector<std::filesystem::path> ourFiles;
std::vector<std::filesystem::path> selectedTitles;
std::vector<std::pair<u64, u32>> installedTitles;
std::vector<long unsigned int> menuIndices;
std::filesystem::path currentDir;
TextBlock::Ref butText;
Rectangle::Ref topRect;
Expand Down
1 change: 1 addition & 0 deletions include/util/util.hpp
Expand Up @@ -25,5 +25,6 @@ namespace inst::util {
void lightningStop();
std::string* getBatteryCharge();
std::vector<std::pair<u64, u32>> listInstalledTitles();
bool isTitleInstalled(std::string filename, const std::vector<std::pair<u64, u32>> &installedTitles);
std::vector<std::string> checkForAppUpdate();
}
34 changes: 10 additions & 24 deletions source/ui/netInstPage.cpp
Expand Up @@ -65,46 +65,32 @@ namespace inst::ui {
if (clearItems) this->selectedUrls = {};
if (clearItems) this->alternativeNames = {};
this->menu->ClearItems();
this->menuIndices = {};

const std::regex idRegex(".*\\[([0-9a-fA-F]+)]\\[v(\\d+)].*");
for (long unsigned int i = 0; i < this->ourUrls.size(); i++) {
auto& url = this->ourUrls[i];

for (auto& url: this->ourUrls) {
std::string formattedURL = inst::util::formatUrlString(url);

std::smatch match;
if (hideInstalled and std::regex_match(formattedURL, match, idRegex)) {
u64 id = stol(match[1], nullptr, 16);
u32 version = stoi(match[2]);
bool installed = false;
for (const auto &title: installedTitles)
if (id == title.first and version <= title.second) {
installed = true;
break;
}
if (installed)
continue;
}
if (hideInstalled and inst::util::isTitleInstalled(formattedURL, installedTitles))
continue;

std::string itm = inst::util::shortenString(formattedURL, 56, true);
auto ourEntry = pu::ui::elm::MenuItem::New(itm);
ourEntry->SetColor(COLOR("#FFFFFFFF"));
ourEntry->SetIcon("romfs:/images/icons/checkbox-blank-outline.png");
for (long unsigned int i = 0; i < this->selectedUrls.size(); i++) {
if (this->selectedUrls[i] == url) {
for (long unsigned int j = 0; j < this->selectedUrls.size(); j++) {
if (this->selectedUrls[j] == url) {
ourEntry->SetIcon("romfs:/images/icons/check-box-outline.png");
}
}
this->menu->AddItem(ourEntry);
this->menuIndices.push_back(i);
}
}

void netInstPage::selectTitle(int selectedIndex) {
long unsigned int urlIndex = 0;
for (long unsigned int i = 0; i < this->ourUrls.size(); i++)
if (inst::util::shortenString(inst::util::formatUrlString(this->ourUrls[i]), 56, true) == this->menu->GetItems()[selectedIndex]->GetName()) {
urlIndex = i;
break;
}
long unsigned int urlIndex = this->menuIndices[selectedIndex];

if (this->menu->GetItems()[selectedIndex]->GetIcon() == "romfs:/images/icons/check-box-outline.png") {
for (long unsigned int i = 0; i < this->selectedUrls.size(); i++) {
Expand Down Expand Up @@ -164,7 +150,7 @@ namespace inst::ui {
netConnected = true;
this->pageInfoText->SetText("inst.net.top_info"_lang);
this->butText->SetText(hideInstalled ? "inst.net.buttons1_show"_lang : "inst.net.buttons1"_lang);
installedTitles = installedTitles = inst::util::listInstalledTitles();
installedTitles = inst::util::listInstalledTitles();
this->drawMenuItems(true);
this->menu->SetSelectedIndex(0);
mainApp->CallForRender();
Expand Down
34 changes: 10 additions & 24 deletions source/ui/sdInstPage.cpp
Expand Up @@ -63,8 +63,7 @@ namespace inst::ui {
if (ourPath == "sdmc:") this->currentDir = std::filesystem::path(ourPath.string() + "/");
else this->currentDir = ourPath;
this->menu->ClearItems();

const std::regex idRegex(".*\\[([0-9a-fA-F]+)]\\[v(\\d+)].*");
this->menuIndices = {};

try {
this->ourDirectories = util::getDirsAtPath(this->currentDir);
Expand All @@ -88,32 +87,24 @@ namespace inst::ui {
ourEntry->SetIcon("romfs:/images/icons/folder.png");
this->menu->AddItem(ourEntry);
}
for (auto& file: this->ourFiles) {
for (long unsigned int i = 0; i < this->ourFiles.size(); i++) {
auto& file = this->ourFiles[i];

std::string itm = file.filename().string();

std::smatch match;
if (hideInstalled and std::regex_match(itm, match, idRegex)) {
u64 id = stol(match[1], nullptr, 16);
u32 version = stoi(match[2]);
bool installed = false;
for (const auto &title: installedTitles)
if (id == title.first and version <= title.second) {
installed = true;
break;
}
if (installed)
continue;
}
if (hideInstalled and inst::util::isTitleInstalled(itm, installedTitles))
continue;

auto ourEntry = pu::ui::elm::MenuItem::New(itm);
ourEntry->SetColor(COLOR("#FFFFFFFF"));
ourEntry->SetIcon("romfs:/images/icons/checkbox-blank-outline.png");
for (long unsigned int i = 0; i < this->selectedTitles.size(); i++) {
if (this->selectedTitles[i] == file) {
for (long unsigned int j = 0; j < this->selectedTitles.size(); j++) {
if (this->selectedTitles[j] == file) {
ourEntry->SetIcon("romfs:/images/icons/check-box-outline.png");
}
}
this->menu->AddItem(ourEntry);
this->menuIndices.push_back(i);
}
}

Expand Down Expand Up @@ -147,12 +138,7 @@ namespace inst::ui {
}

void sdInstPage::selectNsp(int selectedIndex) {
long unsigned int nspIndex = 0;
for (long unsigned int i = 0; i < this->ourFiles.size(); i++)
if (this->ourFiles[i].filename().string() == this->menu->GetItems()[selectedIndex]->GetName()) {
nspIndex = i;
break;
}
long unsigned int nspIndex = this->menuIndices[selectedIndex];

int dirListSize = this->ourDirectories.size();
if (this->currentDir != "sdmc:/") dirListSize++;
Expand Down
35 changes: 11 additions & 24 deletions source/ui/usbHDDInstPage.cpp
Expand Up @@ -72,8 +72,7 @@ namespace inst::ui {
}

this->menu->ClearItems();

const std::regex idRegex(".*\\[([0-9a-fA-F]+)]\\[v(\\d+)].*");
this->menuIndices = {};

try {
this->ourDirectories = util::getDirsAtPath(this->currentDir);
Expand All @@ -97,32 +96,25 @@ namespace inst::ui {
ourEntry->SetIcon("romfs:/images/icons/folder.png");
this->menu->AddItem(ourEntry);
}
for (auto& file: this->ourFiles) {

for (long unsigned int i = 0; i < this->ourFiles.size(); i++) {
auto& file = this->ourFiles[i];

std::string itm = file.filename().string();

std::smatch match;
if (hideInstalled and std::regex_match(itm, match, idRegex)) {
u64 id = stol(match[1], nullptr, 16);
u32 version = stoi(match[2]);
bool installed = false;
for (const auto &title: installedTitles)
if (id == title.first and version <= title.second) {
installed = true;
break;
}
if (installed)
continue;
}
if (hideInstalled and inst::util::isTitleInstalled(itm, installedTitles))
continue;

auto ourEntry = pu::ui::elm::MenuItem::New(itm);
ourEntry->SetColor(COLOR("#FFFFFFFF"));
ourEntry->SetIcon("romfs:/images/icons/checkbox-blank-outline.png");
for (long unsigned int i = 0; i < this->selectedTitles.size(); i++) {
if (this->selectedTitles[i] == file) {
for (long unsigned int j = 0; j < this->selectedTitles.size(); j++) {
if (this->selectedTitles[j] == file) {
ourEntry->SetIcon("romfs:/images/icons/check-box-outline.png");
}
}
this->menu->AddItem(ourEntry);
this->menuIndices.push_back(i);
}
}

Expand Down Expand Up @@ -152,12 +144,7 @@ namespace inst::ui {
}

void usbHDDInstPage::selectNsp(int selectedIndex) {
long unsigned int nspIndex = 0;
for (long unsigned int i = 0; i < this->ourFiles.size(); i++)
if (this->ourFiles[i].filename().string() == this->menu->GetItems()[selectedIndex]->GetName()) {
nspIndex = i;
break;
}
long unsigned int nspIndex = this->menuIndices[selectedIndex];

int dirListSize = this->ourDirectories.size();
dirListSize++;
Expand Down
13 changes: 13 additions & 0 deletions source/util/util.cpp
Expand Up @@ -439,6 +439,19 @@ namespace inst::util {
return installedTitles;
}

bool isTitleInstalled(std::string filename, const std::vector<std::pair<u64, u32>> &installedTitles) {
static const std::regex idRegex(".*\\[([0-9a-fA-F]+)]\\[v(\\d+)].*");
std::smatch match;
if (std::regex_match(filename, match, idRegex)) {
u64 id = stol(match[1], nullptr, 16);
u32 version = stoi(match[2]);
for (const auto &title: installedTitles)
if (id == title.first and version <= title.second)
return true;
}
return false;
}

std::vector<std::string> checkForAppUpdate () {
try {
std::string jsonData = inst::curl::downloadToBuffer("https://api.github.com/repos/dezem/AtmoXL-Titel-Installer/releases/latest", 0, 0, 1000L);
Expand Down

0 comments on commit b606534

Please sign in to comment.