From c95d66f0e438e1b7beefa3aa42ccec7cd2652d48 Mon Sep 17 00:00:00 2001 From: Pk11 Date: Fri, 26 Mar 2021 06:01:37 -0500 Subject: [PATCH] A bunch of minor tweaks from cppcheck --- Universal-Core | 2 +- include/store/storeUtils.hpp | 2 - include/utils/fileBrowse.hpp | 1 - include/utils/queueSystem.hpp | 24 ++++---- include/utils/stringutils.hpp | 2 +- source/menu/downList.cpp | 40 +++---------- source/menu/markMenu.cpp | 10 ++-- source/menu/searchMenu.cpp | 10 ++-- source/menu/settings.cpp | 5 +- source/overlays/dirSelect.cpp | 16 +---- source/overlays/storeSelect.cpp | 100 +++++++++++++++----------------- source/screens/mainScreen.cpp | 10 ++-- source/store/storeUtils.cpp | 16 +---- source/utils/download.cpp | 2 +- source/utils/extract.cpp | 1 - source/utils/fileBrowse.cpp | 64 +++++--------------- source/utils/queueSystem.cpp | 3 - source/utils/screenshot.cpp | 2 +- source/utils/stringutils.cpp | 4 +- 19 files changed, 110 insertions(+), 204 deletions(-) diff --git a/Universal-Core b/Universal-Core index be0f078..a5448d1 160000 --- a/Universal-Core +++ b/Universal-Core @@ -1 +1 @@ -Subproject commit be0f07807c5323876bd5f4c3d106a0463b2bfee6 +Subproject commit a5448d1f578d4bb26fcf200b0c014cec526b8e78 diff --git a/include/store/storeUtils.hpp b/include/store/storeUtils.hpp index 09bdc08..e77b88a 100644 --- a/include/store/storeUtils.hpp +++ b/include/store/storeUtils.hpp @@ -107,8 +107,6 @@ namespace StoreUtils { void search(const std::string &query, bool title, bool author, bool category, bool console, int selectedMarks, bool updateAvl, bool isAND); - void FilterUpdateAvailable(); - void ResetAll(); void RefreshUpdateAVL(); diff --git a/include/utils/fileBrowse.hpp b/include/utils/fileBrowse.hpp index 1d722a8..6c3c3e1 100644 --- a/include/utils/fileBrowse.hpp +++ b/include/utils/fileBrowse.hpp @@ -56,7 +56,6 @@ struct UniStoreInfo { bool nameEndsWith(const std::string &name, const std::vector &extensionList); void getDirectoryContents(std::vector &dirContents, const std::vector &extensionList); void getDirectoryContents(std::vector &dirContents); -std::vector getContents(const std::string &name, const std::vector &extensionList); std::vector GetUniStoreInfo(const std::string &path); diff --git a/include/utils/queueSystem.hpp b/include/utils/queueSystem.hpp index 594ab37..aa8286e 100644 --- a/include/utils/queueSystem.hpp +++ b/include/utils/queueSystem.hpp @@ -54,18 +54,6 @@ enum RequestType { PROMPT_ERROR = 3 // Error message prompt. Unused right now. }; -class Queue { -public: - Queue(nlohmann::json object, const C2D_Image &img, const std::string &name, const std::string &uName, const std::string &eName, const std::string &lUpdated) : - obj(object), icn(img), name(name), unistoreName(uName), entryName(eName), lastUpdated(lUpdated) { }; - - QueueStatus status = QueueStatus::None; - nlohmann::json obj; - C2D_Image icn; - int total, current; - std::string name = "", unistoreName = "", entryName = "", lastUpdated = ""; -}; - /* Of course also a namespace to that part, so we can do that in a Thread. */ namespace QueueSystem { extern int RequestNeeded, RequestAnswer; @@ -79,4 +67,16 @@ namespace QueueSystem { void Resume(); }; +class Queue { +public: + Queue(nlohmann::json object, const C2D_Image &img, const std::string &name, const std::string &uName, const std::string &eName, const std::string &lUpdated) : + obj(object), icn(img), total(object.size()), current(QueueSystem::LastElement), name(name), unistoreName(uName), entryName(eName), lastUpdated(lUpdated) { }; + + QueueStatus status = QueueStatus::None; + nlohmann::json obj; + C2D_Image icn; + int total, current; + std::string name = "", unistoreName = "", entryName = "", lastUpdated = ""; +}; + #endif \ No newline at end of file diff --git a/include/utils/stringutils.hpp b/include/utils/stringutils.hpp index ebba606..953cce6 100644 --- a/include/utils/stringutils.hpp +++ b/include/utils/stringutils.hpp @@ -37,7 +37,7 @@ namespace StringUtils { std::string formatBytes(int bytes); std::string GetMarkString(int marks); std::vector GetMarks(int marks); - std::string format(const std::string &fmt_str, ...); + std::string format(const char *fmt_str, ...); }; #endif \ No newline at end of file diff --git a/source/menu/downList.cpp b/source/menu/downList.cpp index fc0983e..6bead34 100644 --- a/source/menu/downList.cpp +++ b/source/menu/downList.cpp @@ -188,80 +188,58 @@ void StoreUtils::DownloadHandle(const std::unique_ptr &entry, const } if (hRepeat & KEY_DOWN) { - if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid. - if (StoreUtils::store->GetDownloadIndex() < (int)entries.size() - 1) StoreUtils::store->SetDownloadIndex(StoreUtils::store->GetDownloadIndex() + 1); else StoreUtils::store->SetDownloadIndex(0); } if (hRepeat & KEY_UP) { - if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid. - if (StoreUtils::store->GetDownloadIndex() > 0) StoreUtils::store->SetDownloadIndex(StoreUtils::store->GetDownloadIndex() - 1); else StoreUtils::store->SetDownloadIndex(entries.size() - 1); } if (hRepeat & KEY_RIGHT) { - if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid. - if (StoreUtils::store->GetDownloadIndex() + DOWNLOAD_ENTRIES < (int)entries.size()-1) StoreUtils::store->SetDownloadIndex(StoreUtils::store->GetDownloadIndex() + DOWNLOAD_ENTRIES); else StoreUtils::store->SetDownloadIndex(entries.size()-1); } if (hRepeat & KEY_LEFT) { - if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid. - if (StoreUtils::store->GetDownloadIndex() - DOWNLOAD_ENTRIES > 0) StoreUtils::store->SetDownloadIndex(StoreUtils::store->GetDownloadIndex() - DOWNLOAD_ENTRIES); else StoreUtils::store->SetDownloadIndex(0); } if (smallDelay == 0 && hDown & KEY_TOUCH) { - if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid. - - bool didTouch = false; - for (int i = 0; i < DOWNLOAD_ENTRIES; i++) { if (touching(touch, downloadBoxes[i])) { if (i + StoreUtils::store->GetDownloadSIndex() < (int)entries.size()) { if (Msg::promptMsg(Lang::get("EXECUTE_ENTRY") + "\n\n" + entries[i + StoreUtils::store->GetDownloadSIndex()])) { StoreUtils::AddToQueue(entry->GetEntryIndex(), entries[i + StoreUtils::store->GetDownloadSIndex()], entry->GetTitle(), entry->GetLastUpdated()); } - - didTouch = true; - break; } + + break; } - } - if (!didTouch) { - for (int i = 0; i < DOWNLOAD_ENTRIES; i++) { - if (touching(touch, installedPos[i])) { - if (i + StoreUtils::store->GetDownloadSIndex() < (int)entries.size()) { - if (installs[i + StoreUtils::store->GetDownloadSIndex()]) { - StoreUtils::meta->RemoveInstalled(StoreUtils::store->GetUniStoreTitle(), entry->GetTitle(), entries[i + StoreUtils::store->GetDownloadSIndex()]); - installs[i + StoreUtils::store->GetDownloadSIndex()] = false; - } + if (touching(touch, installedPos[i])) { + if (i + StoreUtils::store->GetDownloadSIndex() < (int)entries.size()) { + if (installs[i + StoreUtils::store->GetDownloadSIndex()]) { + StoreUtils::meta->RemoveInstalled(StoreUtils::store->GetUniStoreTitle(), entry->GetTitle(), entries[i + StoreUtils::store->GetDownloadSIndex()]); + installs[i + StoreUtils::store->GetDownloadSIndex()] = false; } - - didTouch = true; - break; } + + break; } } } if (smallDelay == 0 && hDown & KEY_A) { - if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid. - if (Msg::promptMsg(Lang::get("EXECUTE_ENTRY") + "\n\n" + entries[StoreUtils::store->GetDownloadIndex()])) { StoreUtils::AddToQueue(entry->GetEntryIndex(), entries[StoreUtils::store->GetDownloadIndex()], entry->GetTitle(), entry->GetLastUpdated()); } } if (hDown & KEY_X) { - if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid. - if (installs[StoreUtils::store->GetDownloadIndex()]) { StoreUtils::meta->RemoveInstalled(StoreUtils::store->GetUniStoreTitle(), entry->GetTitle(), entries[StoreUtils::store->GetDownloadIndex()]); installs[StoreUtils::store->GetDownloadIndex()] = false; diff --git a/source/menu/markMenu.cpp b/source/menu/markMenu.cpp index 581d56d..d4052cf 100644 --- a/source/menu/markMenu.cpp +++ b/source/menu/markMenu.cpp @@ -47,19 +47,19 @@ static const std::vector markBox = { void StoreUtils::DisplayMarkBox(int marks) { Gui::Draw_Rect(0, 0, 320, 240, DIM_COLOR); // Darken. - Gui::Draw_Rect(markBox[0].x, markBox[0].y, markBox[0].w, markBox[0].h, (marks & favoriteMarks::STAR ? + Gui::Draw_Rect(markBox[0].x, markBox[0].y, markBox[0].w, markBox[0].h, ((marks & favoriteMarks::STAR) ? UIThemes->MarkSelected() : UIThemes->MarkUnselected())); - Gui::Draw_Rect(markBox[1].x, markBox[1].y, markBox[1].w, markBox[1].h, (marks & favoriteMarks::HEART ? + Gui::Draw_Rect(markBox[1].x, markBox[1].y, markBox[1].w, markBox[1].h, ((marks & favoriteMarks::HEART) ? UIThemes->MarkSelected() : UIThemes->MarkUnselected())); - Gui::Draw_Rect(markBox[2].x, markBox[2].y, markBox[2].w, markBox[2].h, (marks & favoriteMarks::DIAMOND ? + Gui::Draw_Rect(markBox[2].x, markBox[2].y, markBox[2].w, markBox[2].h, ((marks & favoriteMarks::DIAMOND) ? UIThemes->MarkSelected() : UIThemes->MarkUnselected())); - Gui::Draw_Rect(markBox[3].x, markBox[3].y, markBox[3].w, markBox[3].h, (marks & favoriteMarks::CLUBS ? + Gui::Draw_Rect(markBox[3].x, markBox[3].y, markBox[3].w, markBox[3].h, ((marks & favoriteMarks::CLUBS) ? UIThemes->MarkSelected() : UIThemes->MarkUnselected())); - Gui::Draw_Rect(markBox[4].x, markBox[4].y, markBox[4].w, markBox[4].h, (marks & favoriteMarks::SPADE ? + Gui::Draw_Rect(markBox[4].x, markBox[4].y, markBox[4].w, markBox[4].h, ((marks & favoriteMarks::SPADE) ? UIThemes->MarkSelected() : UIThemes->MarkUnselected())); Gui::DrawString(markBox[0].x + 15, markBox[0].y + 11, 0.9, UIThemes->TextColor(), "★", 0, 0, font); diff --git a/source/menu/searchMenu.cpp b/source/menu/searchMenu.cpp index 42454a3..bcb32e8 100644 --- a/source/menu/searchMenu.cpp +++ b/source/menu/searchMenu.cpp @@ -90,19 +90,19 @@ void StoreUtils::DrawSearchMenu(const std::vector &searchIncludes, const s /* Filters. */ Gui::DrawString(84, SearchMenu[5].y - 20, 0.5f, UIThemes->TextColor(), Lang::get("FILTER_TO"), 265, 0, font); - Gui::Draw_Rect(SearchMenu[5].x, SearchMenu[5].y, SearchMenu[5].w, SearchMenu[5].h, (marks & favoriteMarks::STAR ? + Gui::Draw_Rect(SearchMenu[5].x, SearchMenu[5].y, SearchMenu[5].w, SearchMenu[5].h, ((marks & favoriteMarks::STAR) ? UIThemes->SideBarUnselected() : UIThemes->BoxInside())); - Gui::Draw_Rect(SearchMenu[6].x, SearchMenu[6].y, SearchMenu[6].w, SearchMenu[6].h, (marks & favoriteMarks::HEART ? + Gui::Draw_Rect(SearchMenu[6].x, SearchMenu[6].y, SearchMenu[6].w, SearchMenu[6].h, ((marks & favoriteMarks::HEART) ? UIThemes->SideBarUnselected() : UIThemes->BoxInside())); - Gui::Draw_Rect(SearchMenu[7].x, SearchMenu[7].y, SearchMenu[7].w, SearchMenu[7].h, (marks & favoriteMarks::DIAMOND ? + Gui::Draw_Rect(SearchMenu[7].x, SearchMenu[7].y, SearchMenu[7].w, SearchMenu[7].h, ((marks & favoriteMarks::DIAMOND) ? UIThemes->SideBarUnselected() : UIThemes->BoxInside())); - Gui::Draw_Rect(SearchMenu[8].x, SearchMenu[8].y, SearchMenu[8].w, SearchMenu[8].h, (marks & favoriteMarks::CLUBS ? + Gui::Draw_Rect(SearchMenu[8].x, SearchMenu[8].y, SearchMenu[8].w, SearchMenu[8].h, ((marks & favoriteMarks::CLUBS) ? UIThemes->SideBarUnselected() : UIThemes->BoxInside())); - Gui::Draw_Rect(SearchMenu[9].x, SearchMenu[9].y, SearchMenu[9].w, SearchMenu[9].h, (marks & favoriteMarks::SPADE ? + Gui::Draw_Rect(SearchMenu[9].x, SearchMenu[9].y, SearchMenu[9].w, SearchMenu[9].h, ((marks & favoriteMarks::SPADE) ? UIThemes->SideBarUnselected() : UIThemes->BoxInside())); Gui::Draw_Rect(SearchMenu[10].x, SearchMenu[10].y, SearchMenu[10].w, SearchMenu[10].h, (updateFilter ? diff --git a/source/menu/settings.cpp b/source/menu/settings.cpp index 484a4b8..35a7994 100644 --- a/source/menu/settings.cpp +++ b/source/menu/settings.cpp @@ -636,14 +636,13 @@ static void LanguageLogic(int &page, int &selection, int &sPos) { sPos = 0; page = 0; } + + break; } } - } - if (hDown & KEY_TOUCH) { if (touching(touch, langButtons[6])) { /* Download Font. */ - std::string l = config->language(); ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/universal-updater.bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", Lang::get("DOWNLOADING_COMPATIBLE_FONT"), true); config->customfont(true); Init::UnloadFont(); diff --git a/source/overlays/dirSelect.cpp b/source/overlays/dirSelect.cpp index de9849b..a80ffbb 100644 --- a/source/overlays/dirSelect.cpp +++ b/source/overlays/dirSelect.cpp @@ -49,7 +49,6 @@ std::string Overlays::SelectDir(const std::string &oldDir, const std::string &ms int selection = 0, sPos = 0; std::vector dirContents; - dirContents.clear(); /* Make sure. */ if (access((oldDir + std::string("/")).c_str(), F_OK) == 0) { @@ -60,12 +59,7 @@ std::string Overlays::SelectDir(const std::string &oldDir, const std::string &ms chdir("sdmc:/"); } - std::vector dirContentsTemp; - getDirectoryContents(dirContentsTemp, {"/"}); - - for(uint i = 0; i < dirContentsTemp.size(); i++) { - dirContents.push_back(dirContentsTemp[i]); - } + getDirectoryContents(dirContents, {"/"}); while(1) { Gui::clearTextBufs(); @@ -110,13 +104,7 @@ std::string Overlays::SelectDir(const std::string &oldDir, const std::string &ms selection = 0; sPos = 0; - dirContents.clear(); - std::vector dirContentsTemp; - getDirectoryContents(dirContentsTemp, {"/"}); - - for(uint i = 0; i < dirContentsTemp.size(); i++) { - dirContents.push_back(dirContentsTemp[i]); - } + getDirectoryContents(dirContents, {"/"}); } diff --git a/source/overlays/storeSelect.cpp b/source/overlays/storeSelect.cpp index da20610..179e05d 100644 --- a/source/overlays/storeSelect.cpp +++ b/source/overlays/storeSelect.cpp @@ -119,39 +119,37 @@ static bool DownloadStore() { if (storeJson.is_discarded()) storeJson = { }; - if (doSheet) { - if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_array()) { - if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_array()) { - const std::vector locs = storeJson["storeInfo"]["sheetURL"].get>(); - const std::vector sht = storeJson["storeInfo"]["sheet"].get>(); + if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_array()) { + if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_array()) { + const std::vector locs = storeJson["storeInfo"]["sheetURL"].get>(); + const std::vector sht = storeJson["storeInfo"]["sheet"].get>(); - if (locs.size() == sht.size()) { - for (int i = 0; i < (int)sht.size(); i++) { - if (!(sht[i].find("/") != std::string::npos)) { - char msg[150]; - snprintf(msg, sizeof(msg), Lang::get("DOWNLOADING_SPRITE_SHEET2").c_str(), i + 1, sht.size()); - Msg::DisplayMsg(msg); - DownloadSpriteSheet(locs[i], sht[i]); + if (locs.size() == sht.size()) { + for (int i = 0; i < (int)sht.size(); i++) { + if (!(sht[i].find("/") != std::string::npos)) { + char msg[150]; + snprintf(msg, sizeof(msg), Lang::get("DOWNLOADING_SPRITE_SHEET2").c_str(), i + 1, sht.size()); + Msg::DisplayMsg(msg); + DownloadSpriteSheet(locs[i], sht[i]); - } else { - Msg::waitMsg(Lang::get("SHEET_SLASH")); - } + } else { + Msg::waitMsg(Lang::get("SHEET_SLASH")); } } } + } - } else if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_string()) { - if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_string()) { - const std::string fl = storeJson["storeInfo"]["sheetURL"]; - const std::string fl2 = storeJson["storeInfo"]["sheet"]; + } else if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_string()) { + if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_string()) { + const std::string fl = storeJson["storeInfo"]["sheetURL"]; + const std::string fl2 = storeJson["storeInfo"]["sheet"]; - if (!(fl2.find("/") != std::string::npos)) { - Msg::DisplayMsg(Lang::get("DOWNLOADING_SPRITE_SHEET")); - DownloadSpriteSheet(fl, fl2); + if (!(fl2.find("/") != std::string::npos)) { + Msg::DisplayMsg(Lang::get("DOWNLOADING_SPRITE_SHEET")); + DownloadSpriteSheet(fl, fl2); - } else { - Msg::waitMsg(Lang::get("SHEET_SLASH")); - } + } else { + Msg::waitMsg(Lang::get("SHEET_SLASH")); } } } @@ -177,39 +175,37 @@ static bool UpdateStore(const std::string &URL) { if (storeJson.is_discarded()) storeJson = { }; - if (doSheet) { - if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_array()) { - if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_array()) { - const std::vector locs = storeJson["storeInfo"]["sheetURL"].get>(); - const std::vector sht = storeJson["storeInfo"]["sheet"].get>(); + if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_array()) { + if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_array()) { + const std::vector locs = storeJson["storeInfo"]["sheetURL"].get>(); + const std::vector sht = storeJson["storeInfo"]["sheet"].get>(); - if (locs.size() == sht.size()) { - for (int i = 0; i < (int)sht.size(); i++) { - if (!(sht[i].find("/") != std::string::npos)) { - char msg[150]; - snprintf(msg, sizeof(msg), Lang::get("DOWNLOADING_SPRITE_SHEET2").c_str(), i + 1, sht.size()); - Msg::DisplayMsg(msg); - DownloadSpriteSheet(locs[i], sht[i]); + if (locs.size() == sht.size()) { + for (int i = 0; i < (int)sht.size(); i++) { + if (!(sht[i].find("/") != std::string::npos)) { + char msg[150]; + snprintf(msg, sizeof(msg), Lang::get("DOWNLOADING_SPRITE_SHEET2").c_str(), i + 1, sht.size()); + Msg::DisplayMsg(msg); + DownloadSpriteSheet(locs[i], sht[i]); - } else { - Msg::waitMsg(Lang::get("SHEET_SLASH")); - } + } else { + Msg::waitMsg(Lang::get("SHEET_SLASH")); } } } + } - } else if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_string()) { - if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_string()) { - const std::string fl = storeJson["storeInfo"]["sheetURL"]; - const std::string fl2 = storeJson["storeInfo"]["sheet"]; + } else if (storeJson["storeInfo"].contains("sheetURL") && storeJson["storeInfo"]["sheetURL"].is_string()) { + if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_string()) { + const std::string fl = storeJson["storeInfo"]["sheetURL"]; + const std::string fl2 = storeJson["storeInfo"]["sheet"]; - if (!(fl2.find("/") != std::string::npos)) { - Msg::DisplayMsg(Lang::get("DOWNLOADING_SPRITE_SHEET")); - DownloadSpriteSheet(fl, fl2); + if (!(fl2.find("/") != std::string::npos)) { + Msg::DisplayMsg(Lang::get("DOWNLOADING_SPRITE_SHEET")); + DownloadSpriteSheet(fl, fl2); - } else { - Msg::waitMsg(Lang::get("SHEET_SLASH")); - } + } else { + Msg::waitMsg(Lang::get("SHEET_SLASH")); } } } @@ -275,10 +271,10 @@ void Overlays::SelectStore() { if (sPos + i == selection) Gui::Draw_Rect(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, UIThemes->MarkSelected()); Gui::DrawStringCentered(10 - 160 + (300 / 2), mainButtons[i].y + 4, 0.45f, UIThemes->TextColor(), info[sPos + i].FileName, 295, 0, font); } + } else { + GFX::DrawBottom(); // Otherwise we'd draw on top. } - if (info.size() <= 0) GFX::DrawBottom(); // Otherwise we'd draw on top. - GFX::DrawIcon(sprites_delete_idx, mainButtons[6].x, mainButtons[6].y, UIThemes->TextColor()); GFX::DrawIcon(sprites_update_idx, mainButtons[7].x, mainButtons[7].y, UIThemes->TextColor()); GFX::DrawIcon(sprites_add_idx, mainButtons[8].x, mainButtons[8].y, UIThemes->TextColor()); diff --git a/source/screens/mainScreen.cpp b/source/screens/mainScreen.cpp index cf8f7fb..7ae3dd4 100644 --- a/source/screens/mainScreen.cpp +++ b/source/screens/mainScreen.cpp @@ -50,13 +50,13 @@ MainScreen::MainScreen() { StoreUtils::meta = std::make_unique(); /* Check if lastStore is accessible. */ - if (config->lastStore() != "universal-db.unistore" || config->lastStore() != "") { - if (access((std::string(_STORE_PATH) + config->lastStore()).c_str(), F_OK) != 0) { + if (config->lastStore() != "universal-db.unistore" && config->lastStore() != "") { + if (access((_STORE_PATH + config->lastStore()).c_str(), F_OK) != 0) { config->lastStore("universal-db.unistore"); } else { /* check version and file here. */ - const UniStoreInfo info = GetInfo((std::string(_STORE_PATH) + config->lastStore()), config->lastStore()); + const UniStoreInfo info = GetInfo((_STORE_PATH + config->lastStore()), config->lastStore()); if (info.Version != 3 && info.Version != _UNISTORE_VERSION) { config->lastStore("universal-db.unistore"); @@ -245,10 +245,8 @@ void MainScreen::Logic(u32 hDown, u32 hHeld, touchPosition touch) { this->dwnldList = StoreUtils::store->GetDownloadList(StoreUtils::entries[StoreUtils::store->GetEntry()]->GetEntryIndex()); this->dwnldSizes = StoreUtils::entries[StoreUtils::store->GetEntry()]->GetSizes(); - bool good = false; - for (int i = 0; i < (int)this->dwnldList.size(); i++) { - good = false; + bool good = false; for (int i2 = 0; i2 < (int)installedNames.size(); i2++) { if (installedNames[i2] == this->dwnldList[i]) { diff --git a/source/store/storeUtils.cpp b/source/store/storeUtils.cpp index e7c06ce..f43424e 100644 --- a/source/store/storeUtils.cpp +++ b/source/store/storeUtils.cpp @@ -140,7 +140,7 @@ void StoreUtils::search(const std::string &query, bool title, bool author, bool || (console && findInVector((*it)->GetConsoleFull(), StringUtils::lower_case(query))) || (!title && !author && !category && !console)) && ((selectedMarks == 0 && !updateAvl) || ((((*it)->GetMarks() & selectedMarks) == selectedMarks) && (!updateAvl || (*it)->GetUpdateAvl()))))) { - StoreUtils::entries.erase(it); + it = StoreUtils::entries.erase(it); --it; } } @@ -153,23 +153,13 @@ void StoreUtils::search(const std::string &query, bool title, bool author, bool || (console && findInVector((*it)->GetConsoleFull(), StringUtils::lower_case(query))) || (!title && !author && !category && !console)) && ((selectedMarks == 0 && !updateAvl) || (*it)->GetMarks() & selectedMarks || (updateAvl && (*it)->GetUpdateAvl())))) { - StoreUtils::entries.erase(it); + it = StoreUtils::entries.erase(it); --it; } } } } -/* Filter for available updates. */ -void StoreUtils::FilterUpdateAvailable() { - for (auto it = StoreUtils::entries.begin(); it != StoreUtils::entries.end(); ++it) { - if (!((*it)->GetUpdateAvl())) { - StoreUtils::entries.erase(it); - --it; - } - } -} - /* Reset everything of the store and clear + fetch the entries again. */ void StoreUtils::ResetAll() { if (StoreUtils::store) { @@ -197,7 +187,7 @@ void StoreUtils::RefreshUpdateAVL() { } void StoreUtils::AddToQueue(int index, const std::string &entry, const std::string &entryName, const std::string &lUpdated) { - if (!StoreUtils::store && !StoreUtils::store->GetValid()) return; + if (!StoreUtils::store || !StoreUtils::store->GetValid()) return; /* Check first for proper JSON. */ if (!StoreUtils::store->GetJson().contains("storeContent")) return; diff --git a/source/utils/download.cpp b/source/utils/download.cpp index ea17473..8648744 100644 --- a/source/utils/download.cpp +++ b/source/utils/download.cpp @@ -436,7 +436,7 @@ Result downloadFromRelease(const std::string &url, const std::string &asset, con @return True if Wi-Fi is connected; false if not. */ bool checkWifiStatus(void) { - //return true; // For citra. + // return true; // For citra. u32 wifiStatus; bool res = false; diff --git a/source/utils/extract.cpp b/source/utils/extract.cpp index d550e9e..718c648 100644 --- a/source/utils/extract.cpp +++ b/source/utils/extract.cpp @@ -68,7 +68,6 @@ Result extractArchive(const std::string &archivePath, const std::string &wantedF archive *a = archive_read_new(); archive_entry *entry; - a = archive_read_new(); archive_read_support_format_all(a); if (archive_read_open_filename(a, archivePath.c_str(), 0x4000) != ARCHIVE_OK) { diff --git a/source/utils/fileBrowse.cpp b/source/utils/fileBrowse.cpp index 6203724..9d393fa 100644 --- a/source/utils/fileBrowse.cpp +++ b/source/utils/fileBrowse.cpp @@ -87,19 +87,6 @@ void getDirectoryContents(std::vector &dirContents) { getDirectoryContents(dirContents, {}); } -std::vector getContents(const std::string &name, const std::vector &extensionList) { - std::vector dirContents; - DIR *pdir = opendir(name.c_str()); - struct dirent *pent; - - while ((pent = readdir(pdir)) != NULL) { - if (nameEndsWith(pent->d_name, extensionList)) dirContents.push_back(pent->d_name); - } - - closedir(pdir); - return dirContents; -} - /* Return UniStore info. @@ -188,17 +175,20 @@ u32 copyBuf[copyBufSize]; /* Copy a directory. - DirEntry *entry: Pointer to a DirEntry. + DirEntry &entry: A DirEntry reference. const char *destinationPath: Pointer to the destination path. const char *sourcePath: Pointer to the source path. */ -void dirCopy(DirEntry *entry, const char *destinationPath, const char *sourcePath) { +void dirCopy(const DirEntry &entry, const char *destinationPath, const char *sourcePath) { std::vector dirContents; dirContents.clear(); - if (entry->isDirectory) chdir((sourcePath + ("/" + entry->name)).c_str()); + if (entry.isDirectory) + chdir((sourcePath + ("/" + entry.name)).c_str()); getDirectoryContents(dirContents); - if (((int)dirContents.size()) == 1) mkdir((destinationPath + ("/" + entry->name)).c_str(), 0777); - if (((int)dirContents.size()) != 1) fcopy((sourcePath + ("/" + entry->name)).c_str(), (destinationPath + ("/" + entry->name)).c_str()); + if (((int)dirContents.size()) == 1) + mkdir((destinationPath + ("/" + entry.name)).c_str(), 0777); + if (((int)dirContents.size()) != 1) + fcopy((sourcePath + ("/" + entry.name)).c_str(), (destinationPath + ("/" + entry.name)).c_str()); } u32 copyOffset = 0, copySize = 0; @@ -220,13 +210,11 @@ int fcopy(const char *sourcePath, const char *destinationPath) { chdir(sourcePath); std::vector dirContents; getDirectoryContents(dirContents); - DirEntry *entry = &dirContents.at(1); mkdir(destinationPath, 0777); for(int i = 1; i < ((int)dirContents.size()); i++) { chdir(sourcePath); - entry = &dirContents.at(i); - dirCopy(entry, destinationPath, sourcePath); + dirCopy(dirContents[i], destinationPath, sourcePath); } chdir(destinationPath); @@ -244,51 +232,27 @@ int fcopy(const char *sourcePath, const char *destinationPath) { fseek(sourceFile, 0, SEEK_END); copySize = ftell(sourceFile); // Get source file's size. fseek(sourceFile, 0, SEEK_SET); - } else { - fclose(sourceFile); return -1; } FILE *destinationFile = fopen(destinationPath, "wb"); - //if (destinationFile) { - fseek(destinationFile, 0, SEEK_SET); - /*} else { + if (!destinationFile) { fclose(sourceFile); - fclose(destinationFile); return -1; - }*/ + } - int numr; while(1) { - scanKeys(); - if (keysHeld() & KEY_B) { - /* Cancel copying. */ - fclose(sourceFile); - fclose(destinationFile); - return -1; - break; - } - - printf("\x1b[16;0H"); - printf("Progress:\n"); - printf("%i/%i Bytes ", (int)copyOffset, (int)copySize); - /* Copy file to destination path. */ - numr = fread(copyBuf, 2, copyBufSize, sourceFile); - fwrite(copyBuf, 2, numr, destinationFile); - copyOffset += copyBufSize; + int numr = fread(copyBuf, sizeof(u32), copyBufSize, sourceFile); + fwrite(copyBuf, sizeof(u32), numr, destinationFile); + copyOffset += copyBufSize * sizeof(u32); if (copyOffset > copySize) { fclose(sourceFile); fclose(destinationFile); - printf("\x1b[17;0H"); - printf("%i/%i Bytes ", (int)copyOffset, (int)copySize); - for(int i = 0; i < 30; i++) gspWaitForVBlank(); - return 1; - break; } } diff --git a/source/utils/queueSystem.cpp b/source/utils/queueSystem.cpp index 980d17a..713e06f 100644 --- a/source/utils/queueSystem.cpp +++ b/source/utils/queueSystem.cpp @@ -105,9 +105,6 @@ void QueueSystem::QueueHandle() { while(QueueRuns) { Result ret = NONE; // No Error as of yet. - queueEntries[0]->total = queueEntries[0]->obj.size(); - queueEntries[0]->current = QueueSystem::LastElement; - for(int i = QueueSystem::LastElement; ret == NONE && i < queueEntries[0]->total && !QueueSystem::CancelCallback; i++) { queueEntries[0]->current++; diff --git a/source/utils/screenshot.cpp b/source/utils/screenshot.cpp index 81dd61f..5a48776 100644 --- a/source/utils/screenshot.cpp +++ b/source/utils/screenshot.cpp @@ -32,7 +32,7 @@ C2D_Image Screenshot::Convert(const std::string &filename) { std::vector ImageBuffer; unsigned width, height; C2D_Image img; - lodepng::decode(ImageBuffer, width, height, filename.c_str()); + lodepng::decode(ImageBuffer, width, height, filename); img.tex = new C3D_Tex; img.subtex = new Tex3DS_SubTexture({(u16)width, (u16)height, 0.0f, 1.0f, width / 512.0f, 1.0f - (height / 512.0f)}); diff --git a/source/utils/stringutils.cpp b/source/utils/stringutils.cpp index 2ba478b..c8cb163 100644 --- a/source/utils/stringutils.cpp +++ b/source/utils/stringutils.cpp @@ -107,11 +107,11 @@ std::string StringUtils::GetMarkString(int marks) { return out; } -std::string StringUtils::format(const std::string &fmt_str, ...) { +std::string StringUtils::format(const char *fmt_str, ...) { va_list ap; char *fp = nullptr; va_start(ap, fmt_str); - vasprintf(&fp, fmt_str.c_str(), ap); + vasprintf(&fp, fmt_str, ap); va_end(ap); std::unique_ptr formatted(fp, free);