Skip to content

Commit

Permalink
[addon] show application Version as ETS (#50)
Browse files Browse the repository at this point in the history
* [addon] show application Version as ETS

The ETS shows the version of the application as hex number with a minor version after a point.
This behavior is recreated with this change.

* [CodeFactor] changes related to CodeFactor hints

* Add ETS version as new textbox

* Update MainWindow.xaml.cs

* Update MainWindow.xaml.cs

* add ETS version textbox to application tab

* show only numeric numbers in ETS version textbox

If there is a version 12(dez) in ETS version field should not show "C".
Now it shows nothing, if there is a not numeric ETS version.

* change converter to minor version numbers 10...15

In ETS versions from 10 to 15 (0xA...0xF) are displayed as x.10...x.15
For example version 2.13 is 45(dec) = 0x2D
  • Loading branch information
olterion authored Sep 12, 2024
1 parent de8fbdd commit f6c8a56
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 1 deletion.
53 changes: 53 additions & 0 deletions Kaenx.Creator/Converter/IntToVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Data;
using System.Linq;

namespace Kaenx.Creator.Converter
{
public class IntToVersion : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
decimal majorVersion = Math.Floor((decimal)((int)value/16));
int minorVersion = (int)value % 16;
return $"{majorVersion}.{minorVersion}";
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
int majorVersion;
int minorVersion;

if(value.ToString().Contains('.'))
{
string[] versions = value.ToString().Split('.');

if(!int.TryParse(versions[0], out majorVersion))
majorVersion = 0;

if(!int.TryParse(versions[1], out minorVersion))
minorVersion = 0;

if(minorVersion > 15)
{
minorVersion /= 10;
if(minorVersion > 15)
minorVersion = 15;
}
}else
{
if(!int.TryParse(value.ToString(), out majorVersion))
majorVersion = 0;

minorVersion = 0;
}

majorVersion *= 16;

return majorVersion + minorVersion;
}
}
}
4 changes: 4 additions & 0 deletions Kaenx.Creator/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Title="Kaenx-Creator" Height="720" Width="1300">
<Window.Resources>
<conv:IntToHex x:Key="IntToHex" />
<conv:IntToVersion x:Key="IntToVersion" />
<conv:BoolNegation x:Key="BoolNegate" />
<conv:EmptyOListToBool x:Key="EmptyListToBool" />
<conv:EmptyToBool x:Key="EmptyToBool" />
Expand Down Expand Up @@ -658,6 +659,9 @@
<HeaderedContentControl Header="{x:Static p:Resources.prop_vers}">
<TextBox Text="{Binding Number, UpdateSourceTrigger=PropertyChanged}" />
</HeaderedContentControl>
<HeaderedContentControl Header="{x:Static p:Resources.prop_etsvers}">
<TextBox Text="{Binding Number, Converter={StaticResource IntToVersion}, UpdateSourceTrigger=PropertyChanged}" />
</HeaderedContentControl>
<HeaderedContentControl Header="{x:Static p:Resources.prop_versreplace}">
<TextBox Text="{Binding ReplacesVersions, UpdateSourceTrigger=PropertyChanged}" />
</HeaderedContentControl>
Expand Down
2 changes: 1 addition & 1 deletion Kaenx.Creator/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,4 +1044,4 @@ private async void ClickCheckVersion(object sender, RoutedEventArgs e)
}
}
}
}
}
9 changes: 9 additions & 0 deletions Kaenx.Creator/Properties/Resources.Designer.cs

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

4 changes: 4 additions & 0 deletions Kaenx.Creator/Properties/Resources.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@
<value>Version</value>
<comment/>
</data>
<data name="prop_etsvers" xml:space="preserve">
<value>ETS Version</value>
<comment/>
</data>
<data name="prop_buscurrent" xml:space="preserve">
<value>Busstrom</value>
<comment/>
Expand Down
4 changes: 4 additions & 0 deletions Kaenx.Creator/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@
<value>Version</value>
<comment/>
</data>
<data name="prop_etsvers" xml:space="preserve">
<value>ETS Version</value>
<comment/>
</data>
<data name="prop_buscurrent" xml:space="preserve">
<value>Bus Current</value>
<comment/>
Expand Down

0 comments on commit f6c8a56

Please sign in to comment.