Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
Add static constructor to WindowsVersion struct
Browse files Browse the repository at this point in the history
  • Loading branch information
spikespaz committed Jul 6, 2020
1 parent 283e993 commit 5ff8640
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions source/common.d
Original file line number Diff line number Diff line change
Expand Up @@ -211,26 +211,27 @@ static struct DeflectorSettings {
}

/// Structure containing Windows version information
struct WindowsVersion {
static struct WindowsVersion {
/// ditto
string release, build, edition;
string release, build, edition, insiderRing;

/// Fetch all version info from registry
static WindowsVersion get() {
static this() {
try {
Key currentVersion = Registry.localMachine.getKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", REGSAM
.KEY_READ);

// dfmt off
return WindowsVersion(
currentVersion.getValue("ReleaseId").value_SZ,
currentVersion.getValue("CurrentBuildNumber").value_SZ,
currentVersion.getValue("EditionID").value_SZ,
);
// dfmt on
key insiderInfo = Registry.localMachine.getKey("SOFTWARE\\Microsoft\\WindowsSelfHost\\Applicability", REGSAM.KEY_READ);
insiderRing = insiderInfo.getValue("BranchName");
} catch (RegistryException)
insiderRing = null;

try {
Key currentVersion = Registry.localMachine.getKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", REGSAM.KEY_READ);

release = currentVersion.getValue("ReleaseId").value_SZ;
build = currentVersion.getValue("CurrentBuildNumber").value_SZ;
edition = currentVersion.getValue("EditionID").value_SZ;
} catch (RegistryException error) {
debug writeln(error.message);
return WindowsVersion("unknown", "unknown", "unknown");
release = build = edition = "unknown";
}
}
}
Expand Down

0 comments on commit 5ff8640

Please sign in to comment.