KiCad PCB EDA Suite
|
Helper class that handles package (un)installation. More...
#include <pcm_task_manager.h>
Public Member Functions | |
PCM_TASK_MANAGER (std::shared_ptr< PLUGIN_CONTENT_MANAGER > pcm) | |
void | DownloadAndInstall (const PCM_PACKAGE &aPackage, const wxString &aVersion, const wxString &aRepositoryId, const bool isUpdate) |
Enqueue package download and installation. More... | |
void | Uninstall (const PCM_PACKAGE &aPackage) |
Enqueue package uninstallation. More... | |
void | RunQueue (wxWindow *aParent) |
Run queue of pending actions. More... | |
void | InstallFromFile (wxWindow *aParent, const wxString &aFilePath) |
Installs package from an archive file on disk. More... | |
bool | ColorSettingsChanged () const |
Private Member Functions | |
int | downloadFile (const wxString &aFilePath, const wxString &aUrl) |
Download URL to a file. More... | |
void | installDownloadedPackage (const PCM_PACKAGE &aPackage, const wxString &aVersion, const wxString &aRepositoryId, const wxFileName &aFilePath, const bool isUpdate) |
Installs downloaded package archive. More... | |
bool | extract (const wxString &aFilePath, const wxString &aPackageId, bool isMultiThreaded) |
Extract package archive. More... | |
void | deletePackageDirectories (const wxString &aPackageId, const std::forward_list< wxRegEx > &aKeep={}) |
Delete all package files. More... | |
Private Attributes | |
std::unique_ptr< DIALOG_PCM_PROGRESS > | m_reporter |
SYNC_QUEUE< PCM_TASK > | m_download_queue |
SYNC_QUEUE< PCM_TASK > | m_install_queue |
std::shared_ptr< PLUGIN_CONTENT_MANAGER > | m_pcm |
std::atomic_bool | m_color_themes_changed |
Helper class that handles package (un)installation.
Package state changes are first enqueued using DownloadAndInstall/Uninstall methods and then applied using RunQueue().
RunQueue() is multithreaded for better experience.
Definition at line 50 of file pcm_task_manager.h.
|
inline |
Definition at line 53 of file pcm_task_manager.h.
bool PCM_TASK_MANAGER::ColorSettingsChanged | ( | ) | const |
Definition at line 655 of file pcm_task_manager.cpp.
References m_color_themes_changed.
Referenced by DIALOG_PCM::OnApplyChangesClicked(), and DIALOG_PCM::OnInstallFromFileClicked().
|
private |
Delete all package files.
aPackageId | id of the package |
aKeep | list of regex indicating which files should not be deleted |
Definition at line 464 of file pcm_task_manager.cpp.
References _, Format(), m_pcm, m_reporter, PCM_PACKAGE_DIRECTORIES(), RPT_SEVERITY_ERROR, and RPT_SEVERITY_INFO.
Referenced by installDownloadedPackage(), InstallFromFile(), and Uninstall().
void PCM_TASK_MANAGER::DownloadAndInstall | ( | const PCM_PACKAGE & | aPackage, |
const wxString & | aVersion, | ||
const wxString & | aRepositoryId, | ||
const bool | isUpdate | ||
) |
Enqueue package download and installation.
Enqueues a download task for a given package version.
Download task fetches the package archive and if successful enqueues an installation task. Installation task verifies sha256 hash if specified, extracts the package, removes the downloaded archive and marks package as installed.
Both tasks report their state independently to a progress dialog.
aPackage | package metadata |
aVersion | version to be installed |
aRepositoryId | id of the source repository |
Definition at line 57 of file pcm_task_manager.cpp.
References _, downloadFile(), Format(), PATHS::GetUserCachePath(), PCM_PACKAGE::identifier, installDownloadedPackage(), m_download_queue, m_install_queue, m_reporter, SYNC_QUEUE< T >::push(), RPT_SEVERITY_ERROR, and PCM_PACKAGE::versions.
Referenced by DIALOG_PCM::OnApplyChangesClicked().
|
private |
Download URL to a file.
aFilePath | path to file |
aUrl | URL to download |
Definition at line 109 of file pcm_task_manager.cpp.
References _, Format(), KICAD_CURL_EASY::GetErrorText(), KICAD_CURL_EASY::GetTransferTotal(), m_reporter, KICAD_CURL_EASY::Perform(), RPT_SEVERITY_ERROR, RPT_SEVERITY_INFO, KICAD_CURL_EASY::SetFollowRedirects(), KICAD_CURL_EASY::SetOutputStream(), KICAD_CURL_EASY::SetTransferCallback(), and KICAD_CURL_EASY::SetURL().
Referenced by DownloadAndInstall().
|
private |
Extract package archive.
aFilePath | path to the archive |
aPackageId | id of the package |
isMultiThreaded | MUST be set to true if the caller is not running in the main thread |
Definition at line 235 of file pcm_task_manager.cpp.
References _, CopyStreamData(), m_pcm, m_reporter, PCM_PACKAGE_DIRECTORIES(), RPT_SEVERITY_ERROR, RPT_SEVERITY_INFO, and zip.
Referenced by installDownloadedPackage(), and InstallFromFile().
|
private |
Installs downloaded package archive.
aPackage | package metadata |
aVersion | version to be installed |
aRepositoryId | id of the source repository |
aFilePath | path to the archive |
isUpdate | true if this is an update operation |
Definition at line 152 of file pcm_task_manager.cpp.
References _, compile_keep_on_update_regex(), deletePackageDirectories(), extract(), Format(), PCM_PACKAGE::identifier, m_color_themes_changed, m_pcm, m_reporter, PT_COLORTHEME, RPT_SEVERITY_ERROR, RPT_SEVERITY_INFO, PCM_PACKAGE::type, and PCM_PACKAGE::versions.
Referenced by DownloadAndInstall().
void PCM_TASK_MANAGER::InstallFromFile | ( | wxWindow * | aParent, |
const wxString & | aFilePath | ||
) |
Installs package from an archive file on disk.
Unlike DownloadAndInstall/Uninstall methods this one immediately extracts the package and marks it as installed.
aParent | parent dialog for progress window |
aFilePath | path to the archive file |
Definition at line 324 of file pcm_task_manager.cpp.
References _, compile_keep_on_update_regex(), CopyStreamData(), deletePackageDirectories(), extract(), Format(), m_color_themes_changed, m_pcm, m_reporter, parse(), PT_COLORTHEME, RPT_SEVERITY_INFO, and zip.
Referenced by DIALOG_PCM::OnInstallFromFileClicked().
void PCM_TASK_MANAGER::RunQueue | ( | wxWindow * | aParent | ) |
Run queue of pending actions.
This method spawns 2 threads to concurrently run tasks in download and install queues until they are drained.
Download queue feeds into install queue so the install thread keeps running until download thread indicated that it's finished AND all installs are processed.
aParent | parent dialog for progress window |
Definition at line 575 of file pcm_task_manager.cpp.
References _, SYNC_QUEUE< T >::empty(), m_color_themes_changed, m_download_queue, m_install_queue, m_reporter, SYNC_QUEUE< T >::pop(), RPT_SEVERITY_INFO, and SYNC_QUEUE< T >::size().
Referenced by DIALOG_PCM::OnApplyChangesClicked().
void PCM_TASK_MANAGER::Uninstall | ( | const PCM_PACKAGE & | aPackage | ) |
Enqueue package uninstallation.
Enqueues uninstallation task that removes all package files and marks package as uninstalled.
aPackage | package metadata |
Definition at line 555 of file pcm_task_manager.cpp.
References _, deletePackageDirectories(), Format(), PCM_PACKAGE::identifier, m_color_themes_changed, m_install_queue, m_pcm, m_reporter, PT_COLORTHEME, SYNC_QUEUE< T >::push(), RPT_SEVERITY_INFO, and PCM_PACKAGE::type.
Referenced by DIALOG_PCM::OnApplyChangesClicked().
|
private |
Definition at line 158 of file pcm_task_manager.h.
Referenced by ColorSettingsChanged(), installDownloadedPackage(), InstallFromFile(), RunQueue(), and Uninstall().
|
private |
Definition at line 155 of file pcm_task_manager.h.
Referenced by DownloadAndInstall(), and RunQueue().
|
private |
Definition at line 156 of file pcm_task_manager.h.
Referenced by DownloadAndInstall(), RunQueue(), and Uninstall().
|
private |
Definition at line 157 of file pcm_task_manager.h.
Referenced by deletePackageDirectories(), extract(), installDownloadedPackage(), InstallFromFile(), and Uninstall().
|
private |
Definition at line 154 of file pcm_task_manager.h.
Referenced by deletePackageDirectories(), DownloadAndInstall(), downloadFile(), extract(), installDownloadedPackage(), InstallFromFile(), RunQueue(), and Uninstall().