Fixes for downloading bundles and resources:
- bed_texture/model may be empty. In that case, do not check for the existence of the file. - In case a vendor is new (=not in resources), it would have crashed when installing any printer from such vendor. The problem was that `install_bundles_rsrc` assumed that the INI is in resources. - several const keywords added - small refactoring - removed commented-out code in AppConfig::profile_archive_url(): the url shall not be customizable
This commit is contained in:
parent
e4313399ea
commit
548205ffd8
@ -671,11 +671,8 @@ std::string AppConfig::version_check_url() const
|
|||||||
return from_settings.empty() ? VERSION_CHECK_URL : from_settings;
|
return from_settings.empty() ? VERSION_CHECK_URL : from_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AppConfig::profile_archive_url() const
|
const std::string& AppConfig::profile_archive_url() const
|
||||||
{
|
{
|
||||||
// Do we want to have settable url?
|
|
||||||
//auto from_settings = get("profile_archive_url");
|
|
||||||
//return from_settings.empty() ? PROFILE_ARCHIVE_URL : from_settings;
|
|
||||||
return PROFILE_ARCHIVE_URL;
|
return PROFILE_ARCHIVE_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ public:
|
|||||||
// This returns a hardcoded string unless it is overriden by "version_check_url" in the ini file.
|
// This returns a hardcoded string unless it is overriden by "version_check_url" in the ini file.
|
||||||
std::string version_check_url() const;
|
std::string version_check_url() const;
|
||||||
// Get the Slic3r url to vendor profile archive zip.
|
// Get the Slic3r url to vendor profile archive zip.
|
||||||
std::string profile_archive_url() const;
|
const std::string& profile_archive_url() const;
|
||||||
|
|
||||||
// Returns the original Slic3r version found in the ini file before it was overwritten
|
// Returns the original Slic3r version found in the ini file before it was overwritten
|
||||||
// by the current version
|
// by the current version
|
||||||
|
@ -2131,26 +2131,22 @@ namespace PresetUtils {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool vendor_profile_has_all_resources(const VendorProfile& vp, bool in_cache)
|
bool vendor_profile_has_all_resources(const VendorProfile& vp)
|
||||||
{
|
{
|
||||||
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
std::string vendor_folder = Slic3r::data_dir() + "/vendor/" + vp.id + "/";
|
std::string vendor_folder = Slic3r::data_dir() + "/vendor/" + vp.id + "/";
|
||||||
std::string rsrc_folder = Slic3r::resources_dir() + "/profiles/" + vp.id + "/";
|
std::string rsrc_folder = Slic3r::resources_dir() + "/profiles/" + vp.id + "/";
|
||||||
std::string cache_folder = Slic3r::data_dir() + "/cache/" + vp.id + "/";
|
std::string cache_folder = Slic3r::data_dir() + "/cache/" + vp.id + "/";
|
||||||
for (const VendorProfile::PrinterModel& model : vp.models)
|
for (const VendorProfile::PrinterModel& model : vp.models) {
|
||||||
{
|
for (const std::string& res : { model.bed_texture, model.bed_model, model.id + "_thumbnail.png" } ) {
|
||||||
if ( !boost::filesystem::exists(boost::filesystem::path(vendor_folder + model.bed_texture))
|
if (! res.empty()
|
||||||
&& !boost::filesystem::exists(boost::filesystem::path(rsrc_folder + model.bed_texture))
|
&& !fs::exists(fs::path(vendor_folder + res))
|
||||||
&& (!in_cache || !boost::filesystem::exists(boost::filesystem::path(cache_folder + model.bed_texture))))
|
&& !fs::exists(fs::path(rsrc_folder + res))
|
||||||
return false;
|
&& (fs::exists(fs::path(cache_folder + res))))
|
||||||
if ( !boost::filesystem::exists(boost::filesystem::path(vendor_folder + model.bed_model))
|
|
||||||
&& !boost::filesystem::exists(boost::filesystem::path(rsrc_folder + model.bed_model))
|
|
||||||
&& (!in_cache || !boost::filesystem::exists(boost::filesystem::path(cache_folder + model.bed_model))))
|
|
||||||
return false;
|
|
||||||
if ( !boost::filesystem::exists(boost::filesystem::path(vendor_folder + model.id + "_thumbnail.png"))
|
|
||||||
&& !boost::filesystem::exists(boost::filesystem::path(rsrc_folder + model.id + "_thumbnail.png"))
|
|
||||||
&& (!in_cache || !boost::filesystem::exists(boost::filesystem::path(cache_folder + model.id + "_thumbnail.png"))))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} // namespace PresetUtils
|
} // namespace PresetUtils
|
||||||
|
@ -620,7 +620,7 @@ namespace PresetUtils {
|
|||||||
const VendorProfile::PrinterModel* system_printer_model(const Preset &preset);
|
const VendorProfile::PrinterModel* system_printer_model(const Preset &preset);
|
||||||
std::string system_printer_bed_model(const Preset& preset);
|
std::string system_printer_bed_model(const Preset& preset);
|
||||||
std::string system_printer_bed_texture(const Preset& preset);
|
std::string system_printer_bed_texture(const Preset& preset);
|
||||||
bool vendor_profile_has_all_resources(const VendorProfile& vp, bool in_cache);
|
bool vendor_profile_has_all_resources(const VendorProfile& vp);
|
||||||
} // namespace PresetUtils
|
} // namespace PresetUtils
|
||||||
|
|
||||||
|
|
||||||
|
@ -3051,7 +3051,7 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
|
|||||||
if (install_bundles.size() > 0) {
|
if (install_bundles.size() > 0) {
|
||||||
// Install bundles from resources or cache / vendor.
|
// Install bundles from resources or cache / vendor.
|
||||||
// Don't create snapshot - we've already done that above if applicable.
|
// Don't create snapshot - we've already done that above if applicable.
|
||||||
if (! updater->install_bundles_rsrc(std::move(install_bundles), false))
|
if (! updater->install_bundles_rsrc_or_cache_vendor(std::move(install_bundles), false))
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
BOOST_LOG_TRIVIAL(info) << "No bundles need to be installed from resources or cache / vendor";
|
BOOST_LOG_TRIVIAL(info) << "No bundles need to be installed from resources or cache / vendor";
|
||||||
|
@ -157,7 +157,7 @@ struct PresetUpdater::priv
|
|||||||
|
|
||||||
priv();
|
priv();
|
||||||
|
|
||||||
void set_download_prefs(AppConfig *app_config);
|
void set_download_prefs(const AppConfig *app_config);
|
||||||
bool get_file(const std::string &url, const fs::path &target_path) const;
|
bool get_file(const std::string &url, const fs::path &target_path) const;
|
||||||
void prune_tmps() const;
|
void prune_tmps() const;
|
||||||
void sync_config(const VendorMap vendors, const std::string& profile_archive_url);
|
void sync_config(const VendorMap vendors, const std::string& profile_archive_url);
|
||||||
@ -183,7 +183,7 @@ PresetUpdater::priv::priv()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pull relevant preferences from AppConfig
|
// Pull relevant preferences from AppConfig
|
||||||
void PresetUpdater::priv::set_download_prefs(AppConfig *app_config)
|
void PresetUpdater::priv::set_download_prefs(const AppConfig *app_config)
|
||||||
{
|
{
|
||||||
enabled_version_check = app_config->get("notify_release") != "none";
|
enabled_version_check = app_config->get("notify_release") != "none";
|
||||||
version_check_url = app_config->version_check_url();
|
version_check_url = app_config->version_check_url();
|
||||||
@ -370,9 +370,12 @@ void PresetUpdater::priv::sync_config(const VendorMap vendors, const std::string
|
|||||||
|
|
||||||
// check the fresh bundle for missing resources
|
// check the fresh bundle for missing resources
|
||||||
// for that, the ini file must be parsed (done above)
|
// for that, the ini file must be parsed (done above)
|
||||||
auto check_and_get_resource = [&self = std::as_const(*this)](const std::string& vendor, const std::string& filename, const std::string& url, const fs::path& vendor_path, const fs::path& rsrc_path, const fs::path& cache_path){
|
auto check_and_get_resource = [&self = std::as_const(*this)](const std::string& vendor, const std::string& filename,
|
||||||
if (!boost::filesystem::exists((vendor_path / (vendor + "/" + filename)))
|
const std::string& url, const fs::path& vendor_path,
|
||||||
&& !boost::filesystem::exists((rsrc_path / (vendor + "/" + filename)))) {
|
const fs::path& rsrc_path, const fs::path& cache_path)
|
||||||
|
{
|
||||||
|
if (!fs::exists((vendor_path / (vendor + "/" + filename)))
|
||||||
|
&& !fs::exists((rsrc_path / (vendor + "/" + filename)))) {
|
||||||
BOOST_LOG_TRIVIAL(info) << "Resources check could not find " << vendor << " / " << filename << " bed texture. Downloading.";
|
BOOST_LOG_TRIVIAL(info) << "Resources check could not find " << vendor << " / " << filename << " bed texture. Downloading.";
|
||||||
const auto resource_url = format("%1%/%2%/%3%", url, vendor, filename);
|
const auto resource_url = format("%1%/%2%/%3%", url, vendor, filename);
|
||||||
const auto resource_path = (cache_path / (vendor + "/" + filename));
|
const auto resource_path = (cache_path / (vendor + "/" + filename));
|
||||||
@ -382,12 +385,12 @@ void PresetUpdater::priv::sync_config(const VendorMap vendors, const std::string
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
for (const auto& model : vp.models) {
|
for (const auto& model : vp.models) {
|
||||||
check_and_get_resource(vp.id, model.bed_texture, vendor.config_update_url, vendor_path, rsrc_path, cache_path);
|
for (const std::string& res : { model.bed_texture, model.bed_model, model.id +"_thumbnail.png"} ) {
|
||||||
if (cancel) { return; }
|
if (! res.empty())
|
||||||
check_and_get_resource(vp.id, model.bed_model, vendor.config_update_url, vendor_path, rsrc_path, cache_path);
|
check_and_get_resource(vp.id, res, vendor.config_update_url, vendor_path, rsrc_path, cache_path);
|
||||||
if (cancel) { return; }
|
if (cancel)
|
||||||
check_and_get_resource(vp.id, model.id +"_thumbnail.png", vendor.config_update_url, vendor_path, rsrc_path, cache_path);
|
return;
|
||||||
if (cancel) { return; }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -515,7 +518,7 @@ Updates PresetUpdater::priv::get_config_updates(const Semver &old_slic3r_version
|
|||||||
if (new_vp.config_version == recommended->config_version) {
|
if (new_vp.config_version == recommended->config_version) {
|
||||||
// The config bundle from the cache directory matches the recommended version of the index from the cache directory.
|
// The config bundle from the cache directory matches the recommended version of the index from the cache directory.
|
||||||
// This is the newest known recommended config. Use it.
|
// This is the newest known recommended config. Use it.
|
||||||
if (PresetUtils::vendor_profile_has_all_resources(new_vp, true)) {
|
if (PresetUtils::vendor_profile_has_all_resources(new_vp)) {
|
||||||
// All resources for the profile in cache dir are existing (either in resources or data_dir/vendor or waiting to be copied to vendor from cache)
|
// All resources for the profile in cache dir are existing (either in resources or data_dir/vendor or waiting to be copied to vendor from cache)
|
||||||
// This final check is not performed for updates from resources dir below.
|
// This final check is not performed for updates from resources dir below.
|
||||||
new_update = Update(std::move(path_in_cache), std::move(bundle_path), *recommended, vp.name, vp.changelog_url, current_not_supported);
|
new_update = Update(std::move(path_in_cache), std::move(bundle_path), *recommended, vp.name, vp.changelog_url, current_not_supported);
|
||||||
@ -523,6 +526,7 @@ Updates PresetUpdater::priv::get_config_updates(const Semver &old_slic3r_version
|
|||||||
bundle_path_idx_to_install = idx.path();
|
bundle_path_idx_to_install = idx.path();
|
||||||
found = true;
|
found = true;
|
||||||
} else {
|
} else {
|
||||||
|
// Resource missing - treat as if the INI file was corrupted.
|
||||||
throw Slic3r::CriticalException("Some resources are missing.");
|
throw Slic3r::CriticalException("Some resources are missing.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -677,11 +681,14 @@ bool PresetUpdater::priv::perform_updates(Updates &&updates, bool snapshot) cons
|
|||||||
for (const auto &name : bundle.obsolete_presets.sla_materials/*filaments*/) { obsolete_remover("sla_material", name); }
|
for (const auto &name : bundle.obsolete_presets.sla_materials/*filaments*/) { obsolete_remover("sla_material", name); }
|
||||||
for (const auto &name : bundle.obsolete_presets.printers) { obsolete_remover("printer", name); }
|
for (const auto &name : bundle.obsolete_presets.printers) { obsolete_remover("printer", name); }
|
||||||
|
|
||||||
auto copy_missing_resource = [](const std::string& vendor, const std::string& filename, const fs::path& vendor_path, const fs::path& rsrc_path, const fs::path& cache_path) {
|
auto copy_missing_resource = [](const std::string& vendor, const std::string& filename,
|
||||||
if ( !boost::filesystem::exists((vendor_path / (vendor + "/" + filename)))
|
const fs::path& vendor_path, const fs::path& rsrc_path,
|
||||||
&& !boost::filesystem::exists((rsrc_path / (vendor + "/" + filename)))) {
|
const fs::path& cache_path)
|
||||||
|
{
|
||||||
|
if ( !fs::exists((vendor_path / (vendor + "/" + filename)))
|
||||||
|
&& !fs::exists((rsrc_path / (vendor + "/" + filename)))) {
|
||||||
|
|
||||||
if (!boost::filesystem::exists((cache_path / (vendor + "/" + filename)))) {
|
if (!fs::exists((cache_path / (vendor + "/" + filename)))) {
|
||||||
BOOST_LOG_TRIVIAL(error) << "Resources missing in cache directory: " << vendor << " / " << filename;
|
BOOST_LOG_TRIVIAL(error) << "Resources missing in cache directory: " << vendor << " / " << filename;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -728,7 +735,7 @@ PresetUpdater::~PresetUpdater()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PresetUpdater::sync(PresetBundle *preset_bundle)
|
void PresetUpdater::sync(const PresetBundle *preset_bundle)
|
||||||
{
|
{
|
||||||
p->set_download_prefs(GUI::wxGetApp().app_config);
|
p->set_download_prefs(GUI::wxGetApp().app_config);
|
||||||
if (!p->enabled_version_check && !p->enabled_config_update) { return; }
|
if (!p->enabled_version_check && !p->enabled_config_update) { return; }
|
||||||
@ -909,7 +916,7 @@ PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3
|
|||||||
return R_NOOP;
|
return R_NOOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PresetUpdater::install_bundles_rsrc(std::vector<std::string> bundles, bool snapshot) const
|
bool PresetUpdater::install_bundles_rsrc_or_cache_vendor(std::vector<std::string> bundles, bool snapshot) const
|
||||||
{
|
{
|
||||||
Updates updates;
|
Updates updates;
|
||||||
|
|
||||||
@ -919,11 +926,16 @@ bool PresetUpdater::install_bundles_rsrc(std::vector<std::string> bundles, bool
|
|||||||
auto path_in_rsrc = (p->rsrc_path / bundle).replace_extension(".ini");
|
auto path_in_rsrc = (p->rsrc_path / bundle).replace_extension(".ini");
|
||||||
auto path_in_cache_vendor = (p->cache_vendor_path / bundle).replace_extension(".ini");
|
auto path_in_cache_vendor = (p->cache_vendor_path / bundle).replace_extension(".ini");
|
||||||
auto path_in_vendors = (p->vendor_path / bundle).replace_extension(".ini");
|
auto path_in_vendors = (p->vendor_path / bundle).replace_extension(".ini");
|
||||||
|
|
||||||
|
bool is_in_rsrc = fs::exists(path_in_rsrc);
|
||||||
|
bool is_in_cache_vendor = fs::exists(path_in_cache_vendor);
|
||||||
|
|
||||||
// find if in cache vendor is newer version than in resources
|
// find if in cache vendor is newer version than in resources
|
||||||
if (boost::filesystem::exists(path_in_cache_vendor)) {
|
if (is_in_cache_vendor) {
|
||||||
auto vp_cache = VendorProfile::from_ini(path_in_cache_vendor, false);
|
auto vp_cache = VendorProfile::from_ini(path_in_cache_vendor, false);
|
||||||
auto vp_rsrc = VendorProfile::from_ini(path_in_rsrc, false);
|
auto vp_rsrc = VendorProfile::from_ini(path_in_rsrc, false);
|
||||||
if (vp_cache.config_version > vp_rsrc.config_version) {
|
|
||||||
|
if (! is_in_rsrc || vp_cache.config_version > vp_rsrc.config_version) {
|
||||||
// in case we are installing from cache / vendor. we should also copy index to cache
|
// in case we are installing from cache / vendor. we should also copy index to cache
|
||||||
// This needs to be done now bcs the current one would be missing this version on next start
|
// This needs to be done now bcs the current one would be missing this version on next start
|
||||||
auto path_idx_cache_vendor(path_in_cache_vendor);
|
auto path_idx_cache_vendor(path_in_cache_vendor);
|
||||||
@ -936,11 +948,19 @@ bool PresetUpdater::install_bundles_rsrc(std::vector<std::string> bundles, bool
|
|||||||
BOOST_LOG_TRIVIAL(error) << GUI::format(_L("Couldn't locate idx file %1% when performing updates."), path_idx_cache_vendor.string());
|
BOOST_LOG_TRIVIAL(error) << GUI::format(_L("Couldn't locate idx file %1% when performing updates."), path_idx_cache_vendor.string());
|
||||||
updates.updates.emplace_back(std::move(path_in_cache_vendor), std::move(path_in_vendors), Version(), "", "");
|
updates.updates.emplace_back(std::move(path_in_cache_vendor), std::move(path_in_vendors), Version(), "", "");
|
||||||
|
|
||||||
} else
|
} else {
|
||||||
|
if (is_in_rsrc)
|
||||||
updates.updates.emplace_back(std::move(path_in_rsrc), std::move(path_in_vendors), Version(), "", "");
|
updates.updates.emplace_back(std::move(path_in_rsrc), std::move(path_in_vendors), Version(), "", "");
|
||||||
} else
|
}
|
||||||
|
} else {
|
||||||
|
if (! is_in_rsrc) {
|
||||||
|
// This should not happen. Instead of an assert, make it crash in Release mode too.
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "Internal error in PresetUpdater! Terminating the application.";
|
||||||
|
std::terminate();
|
||||||
|
}
|
||||||
updates.updates.emplace_back(std::move(path_in_rsrc), std::move(path_in_vendors), Version(), "", "");
|
updates.updates.emplace_back(std::move(path_in_rsrc), std::move(path_in_vendors), Version(), "", "");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return p->perform_updates(std::move(updates), snapshot);
|
return p->perform_updates(std::move(updates), snapshot);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public:
|
|||||||
~PresetUpdater();
|
~PresetUpdater();
|
||||||
|
|
||||||
// If either version check or config updating is enabled, get the appropriate data in the background and cache it.
|
// If either version check or config updating is enabled, get the appropriate data in the background and cache it.
|
||||||
void sync(PresetBundle *preset_bundle);
|
void sync(const PresetBundle *preset_bundle);
|
||||||
|
|
||||||
// If version check is enabled, check if chaced online slic3r version is newer, notify if so.
|
// If version check is enabled, check if chaced online slic3r version is newer, notify if so.
|
||||||
void slic3r_update_notify();
|
void slic3r_update_notify();
|
||||||
@ -53,8 +53,8 @@ public:
|
|||||||
// that the config index installed from the Internet is equal to the index contained in the installation package.
|
// that the config index installed from the Internet is equal to the index contained in the installation package.
|
||||||
UpdateResult config_update(const Semver &old_slic3r_version, UpdateParams params) const;
|
UpdateResult config_update(const Semver &old_slic3r_version, UpdateParams params) const;
|
||||||
|
|
||||||
// "Update" a list of bundles from resources (behaves like an online update).
|
// "Update" a list of bundles from resources or cache/vendor (behaves like an online update).
|
||||||
bool install_bundles_rsrc(std::vector<std::string> bundles, bool snapshot = true) const;
|
bool install_bundles_rsrc_or_cache_vendor(std::vector<std::string> bundles, bool snapshot = true) const;
|
||||||
|
|
||||||
void on_update_notification_confirm();
|
void on_update_notification_confirm();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user