Skip to content

Commit

Permalink
Removing RuntimeInformation dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
libgenapps committed Jan 19, 2018
1 parent 6510d2d commit 0b36a24
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 12 deletions.
1 change: 0 additions & 1 deletion LibgenDesktop.Setup/AppFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static string[] GetFileList(bool is64Bit)
"Dragablz.dll",
"System.Data.SQLite.dll",
"NLog.dll",
"System.Runtime.InteropServices.RuntimeInformation.dll",
(is64Bit ? "x64" : "x86") + @"\SQLite.Interop.dll",
"mirrors.config"
};
Expand Down
2 changes: 1 addition & 1 deletion LibgenDesktop.Setup/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
internal static class Constants
{
public const string CURRENT_VERSION = "0.10";
public const string CURRENT_VERSION = "0.10.1";
public const string PRODUCT_TITLE_FORMAT = "Libgen Desktop " + CURRENT_VERSION + " ({0}-bit)";
public const string SHORTCUT_TITLE_FORMAT = "Libgen Desktop ({0}-bit)";
public const string PRODUCT_COMPANY = "Libgen Apps";
Expand Down
2 changes: 1 addition & 1 deletion LibgenDesktop/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
internal static class Constants
{
public const string CURRENT_VERSION = "0.10";
public const string CURRENT_VERSION = "0.10.1";
public const string CURRENT_DATABASE_VERSION = "0.7";

public const string APP_SETTINGS_FILE_NAME = "libgen.config";
Expand Down
76 changes: 72 additions & 4 deletions LibgenDesktop/Common/Environment.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
using System;
using System.IO;
using System.Linq;
using System.Management;
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using static LibgenDesktop.Common.Constants;

namespace LibgenDesktop.Common
{
internal static class Environment
{
private const string NET_FRAMEWORK_REGISTRY_KEY = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";

static Environment()
{
AppBinariesDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Expand Down Expand Up @@ -44,9 +48,73 @@ static Environment()
LogFilePath = Path.Combine(AppDataDirectory, logFileName);
AppSettingsFilePath = Path.Combine(AppDataDirectory, APP_SETTINGS_FILE_NAME);
MirrorsFilePath = Path.Combine(AppBinariesDirectory, MIRRORS_FILE_NAME);
OsVersion = RuntimeInformation.OSDescription + RuntimeInformation.OSArchitecture;
NetFrameworkVersion = RuntimeInformation.FrameworkDescription;
IsIn64BitProcess = RuntimeInformation.ProcessArchitecture == Architecture.X64;
OsVersion = GetOsVersion();
NetFrameworkVersion = GetNetFrameworkVersion();
IsIn64BitProcess = System.Environment.Is64BitProcess;
}

private static string GetOsVersion()
{
ManagementObject osInfo = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").Get().OfType<ManagementObject>().FirstOrDefault();
if (osInfo != null)
{
return $"{osInfo.Properties["Caption"].Value.ToString()}{osInfo.Properties["Version"].Value.ToString()} {osInfo.Properties["OSArchitecture"].Value.ToString()}";
}
else
{
return "Unknown";
}
}

private static string GetNetFrameworkVersion()
{
using (RegistryKey netFrameworkRegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).
OpenSubKey(NET_FRAMEWORK_REGISTRY_KEY))
{
if (netFrameworkRegistryKey != null)
{
object releaseValue = netFrameworkRegistryKey.GetValue("Release");
if (releaseValue != null)
{
if (Int32.TryParse(releaseValue.ToString(), out int releaseNumber))
{
if (releaseNumber >= 461308)
{
return "4.7.1 or later";
}
else if (releaseNumber >= 460798)
{
return "4.7";
}
else if (releaseNumber >= 394802)
{
return "4.6.2";
}
else if (releaseNumber >= 394254)
{
return "4.6.1";
}
else if (releaseNumber >= 393295)
{
return "4.6";
}
else if (releaseNumber >= 379893)
{
return "4.5.2";
}
else if (releaseNumber >= 378675)
{
return "4.5.1";
}
else if (releaseNumber >= 378389)
{
return "4.5";
}
}
}
}
return "unknown";
}
}

public static string AppBinariesDirectory { get; }
Expand Down
2 changes: 1 addition & 1 deletion LibgenDesktop/Common/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static void LogEnvironmentInformation()
{
logger.Debug("Libgen Desktop " + CURRENT_VERSION);
logger.Debug("OS: " + Environment.OsVersion);
logger.Debug(".NET: " + Environment.NetFrameworkVersion);
logger.Debug(".NET Framework: " + Environment.NetFrameworkVersion);
logger.Debug("Is in 64-bit process: " + Environment.IsIn64BitProcess);
logger.Debug("Is in portable mode: " + Environment.IsInPortableMode);
}
Expand Down
4 changes: 1 addition & 3 deletions LibgenDesktop/LibgenDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@
<Private>True</Private>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
<Reference Include="System.Management" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
Expand Down
1 change: 0 additions & 1 deletion LibgenDesktop/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
<package id="NLog" version="4.4.12" targetFramework="net45" />
<package id="SharpCompress" version="0.19.2" targetFramework="net45" />
<package id="System.Data.SQLite.Core" version="1.0.106.0" targetFramework="net45" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net45" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
</packages>

0 comments on commit 0b36a24

Please sign in to comment.