Skip to content

Commit

Permalink
Get and send Windows version
Browse files Browse the repository at this point in the history
  • Loading branch information
ocdtrekkie committed Jun 17, 2024
1 parent 076b8c1 commit 2948be3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
[assembly: AssemblyVersion("1.0.0.2")]
[assembly: AssemblyFileVersion("1.0.0.2")]
1 change: 1 addition & 0 deletions XRFAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected override void OnStart(string[] args)
modUpdate.CheckVersion();
modDatabase.Load();
modLogging.LogEvent("Database connected", EventLogEntryType.Information);
modSystem.GetWindowsVersion();
modNetwork.Load();
modSync.Load();

Expand Down
4 changes: 2 additions & 2 deletions XRFAgent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -24,9 +25,8 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationRevision>2</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion docs/ErrorCodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
6021 - Update check failed
6022 - Update failed

6031 - External process start error
6031 - External process start error
6032 - Registry access error
3 changes: 2 additions & 1 deletion modSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public static async void SendMessage(string Destination, string MessageType, str
{
HttpClient MessageClient = new HttpClient();
string publicIP = modDatabase.GetConfig("Ping_LastKnownPublicIP");
HttpRequestMessage MessageBuilder = new HttpRequestMessage(HttpMethod.Post, Sync_ServerURL + "?message_type=" + MessageType + "&destination=" + Destination + "&access_key=" + Sync_AccessKey + "&message=" + Message + "&user_agent=XRFAgent/" + Assembly.GetExecutingAssembly().GetName().Version + "&ip_address=" + publicIP);
string windowsVersion = modDatabase.GetConfig("System_LastKnownWindowsVersion");
HttpRequestMessage MessageBuilder = new HttpRequestMessage(HttpMethod.Post, Sync_ServerURL + "?message_type=" + MessageType + "&destination=" + Destination + "&access_key=" + Sync_AccessKey + "&message=" + Message + "&user_agent=XRFAgent/" + Assembly.GetExecutingAssembly().GetName().Version + "&ip_address=" + publicIP + "&windows_version=" + windowsVersion);
TimeSpan httpTimeout = TimeSpan.FromSeconds(10);
MessageClient.Timeout = httpTimeout;
string EncodedCreds = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes("sandstorm:" + Sync_SandstormToken));
Expand Down
27 changes: 27 additions & 0 deletions modSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using Microsoft.Win32;

namespace XRFAgent
{
Expand All @@ -15,6 +16,32 @@ public static void Load() { }
/// </summary>
public static void Unload() { }

/// <summary>
/// Gets a full Windows build number from the registry
/// </summary>
/// <returns>(string) Build number</returns>
public static string GetWindowsVersion()
{
try
{
RegistryKey currentVersion = Registry.LocalMachine.OpenSubKey("SOFTWARE\\MICROSOFT\\Windows NT\\CurrentVersion");
string currentWindowsVersion = currentVersion.GetValue("CurrentMajorVersionNumber").ToString() + "." + currentVersion.GetValue("CurrentMinorVersionNumber").ToString() + "." + currentVersion.GetValue("CurrentBuild").ToString() + "." + currentVersion.GetValue("UBR").ToString();

string oldWindowsVersion = modDatabase.GetConfig("System_LastKnownWindowsVersion");
if (oldWindowsVersion != currentWindowsVersion)
{
modDatabase.AddOrUpdateConfig(new modDatabase.Config { Key = "System_LastKnownWindowsVersion", Value = currentWindowsVersion });
}

return currentWindowsVersion;
}
catch(Exception err)
{
modLogging.LogEvent("Unable to get registry information: " + err.Message, EventLogEntryType.Error, 6032);
return "Registry error";
}
}

/// <summary>
/// Reboots the host computer
/// </summary>
Expand Down

0 comments on commit 2948be3

Please sign in to comment.