From 6a2adf3e66a8009b37d02f84743fa2369228759b Mon Sep 17 00:00:00 2001 From: Li Date: Sun, 16 Jul 2023 14:31:23 +1200 Subject: [PATCH] Add option to redownload games that are already installed. --- src/gameview.cpp | 20 +++++++++++++++----- src/gameview.hpp | 1 + src/log.hpp | 2 +- src/pkgi.cpp | 19 +++++++++++++++---- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/gameview.cpp b/src/gameview.cpp index 24ab2a93..578bbbbb 100644 --- a/src/gameview.cpp +++ b/src/gameview.cpp @@ -257,18 +257,28 @@ void GameView::refresh() _comppack_versions = pkgi_get_comppack_versions(_item->titleid); } + +void GameView::do_download() { + pkgi_start_download(*_downloader, *_item); + _item->presence = PresenceUnknown; +} + void GameView::start_download_package() { if (_item->presence == PresenceInstalled) { LOGF("[{}] {} - already installed", _item->titleid, _item->name); - pkgi_dialog_error("Already installed"); + pkgi_dialog_question( + fmt::format( + "{} is already installed." + "Would you like to redownload it?", + _item->name) + .c_str(), + {{"Redownload.", [this] { this->do_download(); }}, + {"Dont Redownload.", [] {} }}); return; } - - pkgi_start_download(*_downloader, *_item); - - _item->presence = PresenceUnknown; + this->do_download(); } void GameView::cancel_download_package() diff --git a/src/gameview.hpp b/src/gameview.hpp index f3aaec47..21253d66 100644 --- a/src/gameview.hpp +++ b/src/gameview.hpp @@ -58,6 +58,7 @@ class GameView std::string get_min_system_version(); void printDiagnostic(); + void do_download(); void start_download_package(); void cancel_download_package(); void start_download_comppack(bool patch); diff --git a/src/log.hpp b/src/log.hpp index 9f06cbf4..7ef0d43f 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -7,7 +7,7 @@ #define LOG(msg, ...) \ do \ { \ - pkgi_log(msg, ##__VA_ARGS__); \ + pkgi_log(msg, ##__VA_ARGS__); \ } while (0) #define LOGF(msg, ...) \ do \ diff --git a/src/pkgi.cpp b/src/pkgi.cpp index 54164f15..545064b2 100644 --- a/src/pkgi.cpp +++ b/src/pkgi.cpp @@ -289,17 +289,28 @@ bool pkgi_theme_is_installed(std::string contentid) return installed_themes.find(contentid) != installed_themes.end(); } +void do_download(Downloader& downloader, DbItem* item) { + pkgi_start_download(downloader, *item); + item->presence = PresenceUnknown; +} + void pkgi_install_package(Downloader& downloader, DbItem* item) { if (item->presence == PresenceInstalled) { LOGF("[{}] {} - already installed", item->content, item->name); - pkgi_dialog_error("Already installed"); + pkgi_dialog_question( + fmt::format( + "{} is already installed." + "Would you like to redownload it?", + item->name) + .c_str(), + {{"Redownload.", [&downloader, item] { do_download(downloader, item); }}, + {"Dont Redownload.", [] {} }}); return; } - - pkgi_start_download(downloader, *item); - item->presence = PresenceUnknown; + + do_download(downloader, item); } void pkgi_friendly_size(char* text, uint32_t textlen, int64_t size)