### Integrate libappimageupdate into CMake Project Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Demonstrates how to integrate the `libappimageupdate` library into a CMake project. It shows two methods: adding the library as a subdirectory or using `find_package` if it's installed system-wide. The example also includes linking the library to an executable and optionally linking Qt UI support. ```cmake # CMakeLists.txt cmake_minimum_required(VERSION 3.5) project(MyApp) set(CMAKE_CXX_STANDARD 17) # Option 1: Add as subdirectory add_subdirectory(extern/AppImageUpdate) # Option 2: Use find_package (if installed system-wide) # find_package(AppImageUpdate REQUIRED) add_executable(myapp main.cpp) # Link against the library target_link_libraries(myapp PRIVATE libappimageupdate) # For Qt UI support # target_link_libraries(myapp PRIVATE libappimageupdate-qt) ``` -------------------------------- ### Install Library Targets Source: https://github.com/appimagecommunity/appimageupdate/blob/main/src/updater/CMakeLists.txt Defines the installation rules for the shared and static library targets. It specifies the destination directories for libraries and public headers, ensuring proper packaging for development and runtime use. ```cmake install( TARGETS libappimageupdate EXPORT AppImageUpdateTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT LIBAPPIMAGEUPDATE PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/appimage COMPONENT LIBAPPIMAGEUPDATE-DEV ) install( TARGETS libappimageupdate_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT LIBAPPIMAGEUPDATE PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/appimage COMPONENT LIBAPPIMAGEUPDATE-DEV ) ``` -------------------------------- ### Build AppImageUpdate Library Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Provides the necessary commands to build the AppImageUpdate library from source. This includes cloning the repository, creating a build directory, configuring the build with CMake (optionally enabling Qt UI support), compiling the code, and installing the library. ```bash # Clone repository git clone --recursive https://github.com/AppImage/AppImageUpdate cd AppImageUpdate # Create build directory mkdir build && cd build # Configure (without Qt UI) cmake -DBUILD_QT_UI=OFF -DCMAKE_INSTALL_PREFIX=/usr .. # Configure (with Qt UI) cmake -DBUILD_QT_UI=ON -DCMAKE_INSTALL_PREFIX=/usr .. # Build make -j$(nproc) # Install sudo make install ``` -------------------------------- ### Install Executable Target (CMake) Source: https://github.com/appimagecommunity/appimageupdate/blob/main/src/cli/CMakeLists.txt Installs the 'appimageupdatetool' executable to the runtime destination directory specified by 'CMAKE_INSTALL_BINDIR' and assigns it to the 'APPIMAGEUPDATETOOL' component. ```cmake install( TARGETS appimageupdatetool RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT APPIMAGEUPDATETOOL ) ``` -------------------------------- ### Build and Install Signing Validation Utility with CMake Source: https://github.com/appimagecommunity/appimageupdate/blob/main/src/validate/CMakeLists.txt This CMake configuration defines the 'validate' executable by linking the signing library and thread libraries. It also specifies the installation path for the resulting binary within the project's runtime directory. ```cmake add_executable(validate validate_main.cpp) target_link_libraries(validate signing ${CMAKE_THREAD_LIBS_INIT}) install( TARGETS validate RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT validate ) ``` -------------------------------- ### Set Runtime Path (RPATH) (CMake) Source: https://github.com/appimagecommunity/appimageupdate/blob/main/src/cli/CMakeLists.txt Configures the runtime search path (RPATH) for the 'appimageupdatetool' executable to include the installation's library directory relative to the executable's location. ```cmake set_target_properties(appimageupdatetool PROPERTIES INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}") ``` -------------------------------- ### Check Update Availability - C++ Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Checks if a newer version of an AppImage is available without downloading. It queries the remote server using embedded update information. This function should be called before `start()` and returns 0 for no update, 1 for update available, and 2 for errors. ```cpp #include "appimage/update.h" #include using namespace appimage::update; int checkForUpdate(const std::string& appImagePath) { try { Updater updater(appImagePath); bool updateAvailable = false; // Method 0 (default): compare file checksums if (!updater.checkForChanges(updateAvailable, 0)) { // Print any error messages std::string message; while (updater.nextStatusMessage(message)) { std::cerr << message << std::endl; } return 2; // Error checking for updates } if (updateAvailable) { std::cout << "Update available!" << std::endl; // Optionally get remote file size long long fileSize; if (updater.remoteFileSize(fileSize)) { std::cout << "Remote file size: " << (fileSize / 1024.0 / 1024.0) << " MiB" << std::endl; } return 1; // Update available } std::cout << "Already up to date" << std::endl; return 0; // No update available } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; return 2; } } ``` -------------------------------- ### Get AppImage Information - C++ Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Parses an AppImage file to retrieve and format information such as the AppImage type, embedded update details, and the ZSync URL. This is useful for debugging and displaying update metadata. It outputs the description to standard output or standard error if parsing fails. ```cpp #include "appimage/update.h" #include using namespace appimage::update; void describeAppImage(const std::string& appImagePath) { try { Updater updater(appImagePath); std::string description; if (updater.describeAppImage(description)) { std::cout << description << std::endl; // Output example: // Parsing file: /path/to/MyApp.AppImage // AppImage type: 2 // Raw update information: gh-releases-zsync|username|repo|latest|MyApp-*x86_64.AppImage.zsync // Update information type: ZSync via GitHub Releases // Assembled ZSync URL: https://github.com/username/repo/releases/latest/download/MyApp-*x86_64.AppImage.zsync } else { std::cerr << "Failed to describe AppImage" std::cerr << description << std::endl; // Contains error info } // Print any additional status messages std::string message; while (updater.nextStatusMessage(message)) { std::cerr << message << std::endl; } } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; } } ``` -------------------------------- ### Define Shared and Static Libraries in CMake Source: https://github.com/appimagecommunity/appimageupdate/blob/main/src/updater/CMakeLists.txt Configures the libappimageupdate library targets. It sets target properties, links required private dependencies such as cpr and zsync2, and defines include directories for build and install interfaces. ```cmake add_library(libappimageupdate SHARED ${PROJECT_SOURCE_DIR}/include/appimage/update.h updater.cpp ) set_target_properties(libappimageupdate PROPERTIES PREFIX "" PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/appimage/update.h ) target_link_libraries(libappimageupdate PRIVATE ${CMAKE_THREAD_LIBS_INIT} PRIVATE cpr PRIVATE util PRIVATE updateinformation PRIVATE signing ${ZSYNC2_LINK_TYPE} ${ZSYNC2_LIBRARY_NAME} ) target_include_directories(libappimageupdate PUBLIC $ PUBLIC $ ) add_library(libappimageupdate_static STATIC ${PROJECT_SOURCE_DIR}/include/appimage/update.h updater.cpp ) set_target_properties(libappimageupdate_static PROPERTIES PREFIX "" OUTPUT_NAME "libappimageupdate" PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/appimage/update.h ) ``` -------------------------------- ### Initialize Updater with APPIMAGE Environment Variable (C++) Source: https://github.com/appimagecommunity/appimageupdate/wiki/Self-updating-AppImages Demonstrates how to initialize the `appimage::update::Updater` class using the APPIMAGE environment variable. This is a common pattern for self-updating applications. Error handling should be added for robustness. ```cpp #include #include // For getenv // ... inside a function or method ... const char* appimagePath = std::getenv("APPIMAGE"); if (appimagePath) { appimage::update::Updater updater(appimagePath); // Proceed with update operations using 'updater' // Remember to add error handling for getenv and updater initialization } else { // Handle the case where APPIMAGE environment variable is not set } ``` -------------------------------- ### QtUpdater::fromEnv - Self-Updating AppImage (C++) Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Creates a QtUpdater instance specifically for self-updating when the application is run from within an AppImage. It leverages the `APPIMAGE` environment variable to find the AppImage path. If not run from an AppImage, it returns null. This enables seamless updates initiated from within the running application. ```cpp #include "appimage/update/qt-ui.h" #include #include #include #include using namespace appimage::update::qt; class MainWindow : public QMainWindow { public: MainWindow() { // Add "Check for Updates" menu action QMenu* helpMenu = menuBar()->addMenu("Help"); QAction* updateAction = helpMenu->addAction("Check for Updates..."); connect(updateAction, &QAction::triggered, this, &MainWindow::checkForUpdates); } private slots: void checkForUpdates() { // Create updater from environment (returns nullptr if not in AppImage) QtUpdater* updater = QtUpdater::fromEnv(); if (updater == nullptr) { QMessageBox::information(this, "Updates", "Self-update is only available when running as an AppImage."); return; } // Check if update is available int result = updater->checkForUpdates(false); if (result == 0) { QMessageBox::information(this, "Updates", "You are running the latest version."); delete updater; return; } if (result == 1) { // Show update dialog updater->enableRunUpdatedAppImageButton(true); // Connect to restart application after update connect(updater, &QtUpdater::runUpdatedAppImageClicked, [this]() { // Close main window to exit application // The updated AppImage will be launched by QtUpdater this->close(); }); updater->exec(); } else { QMessageBox::warning(this, "Updates", "Could not check for updates."); } delete updater; } }; ``` -------------------------------- ### appimageupdatetool - Basic Usage (Bash) Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Demonstrates the basic command-line usage of the `appimageupdatetool`. This tool allows users to check for, describe, and perform updates on AppImages directly from the terminal. It supports various options for controlling the update process, including overwriting, removing old versions, and self-updating. ```bash # Display help and available options appimageupdatetool --help # Check version appimageupdatetool --version # Describe an AppImage and its update information appimageupdatetool --describe /path/to/MyApp.AppImage # Output: # Parsing file: /path/to/MyApp.AppImage # AppImage type: 2 # Raw update information: gh-releases-zsync|user|repo|latest|MyApp-*.AppImage.zsync # Update information type: ZSync via GitHub Releases # Assembled ZSync URL: https://github.com/user/repo/releases/latest/download/... # Check if an update is available (exit code: 0=no update, 1=update available, 2=error) appimageupdatetool --check-for-update /path/to/MyApp.AppImage echo $? # Check exit code # Update an AppImage (creates new file alongside original) appimageupdatetool /path/to/MyApp.AppImage # Update and overwrite the original file appimageupdatetool --overwrite /path/to/MyApp.AppImage # Update and remove the old AppImage after successful update appimageupdatetool --remove-old /path/to/MyApp.AppImage # Self-update when running from within an AppImage appimageupdatetool --self-update # Override update information manually appimageupdatetool --update-info "zsync|https://example.com/app.zsync" /path/to/MyApp.AppImage ``` -------------------------------- ### Perform AppImage Update using C++ Updater Class Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Demonstrates how to use the appimage::update::Updater class to check for updates, perform an asynchronous delta update, and validate the resulting file's GPG signature. This implementation handles progress monitoring, status reporting, and file permission management. ```cpp #include "appimage/update.h" #include #include #include using namespace appimage::update; int main() { try { // Initialize updater with path to AppImage // Set overwrite=true to replace existing file, false to create new file Updater updater("/path/to/MyApp.AppImage", false); // Check for available updates before starting bool updateAvailable = false; if (!updater.checkForChanges(updateAvailable)) { std::cerr << "Failed to check for updates" << std::endl; return 1; } if (!updateAvailable) { std::cout << "Already up to date!" << std::endl; return 0; } // Start the asynchronous update process if (!updater.start()) { std::cerr << "Failed to start update" << std::endl; return 1; } // Monitor progress while update runs while (!updater.isDone()) { double progress; if (updater.progress(progress)) { std::cout << "\rProgress: " << (progress * 100) << "%" << std::flush; } // Print status messages std::string message; while (updater.nextStatusMessage(message)) { std::cout << "\n" << message << std::endl; } std::this_thread::sleep_for(std::chrono::milliseconds(100)); } // Check for errors if (updater.hasError()) { std::cerr << "Update failed!" << std::endl; return 1; } // Validate signature of the new AppImage auto validationResult = updater.validateSignature(); if (validationResult >= Updater::VALIDATION_FAILED) { std::cerr << "Signature validation failed: " << Updater::signatureValidationMessage(validationResult) << std::endl; updater.restoreOriginalFile(); return 1; } // Copy permissions from old file to new file updater.copyPermissionsToNewFile(); // Get path to the new AppImage std::string newPath; if (updater.pathToNewFile(newPath)) { std::cout << "Update successful: " << newPath << std::endl; } return 0; } catch (const std::invalid_argument& e) { std::cerr << "Error: " << e.what() << std::endl; return 1; } } ``` -------------------------------- ### Link AppImageUpdate Library with CMake Source: https://github.com/appimagecommunity/appimageupdate/blob/main/README.md This snippet demonstrates how to integrate the AppImageUpdate library into a CMake project. It shows how to add the AppImageUpdate repository as a submodule and link your target application against the `libappimageupdate` library. ```cmake add_subdirectory(path/to/appimageupdate/submodule) target_link_libraries(mytarget libappimageupdate) ``` -------------------------------- ### Create Executable and Link Libraries (CMake) Source: https://github.com/appimagecommunity/appimageupdate/blob/main/src/cli/CMakeLists.txt Defines the 'appimageupdatetool' executable from 'main.cpp' and links it to the 'libappimageupdate' and 'util' libraries. Conditionally links to 'ZSYNC2_LIBRARY_NAME' if 'USE_SYSTEM_ZSYNC2' is not enabled. ```cmake add_executable(appimageupdatetool main.cpp) # link to core lib target_link_libraries(appimageupdatetool libappimageupdate util) if(NOT USE_SYSTEM_ZSYNC2) target_link_libraries(appimageupdatetool ${ZSYNC2_LIBRARY_NAME}) endif() ``` -------------------------------- ### QtUpdater Class - Qt Dialog Widget for AppImage Updates Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Provides a ready-to-use Qt dialog widget for updating AppImages. It includes progress display, status logging, and signature validation feedback, and can be embedded in existing Qt applications. It requires the `appimage/update/qt-ui.h` header and Qt libraries. The dialog can be configured to enable a 'Run updated AppImage' button and connect to signals for custom event handling. ```cpp #include "appimage/update/qt-ui.h" #include #include #include using namespace appimage::update::qt; int main(int argc, char* argv[]) { QApplication app(argc, argv); // Create updater dialog with path to AppImage QtUpdater* updater = new QtUpdater("/path/to/MyApp.AppImage"); // Enable the "Run updated AppImage" button after successful update updater->enableRunUpdatedAppImageButton(true); // Connect to signals for custom behavior QObject::connect(updater, &QtUpdater::canceled, []() { std::cout << "Update was canceled" << std::endl; }); QObject::connect(updater, &QtUpdater::runUpdatedAppImageClicked, []() { std::cout << "User clicked run updated AppImage" << std::endl; }); // Show dialog (update starts automatically on show) updater->exec(); // Get path to new AppImage after update QString newPath; if (updater->pathToNewFile(newPath)) { std::cout << "New AppImage: " << newPath.toStdString() << std::endl; } delete updater; return 0; } ``` -------------------------------- ### QtUpdater Class Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt A Qt-based dialog widget for managing the update process with built-in UI components. ```APIDOC ## [CLASS] QtUpdater ### Description Provides a GUI dialog for updating AppImages, featuring progress bars, logging, and signature feedback. ### Method Constructor: QtUpdater(QString path) ### Parameters - **path** (QString) - Required - Filesystem path to the AppImage to be updated. ### Signals - **canceled()** - Emitted when the user cancels the update. - **runUpdatedAppImageClicked()** - Emitted when the user clicks the run button after a successful update. ### Response - **pathToNewFile(QString&)** (Method) - Returns the path to the successfully updated AppImage. ``` -------------------------------- ### Configure CMake static library for AppImageUpdate Source: https://github.com/appimagecommunity/appimageupdate/blob/main/src/util/CMakeLists.txt Defines a static library named 'util' using source files from the project. It sets up public include directories and links necessary dependencies including libappimage_shared, ZSYNC2, and cpr. ```cmake cmake_minimum_required(VERSION 3.19) add_library(util STATIC util.cpp updatableappimage.cpp ) target_include_directories(util PUBLIC $/src ) target_link_libraries(util PRIVATE libappimage_shared ${ZSYNC2_LIBRARY_NAME} cpr) ``` -------------------------------- ### Automate AppImage Updates with Shell Script Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt This bash script automates the process of checking for and applying updates to AppImages within a specified directory using the `appimageupdatetool`. It iterates through all `.AppImage` files, checks for updates, and downloads them if available, handling different exit codes from the update check. ```bash #!/bin/bash # Script to check and update all AppImages in a directory APPIMAGE_DIR="$HOME/Applications" for appimage in "$APPIMAGE_DIR"/*.AppImage; do if [ -f "$appimage" ]; then echo "Checking: $appimage" # Check for update (capture exit code) appimageupdatetool --check-for-update "$appimage" 2>/dev/null result=$? case $result in 0) echo " -> Up to date" ;; 1) echo " -> Update available, downloading..." appimageupdatetool --overwrite --remove-old "$appimage" if [ $? -eq 0 ]; then echo " -> Updated successfully" else echo " -> Update failed" fi ;; *) echo " -> Error checking for updates" ;; esac echo "" fi done ``` -------------------------------- ### AppImage Update Information Formats (ZSync) Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Defines various formats for specifying update information, primarily using the zsync protocol. These formats are used by `appimageupdatetool` and `libappimageupdate` to locate and download update files. Supported formats include GitHub Releases ZSync, Generic ZSync URL, and Pling/OCS V1. ```text # Format: gh-releases-zsync|username|repository|release-tag|filename-pattern # Update from latest release gh-releases-zsync|probonopd|linuxdeployqt|latest|linuxdeployqt-*-x86_64.AppImage.zsync # Update from specific release tag gh-releases-zsync|myuser|myapp|v2.0.0|MyApp-*-x86_64.AppImage.zsync # Using wildcards in filename gh-releases-zsync|username|repo|latest|*-x86_64.AppImage.zsync # Format: zsync|full-url-to-zsync-file # Direct URL zsync|https://download.example.com/releases/myapp-latest.AppImage.zsync # With version in URL zsync|https://releases.myproject.org/v2.0/MyApp-2.0.0-x86_64.AppImage.zsync # Format: pling-v1-zsync|product-id|filename-pattern pling-v1-zsync|1234567|MyApp-*-x86_64.AppImage.zsync ``` -------------------------------- ### Set Custom Update Information - C++ Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Allows overriding the default embedded update information with custom values, enabling support for multiple update channels like stable, beta, or nightly, or directing to alternative update servers. The function demonstrates setting update information and then proceeding with an update check. ```cpp #include "appimage/update.h" #include #include #include using namespace appimage::update; void updateWithCustomChannel(const std::string& appImagePath, const std::string& channel) { Updater updater(appImagePath); // Override update information based on channel if (channel == "stable") { updater.setUpdateInformation( "gh-releases-zsync|myorg|myapp|latest|MyApp-*x86_64.AppImage.zsync" ); } else if (channel == "beta") { updater.setUpdateInformation( "gh-releases-zsync|myorg|myapp|beta|MyApp-*x86_64.AppImage.zsync" ); } else if (channel == "nightly") { updater.setUpdateInformation( "zsync|https://builds.example.com/nightly/MyApp-latest-x86_64.AppImage.zsync" ); } // Get current update information std::cout << "Using update info: " << updater.updateInformation() << std::endl; // Proceed with update check bool updateAvailable = false; if (updater.checkForChanges(updateAvailable) && updateAvailable) { updater.start(); while (!updater.isDone()) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); } } } ``` -------------------------------- ### Configure CMake Build Environment for AppImageUpdate Source: https://github.com/appimagecommunity/appimageupdate/blob/main/src/CMakeLists.txt This CMake configuration sets up the build environment by enforcing position-independent code, locating required system libraries, and defining versioning macros. It also manages conditional inclusion of subdirectories based on user-defined build options. ```cmake set(CMAKE_POSITION_INDEPENDENT_CODE true) find_package(Threads REQUIRED) find_package(X11 REQUIRED) if(NOT ${X11_Xpm_FOUND}) message(FATAL_ERROR "libxpm could not be found!") else() message(STATUS "Found libxpm: ${X11_Xpm_LIB}") endif() add_definitions("-DAPPIMAGEUPDATE_VERSION=\"${VERSION}\"") add_definitions("-DAPPIMAGEUPDATE_GIT_COMMIT=\"${GIT_COMMIT}\"") add_definitions("-DBUILD_DATE=\"${DATE}\"") add_definitions("-DBUILD_NUMBER=\"${BUILD_NUMBER}\"") if(USE_SYSTEM_ZSYNC2) set(ZSYNC2_LIBRARY_NAME libzsync2) set(ZSYNC2_LINK_TYPE PUBLIC) else() set(ZSYNC2_LIBRARY_NAME libzsync2_static) set(ZSYNC2_LINK_TYPE PRIVATE) endif() add_subdirectory(util) add_subdirectory(updateinformation) add_subdirectory(signing) add_subdirectory(updater) if(NOT BUILD_LIBAPPIMAGEUPDATE_ONLY) add_subdirectory(cli) add_subdirectory(validate) endif() if(BUILD_QT_UI) add_subdirectory(qt-ui) endif() ``` -------------------------------- ### Updater State Management Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Methods to monitor the lifecycle and progress of an update operation. ```APIDOC ## [METHOD] Updater::state ### Description Retrieves the current status of the update operation. Use in conjunction with isDone() and hasError() to handle flow control. ### Method C++ Method Call ### Response - **INITIALIZED** (Enum) - Updater ready. - **RUNNING** (Enum) - Update in progress. - **STOPPING** (Enum) - Update cancellation in progress. - **SUCCESS** (Enum) - Update finished successfully. - **ERROR** (Enum) - Update failed. ``` -------------------------------- ### Validate GPG Signature of AppImage Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Validates the GPG signature of an AppImage. It returns various states indicating success, warnings (e.g., unsigned AppImage), or errors (e.g., bad signature, key change). Dependencies include the appimage/update.h header. Handles status messages and performs actions like copying permissions or restoring the original file based on the validation result. ```cpp #include "appimage/update.h" #include using namespace appimage::update; void handleSignatureValidation(Updater& updater) { auto result = updater.validateSignature(); // Print status messages from validation std::string message; while (updater.nextStatusMessage(message)) { std::cout << message << std::endl; } switch (result) { case Updater::VALIDATION_PASSED: std::cout << "Signature validation passed!" << std::endl; updater.copyPermissionsToNewFile(); break; case Updater::VALIDATION_NOT_SIGNED: std::cout << "Warning: AppImage is not signed" << std::endl; updater.copyPermissionsToNewFile(); break; case Updater::VALIDATION_WARNING: std::cout << "Warning: " << Updater::signatureValidationMessage(result) << std::endl; updater.copyPermissionsToNewFile(); break; case Updater::VALIDATION_KEY_CHANGED: std::cerr << "Error: Signing key has changed!" << std::endl; std::cerr << "This could indicate a security issue." << std::endl; updater.restoreOriginalFile(); break; case Updater::VALIDATION_NO_LONGER_SIGNED: std::cerr << "Error: AppImage was previously signed but no longer is!" << std::endl; updater.restoreOriginalFile(); break; case Updater::VALIDATION_BAD_SIGNATURE: std::cerr << "Error: Bad signature detected!" << std::endl; updater.restoreOriginalFile(); break; default: std::cerr << "Error: " << Updater::signatureValidationMessage(result) << std::endl; updater.restoreOriginalFile(); break; } } ``` -------------------------------- ### QtUpdater::checkForUpdates - Check for Updates (C++) Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Checks for available updates for an AppImage without displaying a dialog. It returns an integer status code indicating whether an update is available, not found, or if an error occurred. This function is useful for integrating update checks into existing Qt applications. ```cpp #include "appimage/update/qt-ui.h" #include #include using namespace appimage::update::qt; void checkAndPromptUpdate(const QString& appImagePath) { QtUpdater updater(appImagePath); // Check for updates (optionally write status to stderr) int result = updater.checkForUpdates(true); switch (result) { case 0: // No update available QMessageBox::information(nullptr, "Updates", "Your application is up to date!"); break; case 1: // Update available - show update dialog if (QMessageBox::question(nullptr, "Update Available", "A new version is available. Update now?") == QMessageBox::Yes) { QtUpdater* dialog = new QtUpdater(appImagePath); dialog->enableRunUpdatedAppImageButton(true); dialog->exec(); delete dialog; } break; case -1: QMessageBox::warning(nullptr, "Updates", "No update information found in this AppImage."); break; default: QMessageBox::critical(nullptr, "Updates", "Error checking for updates."); break; } } ``` -------------------------------- ### Monitor Updater State Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Monitors the current state of an AppImage update operation. It uses the `Updater::State` enum and methods like `state()`, `isDone()`, and `hasError()` to determine the progress and outcome of the update. The state can be INITIALIZED, RUNNING, STOPPING, SUCCESS, or ERROR. ```cpp #include "appimage/update.h" #include using namespace appimage::update; void monitorUpdateState(Updater& updater) { // State values: // INITIALIZED - Updater created but not started // RUNNING - Update in progress // STOPPING - Stop requested, finishing up // SUCCESS - Update completed successfully // ERROR - Update failed switch (updater.state()) { case Updater::INITIALIZED: std::cout << "Ready to start update" << std::endl; break; case Updater::RUNNING: std::cout << "Update in progress..." << std::endl; break; case Updater::STOPPING: std::cout << "Stopping update..." << std::endl; break; case Updater::SUCCESS: std::cout << "Update completed successfully!" << std::endl; break; case Updater::ERROR: std::cout << "Update failed!" << std::endl; break; } // Convenience methods if (updater.isDone()) { // Returns true for SUCCESS, ERROR, or any terminal state if (!updater.hasError()) { std::cout << "Update successful" << std::endl; } } } ``` -------------------------------- ### Updater::validateSignature Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt Validates the GPG signature of an updated AppImage against the original to ensure integrity and authenticity. ```APIDOC ## [METHOD] Updater::validateSignature ### Description Validates the GPG signature of the updated AppImage. Returns status codes indicating success, warnings (e.g., unsigned), or security errors (e.g., key change, bad signature). ### Method C++ Method Call ### Parameters - **None** ### Response #### Success Response - **VALIDATION_PASSED** (Enum) - Signature is valid. - **VALIDATION_NOT_SIGNED** (Enum) - AppImage is not signed. - **VALIDATION_WARNING** (Enum) - Non-critical validation warning. #### Error Response - **VALIDATION_KEY_CHANGED** (Enum) - Signing key mismatch. - **VALIDATION_NO_LONGER_SIGNED** (Enum) - Previously signed, now unsigned. - **VALIDATION_BAD_SIGNATURE** (Enum) - Signature verification failed. ``` -------------------------------- ### Updater Class API Source: https://context7.com/appimagecommunity/appimageupdate/llms.txt The Updater class is the primary interface for managing the lifecycle of an AppImage update, including checking for changes, executing the download, and validating signatures. ```APIDOC ## CLASS appimage::update::Updater ### Description The Updater class provides an asynchronous interface to check for, download, and validate updates for a specific AppImage file. ### Constructor `Updater(const std::string& pathToAppImage, bool overwrite)` - **pathToAppImage** (string) - Required - Absolute path to the AppImage file. - **overwrite** (bool) - Required - If true, replaces the original file; if false, creates a new file. ### Methods - **checkForChanges(bool& updateAvailable)** (bool) - Checks the embedded update information for a newer version. - **start()** (bool) - Initiates the asynchronous update process in a background thread. - **isDone()** (bool) - Returns true if the update process has finished. - **progress(double& progress)** (bool) - Retrieves the current completion percentage (0.0 to 1.0). - **nextStatusMessage(std::string& message)** (bool) - Retrieves the next available status log message. - **validateSignature()** (int) - Validates the GPG signature of the downloaded file. Returns a status code (e.g., VALIDATION_FAILED). - **copyPermissionsToNewFile()** (void) - Applies the original file's permissions to the updated file. ### Request Example ```cpp Updater updater("/path/to/MyApp.AppImage", false); updater.start(); ``` ### Response #### Success Response - **updateAvailable** (bool) - Indicates if a newer version exists. - **progress** (double) - Current update progress. - **validationResult** (int) - Result of the GPG signature check. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.