38#include <wx/progdlg.h>
40#include <wx/statline.h>
50#include "expand_icon.h"
60wxDEFINE_EVENT(EVT_PLUGINS_RELOAD, wxCommandEvent);
65static bool checksum_ok(
const std::string& path,
67 wxLogDebug(
"Checksum test on %s", metadata.name.c_str());
68 if (metadata.checksum ==
"") {
69 wxLogDebug(
"No metadata checksum, aborting check,");
72 const size_t pos = metadata.checksum.find(
':');
73 std::string checksum(metadata.checksum);
74 if (pos == std::string::npos) {
75 checksum = std::string(
"sha256:") + checksum;
77 std::ifstream f(path, std::ios::binary);
78 picosha2::hash256_one_by_one hasher;
81 f.read(buff,
sizeof(buff));
82 const std::string
block(buff, f.gcount());
86 std::string tarball_hash =
87 std::string(
"sha256:") + picosha2::get_hash_hex_string(hasher);
89 if (tarball_hash == checksum) {
90 wxLogDebug(
"Checksum ok: %s", tarball_hash.c_str());
93 wxLogMessage(
"Checksum fail on %s, tarball: %s, metadata: %s",
94 metadata.name.c_str(), tarball_hash.c_str(), checksum.c_str());
102static ssize_t PlugInIxByName(
const std::string name,
103 const ArrayOfPlugIns* plugins) {
104 for (
unsigned i = 0; i < plugins->GetCount(); i += 1) {
105 if (name == plugins->Item(i)->m_common_name.Lower().ToStdString()) {
120std::string GuiDownloader::run(wxWindow* parent,
bool remove_current) {
122 bool downloaded =
false;
126 std::string label(_(
"Downloading "));
129 new wxProgressDialog(_(
"Downloading"), label.c_str(), size, parent,
130 wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT);
132 m_dialog->SetBackgroundColour(wxColour(0x7c, 0xb0, 0xe9));
135 g_Platform->HideBusySpinner();
139 showErrorDialog(
"Download error");
145 showErrorDialog(
"Download aborted");
150 if (!checksum_ok(path, m_plugin)) {
151 showErrorDialog(
"Checksum error");
159 if (remove_current) {
160 wxLogMessage(
"Uninstalling %s", m_plugin.name.c_str());
161 pluginHandler->Uninstall(m_plugin.name);
163 ok = pluginHandler->InstallPlugin(m_plugin, path);
165 showErrorDialog(
"Installation error");
171 wxURI uri(wxString(m_plugin.tarball_url.c_str()));
172 wxFileName fn(uri.GetPath());
173 auto basename = fn.GetFullName().ToStdString();
175 wxLogMessage(
"Copied %s to local cache at %s", path.c_str(),
180 wxMessageDialog* dlg =
new wxMessageDialog(
182 m_plugin.name +
" " + m_plugin.version + _(
" successfully installed"),
183 _(
"Installation complete"), wxOK | wxCENTRE | wxICON_INFORMATION);
190 m_downloaded += bytes;
191 if (m_dialog && !m_dialog->Update(m_downloaded)) {
198void GuiDownloader::showErrorDialog(
const char* msg) {
199 auto dlg =
new wxMessageDialog(m_parent,
"", _(
"Installation error"),
200 wxOK | wxICON_ERROR);
202 std::string text = msg;
203 if (last_error_msg !=
"") {
204 text = text +
": " + error_msg;
206 text = text +
"\nPlease check system log for more info.";
207 dlg->SetMessage(text);
Catalog options dialog, by default disabled.
Default downloader, usable in a CLI context.
bool download(std::ostream *stream)
Download url into stream, return false on errors.
long get_filesize()
Try to get remote filesize, return 0 on failure.
std::string last_error()
Last Curl error message.
virtual void on_chunk(const char *buff, unsigned bytes)
Called when given bytes has been transferred from remote.
void on_chunk(const char *buff, unsigned bytes) override
Called when given bytes has been transferred from remote.
GuiDownloader(wxWindow *parent, PluginMetadata plugin)
Add progress and final message dialogs to the basic Downloader.
static PluginHandler * GetInstance()
Singleton factory.
Generic GUI downloads tool.
Handle downloading of files from remote urls.
std::string lookup_tarball(const char *uri)
Get path to tarball in cache for given filename.
bool store_tarball(const char *path, const char *basename)
Store a tarball in tarball cache, return success/fail.
Downloaded plugins cache.
Plugin remote repositories installation and Uninstall/list operations.
PlugInManager and helper classes – Mostly gui parts (dialogs) and plugin API stuff.
Semantic version encode/decode object.
Runtime representation of a plugin block.