40#include <wx/progdlg.h>
42#include <wx/statline.h>
52#include "expand_icon.h"
62wxDEFINE_EVENT(EVT_PLUGINS_RELOAD, wxCommandEvent);
67static bool checksum_ok(
const std::string& path,
69 wxLogDebug(
"Checksum test on %s", metadata.name.c_str());
70 if (metadata.checksum ==
"") {
71 wxLogDebug(
"No metadata checksum, aborting check,");
74 const size_t pos = metadata.checksum.find(
':');
75 std::string checksum(metadata.checksum);
76 if (pos == std::string::npos) {
77 checksum = std::string(
"sha256:") + checksum;
79 std::ifstream f(path, std::ios::binary);
80 picosha2::hash256_one_by_one hasher;
83 f.read(buff,
sizeof(buff));
84 const std::string
block(buff, f.gcount());
88 std::string tarball_hash =
89 std::string(
"sha256:") + picosha2::get_hash_hex_string(hasher);
91 if (tarball_hash == checksum) {
92 wxLogDebug(
"Checksum ok: %s", tarball_hash.c_str());
95 wxLogMessage(
"Checksum fail on %s, tarball: %s, metadata: %s",
96 metadata.name.c_str(), tarball_hash.c_str(), checksum.c_str());
104static ssize_t PlugInIxByName(
const std::string name,
105 const ArrayOfPlugIns* plugins) {
106 for (
unsigned i = 0; i < plugins->GetCount(); i += 1) {
107 if (name == plugins->Item(i)->m_common_name.Lower().ToStdString()) {
122std::string GuiDownloader::run(wxWindow* parent,
bool remove_current) {
124 bool downloaded =
false;
128 std::string label(_(
"Downloading "));
131 new wxProgressDialog(_(
"Downloading"), label.c_str(), size, parent,
132 wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT);
134 m_dialog->SetBackgroundColour(wxColour(0x7c, 0xb0, 0xe9));
137 g_Platform->HideBusySpinner();
141 showErrorDialog(
"Download error");
147 showErrorDialog(
"Download aborted");
152 if (!checksum_ok(path, m_plugin)) {
153 showErrorDialog(
"Checksum error");
161 if (remove_current) {
162 wxLogMessage(
"Uninstalling %s", m_plugin.name.c_str());
163 pluginHandler->Uninstall(m_plugin.name);
165 ok = pluginHandler->InstallPlugin(m_plugin, path);
167 showErrorDialog(
"Installation error");
173 wxURI uri(wxString(m_plugin.tarball_url.c_str()));
174 wxFileName fn(uri.GetPath());
175 auto basename = fn.GetFullName().ToStdString();
177 wxLogMessage(
"Copied %s to local cache at %s", path.c_str(),
182 wxMessageDialog* dlg =
new wxMessageDialog(
184 m_plugin.name +
" " + m_plugin.version + _(
" successfully installed"),
185 _(
"Installation complete"), wxOK | wxCENTRE | wxICON_INFORMATION);
192 m_downloaded += bytes;
193 if (m_dialog && !m_dialog->Update(m_downloaded)) {
200void GuiDownloader::showErrorDialog(
const char* msg) {
201 auto dlg =
new wxMessageDialog(m_parent,
"", _(
"Installation error"),
202 wxOK | wxICON_ERROR);
204 std::string text = msg;
205 if (last_error_msg !=
"") {
206 text = text +
": " + error_msg;
208 text = text +
"\nPlease check system log for more info.";
209 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.