Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SerialPrograms/Source/CommonFramework/ProgramSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -74,29 +72,6 @@ const std::vector<DownloadedResourceMetadata>& 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<DownloadedResourceMetadata>& remote_resource_download_list(){
// cout << "remote_resource_download_list" << endl;
static std::vector<DownloadedResourceMetadata> remote_resources = deserialize_resource_list_json(remote_resource_download_list_json());

return remote_resources;
}

std::optional<uint16_t> get_resource_version_num(Filesystem::Path folder_path){
try{
Expand Down Expand Up @@ -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<DownloadedResourceMetadata> 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<OperationFailedException>(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<OperationFailedException>(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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <string>
#include <vector>
#include <unordered_set>

#include "Common/Cpp/Json/JsonValue.h"

namespace PokemonAutomation{

Expand Down Expand Up @@ -45,14 +45,15 @@ struct ResourceVersionInfo{
std::optional<uint16_t> current_version_num;
};

std::vector<DownloadedResourceMetadata> 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.
// - remote_resource_download_list(): list of remote resources. the remote version numbers may or may not match the local list. from the remote ResourceDownloadList.json

const std::vector<DownloadedResourceMetadata>& expected_resource_download_list();

const std::vector<DownloadedResourceMetadata>& 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,
Expand All @@ -61,11 +62,8 @@ const std::vector<DownloadedResourceMetadata>& 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<DownloadedResourceMetadata>& 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <iostream>
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<DownloadedResourceMetadata>& remote_resource_download_list(){
// cout << "remote_resource_download_list" << endl;
static std::vector<DownloadedResourceMetadata> 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<DownloadedResourceMetadata> 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<OperationFailedException>(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<OperationFailedException>(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.");
}
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Resource Download Helpers using Qt headers
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_ResourceDownloadHelpersQt_H
#define PokemonAutomation_ResourceDownloadHelpersQt_H

#include <optional>
#include <string>
#include <vector>
#include <unordered_set>
#include "ResourceDownloadHelpers.h"


namespace PokemonAutomation{


const std::vector<DownloadedResourceMetadata>& 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
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading