mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
Fix all warnings & Trim (#2226)
* Fix AutoFishing crash * Fix all warnings * Remove DotNetZip. * Fix the usage of HttpClient.
This commit is contained in:
parent
4aa6c1c99f
commit
1d52d1eadd
227 changed files with 2201 additions and 43564 deletions
|
|
@ -22,25 +22,20 @@ namespace MinecraftClient.WinAPI
|
|||
{
|
||||
get
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
dynamic major;
|
||||
// The 'CurrentMajorVersionNumber' string value in the CurrentVersion key is new for Windows 10,
|
||||
// and will most likely (hopefully) be there for some time before MS decides to change this - again...
|
||||
if (TryGetRegistryKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentMajorVersionNumber", out major))
|
||||
{
|
||||
return (uint) major;
|
||||
}
|
||||
if (TryGetRegistryKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentMajorVersionNumber", out dynamic? major))
|
||||
return (uint)major;
|
||||
|
||||
// When the 'CurrentMajorVersionNumber' value is not present we fallback to reading the previous key used for this: 'CurrentVersion'
|
||||
dynamic version;
|
||||
if (!TryGetRegistryKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", out version))
|
||||
if (!TryGetRegistryKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", out dynamic? version))
|
||||
return 0;
|
||||
|
||||
var versionParts = ((string) version).Split('.');
|
||||
var versionParts = ((string)version!).Split('.');
|
||||
if (versionParts.Length != 2) return 0;
|
||||
uint majorAsUInt;
|
||||
return uint.TryParse(versionParts[0], out majorAsUInt) ? majorAsUInt : 0;
|
||||
return uint.TryParse(versionParts[0], out uint majorAsUInt) ? majorAsUInt : 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -54,25 +49,20 @@ namespace MinecraftClient.WinAPI
|
|||
{
|
||||
get
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
dynamic minor;
|
||||
// The 'CurrentMinorVersionNumber' string value in the CurrentVersion key is new for Windows 10,
|
||||
// and will most likely (hopefully) be there for some time before MS decides to change this - again...
|
||||
if (TryGetRegistryKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentMinorVersionNumber", out minor))
|
||||
{
|
||||
return (uint) minor;
|
||||
}
|
||||
if (TryGetRegistryKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentMinorVersionNumber", out dynamic? minor))
|
||||
return (uint)minor;
|
||||
|
||||
// When the 'CurrentMinorVersionNumber' value is not present we fallback to reading the previous key used for this: 'CurrentVersion'
|
||||
dynamic version;
|
||||
if (!TryGetRegistryKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", out version))
|
||||
if (!TryGetRegistryKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", out dynamic? version))
|
||||
return 0;
|
||||
|
||||
var versionParts = ((string) version).Split('.');
|
||||
var versionParts = ((string)version!).Split('.');
|
||||
if (versionParts.Length != 2) return 0;
|
||||
uint minorAsUInt;
|
||||
return uint.TryParse(versionParts[1], out minorAsUInt) ? minorAsUInt : 0;
|
||||
return uint.TryParse(versionParts[1], out uint minorAsUInt) ? minorAsUInt : 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -86,18 +76,20 @@ namespace MinecraftClient.WinAPI
|
|||
/// <param name="key">Key</param>
|
||||
/// <param name="value">Value (output)</param>
|
||||
/// <returns>TRUE if successfully retrieved</returns>
|
||||
private static bool TryGetRegistryKey(string path, string key, out dynamic value)
|
||||
private static bool TryGetRegistryKey(string path, string key, out dynamic? value)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
value = null;
|
||||
try {
|
||||
try
|
||||
{
|
||||
var rk = Registry.LocalMachine.OpenSubKey(path);
|
||||
if (rk == null) return false;
|
||||
value = rk.GetValue(key);
|
||||
return value != null;
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue