NDEVR
API Documentation
UpdateChecker.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: UpdateChecker
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/SoftwareService.h>
34#include <NDEVR/ItemDownloader.h>
35#include <NDEVR/ApplicationResource.h>
36#include <NDEVR/File.h>
37#include <NDEVR/String.h>
38#include <NDEVR/Time.h>
39#include <NDEVR/TimeSpan.h>
40#include <NDEVR/INIFactory.h>
41#include <QObject>
42#include <QPointer>
43#ifndef Q_OS_WASM
44namespace NDEVR
45{
49 class NDEVR_WIDGETS_API UpdateChecker : public QObject, public SoftwareService
50 {
51 Q_OBJECT
52 public:
63
68 UpdateChecker(StringView update_version);
71 virtual void requestCheckForUpdate(const StringView& current_version = StringView()) = 0;
74 virtual bool requstDownloadUpdate();
78 virtual bool requestInstallUpdate(bool wait_for_completion = false);
81 virtual bool updateSupported() const;
84 virtual String updateName() const { return m_update_file_name; };
87 virtual String updateVersion() const { return m_update_version; };
90 virtual String updateURLPage() const = 0;
93 virtual String updateURLDownload() const { return m_update_url; };
96 virtual bool updateRequiresApplicationClose() const;
109 virtual void createUpdateFile(const String& installer_url, File output_location);
112 virtual void processUpdateString(const String& s);
134 void setMaxNoUpdateTime(const TimeSpan& max_no_update_check_time);
137 virtual String defaultURLPathName() const;
147 public:
149 signals:
155 void updateDownloadCompletedSignal(const File& location);
162 protected slots:
167 protected:
169 virtual void onCheckForUpdateComplete(){};
170 protected:
173 QPointer<ItemDownloader> m_downloader;
180 private:
182 void init();
184 };
185
188 class NDEVR_WIDGETS_API UpdateCheckManager : public SoftwareServiceManager
189 {
190 public:
200 private:
201 static UpdateChecker* s_app_update_checker;
202 };
203}
204#endif
The default object to store data of any type that should persist through sessions of the application.
ReleaseType
The release maturity level of the application build.
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
Contains methods for easily reading and writing to an INI file including efficient casting,...
Definition INIReader.h:107
Software Service Managers take a Software service to modify the behavior of the software.
Base interface for services that extend or modify software behavior through modules.
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
Provides place to set an update checker for checking for software updates.
static void SetApplicationUpdateChecker(UpdateChecker *checker)
Sets the global application update checker.
static Time CompileTime()
Returns the compile time of the application.
static UpdateChecker * ApplicationUpdateChecker()
Returns the global application update checker.
Provides logic for checking a source, typically online, for an update to the software.
ApplicationResource::ReleaseType recommendedReleaseType() const
Returns the recommended release type based on user preference and availability.
void checkForUpdateCompleteSlot()
Slot invoked when the update check network request completes.
void setReleaseTypes(const Buffer< ApplicationResource::ReleaseType > &types)
Sets the available release types for the update checker.
Time lastUpdateCheckTime() const
Returns the time of the last update check.
virtual INIFactory getINI()
Returns an INI factory configured for update settings.
virtual String updateName() const
Returns the file name of the available update.
Time m_last_application_update_check
The time of the last update check.
virtual bool requestInstallUpdate(bool wait_for_completion=false)
Requests installation of the downloaded update.
void checkForUpdateCompletedSignal(UpdateStatus update)
Signal emitted when an update check completes.
void appStartupCheck()
Performs an update check at application startup if enough time has elapsed.
void showUpdateDialogIfNeeded()
Shows a dialog prompting the user to update if one is available.
virtual String defaultURLPathName() const
Returns the default URL path segment used for update requests.
void setUpdateStatus(UpdateStatus status)
Sets the current update status and emits statusChangedSignal.
static ApplicationOption< ApplicationResource::ReleaseType > release_check_type
The user's preferred release type for update checks.
File updateFile() const
Returns the local file path of the downloaded update.
TimeSpan m_max_no_update_time
The maximum allowed time between automatic update checks.
void setMaxNoUpdateTime(const TimeSpan &max_no_update_check_time)
Sets the maximum time between automatic update checks.
String m_current_version
The current application version string.
String m_update_file_name
The file name of the available update.
virtual void requestCheckForUpdate(const StringView &current_version=StringView())=0
Initiates an asynchronous check for available updates.
virtual bool updateSupported() const
Returns whether software updates are supported on this platform.
QPointer< ItemDownloader > m_downloader
The downloader managing the update file transfer.
virtual bool updateRequiresApplicationClose() const
Returns whether the update requires closing the application first.
String m_update_url
The download URL for the available update.
virtual String updateVersion() const
Returns the version string of the available update.
File m_download_location
The local file path for downloaded updates.
String m_update_version
The version string of the available update.
UpdateStatus
The possible states of the update check/download lifecycle.
@ e_need_to_check
An update check has not yet been performed.
@ e_update_available_to_download
A new version is available for download.
@ e_update_available_to_install
A downloaded update is ready to install.
@ e_unsupported
Updates are not supported on this platform.
@ e_could_not_connect
Failed to connect to the update server.
@ e_no_new_updates
The software is up to date.
void releaseTypesChangedSignal()
Signal emitted when the available release types change.
virtual void onCheckForUpdateComplete()
Virtual callback invoked when an update check completes.
virtual String updateURLPage() const =0
Returns the URL of the update information page.
uint08 totalDownloadSize() const
Returns the total size of the update download.
virtual String updateURLDownload() const
Returns the direct download URL for the update.
UpdateChecker()
Constructs an UpdateChecker with default settings.
void statusChangedSignal()
Signal emitted when the update status changes.
UpdateStatus updateStatus() const
Returns the current update status.
fltp08 downloadPercent() const
Returns the download progress as a percentage.
virtual void processUpdateString(const String &s)
Parses an update response string to extract version and URL information.
virtual void createUpdateFile(const String &installer_url, File output_location)
Creates an update file from the given installer URL.
Buffer< ApplicationResource::ReleaseType > m_release_types
The available release types.
virtual bool requstDownloadUpdate()
Requests download of the available update.
UpdateChecker(StringView update_version)
Constructs an UpdateChecker with a known current version.
uint08 currentDownloadSize() const
Returns the number of bytes downloaded so far.
void percentChangedSignal()
Signal emitted when download progress changes.
const Buffer< ApplicationResource::ReleaseType > & availableReleaseTypes() const
Returns the list of available release types for this application.
void onUpdateDownloadCompleteSlot()
Slot invoked when the update file download completes.
void updateDownloadCompletedSignal(const File &location)
Signal emitted when an update download completes.
The primary namespace for the NDEVR SDK.
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
double fltp08
Defines an alias representing an 8 byte floating-point number.