Skip to content

Commit

Permalink
Check for Framework 4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
uholeschak committed Dec 12, 2024
1 parent 715d554 commit c9a0ec6
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 29 deletions.
12 changes: 12 additions & 0 deletions EdiabasLib/EdiabasLibConfigTool/EdiabasLibConfigTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,24 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Resources\Strings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Strings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Strings.ru.resx">
<Generator></Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
Expand Down
26 changes: 0 additions & 26 deletions EdiabasLib/EdiabasLibConfigTool/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,32 +177,6 @@ private bool IsWinVistaOrHigher()
return (os.Platform == PlatformID.Win32NT) && (os.Version.Major >= 6);
}

private int GetNetFrameworkVersion()
{
try
{
using (RegistryKey localMachine32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
{
using (RegistryKey ndpKey = localMachine32.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"))
{
if (ndpKey != null)
{
object releaseValue = ndpKey.GetValue("Release");
if (releaseValue is int releaseKey)
{
return releaseKey;
}
}
}
}
}
catch (Exception)
{
return -1;
}
return -1;
}

private void GetDirectories()
{
string dirBmw = Environment.GetEnvironmentVariable("ediabas_config_dir");
Expand Down
96 changes: 95 additions & 1 deletion EdiabasLib/EdiabasLibConfigTool/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Win32;
using System;
using System.Runtime.Versioning;
using System.Text;
using System.Windows.Forms;
Expand All @@ -17,7 +18,100 @@ static void Main()
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (GetNetFrameworkVersion() < 0x480)
{
string message = string.Format(Resources.Strings.NetFrameworkMissing, "4.8");
MessageBox.Show(message, Resources.Strings.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

Application.Run(new FormMain());
}

public static int GetNetFrameworkVersion()
{
try
{
using (RegistryKey localMachine32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
{
using (RegistryKey ndpKey = localMachine32.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"))
{
if (ndpKey != null)
{
object releaseValue = ndpKey.GetValue("Release");
if (releaseValue is int releaseKey)
{
return ConvertNetFrameworkVersion(releaseKey);
}
}
}
}
}
catch (Exception)
{
return -1;
}
return -1;
}

public static int ConvertNetFrameworkVersion(int releaseKey)
{
if (releaseKey >= 533320)
{
return 0x481;
}

if (releaseKey >= 528040)
{
return 0x480;
}

if (releaseKey >= 461808)
{
return 0x472;
}

if (releaseKey >= 461308)
{
return 0x471;
}

if (releaseKey >= 460798)
{
return 0x470;
}

if (releaseKey >= 394802)
{
return 0x462;
}

if (releaseKey >= 394254)
{
return 0x461;
}

if (releaseKey >= 393295)
{
return 0x460;
}

if (releaseKey >= 379893)
{
return 0x452;
}

if (releaseKey >= 378675)
{
return 0x451;
}

if (releaseKey >= 378389)
{
return 0x450;
}

return 0x000;
}
}
}
23 changes: 21 additions & 2 deletions EdiabasLib/EdiabasLibConfigTool/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions EdiabasLib/EdiabasLibConfigTool/Resources/Strings.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,10 @@ fehlgeschlagen.</value>
<value>Löschen des Registrierungsschlüssels
'{0}'.</value>
</data>
<data name="NetFrameworkMissing" xml:space="preserve">
<value>Diese Applikation benötigt .NET Framework {0} oder höher.</value>
</data>
<data name="TitleError" xml:space="preserve">
<value>Fehler</value>
</data>
</root>
6 changes: 6 additions & 0 deletions EdiabasLib/EdiabasLibConfigTool/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,10 @@ failed.</value>
<value>Removing registry key:
'{0}'.</value>
</data>
<data name="NetFrameworkMissing" xml:space="preserve">
<value>This application requires .NET Framework {0} or higher.</value>
</data>
<data name="TitleError" xml:space="preserve">
<value>Error</value>
</data>
</root>
6 changes: 6 additions & 0 deletions EdiabasLib/EdiabasLibConfigTool/Resources/Strings.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,10 @@ Ediabas настройки по умолчанию (ediabas.ini).</value>
<value>Удаление ключa регистрации
'{0}'.</value>
</data>
<data name="NetFrameworkMissing" xml:space="preserve">
<value>Для этого приложения требуется .NET Framework {0} или выше.</value>
</data>
<data name="TitleError" xml:space="preserve">
<value>Ошибка</value>
</data>
</root>

0 comments on commit c9a0ec6

Please sign in to comment.