diff --git a/SerialPrograms/Source/CommonFramework/ProgramSession.cpp b/SerialPrograms/Source/CommonFramework/ProgramSession.cpp index 256273edcb..db1759d215 100644 --- a/SerialPrograms/Source/CommonFramework/ProgramSession.cpp +++ b/SerialPrograms/Source/CommonFramework/ProgramSession.cpp @@ -17,6 +17,7 @@ #include "CommonFramework/ResourceDownload/ProgramMissingResourceTracker.h" #include "CommonFramework/ResourceDownload/GlobalResourceDownloadManager.h" #include "CommonFramework/ResourceDownload/ResourceDownloadHelpers.h" +#include "CommonFramework/ResourceDownload/ResourceDownloadHelpersQt.h" #include "Integrations/ProgramTracker.h" namespace PokemonAutomation{ diff --git a/SerialPrograms/Source/CommonFramework/ResourceDownload/GlobalResourceDownloadManager.cpp b/SerialPrograms/Source/CommonFramework/ResourceDownload/GlobalResourceDownloadManager.cpp index c5a269d5e1..41cc4980d5 100644 --- a/SerialPrograms/Source/CommonFramework/ResourceDownload/GlobalResourceDownloadManager.cpp +++ b/SerialPrograms/Source/CommonFramework/ResourceDownload/GlobalResourceDownloadManager.cpp @@ -8,6 +8,7 @@ #include "Common/Cpp/Exceptions.h" #include "CommonFramework/GlobalSettingsPanel.h" #include "CommonFramework/ResourceDownload/ResourceDownloadHelpers.h" +#include "CommonFramework/ResourceDownload/ResourceDownloadHelpersQt.h" #include "CommonFramework/ResourceDownload/ResourceDownload.h" #include "GlobalResourceDownloadManager.h" diff --git a/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpers.cpp b/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpers.cpp index 399bd4c40a..e7e41bd0ac 100644 --- a/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpers.cpp +++ b/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpers.cpp @@ -6,8 +6,6 @@ #include "CommonFramework/Globals.h" #include "CommonFramework/Logging/Logger.h" -// #include "CommonFramework/Tools/GlobalThreadPools.h" -#include "CommonFramework/Tools/FileDownloader.h" #include "CommonFramework/Exceptions/OperationFailedException.h" #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" @@ -74,29 +72,6 @@ const std::vector& expected_resource_download_list() } -JsonValue fetch_resource_download_list_json_from_remote(){ - Logger& logger = global_logger_tagged(); - JsonValue json = - FileDownloader::download_json_file( - logger, - "https://raw.githubusercontent.com/PokemonAutomation/Packages/refs/heads/master/Resources/ResourceDownloadList.json" - ); - - return json; -} - -const JsonValue& remote_resource_download_list_json(){ - static const JsonValue json = fetch_resource_download_list_json_from_remote(); - - return json; -} - -const std::vector& remote_resource_download_list(){ - // cout << "remote_resource_download_list" << endl; - static std::vector remote_resources = deserialize_resource_list_json(remote_resource_download_list_json()); - - return remote_resources; -} std::optional get_resource_version_num(Filesystem::Path folder_path){ try{ @@ -163,29 +138,6 @@ DownloadedResourceMetadata get_resource_metadata_from_resource_type(const std::s } -DownloadedResourceMetadata get_remote_resource_metadata_from_resource_slug(const std::string& target_resource_slug){ - Logger& logger = global_logger_tagged(); - std::vector remote_resources; - - // Step 1: Attempt to fetch the list of available downloads - try{ - remote_resources = remote_resource_download_list(); - }catch(OperationFailedException&){ - std::cerr << "get_remote_resource_metadata_from_resource_slug: Error" << endl; - throw_and_log(logger, ErrorReport::NO_ERROR_REPORT, - "Error: Download failed. Failed to fetch the list of available downloads. Check your internet connection."); - } - - // Step 2: Attempt to extract metadata for the specific slug - try{ - return get_resource_metadata_from_resource_type(target_resource_slug, remote_resources); - }catch(OperationFailedException&){ - std::cerr << "get_remote_resource_metadata_from_resource_slug: Error" << endl; - throw_and_log(logger, ErrorReport::NO_ERROR_REPORT, - "get_remote_resource_metadata_from_resource_slug: Unable to find " + target_resource_slug + " within resource_list. " - "Likely caused by resource being no longer available for download. We recommend updating the Computer Control program."); - } -} DownloadedResourceMetadata get_expected_resource_metadata_from_resource_slug(const std::string& target_resource_slug){ try{ diff --git a/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpers.h b/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpers.h index 27b1cfc685..52776882d2 100644 --- a/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpers.h +++ b/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpers.h @@ -11,7 +11,7 @@ #include #include #include - +#include "Common/Cpp/Json/JsonValue.h" namespace PokemonAutomation{ @@ -45,6 +45,8 @@ struct ResourceVersionInfo{ std::optional current_version_num; }; +std::vector deserialize_resource_list_json(const JsonValue& json); + // there are three lists: // - expected_resource_download_list(): List of resources with the version numbers that the programs expect. from the local ResourceDownloadList.json // - list of resources downloaded locally. use get_local_version_info() to determine ResourceVersionStatus relative to the expected resource version number. @@ -52,7 +54,6 @@ struct ResourceVersionInfo{ const std::vector& expected_resource_download_list(); -const std::vector& remote_resource_download_list(); // - This returns the version information for a resource that has been downloaded locally. // - This returns a struct containing a boolean representing whether the resource has been downloaded, @@ -61,11 +62,8 @@ const std::vector& remote_resource_download_list(); // corresponding expected_resource from expected_resource_download_list() ResourceVersionInfo get_local_version_info(const std::string& target_resource_slug); +DownloadedResourceMetadata get_resource_metadata_from_resource_type(const std::string& target_resource_slug, const std::vector& resource_list); -// - throws OperationFailedException if target_resource_slug isn't found within remote_resource_download_list -// this would indicate that CC is out of date. -// - also throws OperationFailedException if Internet is not turned on. -DownloadedResourceMetadata get_remote_resource_metadata_from_resource_slug(const std::string& target_resource_slug); // ASSUMES: given target_resource_slug is listed within expected_resource_download_list(). // PanelInstance::validate_resource_list() should ensure that target_resource_slug is valid. diff --git a/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpersQt.cpp b/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpersQt.cpp new file mode 100644 index 0000000000..8e6a058931 --- /dev/null +++ b/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpersQt.cpp @@ -0,0 +1,72 @@ +/* Resource Download Helpers using Qt headers + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "CommonFramework/Logging/Logger.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "Common/Cpp/Json/JsonValue.h" +#include "CommonFramework/Tools/FileDownloader.h" +#include "ResourceDownloadHelpersQt.h" + + +#include +using std::cout; +using std::endl; + +namespace PokemonAutomation{ + + +JsonValue fetch_resource_download_list_json_from_remote(){ + Logger& logger = global_logger_tagged(); + JsonValue json = + FileDownloader::download_json_file( + logger, + "https://raw.githubusercontent.com/PokemonAutomation/Packages/refs/heads/master/Resources/ResourceDownloadList.json" + ); + + return json; +} + + +const JsonValue& remote_resource_download_list_json(){ + static const JsonValue json = fetch_resource_download_list_json_from_remote(); + + return json; +} + +const std::vector& remote_resource_download_list(){ + // cout << "remote_resource_download_list" << endl; + static std::vector remote_resources = deserialize_resource_list_json(remote_resource_download_list_json()); + + return remote_resources; +} + +DownloadedResourceMetadata get_remote_resource_metadata_from_resource_slug(const std::string& target_resource_slug){ + Logger& logger = global_logger_tagged(); + std::vector remote_resources; + + // Step 1: Attempt to fetch the list of available downloads + try{ + remote_resources = remote_resource_download_list(); + }catch(OperationFailedException&){ + std::cerr << "get_remote_resource_metadata_from_resource_slug: Error" << endl; + throw_and_log(logger, ErrorReport::NO_ERROR_REPORT, + "Error: Download failed. Failed to fetch the list of available downloads. Check your internet connection."); + } + + // Step 2: Attempt to extract metadata for the specific slug + try{ + return get_resource_metadata_from_resource_type(target_resource_slug, remote_resources); + }catch(OperationFailedException&){ + std::cerr << "get_remote_resource_metadata_from_resource_slug: Error" << endl; + throw_and_log(logger, ErrorReport::NO_ERROR_REPORT, + "get_remote_resource_metadata_from_resource_slug: Unable to find " + target_resource_slug + " within resource_list. " + "Likely caused by resource being no longer available for download. We recommend updating the Computer Control program."); + } +} + + + +} diff --git a/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpersQt.h b/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpersQt.h new file mode 100644 index 0000000000..43753d2564 --- /dev/null +++ b/SerialPrograms/Source/CommonFramework/ResourceDownload/ResourceDownloadHelpersQt.h @@ -0,0 +1,30 @@ +/* Resource Download Helpers using Qt headers + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_ResourceDownloadHelpersQt_H +#define PokemonAutomation_ResourceDownloadHelpersQt_H + +#include +#include +#include +#include +#include "ResourceDownloadHelpers.h" + + +namespace PokemonAutomation{ + + +const std::vector& remote_resource_download_list(); + + +// - throws OperationFailedException if target_resource_slug isn't found within remote_resource_download_list +// this would indicate that CC is out of date. +// - also throws OperationFailedException if Internet is not turned on. +DownloadedResourceMetadata get_remote_resource_metadata_from_resource_slug(const std::string& target_resource_slug); + + +} +#endif diff --git a/SerialPrograms/Source/CommonFramework/ResourceDownload/SettingsResourceDownloadRow.cpp b/SerialPrograms/Source/CommonFramework/ResourceDownload/SettingsResourceDownloadRow.cpp index fc8d84cfbb..24c526c02b 100644 --- a/SerialPrograms/Source/CommonFramework/ResourceDownload/SettingsResourceDownloadRow.cpp +++ b/SerialPrograms/Source/CommonFramework/ResourceDownload/SettingsResourceDownloadRow.cpp @@ -17,6 +17,7 @@ #include "CommonFramework/Logging/Logger.h" #include "CommonFramework/ResourceDownload/GlobalResourceDownloadManager.h" #include "ResourceDownloadHelpers.h" +#include "ResourceDownloadHelpersQt.h" // #include "SettingsResourceDownloadTable.h" #include "SettingsResourceDownloadRow.h" diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 7bbf7d6615..9697fffe8b 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -525,6 +525,8 @@ file(GLOB LIBRARY_SOURCES Source/CommonFramework/ResourceDownload/ResourceDownload.h Source/CommonFramework/ResourceDownload/ResourceDownloadHelpers.cpp Source/CommonFramework/ResourceDownload/ResourceDownloadHelpers.h + Source/CommonFramework/ResourceDownload/ResourceDownloadHelpersQt.cpp + Source/CommonFramework/ResourceDownload/ResourceDownloadHelpersQt.h Source/CommonFramework/ResourceDownload/SettingsResourceDownloadOptions.cpp Source/CommonFramework/ResourceDownload/SettingsResourceDownloadOptions.h Source/CommonFramework/ResourceDownload/SettingsResourceDownloadRow.cpp