40#include <wx/progdlg.h>
42#include <wx/statline.h>
45#include "libgui/expand_icon.h"
63wxDEFINE_EVENT(EVT_PLUGINS_RELOAD, wxCommandEvent);
68static bool checksum_ok(
const std::string& path,
70 wxLogDebug(
"Checksum test on %s", metadata.name.c_str());
71 if (metadata.checksum ==
"") {
72 wxLogDebug(
"No metadata checksum, aborting check,");
75 const size_t pos = metadata.checksum.find(
':');
76 std::string checksum(metadata.checksum);
77 if (pos == std::string::npos) {
78 checksum = std::string(
"sha256:") + checksum;
80 std::ifstream f(path, std::ios::binary);
81 picosha2::hash256_one_by_one hasher;
84 f.read(buff,
sizeof(buff));
85 const std::string
block(buff, f.gcount());
89 std::string tarball_hash =
90 std::string(
"sha256:") + picosha2::get_hash_hex_string(hasher);
92 if (tarball_hash == checksum) {
93 wxLogDebug(
"Checksum ok: %s", tarball_hash.c_str());
96 wxLogMessage(
"Checksum fail on %s, tarball: %s, metadata: %s",
97 metadata.name.c_str(), tarball_hash.c_str(), checksum.c_str());
105static ssize_t PlugInIxByName(
const std::string name,
106 const ArrayOfPlugIns* plugins) {
107 for (
unsigned i = 0; i < plugins->GetCount(); i += 1) {
108 if (name == plugins->Item(i)->m_common_name.Lower().ToStdString()) {
123std::string GuiDownloader::run(wxWindow* parent,
bool remove_current) {
125 bool downloaded =
false;
129 std::string label(_(
"Downloading "));
132 new wxProgressDialog(_(
"Downloading"), label.c_str(), size, parent,
133 wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT);
135 m_dialog->SetBackgroundColour(wxColour(0x7c, 0xb0, 0xe9));
138 g_Platform->HideBusySpinner();
142 showErrorDialog(
"Download error");
148 showErrorDialog(
"Download aborted");
153 if (!checksum_ok(path, m_plugin)) {
154 showErrorDialog(
"Checksum error");
162 if (remove_current) {
163 wxLogMessage(
"Uninstalling %s", m_plugin.name.c_str());
164 pluginHandler->Uninstall(m_plugin.name);
166 ok = pluginHandler->InstallPlugin(m_plugin, path);
168 showErrorDialog(
"Installation error");
174 wxURI uri(wxString(m_plugin.tarball_url.c_str()));
175 wxFileName fn(uri.GetPath());
176 auto basename = fn.GetFullName().ToStdString();
178 wxLogMessage(
"Copied %s to local cache at %s", path.c_str(),
183 wxMessageDialog* dlg =
new wxMessageDialog(
185 m_plugin.name +
" " + m_plugin.version + _(
" successfully installed"),
186 _(
"Installation complete"), wxOK | wxCENTRE | wxICON_INFORMATION);
193 m_downloaded += bytes;
194 if (m_dialog && !m_dialog->Update(m_downloaded)) {
201void GuiDownloader::showErrorDialog(
const char* msg) {
202 auto dlg =
new wxMessageDialog(m_parent,
"", _(
"Installation error"),
203 wxOK | wxICON_ERROR);
205 std::string text = msg;
206 if (last_error_msg !=
"") {
207 text = text +
": " + error_msg;
209 text = text +
"\nPlease check system log for more info.";
210 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.