From df19e91845b869db5cae4a5c5505584a0206b6fc Mon Sep 17 00:00:00 2001 From: SoftFever Date: Mon, 31 Mar 2025 15:27:46 +0800 Subject: [PATCH] fix a bug for OTA updating feature. Add a help script to pack OTA package --- scripts/pack_profiles.sh | 81 ++++++++++++++++++++++++++++++ src/slic3r/GUI/GUI_App.cpp | 1 + src/slic3r/Utils/PresetUpdater.cpp | 15 +++--- 3 files changed, 89 insertions(+), 8 deletions(-) create mode 100755 scripts/pack_profiles.sh diff --git a/scripts/pack_profiles.sh b/scripts/pack_profiles.sh new file mode 100755 index 0000000000..946f7814bc --- /dev/null +++ b/scripts/pack_profiles.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +# Check if required arguments are provided +if [ "$#" -lt 3 ]; then + echo "Usage: $0 VERSION NUMBER VENDOR1 [VENDOR2 ...]" + echo "Example: $0 2.3.0 1 OrcaFilamentLibrary BBL" + exit 1 +fi + +# Get version and number from arguments +VERSION="$1" +NUMBER="$2" +shift 2 # Remove first two arguments, leaving only vendor names + +# Set paths +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +RESOURCES_DIR="$SCRIPT_DIR/../resources/profiles" +ORIGINAL_DIR="$(pwd)" +OUTPUT_FILE="orcaslicer-profiles_ota_${VERSION}.${NUMBER}.zip" +TEMP_DIR="/tmp/orca_profiles_$$" # Use PID to make temp dir unique + +# Check if resources directory exists +if [ ! -d "$RESOURCES_DIR" ]; then + echo "Error: Profiles directory not found at $RESOURCES_DIR" + exit 1 +fi + +# Create temporary directory with profiles root folder +mkdir -p "$TEMP_DIR/profiles" + +# Process each vendor +for VENDOR in "$@"; do + echo "Processing vendor: $VENDOR" + + # Copy JSON file if it exists + if [ -f "$RESOURCES_DIR/$VENDOR.json" ]; then + cp "$RESOURCES_DIR/$VENDOR.json" "$TEMP_DIR/profiles/" + echo "Added $VENDOR.json" + else + echo "Warning: $VENDOR.json not found" + fi + + # Copy vendor directory if it exists + if [ -d "$RESOURCES_DIR/$VENDOR" ]; then + cp -r "$RESOURCES_DIR/$VENDOR" "$TEMP_DIR/profiles/" + echo "Added $VENDOR directory" + + # Remove excluded file types + find "$TEMP_DIR/profiles/$VENDOR" -type f \( \ + -name "*.jpg" -o \ + -name "*.stl" -o \ + -name "*.svg" -o \ + -name "*.png" -o \ + -name "*.py" \ + \) -delete + else + echo "Warning: $VENDOR directory not found" + fi +done + +# Create zip file +cd "$TEMP_DIR" +zip -r "$OUTPUT_FILE" profiles/ + +# Move zip file to original directory +mv "$OUTPUT_FILE" "$ORIGINAL_DIR/" + +# Return to original directory +cd "$ORIGINAL_DIR" + +# Clean up +rm -rf "$TEMP_DIR" + +# Print results +if [ -f "$OUTPUT_FILE" ]; then + echo "Created profiles package: $OUTPUT_FILE" + echo "Size: $(du -h "$OUTPUT_FILE" | cut -f1)" +else + echo "Error: Failed to create zip file" + exit 1 +fi \ No newline at end of file diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 10c1199f87..03bcd4b644 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -4789,6 +4789,7 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg) [this, progressFn, cancelFn, finishFn, t = std::weak_ptr(m_user_sync_token)] { // get setting list, update setting list std::string version = preset_bundle->get_vendor_profile_version(PresetBundle::ORCA_DEFAULT_BUNDLE).to_string(); + if(!m_agent) return; int ret = m_agent->get_setting_list2(version, [this](auto info) { auto type = info[BBL_JSON_KEY_TYPE]; auto name = info[BBL_JSON_KEY_NAME]; diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index 89a7b58f90..d09f69b663 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -1203,9 +1203,9 @@ Updates PresetUpdater::priv::get_config_updates(const Semver &old_slic3r_version auto machine_in_cache = (cache_profile_path / vendor_name / PRESET_PRINTER_NAME); if (( fs::exists(path_in_vendor)) - &&( fs::exists(print_in_cache)) - &&( fs::exists(filament_in_cache)) - &&( fs::exists(machine_in_cache))) { + || fs::exists(print_in_cache) + || fs::exists(filament_in_cache) + || fs::exists(machine_in_cache)) { Semver vendor_ver = get_version_from_json(path_in_vendor.string()); std::map key_values; @@ -1240,11 +1240,10 @@ Updates PresetUpdater::priv::get_config_updates(const Semver &old_slic3r_version Version version; version.config_version = cache_ver; version.comment = description; - - updates.updates.emplace_back(std::move(file_path), std::move(path_in_vendor.string()), std::move(version), vendor_name, changelog, "", force_update, false); - - //BBS: add directory support - updates.updates.emplace_back(cache_path / vendor_name, vendor_path / vendor_name, Version(), vendor_name, "", "", force_update, true); + // Orca: update vendor.json + updates.updates.emplace_back(std::move(file_path), std::move(path_in_vendor.string()), std::move(version), vendor_name, changelog, "", force_update, false); + //Orca: update vendor folder + updates.updates.emplace_back(cache_profile_path / vendor_name, vendor_path / vendor_name, Version(), vendor_name, "", "", force_update, true); } } }