Skip to content

oclero/qtupdater

Repository files navigation

QtUpdater

License: MIT CMake version C++ version Qt version

Updater for Qt6 (auto-updates).


Table of Contents


Requirements

Features

This library contains:

  • A core: oclero::qtupdater::Updater.
  • A controller: oclero::qtupdater::Controller, that may be use with QtWidgets or QtQuick/QML.

It provides these features:

  • Get latest update information.
  • Get changelog.
  • Get installer.
  • Execute installer.
  • Temporarly stores the update data in the temp folder.
  • Verify checksum after downloading and before executing installer.

Usage

  1. Add the library as a dependency with CMake.

    find_package(QtUpdater REQUIRED)
  2. Link with the library in CMake.

    target_link_libraries(your_project oclero::QtUpdater)
  3. Include the only necessary header in your C++ file.

    #include <oclero/qtupdater/Updater.h>
  4. Use the oclero::qtupdater::Updater class to check for updates, download changelog and installer, and execute the installer. See the Client Example section for more details.

Server Specifications

Protocol

The protocol is the following:

  1. The client sends a GET request to the endpoint URL of your choice. Example (with curl):

    curl http://server/endpoint\?version\=latest
  2. The server answers by sending back an appcast: a JSON file containing the necessary information. The appcast must look like the following:

    {
      "version": "x.y.z",
      "date": "dd/MM/YYYY",
      "checksum": "418397de9ef332cd0e477ff5e8ca38d4",
      "checksumType": "md5",
      "installerUrl": "http://server/endpoint/package-name.exe",
      "changelogUrl": "http://server/endpoint/changelog-name.md"
    }
  3. The client downloads the changelog from changelogUrl, if any provided (facultative step).

  4. The client downloads the installer from installerUrl, if any provided.

  5. The client installs the installer:

    • The client may start the installer and quit, if necessary.
    • It may also move the downloaded file to some location.

Example

Client

Usage is straightforward:

using namespace oclero::qtupdater;

// Create an updater.
Updater updater("https://server/endpoint");

// Subscribe to all necessary signals. See documentation for complete list.
QObject::connect(&updater, &Updater::updateAvailabilityChanged,
                 &updater, [&updater]() {
  if (updater.updateAvailability() == UpdateAvailability::Available) {
    // An update is available!
    qDebug() << "Update available!"
      << " - You have: "
      << qPrintable(updater.currentVersion())
      << " - Latest is: "
      << qPrintable(updater.latestVersion());

  } else if (updater.updateAvailability() == UpdateAvailability::UpToDate) {
    // You have the latest version.
    qDebug() << "You have the latest version.";

  } else {
    // An error occurred.
    // Subscribe to checkForUpdateFailed() signal for more details.
    qDebug() << "Error.";
  }
});

// Start checking.
updater.checkForUpdate();

If you server does not provide a JSON in the expected format, you can use a custom parser:

updater.setAppCastParser([](const QByteArray& data) -> oclero::qtupdater::AppCast {
  // Your custom parsing code here.
});

When an update is available, you can download the changelog and installer:

// See signals changelogAvailableChanged() and installerAvailableChanged().
updater.downloadInstaller();

You can then execute the installer:

// This will start the installer and quit the application if necessary.
updater.installUpdate();

Server

A very basic development server written in Python is included as testing purposes during development. Don't use in production environment!

  • It does not implement any security mechanism, nor HTTPS.
  • It does not cache anything and reads files from disk on each request.

Setup

# Start with default config.
cd examples/dev_server
pip install -r requirements.txt
python main.py

# ... Or set your own config.
python main.py --dir /some-directory --port 8000 --address 127.0.0.1

File Structure

This development server expects files in the following format:

public/
  v1.0.0.json      # Version metadata
  v1.0.0.exe       # Windows installer (or .dmg for macOS)
  v1.0.0.md        # Changelog
  v1.1.0.json
  v1.1.0.exe
  v1.1.0.md
  # etc.

API

  • GET /?version=latest - Get latest version JSON.
  • GET / - Same as above.
  • GET /?version=1.0.0 - Get specific version JSON.
  • GET /v1.0.0.exe - Download installer.
  • GET /v1.0.0.md - Download changelog.

Author

Olivier Cléro | email | website | github | gitlab

License

QtUpdater is available under the MIT license. See the LICENSE file for more info.

About

Updater for Qt5, enabling application auto-updates.

Topics

Resources

License

Stars

Watchers

Forks

Contributors