summaryrefslogtreecommitdiff
path: root/src/envwindows.h
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-07-18 23:13:57 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-07-22 07:33:38 -0400
commitb2a1e1391fdd6bdee1c5e8d337b273447c70a506 (patch)
treebbcee13a329fd9276a43a2d524f48ff83c32517b /src/envwindows.h
parentf95479b981b41f51a3ecf055c73f42440766e5d7 (diff)
split env
Diffstat (limited to 'src/envwindows.h')
-rw-r--r--src/envwindows.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/envwindows.h b/src/envwindows.h
new file mode 100644
index 00000000..c23f99f4
--- /dev/null
+++ b/src/envwindows.h
@@ -0,0 +1,106 @@
+#include <QString>
+#include <optional>
+
+namespace env
+{
+
+// a variety of information on windows
+//
+class WindowsInfo
+{
+public:
+ struct Version
+ {
+ DWORD major=0, minor=0, build=0;
+
+ QString toString() const
+ {
+ return QString("%1.%2.%3").arg(major).arg(minor).arg(build);
+ }
+
+ friend bool operator==(const Version& a, const Version& b)
+ {
+ return
+ a.major == b.major &&
+ a.minor == b.minor &&
+ a.build == b.build;
+ }
+
+ friend bool operator!=(const Version& a, const Version& b)
+ {
+ return !(a == b);
+ }
+ };
+
+ struct Release
+ {
+ // the BuildLab entry from the registry, may be empty
+ QString buildLab;
+
+ // product name such as "Windows 10 Pro", may not be in English, may be
+ // empty
+ QString productName;
+
+ // release ID such as 1809, may be mepty
+ QString ID;
+
+ // some sub-build number, undocumented, may be empty
+ DWORD UBR;
+
+ Release()
+ : UBR(0)
+ {
+ }
+ };
+
+
+ WindowsInfo();
+
+ // tries to guess whether this process is running in compatibility mode
+ //
+ bool compatibilityMode() const;
+
+ // returns the Windows version, may not correspond to the actual version
+ // if the process is running in compatibility mode
+ //
+ const Version& reportedVersion() const;
+
+ // tries to guess the real Windows version that's running, can be empty
+ //
+ const Version& realVersion() const;
+
+ // various information about the current release
+ //
+ const Release& release() const;
+
+ // whether this process is running as administrator, may be empty if the
+ // information is not available
+ std::optional<bool> isElevated() const;
+
+ // returns a string with all the above information on one line
+ //
+ QString toString() const;
+
+private:
+ Version m_reported, m_real;
+ Release m_release;
+ std::optional<bool> m_elevated;
+
+ // uses RtlGetVersion() to get the version number as reported by Windows
+ //
+ Version getReportedVersion(HINSTANCE ntdll) const;
+
+ // uses RtlGetNtVersionNumbers() to get the real version number
+ //
+ Version getRealVersion(HINSTANCE ntdll) const;
+
+ // gets various information from the registry
+ //
+ Release getRelease() const;
+
+ // gets whether the process is elevated
+ //
+ std::optional<bool> getElevated() const;
+};
+
+} // namespace