KiCad PCB EDA Suite
pcm_task_manager.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2021 Andrew Lutsenko, anlutsenko at gmail dot com
5 * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef PCM_TASK_MANAGER_H_
22#define PCM_TASK_MANAGER_H_
23
25#include "pcm.h"
26#include "pcm_data.h"
27#include "sync_queue.h"
28#include <atomic>
29#include <condition_variable>
30#include <functional>
31#include <memory>
32#include <mutex>
33#include <nlohmann/json-schema.hpp>
35#include <wx/regex.h>
36#include <wx/string.h>
37
38
39typedef std::function<void()> PCM_TASK;
40
41
51{
52public:
53 PCM_TASK_MANAGER( std::shared_ptr<PLUGIN_CONTENT_MANAGER> pcm ) : m_pcm( pcm ){};
54
70 void DownloadAndInstall( const PCM_PACKAGE& aPackage, const wxString& aVersion,
71 const wxString& aRepositoryId, const bool isUpdate );
72
81 void Uninstall( const PCM_PACKAGE& aPackage );
82
94 void RunQueue( wxWindow* aParent );
95
105 void InstallFromFile( wxWindow* aParent, const wxString& aFilePath );
106
110 bool ColorSettingsChanged() const;
111
112private:
120 int downloadFile( const wxString& aFilePath, const wxString& aUrl );
121
131 void installDownloadedPackage( const PCM_PACKAGE& aPackage, const wxString& aVersion,
132 const wxString& aRepositoryId, const wxFileName& aFilePath,
133 const bool isUpdate );
134
143 bool extract( const wxString& aFilePath, const wxString& aPackageId, bool isMultiThreaded );
144
151 void deletePackageDirectories( const wxString& aPackageId,
152 const std::forward_list<wxRegEx>& aKeep = {} );
153
154 std::unique_ptr<DIALOG_PCM_PROGRESS> m_reporter;
157 std::shared_ptr<PLUGIN_CONTENT_MANAGER> m_pcm;
158 std::atomic_bool m_color_themes_changed;
159};
160
161
162#endif // PCM_TASK_MANAGER_H_
Helper class that handles package (un)installation.
std::atomic_bool m_color_themes_changed
void deletePackageDirectories(const wxString &aPackageId, const std::forward_list< wxRegEx > &aKeep={})
Delete all package files.
void InstallFromFile(wxWindow *aParent, const wxString &aFilePath)
Installs package from an archive file on disk.
SYNC_QUEUE< PCM_TASK > m_install_queue
std::shared_ptr< PLUGIN_CONTENT_MANAGER > m_pcm
void Uninstall(const PCM_PACKAGE &aPackage)
Enqueue package uninstallation.
SYNC_QUEUE< PCM_TASK > m_download_queue
void DownloadAndInstall(const PCM_PACKAGE &aPackage, const wxString &aVersion, const wxString &aRepositoryId, const bool isUpdate)
Enqueue package download and installation.
int downloadFile(const wxString &aFilePath, const wxString &aUrl)
Download URL to a file.
void installDownloadedPackage(const PCM_PACKAGE &aPackage, const wxString &aVersion, const wxString &aRepositoryId, const wxFileName &aFilePath, const bool isUpdate)
Installs downloaded package archive.
bool extract(const wxString &aFilePath, const wxString &aPackageId, bool isMultiThreaded)
Extract package archive.
void RunQueue(wxWindow *aParent)
Run queue of pending actions.
PCM_TASK_MANAGER(std::shared_ptr< PLUGIN_CONTENT_MANAGER > pcm)
std::unique_ptr< DIALOG_PCM_PROGRESS > m_reporter
bool ColorSettingsChanged() const
std::function< void()> PCM_TASK
Repository reference to a resource.
Definition: pcm_data.h:95