summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qcoreapplication_win.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel/qcoreapplication_win.cpp')
-rw-r--r--src/corelib/kernel/qcoreapplication_win.cpp85
1 files changed, 67 insertions, 18 deletions
diff --git a/src/corelib/kernel/qcoreapplication_win.cpp b/src/corelib/kernel/qcoreapplication_win.cpp
index a9ca82c757..50888dd0aa 100644
--- a/src/corelib/kernel/qcoreapplication_win.cpp
+++ b/src/corelib/kernel/qcoreapplication_win.cpp
@@ -51,27 +51,20 @@
#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;
-// GetModuleFileName only exists for MSVC2015 and upwards for WinRT, meaning
-// Windows 10 (Mobile). Hence take the first argument passed to the
-// QCoreApplication contructor for older versions as a fallback on older platforms.
-#if defined(Q_OS_WINRT) && _MSC_VER < 1900
-
-Q_CORE_EXPORT QString qAppFileName()
-{
- return QFileInfo(QCoreApplication::arguments().constFirst()).filePath();
-}
-
-QString QCoreApplicationPrivate::appName() const
-{
- return QFileInfo(QCoreApplication::arguments().constFirst()).baseName();
-}
-
-#else // !(defined(Q_OS_WINRT) && _MSC_VER < 1900)
-
Q_CORE_EXPORT QString qAppFileName() // get application file name
{
// We do MAX_PATH + 2 here, and request with MAX_PATH + 1, so we can handle all paths
@@ -118,7 +111,63 @@ QString QCoreApplicationPrivate::appName() const
return QFileInfo(qAppFileName()).baseName();
}
-#endif // !(defined(Q_OS_WINRT) && _MSC_VER < 1900)
+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;
+}
#ifndef Q_OS_WINRT