Add option to download missing stylesheets on startup

This commit is contained in:
GenevensiS
2026-05-18 23:25:22 +02:00
parent 2f77e8c4c1
commit c531b8aa74
54 changed files with 638 additions and 177 deletions
+1 -1
View File
@@ -640,8 +640,8 @@ ApprenticeExportWindow::ApprenticeExportWindow(Window* parent, const SetP& set)
s->Add(new wxStaticText(this, -1, _HELP_( "set code")), 0, wxALL, 4);
s->AddSpacer(4);
s->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxEXPAND | (wxALL & ~wxTOP), 8);
s->SetSizeHints(this);
SetSizer(s);
s->SetSizeHints(this);
}
void ApprenticeExportWindow::onApprenticeBrowse(wxCommandEvent& ev) {
+22
View File
@@ -16,6 +16,7 @@
#include <util/io/package_manager.hpp>
#include <util/platform.hpp>
#include <gui/util.hpp> // load_resource_image
#include <wx/webrequest.h>
#include <wx/filename.h>
#include <wx/wfstream.h>
#include <wx/zipstrm.h>
@@ -319,6 +320,27 @@ void InstallablePackage::determineStatus() {
}
}
bool InstallablePackage::ensureIsDownloaded() {
if (!installer) return true; // Nothing to download
if (installer->installer) return true; // Already loaded
if (installer->installer_url.empty()) return false; // No URL
// download installer
wxWebRequestSync request = wxWebSessionSync::GetDefault().CreateRequest(installer->installer_url);
auto const result = request.Execute();
if (!result) {
throw Error(_ERROR_2_("can't download installer", description->name, installer->installer_url));
}
wxInputStream* is(request.GetResponse().GetStream());
installer->installer_file = wxFileName::CreateTempFileName(_("mse-installer"));
wxFileOutputStream os(installer->installer_file);
os.Write(*is);
os.Close();
// open installer
installer->installer = make_intrusive<Installer>();
installer->installer->open(installer->installer_file);
return true;
}
bool InstallablePackage::willBeInstalled() const {
return has(PACKAGE_ACT_INSTALL) ||
(has(PACKAGE_INSTALLED) && !has(PACKAGE_ACT_REMOVE));
+2 -1
View File
@@ -152,7 +152,8 @@ public:
int old_automatic;
void determineStatus();
bool ensureIsDownloaded();
/// After the action, will the package be installed?
bool willBeInstalled() const;
+3 -11
View File
@@ -38,21 +38,13 @@ StyleSheetP StyleSheet::byGameAndName(const Game& game, const String& name) {
return package_manager.open<StyleSheet>(full_name);
}
} catch (PackageNotFoundError& e) {
queue_message(MESSAGE_ERROR, _("Missing stylesheet: ") + full_name);
// This causes a freeze when the set contains two cards that use the same missing StyleSheet, and the second one has styling_data
// Also, it's probably better to ask the user for an alternative for each missing StyleSheet individually
//if (stylesheet_for_reading()) {
// // we already have a stylesheet higher up, so just return a null pointer
// return StyleSheetP();
//}
// load an alternative stylesheet
StyleSheetP ss = select_stylesheet(game, name);
StyleSheetP ss = select_stylesheet(game, full_name);
if (ss) {
stylesheet_alternatives[full_name] = ss->relativeFilename();
return ss;
} else {
queue_message(MESSAGE_ERROR, _("Missing stylesheet: ") + full_name);
throw e;
}
}
@@ -103,8 +95,8 @@ void mark_dependency_value(const StyleSheet& stylesheet, const Dependency& dep)
IMPLEMENT_REFLECTION(StyleSheet) {
REFLECT(game);
REFLECT_BASE(Packaged);
REFLECT(game);
REFLECT(card_width);
REFLECT(card_height);
REFLECT(card_dpi);