diff options
author | Jake Petroules <jake.petroules@qt.io> | 2016-12-19 18:56:46 -0800 |
---|---|---|
committer | Jake Petroules <jake.petroules@qt.io> | 2017-01-12 02:13:21 +0000 |
commit | 2b928ef6f95c528449d6ec9650325f3ccaac5094 (patch) | |
tree | cfffe1bfa4e027f6de84773137232f96543a8636 /src/corelib/kernel/qcoreapplication_win.cpp | |
parent | 5865e582fd537fff530c13301e5229a7b4ed21c7 (diff) |
Provide sensible defaults for QCoreApplication::applicationVersion
[ChangeLog][QtCore] QCoreApplication::applicationVersion now defaults to
an appropriate platform-specific value. On Windows, it defaults to the
PRODUCTVERSION parameter of the VERSIONINFO resource for classic desktop
apps, and the version attribute of the application package manifest for
Univeral Windows Platform apps. On Apple Platforms (macOS, iOS, tvOS,
watchOS), it defaults to the CFBundleVersion property of the information
property list (Info.plist) file. On Android, it defaults to the
android:versionName attribute of the AndroidManifest.xml manifest
element. On other platforms, the default remains an empty string.
Task-number: QTBUG-57715
Change-Id: I26f83dd00737e06f4321cf962aa5fab8398104ec
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qcoreapplication_win.cpp')
-rw-r--r-- | src/corelib/kernel/qcoreapplication_win.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/corelib/kernel/qcoreapplication_win.cpp b/src/corelib/kernel/qcoreapplication_win.cpp index 67e509eeef..4057c03b84 100644 --- a/src/corelib/kernel/qcoreapplication_win.cpp +++ b/src/corelib/kernel/qcoreapplication_win.cpp @@ -51,6 +51,16 @@ #include <ctype.h> #include <qt_windows.h> +#ifdef Q_OS_WINRT +#include <qfunctions_winrt.h> +#include <wrl.h> +#include <Windows.ApplicationModel.core.h> +#include <windows.foundation.h> +using namespace ABI::Windows::ApplicationModel; +using namespace Microsoft::WRL; +using namespace Microsoft::WRL::Wrappers; +#endif + QT_BEGIN_NAMESPACE int appCmdShow = 0; @@ -118,6 +128,64 @@ QString QCoreApplicationPrivate::appName() const return QFileInfo(qAppFileName()).baseName(); } +QString QCoreApplicationPrivate::appVersion() const +{ + QString applicationVersion; +#ifndef QT_BOOTSTRAPPED +# ifdef Q_OS_WINRT + HRESULT hr; + + ComPtr<IPackageStatics> packageFactory; + hr = RoGetActivationFactory( + HString::MakeReference(RuntimeClass_Windows_ApplicationModel_Package).Get(), + IID_PPV_ARGS(&packageFactory)); + RETURN_IF_FAILED("Failed to create package instance", return QString()); + + ComPtr<IPackage> package; + packageFactory->get_Current(&package); + RETURN_IF_FAILED("Failed to get current application package", return QString()); + + ComPtr<IPackageId> packageId; + package->get_Id(&packageId); + RETURN_IF_FAILED("Failed to get current application package ID", return QString()); + + PackageVersion version; + packageId->get_Version(&version); + RETURN_IF_FAILED("Failed to get current application package version", return QString()); + + applicationVersion = QStringLiteral("%1.%2.%3.%4") + .arg(version.Major) + .arg(version.Minor) + .arg(version.Build) + .arg(version.Revision); +# else + const QString appFileName = qAppFileName(); + QVarLengthArray<wchar_t> buffer(appFileName.size() + 1); + buffer[appFileName.toWCharArray(buffer.data())] = 0; + + DWORD versionInfoSize = GetFileVersionInfoSize(buffer.data(), nullptr); + if (versionInfoSize) { + QVarLengthArray<BYTE> info(static_cast<int>(versionInfoSize)); + if (GetFileVersionInfo(buffer.data(), 0, versionInfoSize, info.data())) { + UINT size; + DWORD *fi; + + if (VerQueryValue(info.data(), __TEXT("\\"), + reinterpret_cast<void **>(&fi), &size) && size) { + const VS_FIXEDFILEINFO *verInfo = reinterpret_cast<const VS_FIXEDFILEINFO *>(fi); + applicationVersion = QStringLiteral("%1.%2.%3.%4") + .arg(HIWORD(verInfo->dwProductVersionMS)) + .arg(LOWORD(verInfo->dwProductVersionMS)) + .arg(HIWORD(verInfo->dwProductVersionLS)) + .arg(LOWORD(verInfo->dwProductVersionLS)); + } + } + } +# endif +#endif + return applicationVersion; +} + #endif // !(defined(Q_OS_WINRT) && _MSC_VER < 1900) #ifndef Q_OS_WINRT |