This is a little test app for libpalaso PR#998 so that we can compare different environments.
Last active
November 24, 2020 16:43
-
-
Save ermshiperete/2426881ad8ef3066f604e0d9fc6bb171 to your computer and use it in GitHub Desktop.
PR998 test app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.idea/ | |
bin/ | |
obj/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
using System.Windows.Forms; | |
using Microsoft.Win32; | |
namespace TestAppPR998 | |
{ | |
internal static class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var productName = (string) Registry.GetValue( | |
@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion", | |
"ProductName", null); | |
var releaseId = Registry | |
.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", | |
"ReleaseId", "").ToString(); | |
Console.WriteLine( | |
$"Running on {productName} (release {releaseId}) ({RuntimeInformation.OSDescription})"); | |
Console.WriteLine( | |
$"{RuntimeInformation.ProcessArchitecture} process on {RuntimeInformation.OSArchitecture} system"); | |
Console.WriteLine($"Running with {RuntimeInformation.FrameworkDescription}"); | |
Console.WriteLine("Installed framework versions:"); | |
Get1To45VersionFromRegistry(); | |
Get45PlusFromRegistry(); | |
Console.WriteLine(); | |
Console.WriteLine( | |
"The following input languages have a mismatch between the input language handle and keyboard layout id:"); | |
var mismatches = 0; | |
foreach (InputLanguage inputLanguage in InputLanguage.InstalledInputLanguages) | |
{ | |
if ((short) inputLanguage.Handle == inputLanguage.Culture.KeyboardLayoutId) | |
continue; | |
mismatches++; | |
Console.WriteLine( | |
$" - Handle (0x{(short) inputLanguage.Handle:x8}) and culture.KeyboardLayoutId (0x{inputLanguage.Culture.KeyboardLayoutId:x8}) for {inputLanguage.Culture.Name}"); | |
} | |
if (mismatches != 0) | |
return; | |
Console.WriteLine(); | |
Console.WriteLine("No mismatches"); | |
} | |
private static void WriteVersion(string version, string spLevel = "") | |
{ | |
version = version.Trim(); | |
if (string.IsNullOrEmpty(version)) | |
return; | |
var spLevelString = ""; | |
if (!string.IsNullOrEmpty(spLevel)) | |
spLevelString = " Service Pack " + spLevel; | |
Console.WriteLine($" {version}{spLevelString}"); | |
} | |
private static void Get1To45VersionFromRegistry() | |
{ | |
// Opens the registry key for the .NET Framework entry. | |
using (var ndpKey = | |
Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\")) | |
{ | |
foreach (var versionKeyName in ndpKey.GetSubKeyNames()) | |
{ | |
// Skip .NET Framework 4.5 version information. | |
if (versionKeyName == "v4") | |
{ | |
continue; | |
} | |
if (versionKeyName.StartsWith("v")) | |
{ | |
var versionKey = ndpKey.OpenSubKey(versionKeyName); | |
// Get the .NET Framework version value. | |
var name = (string) versionKey.GetValue("Version", ""); | |
// Get the service pack (SP) number. | |
var sp = versionKey.GetValue("SP", "").ToString(); | |
// Get the installation flag, or an empty string if there is none. | |
var install = versionKey.GetValue("Install", "").ToString(); | |
if (string.IsNullOrEmpty(install) | |
) // No install info; it must be in a child subkey. | |
WriteVersion(name); | |
else | |
{ | |
if (!(string.IsNullOrEmpty(sp)) && install == "1") | |
{ | |
WriteVersion(name, sp); | |
} | |
} | |
if (!string.IsNullOrEmpty(name)) | |
{ | |
continue; | |
} | |
foreach (var subKeyName in versionKey.GetSubKeyNames()) | |
{ | |
var subKey = versionKey.OpenSubKey(subKeyName); | |
name = (string) subKey.GetValue("Version", ""); | |
if (!string.IsNullOrEmpty(name)) | |
sp = subKey.GetValue("SP", "").ToString(); | |
install = subKey.GetValue("Install", "").ToString(); | |
if (string.IsNullOrEmpty(install) | |
) //No install info; it must be later. | |
WriteVersion(name); | |
else | |
{ | |
if (!(string.IsNullOrEmpty(sp)) && install == "1") | |
{ | |
WriteVersion(name, sp); | |
} | |
else if (install == "1") | |
{ | |
WriteVersion(name); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
private static void Get45PlusFromRegistry() | |
{ | |
const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"; | |
using (var ndpKey = Registry.LocalMachine.OpenSubKey(subkey)) | |
{ | |
if (ndpKey == null) | |
return; | |
//First check if there's an specific version indicated | |
if (ndpKey.GetValue("Version") != null) | |
{ | |
WriteVersion(ndpKey.GetValue("Version").ToString()); | |
} | |
else | |
{ | |
if (ndpKey != null && ndpKey.GetValue("Release") != null) | |
{ | |
WriteVersion( | |
CheckFor45PlusVersion( | |
(int) ndpKey.GetValue("Release") | |
) | |
); | |
} | |
} | |
} | |
// Checking the version using >= enables forward compatibility. | |
string CheckFor45PlusVersion(int releaseKey) | |
{ | |
if (releaseKey >= 528040) | |
return "4.8"; | |
if (releaseKey >= 461808) | |
return "4.7.2"; | |
if (releaseKey >= 461308) | |
return "4.7.1"; | |
if (releaseKey >= 460798) | |
return "4.7"; | |
if (releaseKey >= 394802) | |
return "4.6.2"; | |
if (releaseKey >= 394254) | |
return "4.6.1"; | |
if (releaseKey >= 393295) | |
return "4.6"; | |
if (releaseKey >= 379893) | |
return "4.5.2"; | |
if (releaseKey >= 378675) | |
return "4.5.1"; | |
if (releaseKey >= 378389) | |
return "4.5"; | |
// This code should never execute. A non-null release key should mean | |
// that 4.5 or later is installed. | |
return ""; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | |
<PropertyGroup> | |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |
<ProjectGuid>{2567A225-F200-4BFE-8501-187C3FBF1AAE}</ProjectGuid> | |
<OutputType>Exe</OutputType> | |
<AppDesignerFolder>Properties</AppDesignerFolder> | |
<RootNamespace>TestAppPR998</RootNamespace> | |
<AssemblyName>TestAppPR998</AssemblyName> | |
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> | |
<FileAlignment>512</FileAlignment> | |
</PropertyGroup> | |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |
<PlatformTarget>AnyCPU</PlatformTarget> | |
<DebugSymbols>true</DebugSymbols> | |
<DebugType>full</DebugType> | |
<Optimize>false</Optimize> | |
<OutputPath>bin\Debug\</OutputPath> | |
<DefineConstants>DEBUG;TRACE</DefineConstants> | |
<ErrorReport>prompt</ErrorReport> | |
<WarningLevel>4</WarningLevel> | |
</PropertyGroup> | |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |
<PlatformTarget>AnyCPU</PlatformTarget> | |
<DebugType>pdbonly</DebugType> | |
<Optimize>true</Optimize> | |
<OutputPath>bin\Release\</OutputPath> | |
<DefineConstants>TRACE</DefineConstants> | |
<ErrorReport>prompt</ErrorReport> | |
<WarningLevel>4</WarningLevel> | |
</PropertyGroup> | |
<ItemGroup> | |
<Reference Include="System" /> | |
<Reference Include="System.Core" /> | |
<Reference Include="System.Data" /> | |
<Reference Include="System.Windows.Forms" /> | |
<Reference Include="System.Xml" /> | |
</ItemGroup> | |
<ItemGroup> | |
<Compile Include="Program.cs" /> | |
</ItemGroup> | |
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | |
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |
Other similar extension points exist, see Microsoft.Common.targets. | |
<Target Name="BeforeBuild"> | |
</Target> | |
<Target Name="AfterBuild"> | |
</Target> | |
--> | |
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| |
Microsoft Visual Studio Solution File, Format Version 12.00 | |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAppPR998", "TestAppPR998.csproj", "{2567A225-F200-4BFE-8501-187C3FBF1AAE}" | |
EndProject | |
Global | |
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |
Debug|Any CPU = Debug|Any CPU | |
Release|Any CPU = Release|Any CPU | |
EndGlobalSection | |
GlobalSection(ProjectConfigurationPlatforms) = postSolution | |
{2567A225-F200-4BFE-8501-187C3FBF1AAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |
{2567A225-F200-4BFE-8501-187C3FBF1AAE}.Debug|Any CPU.Build.0 = Debug|Any CPU | |
{2567A225-F200-4BFE-8501-187C3FBF1AAE}.Release|Any CPU.ActiveCfg = Release|Any CPU | |
{2567A225-F200-4BFE-8501-187C3FBF1AAE}.Release|Any CPU.Build.0 = Release|Any CPU | |
EndGlobalSection | |
EndGlobal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment