diff options
author | Kai Koehne <kai.koehne@theqtcompany.com> | 2014-12-03 10:41:48 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2014-12-05 14:02:38 +0100 |
commit | de748023e53ce84afd01cde0ca380cddad057a4d (patch) | |
tree | 9f20ee8f0e374ac97ac37f8df2fa8ba56341481b /examples | |
parent | 587bc6fb7c905422c3f09bc8ea2ac91c91d25cc8 (diff) |
Expose systemInfo API
Add systemInfo as a wrapper for QSystemInfo.
Task-number: QTIFW-592
Change-Id: Ib54fcea8b0ef3a397a74f5315202f3000abd63cd
Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@theqtcompany.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/doc/systeminfo.qdoc | 116 | ||||
-rw-r--r-- | examples/examples.pro | 3 | ||||
-rw-r--r-- | examples/systeminfo/README | 13 | ||||
-rw-r--r-- | examples/systeminfo/config/config.xml | 10 | ||||
-rw-r--r-- | examples/systeminfo/packages/root.i386/meta/package.xml | 8 | ||||
-rw-r--r-- | examples/systeminfo/packages/root.x86_64/meta/package.xml | 8 | ||||
-rw-r--r-- | examples/systeminfo/packages/root/meta/installscript.qs | 121 | ||||
-rw-r--r-- | examples/systeminfo/packages/root/meta/package.xml | 8 | ||||
-rw-r--r-- | examples/systeminfo/systeminfo.pro | 13 |
9 files changed, 299 insertions, 1 deletions
diff --git a/examples/doc/systeminfo.qdoc b/examples/doc/systeminfo.qdoc new file mode 100644 index 000000000..bd5ed2779 --- /dev/null +++ b/examples/doc/systeminfo.qdoc @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example systeminfo + \ingroup qtifwexamples + \title System Information Example + + \brief Checking operating system version and bitness in a script. + + The \e{System Information Example} demonstrates how to use the \l{systemInfo} API to detect + details about the target operating system. + + The example installer consists of three packages: \c root, \c root.i386 and \c root.x86_64. + The \c root.i386 and \c root.x86_64 packages are assumed to contain binaries specific to the + architecture. The \c root package contains logic to check for minimum operating system version. + It also hides either the \c root.i386 or \c root.x86_64 package, based on the operating system + architecture. + + The logic to detect the operating system features is scripted in the + \c{root}'s \l{systeminfo/packages/root/meta/installscript.qs}{installscript.qs} file. + + \quotefromfile systeminfo/packages/root/meta/installscript.qs + + \section1 Helper Functions + + The \l{systeminfo/packages/root/meta/installscript.qs}{installscript.qs} file first + declares two helper functions: \c cancelInstaller() and \c majorVersion(). + + \skipto cancelInstaller + \printuntil /^\}/ + + \c cancelInstaller() sets all except the last installer page to invisible, and shows an error + message on the last one. This is a technique also demonstrated in the \l{componenterror} and + \l{quit_installer} examples. + + \skipto majorVersion + + \printuntil /^\}/ + + \c majorVersion() takes a string of the format \c {<number>.<number>.<number>.[...]}. + It uses the built-in JavaScript functions \c string.split() and \c parseInt() to return the + first \c <number> as an integer. + + \section1 Checking the Operating System Type + + The actual checks are executed as soon as the package is loaded, in the \c Component constructor + function. + + \skipto /function Component/ + \printuntil /\{/ + + The function uses the built-in \l{systemInfo::kernelType}{systemInfo.kernelType}, + \l{systemInfo::kernelVersion}{systemInfo.kernelVersion}, \l{systemInfo::productType}, + and \l{systemInfo::productVersion}{systemInfo.productVersion} properties to check the minimum + system requirements. + + \skipto validOs + \printto /\!validOs/ + + The script uses \l{systemInfo::productType}{systemInfo.productType} to differentiate + between Windows, OS X, and individual Linux distributions. + + For OS X and Windows, the script checks the operating system kernel version. + For a mapping of kernel to operating system versions, see + \l{http://en.wikipedia.org/wiki/Darwin_%28operating_system%29}{Darwin} and + \l{http://en.wikipedia.org/wiki/Windows_NT}{Windows NT}. + + In the case of Linux, it checks the distribution name and version. If it does not match + the specific distribution and version the binaries are presumably built for, + the installer shows a warning in a modal dialog, but allows installation. + + If the Windows or OS X version is too old, though, the script calls the \c cancelInstaller() + helper function to prevent an actual installation: + + \printuntil /\}/ + + \section1 Checking the Operating System Architecture + + The next section demonstrates the use of + \l{systemInfo::currentCpuArchitecture}{systemInfo.currentCpuArchitecture} to choose + the appropriate sub-package for a particular architecture: + + \skipto root.i386 + \printuntil /^\}/ + + Depending on the operating system architecture, either the package \c root.i386 or + \c root.x86_64 is marked \c Virtual, hiding it from the user. For the package that matches + the local architecture, the \c Default property is set to check the package by default. + + \include installerfw-examples-generating.qdocinc +*/ diff --git a/examples/examples.pro b/examples/examples.pro index ac886cd8a..1e5a816cd 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -9,4 +9,5 @@ SUBDIRS += \ openreadme \ quit_installer \ registerfileextension \ - startmenu + startmenu \ + systeminfo diff --git a/examples/systeminfo/README b/examples/systeminfo/README new file mode 100644 index 000000000..69440c088 --- /dev/null +++ b/examples/systeminfo/README @@ -0,0 +1,13 @@ +Shows how to use the systemInfo JS API. + +The installer rejects installations on Windows XP, +and OS X 10.6 or older. It shows a warning if +it is run on any Linux distribution other than openSUSE 13.2. + +It also shows only one of the two sub-packages, based on +the CPU architecture: "i386" on an 32-bit system, and +"x86_64" on an 64-bit system. + +Generate installer with + +binarycreator --offline-only -c config/config.xml -p packages installer diff --git a/examples/systeminfo/config/config.xml b/examples/systeminfo/config/config.xml new file mode 100644 index 000000000..ffbfd9d7f --- /dev/null +++ b/examples/systeminfo/config/config.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Installer> + <Name>SystemInfo Example</Name> + <Version>1.0.0</Version> + <Title>SystemInfo Example</Title> + <Publisher>The Qt Company</Publisher> + <!-- Directory name is used in component.xml --> + <StartMenuDir>Qt Installer Framework Example</StartMenuDir> + <TargetDir>@HomeDir@/IFWSystemInfoExample</TargetDir> +</Installer> diff --git a/examples/systeminfo/packages/root.i386/meta/package.xml b/examples/systeminfo/packages/root.i386/meta/package.xml new file mode 100644 index 000000000..4d56928ce --- /dev/null +++ b/examples/systeminfo/packages/root.i386/meta/package.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Package> + <DisplayName>i386 binaries</DisplayName> + <Description>Binaries that require a x86 CPU.</Description> + <Version>1.0.0-1</Version> + <ReleaseDate>2014-12-01</ReleaseDate> + <Default>false</Default> +</Package> diff --git a/examples/systeminfo/packages/root.x86_64/meta/package.xml b/examples/systeminfo/packages/root.x86_64/meta/package.xml new file mode 100644 index 000000000..66cffdfd4 --- /dev/null +++ b/examples/systeminfo/packages/root.x86_64/meta/package.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Package> + <DisplayName>x86-64 bit binaries</DisplayName> + <Description>Binaries that require a x86-64 CPU.</Description> + <Version>1.0.0-1</Version> + <ReleaseDate>2014-12-01</ReleaseDate> + <Default>false</Default> +</Package> diff --git a/examples/systeminfo/packages/root/meta/installscript.qs b/examples/systeminfo/packages/root/meta/installscript.qs new file mode 100644 index 000000000..213a3c42c --- /dev/null +++ b/examples/systeminfo/packages/root/meta/installscript.qs @@ -0,0 +1,121 @@ +/************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +// Skip all pages and go directly to finished page. +// (see also componenterror example) +function cancelInstaller(message) +{ + installer.setDefaultPageVisible(QInstaller.Introduction, false); + installer.setDefaultPageVisible(QInstaller.TargetDirectory, false); + installer.setDefaultPageVisible(QInstaller.ComponentSelection, false); + installer.setDefaultPageVisible(QInstaller.ReadyForInstallation, false); + installer.setDefaultPageVisible(QInstaller.StartMenuSelection, false); + installer.setDefaultPageVisible(QInstaller.PerformInstallation, false); + installer.setDefaultPageVisible(QInstaller.LicenseCheck, false); + + var abortText = "<font color='red'>" + message +"</font>"; + installer.setValue("FinishedText", abortText); +} + +// Returns the major version number as int +// string.split(".", 1) returns the string before the first '.', +// parseInt() converts it to an int. +function majorVersion(str) +{ + return parseInt(str.split(".", 1)); +} + +function Component() +{ + // + // Check whether OS is supported. + // + // For Windows and OS X we check the kernel version: + // - Require at least Windows Vista (winnt kernel version 6.0.x) + // - Require at least OS X 10.7 (Lion) (darwin kernel version 11.x) + // + // If the kernel version is older we move directly + // to the final page & show an error. + // + // For Linux, we check the distribution and version, but only + // show a warning if it does not match our preferred distribution. + // + + // start installer with -v to see debug output + console.log("OS: " + systemInfo.productType); + console.log("Kernel: " + systemInfo.kernelType + "/" + systemInfo.kernelVersion); + + var validOs = false; + + if (systemInfo.kernelType === "winnt") { + if (majorVersion(systemInfo.kernelVersion) >= 6) + validOs = true; + } else if (systemInfo.kernelType === "darwin") { + if (majorVersion(systemInfo.kernelVersion) >= 11) + validOs = true; + } else { + if (systemInfo.productType !== "opensuse" + || systemInfo.productVersion !== "13.2") { + QMessageBox["warning"]("os.warning", "Installer", + "Note that the binaries are only tested on OpenSUSE 13.2.", + QMessageBox.Ok); + } + validOs = true; + } + + if (!validOs) { + cancelInstaller("Installation on " + systemInfo.prettyProductName + " is not supported"); + return; + } + + // + // Hide/select packages based on architecture + // + // Marking a component as "Virtual" will hide it in the UI. + // Marking a component with "Default" will check it. + // + console.log("CPU Architecture: " + systemInfo.currentCpuArchitecture); + + installer.componentByName("root.i386").setValue("Virtual", "true"); + installer.componentByName("root.x86_64").setValue("Virtual", "true"); + + if ( systemInfo.currentCpuArchitecture === "i386") { + installer.componentByName("root.i386").setValue("Virtual", "false"); + installer.componentByName("root.i386").setValue("Default", "true"); + } + if ( systemInfo.currentCpuArchitecture === "x86_64") { + installer.componentByName("root.x86_64").setValue("Virtual", "false"); + installer.componentByName("root.x86_64").setValue("Default", "true"); + } +} diff --git a/examples/systeminfo/packages/root/meta/package.xml b/examples/systeminfo/packages/root/meta/package.xml new file mode 100644 index 000000000..0e67c1bc9 --- /dev/null +++ b/examples/systeminfo/packages/root/meta/package.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Package> + <DisplayName>systemInfo example</DisplayName> + <Description>Shows the use of the systemInfo JS API.</Description> + <Version>1.0.0-1</Version> + <ReleaseDate>2013-01-01</ReleaseDate> + <Script>installscript.qs</Script> +</Package> diff --git a/examples/systeminfo/systeminfo.pro b/examples/systeminfo/systeminfo.pro new file mode 100644 index 000000000..415df49d5 --- /dev/null +++ b/examples/systeminfo/systeminfo.pro @@ -0,0 +1,13 @@ +TEMPLATE = aux + +INSTALLER = installer + +INPUT = $$PWD/config/config.xml $$PWD/packages +example.input = INPUT +example.output = $$INSTALLER +example.commands = ../../bin/binarycreator -c $$PWD/config/config.xml -p $$PWD/packages ${QMAKE_FILE_OUT} +example.CONFIG += target_predeps no_link combine + +QMAKE_EXTRA_COMPILERS += example + +OTHER_FILES = README |