mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-29 05:42:33 +00:00
Compare commits
8 Commits
v2.4.2
...
agent/prof
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33be3c71bd | ||
|
|
a5bb94f3c8 | ||
|
|
b87b38bd7c | ||
|
|
3f0ef7e6d9 | ||
|
|
7ad7f8b65b | ||
|
|
70a6403ab0 | ||
|
|
e7936297a1 | ||
|
|
b1a66da542 |
@@ -42,6 +42,9 @@ namespace Slic3r {
|
|||||||
|
|
||||||
static const std::string VERSION_CHECK_URL = "https://check-version.orcaslicer.com/latest";
|
static const std::string VERSION_CHECK_URL = "https://check-version.orcaslicer.com/latest";
|
||||||
static const std::string PROFILE_UPDATE_URL = "https://check-version.orcaslicer.com/profile";
|
static const std::string PROFILE_UPDATE_URL = "https://check-version.orcaslicer.com/profile";
|
||||||
|
|
||||||
|
constexpr const char* CONFIG_ORCA_UPDATER_URL = "orca_updater_url";
|
||||||
|
|
||||||
static const std::string MODELS_STR = "models";
|
static const std::string MODELS_STR = "models";
|
||||||
|
|
||||||
const std::string AppConfig::SECTION_FILAMENTS = "filaments";
|
const std::string AppConfig::SECTION_FILAMENTS = "filaments";
|
||||||
@@ -1747,7 +1750,10 @@ std::string AppConfig::version_check_url() const
|
|||||||
|
|
||||||
std::string AppConfig::profile_update_url() const
|
std::string AppConfig::profile_update_url() const
|
||||||
{
|
{
|
||||||
|
std::string orca_updater_url = get(CONFIG_ORCA_UPDATER_URL);
|
||||||
|
if (orca_updater_url.empty())
|
||||||
return PROFILE_UPDATE_URL;
|
return PROFILE_UPDATE_URL;
|
||||||
|
return orca_updater_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppConfig::exists()
|
bool AppConfig::exists()
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <boost/nowide/fstream.hpp>
|
#include <boost/nowide/fstream.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <mutex>
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@@ -204,7 +203,6 @@ struct PresetUpdater::priv
|
|||||||
|
|
||||||
// Per-vendor update checking
|
// Per-vendor update checking
|
||||||
std::set<std::string> checked_vendors;
|
std::set<std::string> checked_vendors;
|
||||||
std::mutex vendor_check_mutex;
|
|
||||||
std::vector<std::thread> vendor_check_threads;
|
std::vector<std::thread> vendor_check_threads;
|
||||||
std::atomic<bool> vendor_check_cancel{false};
|
std::atomic<bool> vendor_check_cancel{false};
|
||||||
|
|
||||||
@@ -224,7 +222,7 @@ struct PresetUpdater::priv
|
|||||||
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;
|
||||||
//BBS: refine preset update logic
|
//BBS: refine preset update logic
|
||||||
bool extract_file(const fs::path &source_path, const fs::path &dest_path = {});
|
bool extract_file(const fs::path &source_path, const fs::path &dest_path = {});
|
||||||
void prune_tmps() const;
|
void prune_tmp(const std::string& vendor_id) const;
|
||||||
void sync_version() const;
|
void sync_version() const;
|
||||||
void parse_version_string(const std::string& body) const;
|
void parse_version_string(const std::string& body) const;
|
||||||
void sync_resources(std::string http_url, std::map<std::string, Resource> &resources, bool check_patch = false, std::string current_version="", std::string changelog_file="");
|
void sync_resources(std::string http_url, std::map<std::string, Resource> &resources, bool check_patch = false, std::string current_version="", std::string changelog_file="");
|
||||||
@@ -371,14 +369,14 @@ bool PresetUpdater::priv::extract_file(const fs::path &source_path, const fs::pa
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove leftover paritally downloaded files, if any.
|
// Remove a leftover partial archive for the vendor about to be synchronized.
|
||||||
void PresetUpdater::priv::prune_tmps() const
|
void PresetUpdater::priv::prune_tmp(const std::string& vendor_id) const
|
||||||
{
|
{
|
||||||
for (auto &dir_entry : boost::filesystem::directory_iterator(cache_path))
|
boost::system::error_code ec;
|
||||||
if (is_plain_file(dir_entry) && dir_entry.path().extension() == TMP_EXTENSION) {
|
const fs::path tmp_path = cache_path / (vendor_id + TMP_EXTENSION);
|
||||||
BOOST_LOG_TRIVIAL(debug) << "[Orca Updater]remove old cached files: " << dir_entry.path().string();
|
fs::remove(tmp_path, ec);
|
||||||
fs::remove(dir_entry.path());
|
if (ec)
|
||||||
}
|
BOOST_LOG_TRIVIAL(warning) << "[Orca Updater]failed to remove " << tmp_path.string() << ": " << ec.message();
|
||||||
}
|
}
|
||||||
|
|
||||||
//BBS: refine the Preset Updater logic
|
//BBS: refine the Preset Updater logic
|
||||||
@@ -1094,10 +1092,9 @@ void PresetUpdater::priv::check_installed_vendor_profiles() const
|
|||||||
Semver resource_ver = get_version_from_json(file_path);
|
Semver resource_ver = get_version_from_json(file_path);
|
||||||
Semver vendor_ver = get_version_from_json(path_in_vendor.string());
|
Semver vendor_ver = get_version_from_json(path_in_vendor.string());
|
||||||
|
|
||||||
bool version_match = ((resource_ver.maj() == vendor_ver.maj()) && (resource_ver.min() == vendor_ver.min()));
|
if (vendor_ver < resource_ver) {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "[Orca Updater]:found vendor " << vendor_name << " newer version "
|
||||||
if (!version_match || (vendor_ver < resource_ver)) {
|
<< resource_ver.to_string() << " from resource, old version " << vendor_ver.to_string();
|
||||||
BOOST_LOG_TRIVIAL(info) << "[Orca Updater]:found vendor "<<vendor_name<<" newer version "<<resource_ver.to_string() <<" from resource, old version "<<vendor_ver.to_string();
|
|
||||||
bundles.insert(vendor_name);
|
bundles.insert(vendor_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1339,49 +1336,29 @@ PresetUpdater::~PresetUpdater()
|
|||||||
|
|
||||||
//BBS: change directories by design
|
//BBS: change directories by design
|
||||||
//BBS: refine the preset updater logic
|
//BBS: refine the preset updater logic
|
||||||
void PresetUpdater::sync(std::string http_url, std::string language, std::string plugin_version, PresetBundle *preset_bundle)
|
void PresetUpdater::sync(std::string http_url, std::string language, std::string plugin_version, 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; }
|
||||||
|
|
||||||
// Copy the whole vendors data for use in the background thread
|
p->thread = std::thread([this, http_url, language, plugin_version]() {
|
||||||
// Unfortunatelly as of C++11, it needs to be copied again
|
try {
|
||||||
// into the closure (but perhaps the compiler can elide this).
|
|
||||||
VendorMap vendors = preset_bundle ? preset_bundle->vendors : VendorMap{};
|
|
||||||
|
|
||||||
// Determine active vendor before entering the thread
|
|
||||||
std::string active_vendor;
|
|
||||||
if (preset_bundle) {
|
|
||||||
const Preset& printer = preset_bundle->printers.get_edited_preset();
|
|
||||||
if (printer.vendor)
|
|
||||||
active_vendor = printer.vendor->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
p->thread = std::thread([this, vendors, active_vendor, http_url, language, plugin_version]() {
|
|
||||||
this->p->prune_tmps();
|
|
||||||
if (p->cancel)
|
|
||||||
return;
|
|
||||||
this->p->sync_version();
|
this->p->sync_version();
|
||||||
if (p->cancel)
|
if (p->cancel)
|
||||||
return;
|
return;
|
||||||
// Per-vendor config check for the active vendor at startup
|
// Vendor profile updates are triggered by check_vendor_update()
|
||||||
if (!active_vendor.empty() && !vendors.empty()) {
|
// after the startup printer preset has been restored.
|
||||||
this->p->sync_vendor_config(active_vendor);
|
|
||||||
if (p->cancel)
|
|
||||||
return;
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(this->p->vendor_check_mutex);
|
|
||||||
this->p->checked_vendors.insert(active_vendor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (p->cancel)
|
|
||||||
return;
|
|
||||||
this->p->sync_plugins(http_url, plugin_version);
|
this->p->sync_plugins(http_url, plugin_version);
|
||||||
this->p->sync_printer_config(http_url);
|
this->p->sync_printer_config(http_url);
|
||||||
//if (p->cancel)
|
//if (p->cancel)
|
||||||
// return;
|
// return;
|
||||||
//remove the tooltip currently
|
//remove the tooltip currently
|
||||||
//this->p->sync_tooltip(http_url, language);
|
//this->p->sync_tooltip(http_url, language);
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "[Orca Updater] background sync failed: " << e.what();
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "[Orca Updater] background sync failed with an unknown exception";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1390,16 +1367,17 @@ void PresetUpdater::check_vendor_update(const std::string& vendor_id)
|
|||||||
if (!p->enabled_config_update) return;
|
if (!p->enabled_config_update) return;
|
||||||
if (vendor_id.empty()) return;
|
if (vendor_id.empty()) return;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(p->vendor_check_mutex);
|
|
||||||
|
|
||||||
if (!p->checked_vendors.insert(vendor_id).second)
|
if (!p->checked_vendors.insert(vendor_id).second)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p->vendor_check_threads.emplace_back([this, vendor_id]() {
|
p->vendor_check_threads.emplace_back([this, vendor_id]() {
|
||||||
try {
|
try {
|
||||||
|
this->p->prune_tmp(vendor_id);
|
||||||
this->p->sync_vendor_config(vendor_id);
|
this->p->sync_vendor_config(vendor_id);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
BOOST_LOG_TRIVIAL(error) << "[Orca Updater] vendor update failed for " << vendor_id << ": " << e.what();
|
BOOST_LOG_TRIVIAL(error) << "[Orca Updater] vendor update failed for " << vendor_id << ": " << e.what();
|
||||||
|
} catch (...) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "[Orca Updater] vendor update failed for " << vendor_id << " with an unknown exception";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user