![]() |
KiCad PCB EDA Suite
|
Main class of Plugin and Content Manager subsystem. More...
#include <pcm.h>
Public Member Functions | |
PLUGIN_CONTENT_MANAGER (wxWindow *aParent) | |
~PLUGIN_CONTENT_MANAGER () | |
bool | FetchRepository (const wxString &aUrl, PCM_REPOSITORY &aRepository, WX_PROGRESS_REPORTER *aReporter) |
Fetches repository metadata from given url. More... | |
void | ValidateJson (const nlohmann::json &aJson, const nlohmann::json_uri &aUri=nlohmann::json_uri("#")) const |
Validates json against a specific definition in the PCM schema. More... | |
bool | VerifyHash (std::istream &aStream, const wxString &aHash) const |
Verifies SHA256 hash of a binary stream. More... | |
void | SetRepositoryList (const STRING_PAIR_LIST &aRepositories) |
Set list of repositories. More... | |
void | DiscardRepositoryCache (const wxString &aRepositoryId) |
Discard in-memory and on-disk cache of a repository. More... | |
void | MarkInstalled (const PCM_PACKAGE &aPackage, const wxString &aVersion, const wxString &aRepositoryId) |
Mark package as installed. More... | |
void | MarkUninstalled (const PCM_PACKAGE &aPackage) |
Mark package as uninstalled. More... | |
const STRING_TUPLE_LIST & | GetRepositoryList () const |
Get list of repositories. More... | |
const bool | CacheRepository (const wxString &aRepositoryId) |
Cache specified repository packages and other metadata. More... | |
const std::vector< PCM_PACKAGE > & | GetRepositoryPackages (const wxString &aRepositoryId) const |
Get the packages metadata from a previously cached repository. More... | |
const std::vector< PCM_INSTALLATION_ENTRY > | GetInstalledPackages () const |
Get list of installed packages. More... | |
const wxString & | GetInstalledPackageVersion (const wxString &aPackageId) const |
Get the current version of an installed package. More... | |
const wxString & | Get3rdPartyPath () const |
PCM_PACKAGE_STATE | GetPackageState (const wxString &aRepositoryId, const wxString &aPackageId) |
Get current state of the package. More... | |
bool | DownloadToStream (const wxString &aUrl, std::ostream *aOutput, WX_PROGRESS_REPORTER *aReporter, const size_t aSizeLimit=DEFAULT_DOWNLOAD_MEM_LIMIT) |
Downloads url to an output stream. More... | |
int | GetPackageSearchRank (const PCM_PACKAGE &aPackage, const wxString &aSearchTerm) |
Get the approximate measure of how much given package matches the search term. More... | |
std::unordered_map< wxString, wxBitmap > | GetRepositoryPackageBitmaps (const wxString &aRepositoryId) |
Get the icon bitmaps for repository packages. More... | |
std::unordered_map< wxString, wxBitmap > | GetInstalledPackageBitmaps () |
Get the icon bitmaps for installed packages. More... | |
Private Member Functions | |
bool | fetchPackages (const wxString &aUrl, const boost::optional< wxString > &aHash, std::vector< PCM_PACKAGE > &aPackages, WX_PROGRESS_REPORTER *aReporter) |
Downloads packages metadata to in memory stream, verifies hash and attempts to parse it. More... | |
const PCM_REPOSITORY & | getCachedRepository (const wxString &aRepositoryId) const |
Get the cached repository metadata. More... | |
time_t | getCurrentTimestamp () const |
Static Private Member Functions | |
static void | preparePackage (PCM_PACKAGE &aPackage) |
Parses version strings and calculates compatibility. More... | |
Private Attributes | |
wxWindow * | m_dialog |
nlohmann::json_schema::json_validator | m_schema_validator |
wxString | m_3rdparty_path |
wxString | m_cache_path |
std::unordered_map< wxString, PCM_REPOSITORY > | m_repository_cache |
STRING_TUPLE_LIST | m_repository_list |
std::map< wxString, PCM_INSTALLATION_ENTRY > | m_installed |
Static Private Attributes | |
static constexpr size_t | DEFAULT_DOWNLOAD_MEM_LIMIT = 10 * 1024 * 1024 |
< Default download limit of 10 Mb to not use too much memory More... | |
static const std::tuple< int, int > | m_kicad_version |
Main class of Plugin and Content Manager subsystem.
This class handles logistics of repository management, caching, json validation, tracking installed packages and provides some utility methods.
Repository caching is done in $KICADX_3RD_PARTY/cache directory with each repository storing it's metadata, packages and optionally resource files under it's id subdirectory.
Repository id is a prefix of sha256 of it's main url.
JSON schema file is expected to be in $KICAD_DATA/schemas directory
Installed packages are stored in <user_settings>/installed_packages.json If that file is missing PCM will try to reconstruct it from existing directory structure inside $KICADX_3RD_PARTY but package descriptions and other metadata will be lost.
PLUGIN_CONTENT_MANAGER::PLUGIN_CONTENT_MANAGER | ( | wxWindow * | aParent | ) |
Definition at line 63 of file pcm.cpp.
References _, PCM_INSTALLATION_ENTRY::current_version, Format(), PATHS::GetDefault3rdPartyPath(), PATHS::GetStockDataPath(), SETTINGS_MANAGER::GetUserSettingsPath(), PCM_PACKAGE::identifier, PCM_INSTALLATION_ENTRY::install_timestamp, PACKAGE_VERSION::kicad_version, m_3rdparty_path, m_installed, m_schema_validator, PCM_PACKAGE::name, PCM_INSTALLATION_ENTRY::package, PCM_PACKAGE_DIRECTORIES(), Pgm(), preparePackage(), PVS_STABLE, PCM_INSTALLATION_ENTRY::repository_name, PACKAGE_VERSION::status, PACKAGE_VERSION::version, and PCM_PACKAGE::versions.
PLUGIN_CONTENT_MANAGER::~PLUGIN_CONTENT_MANAGER | ( | ) |
Definition at line 673 of file pcm.cpp.
References SETTINGS_MANAGER::GetUserSettingsPath(), and m_installed.
const bool PLUGIN_CONTENT_MANAGER::CacheRepository | ( | const wxString & | aRepositoryId | ) |
Cache specified repository packages and other metadata.
This method fetches latest repository metadata, checks if there is cache on disk, compares it's last update timestamp to repository metadata and redownloads packages list if necessary. Then it checks sha256 if provided and parses the package list. Parsed packages metadata is stored in memory.
Process is repeated with resources file except it is just stored on disk and any errors at this stage are ignored.
aRepositoryId | id of the repository to cache |
Definition at line 345 of file pcm.cpp.
References _, DownloadToStream(), fetchPackages(), FetchRepository(), getCurrentTimestamp(), m_3rdparty_path, m_dialog, m_repository_cache, m_repository_list, PCM_REPOSITORY::package_list, PCM_REPOSITORY::packages, preparePackage(), PCM_REPOSITORY::resources, PCM_RESOURCE_REFERENCE::sha256, PCM_RESOURCE_REFERENCE::update_timestamp, PCM_RESOURCE_REFERENCE::url, and VerifyHash().
Referenced by GetPackageState().
void PLUGIN_CONTENT_MANAGER::DiscardRepositoryCache | ( | const wxString & | aRepositoryId | ) |
Discard in-memory and on-disk cache of a repository.
aRepositoryId | id of the repository |
Definition at line 591 of file pcm.cpp.
References m_3rdparty_path, and m_repository_cache.
Referenced by SetRepositoryList().
bool PLUGIN_CONTENT_MANAGER::DownloadToStream | ( | const wxString & | aUrl, |
std::ostream * | aOutput, | ||
WX_PROGRESS_REPORTER * | aReporter, | ||
const size_t | aSizeLimit = DEFAULT_DOWNLOAD_MEM_LIMIT |
||
) |
Downloads url to an output stream.
aUrl | URL to download |
aOutput | output stream |
aReporter | progress dialog to use |
aSizeLimit | maximum download size, 0 for unlimited |
Definition at line 187 of file pcm.cpp.
References _, Format(), KICAD_CURL_EASY::GetErrorText(), PROGRESS_REPORTER_BASE::IsCancelled(), PROGRESS_REPORTER_BASE::KeepRefreshing(), KICAD_CURL_EASY::Perform(), PROGRESS_REPORTER_BASE::Report(), PROGRESS_REPORTER_BASE::SetCurrentProgress(), KICAD_CURL_EASY::SetFollowRedirects(), KICAD_CURL_EASY::SetOutputStream(), KICAD_CURL_EASY::SetTransferCallback(), and KICAD_CURL_EASY::SetURL().
Referenced by CacheRepository(), fetchPackages(), and FetchRepository().
|
private |
Downloads packages metadata to in memory stream, verifies hash and attempts to parse it.
aUrl | URL of the packages metadata |
aHash | optional sha256 hash |
aPackages | resulting packages metadata list |
aReporter | progress dialog to use for download |
Definition at line 283 of file pcm.cpp.
References _, DownloadToStream(), Format(), parse(), WX_PROGRESS_REPORTER::SetTitle(), ValidateJson(), and VerifyHash().
Referenced by CacheRepository().
bool PLUGIN_CONTENT_MANAGER::FetchRepository | ( | const wxString & | aUrl, |
PCM_REPOSITORY & | aRepository, | ||
WX_PROGRESS_REPORTER * | aReporter | ||
) |
Fetches repository metadata from given url.
aUrl | URL of the repository |
aRepository | fetched repository metadata |
aReporter | progress reporter dialog to use for download |
Definition at line 242 of file pcm.cpp.
References _, DownloadToStream(), Format(), WX_PROGRESS_REPORTER::SetTitle(), and ValidateJson().
Referenced by CacheRepository().
|
inline |
|
private |
Get the cached repository metadata.
aRepositoryId | id of the repository |
Definition at line 336 of file pcm.cpp.
References m_repository_cache.
Referenced by GetPackageState(), GetRepositoryPackages(), and MarkInstalled().
|
private |
std::unordered_map< wxString, wxBitmap > PLUGIN_CONTENT_MANAGER::GetInstalledPackageBitmaps | ( | ) |
Get the icon bitmaps for installed packages.
Icons for installed packages are taken from package extracted files in $KICADX_3RD_PARTY/resources/<packageid> directories
Definition at line 824 of file pcm.cpp.
References m_3rdparty_path.
const std::vector< PCM_INSTALLATION_ENTRY > PLUGIN_CONTENT_MANAGER::GetInstalledPackages | ( | ) | const |
Get list of installed packages.
Definition at line 699 of file pcm.cpp.
References m_installed.
const wxString & PLUGIN_CONTENT_MANAGER::GetInstalledPackageVersion | ( | const wxString & | aPackageId | ) | const |
Get the current version of an installed package.
aPackageId | id of the package |
std::out_of_range | if package with given id is not installedReturns current 3rd party directory path |
Definition at line 714 of file pcm.cpp.
References m_installed.
int PLUGIN_CONTENT_MANAGER::GetPackageSearchRank | ( | const PCM_PACKAGE & | aPackage, |
const wxString & | aSearchTerm | ||
) |
Get the approximate measure of how much given package matches the search term.
aPackage | package metadata object |
aSearchTerm | search term |
Definition at line 723 of file pcm.cpp.
References PCM_PACKAGE::author, PCM_PACKAGE::description, PCM_PACKAGE::description_full, PCM_PACKAGE::identifier, PCM_PACKAGE::license, PCM_PACKAGE::maintainer, PCM_CONTACT::name, PCM_PACKAGE::name, PCM_PACKAGE::resources, and PCM_PACKAGE::tags.
PCM_PACKAGE_STATE PLUGIN_CONTENT_MANAGER::GetPackageState | ( | const wxString & | aRepositoryId, |
const wxString & | aPackageId | ||
) |
Get current state of the package.
aRepositoryId | repository id |
aPackageId | package id |
Definition at line 630 of file pcm.cpp.
References CacheRepository(), getCachedRepository(), m_installed, PCM_REPOSITORY::package_list, PPS_AVAILABLE, PPS_INSTALLED, PPS_UNAVAILABLE, and PCM_PACKAGE::versions.
|
inline |
Get list of repositories.
Definition at line 170 of file pcm.h.
References m_repository_list.
std::unordered_map< wxString, wxBitmap > PLUGIN_CONTENT_MANAGER::GetRepositoryPackageBitmaps | ( | const wxString & | aRepositoryId | ) |
Get the icon bitmaps for repository packages.
Repository package icons are taken from repository's resources zip file
aRepositoryId | id of the repository |
Definition at line 781 of file pcm.cpp.
References image, m_3rdparty_path, and zip.
const std::vector< PCM_PACKAGE > & PLUGIN_CONTENT_MANAGER::GetRepositoryPackages | ( | const wxString & | aRepositoryId | ) | const |
Get the packages metadata from a previously cached repository.
This should only be called after a successful CacheRepository call
aRepositoryId | id of the repository |
Definition at line 556 of file pcm.cpp.
References getCachedRepository(), and PCM_REPOSITORY::package_list.
void PLUGIN_CONTENT_MANAGER::MarkInstalled | ( | const PCM_PACKAGE & | aPackage, |
const wxString & | aVersion, | ||
const wxString & | aRepositoryId | ||
) |
Mark package as installed.
aPackage | package metadata |
aVersion | installed package version |
aRepositoryId | id of the source repository or empty estring if installed from a local file |
Definition at line 605 of file pcm.cpp.
References _, PCM_INSTALLATION_ENTRY::current_version, getCachedRepository(), getCurrentTimestamp(), PCM_PACKAGE::identifier, PCM_INSTALLATION_ENTRY::install_timestamp, m_installed, PCM_REPOSITORY::name, PCM_INSTALLATION_ENTRY::package, PCM_INSTALLATION_ENTRY::repository_id, and PCM_INSTALLATION_ENTRY::repository_name.
void PLUGIN_CONTENT_MANAGER::MarkUninstalled | ( | const PCM_PACKAGE & | aPackage | ) |
Mark package as uninstalled.
aPackage | package metadata |
Definition at line 624 of file pcm.cpp.
References PCM_PACKAGE::identifier, and m_installed.
|
staticprivate |
Parses version strings and calculates compatibility.
This should be called after loading package metadata from repository or from installation entries
aPackage | package metadata objectReturns current UTC timestamp |
Definition at line 488 of file pcm.cpp.
References PACKAGE_VERSION::compatible, PACKAGE_VERSION::kicad_version, PACKAGE_VERSION::kicad_version_max, m_kicad_version, PACKAGE_VERSION::parsed_version, PACKAGE_VERSION::platforms, PACKAGE_VERSION::version, PACKAGE_VERSION::version_epoch, and PCM_PACKAGE::versions.
Referenced by CacheRepository(), and PLUGIN_CONTENT_MANAGER().
void PLUGIN_CONTENT_MANAGER::SetRepositoryList | ( | const STRING_PAIR_LIST & | aRepositories | ) |
Set list of repositories.
Discards cache of repositories that were previously cached but are not on the new list of repositories.
aRepositories | list of <URL, name> pairs of repositories |
Definition at line 562 of file pcm.cpp.
References DiscardRepositoryCache(), m_repository_cache, and m_repository_list.
void PLUGIN_CONTENT_MANAGER::ValidateJson | ( | const nlohmann::json & | aJson, |
const nlohmann::json_uri & | aUri = nlohmann::json_uri( "#" ) |
||
) | const |
Validates json against a specific definition in the PCM schema.
aJson | JSON object to validate |
aUri | JSON URI of a definition to validate against, default is root |
std::invalid_argument | on validation failure |
Definition at line 275 of file pcm.cpp.
References m_schema_validator.
Referenced by fetchPackages(), and FetchRepository().
bool PLUGIN_CONTENT_MANAGER::VerifyHash | ( | std::istream & | aStream, |
const wxString & | aHash | ||
) | const |
Verifies SHA256 hash of a binary stream.
aStream | input stream |
aHash | sha256 lowercase hex string |
Definition at line 323 of file pcm.cpp.
Referenced by CacheRepository(), and fetchPackages().
|
staticprivate |
|
private |
Definition at line 310 of file pcm.h.
Referenced by CacheRepository(), DiscardRepositoryCache(), Get3rdPartyPath(), GetInstalledPackageBitmaps(), GetRepositoryPackageBitmaps(), and PLUGIN_CONTENT_MANAGER().
|
private |
Definition at line 308 of file pcm.h.
Referenced by CacheRepository().
|
private |
Definition at line 315 of file pcm.h.
Referenced by GetInstalledPackages(), GetInstalledPackageVersion(), GetPackageState(), MarkInstalled(), MarkUninstalled(), PLUGIN_CONTENT_MANAGER(), and ~PLUGIN_CONTENT_MANAGER().
|
staticprivate |
Definition at line 316 of file pcm.h.
Referenced by preparePackage().
|
private |
Definition at line 312 of file pcm.h.
Referenced by CacheRepository(), DiscardRepositoryCache(), getCachedRepository(), and SetRepositoryList().
|
private |
Definition at line 313 of file pcm.h.
Referenced by CacheRepository(), GetRepositoryList(), and SetRepositoryList().
|
private |
Definition at line 309 of file pcm.h.
Referenced by PLUGIN_CONTENT_MANAGER(), and ValidateJson().