diff --git a/assets/gfx/sprites.t3s b/assets/gfx/sprites.t3s index 145e747..3e612b3 100644 --- a/assets/gfx/sprites.t3s +++ b/assets/gfx/sprites.t3s @@ -10,6 +10,7 @@ sprites/noIcon.png sprites/qr_code.png sprites/search.png sprites/settings.png +sprites/sheet.png sprites/sort.png sprites/sort_checked.png sprites/sort_unchecked.png diff --git a/assets/gfx/sprites/sheet.png b/assets/gfx/sprites/sheet.png new file mode 100644 index 0000000..1167bfe Binary files /dev/null and b/assets/gfx/sprites/sheet.png differ diff --git a/screenshots/StoreSelection.png b/screenshots/StoreSelection.png index 719b5cc..fa0ac9f 100644 Binary files a/screenshots/StoreSelection.png and b/screenshots/StoreSelection.png differ diff --git a/source/overlays/storeSelect.cpp b/source/overlays/storeSelect.cpp index 6207e48..34b7786 100644 --- a/source/overlays/storeSelect.cpp +++ b/source/overlays/storeSelect.cpp @@ -46,10 +46,11 @@ static const std::vector mainButtons = { { 10, 184, 300, 22 }, /* Add, Delete, Info.. */ - { 92, 215, 16, 16 }, - { 136, 215, 16, 16 }, - { 180, 215, 16, 16 }, - { 224, 215, 16, 16 } + { 70, 215, 16, 16 }, + { 114, 215, 16, 16 }, + { 158, 215, 16, 16 }, + { 202, 215, 16, 16 }, + { 246, 215, 16, 16 } }; /* @@ -66,8 +67,6 @@ static void DeleteStore(const std::string &file) { if (storeJson["storeInfo"].contains("sheet") && storeJson["storeInfo"]["sheet"].is_array()) { const std::vector sht = storeJson["storeInfo"]["sheet"].get>(); - - /* Cause it's an array, delete all Spritesheets which exist. */ for (int i = 0; i < (int)sht.size(); i++) { if ((std::string(_STORE_PATH) + sht[i]) != "") { @@ -153,6 +152,56 @@ static bool DownloadStore(bool Cam = true) { return doSheet; } +/* + Re-Download SpriteSheets optional. + + const std::string &file: Const Reference to the UniStore filename. +*/ +static bool DownloadSheet(const std::string &file) { + FILE *temp = fopen((std::string(_STORE_PATH) + file).c_str(), "rt"); + nlohmann::json storeJson = nlohmann::json::parse(temp, nullptr, false); + fclose(temp); + + 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]); + + } else { + Msg::waitMsg(Lang::get("SHEET_SLASH")); + return false; + } + } + } + } + + } 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); + + } else { + Msg::waitMsg(Lang::get("SHEET_SLASH")); + return false; + } + } + } + + return true; +} + /* This is the UniStore Manage Handle. Here you can.. @@ -226,8 +275,9 @@ void Overlays::SelectStore(std::unique_ptr &store, std::vector &store, std::vector 0) { @@ -309,11 +369,12 @@ void Overlays::SelectStore(std::unique_ptr &store, std::vector &store, std::vector sPos + 7 - 1) sPos = selection - 7 + 1; } - if ((hidKeysDown() & KEY_Y) || (hidKeysDown() & KEY_TOUCH && touching(touch, mainButtons[9]))) { + /* UniStore URL Download. */ + if ((hidKeysDown() & KEY_Y) || (hidKeysDown() & KEY_TOUCH && touching(touch, mainButtons[10]))) { if (checkWifiStatus()) { if (DownloadStore(false)) { selection = 0; @@ -330,7 +392,8 @@ void Overlays::SelectStore(std::unique_ptr &store, std::vector #include #include +#include #include #define USER_AGENT APP_TITLE "-" VERSION_STRING @@ -45,8 +46,6 @@ static char *result_buf = nullptr; static size_t result_sz = 0; static size_t result_written = 0; -std::vector _topText; -std::string jsonName; #define TIME_IN_US 1 #define TIMETYPE curl_off_t @@ -138,13 +137,13 @@ static size_t file_handle_data(char *ptr, size_t size, size_t nmemb, void *userd } Result downloadToFile(const std::string &url, const std::string &path) { + bool needToDelete = false; downloadTotal = 1; downloadNow = 0; CURLcode curlResult; CURL *hnd; Result retcode = 0; - downloadTotal = 1; int res; printf("Downloading from:\n%s\nto:\n%s\n", url.c_str(), path.c_str()); @@ -191,6 +190,7 @@ Result downloadToFile(const std::string &url, const std::string &path) { if (curlResult != CURLE_OK) { retcode = -curlResult; + needToDelete = true; goto exit; } @@ -203,6 +203,7 @@ Result downloadToFile(const std::string &url, const std::string &path) { if (!filecommit()) { retcode = -3; + needToDelete = true; goto exit; } @@ -240,6 +241,11 @@ exit: file_buffer_pos = 0; file_toCommit_size = 0; writeError = false; + + if (needToDelete) { + if (access(path.c_str(), F_OK) == 0) deleteFile(path.c_str()); // Delete file, cause not fully downloaded. + } + return retcode; }