Skip to content

Commit

Permalink
Merge pull request #195 from jannikbecker/staging
Browse files Browse the repository at this point in the history
Version 0.6.0
  • Loading branch information
jannikbecker authored May 29, 2022
2 parents d2c0781 + d2c9af1 commit 46f616d
Show file tree
Hide file tree
Showing 20 changed files with 325 additions and 49 deletions.
3 changes: 2 additions & 1 deletion Leibit.BLL/InitializationBLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ private ESTW __GetEstw(XmlNode node, Area area)
var EstwDataFile = node.Attributes["dataFile"];
var InfrastructureManagerAttr = node.Attributes["infrastructureManager"];
var IgnoreRoutingDigitsAttr = node.Attributes["ignoreRoutingDigits"];
var ProductNameAttr = node.Attributes["productName"];

if (EstwId == null || EstwName == null || EstwDataFile == null || InfrastructureManagerAttr == null || !Enum.TryParse(InfrastructureManagerAttr.InnerText, true, out eInfrastructureManager InfrastructureManager))
return null;
Expand All @@ -275,7 +276,7 @@ private ESTW __GetEstw(XmlNode node, Area area)
if (IgnoreRoutingDigitsAttr != null && !bool.TryParse(IgnoreRoutingDigitsAttr.InnerText, out IgnoreRoutingDigits))
return null;

return new ESTW(EstwId.InnerText, EstwName.InnerText, EstwDataFile.InnerText, InfrastructureManager, IgnoreRoutingDigits, area);
return new ESTW(EstwId.InnerText, EstwName.InnerText, EstwDataFile.InnerText, InfrastructureManager, IgnoreRoutingDigits, ProductNameAttr?.InnerText ?? EstwName.InnerText, area);
}
#endregion

Expand Down
1 change: 1 addition & 0 deletions Leibit.BLL/Leibit.BLL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
Expand Down
18 changes: 17 additions & 1 deletion Leibit.BLL/SettingsBLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class SettingsBLL : BLLBase
#region - Ctor -
public SettingsBLL()
{
m_SettingsFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "LeiBIT", "settings.json");
__MoveSettingsFileIfNeeded();
m_SettingsFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "LeibitForESTWsim", "settings.json");
}
#endregion

Expand Down Expand Up @@ -257,6 +258,21 @@ private Settings __GetDefaultSettings()
return settings;
}

private void __MoveSettingsFileIfNeeded()
{
var oldFileDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "LeiBIT");
var oldFilePath = Path.Combine(oldFileDirectory, "settings.json");
var newFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "LeibitForESTWsim", "settings.json");

if (File.Exists(oldFilePath) && !File.Exists(newFilePath))
File.Move(oldFilePath, newFilePath);
else if (File.Exists(oldFilePath) && File.Exists(newFilePath))
File.Delete(oldFilePath);

if (Directory.Exists(oldFileDirectory) && !Directory.EnumerateFiles(oldFileDirectory).Any())
Directory.Delete(oldFileDirectory);
}

#endregion

}
Expand Down
75 changes: 75 additions & 0 deletions Leibit.BLL/SoftwareInfoBLL.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Leibit.Core.Common;
using Leibit.Entities;
using Microsoft.Win32;
using System;
using System.Runtime.InteropServices;

namespace Leibit.BLL
{
public class SoftwareInfoBLL : BLLBase
{

#region - Public methods -

#region [GetSoftwareInfo]
public OperationResult<SoftwareInfo> GetSoftwareInfo(string softwareName)
{
try
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return OperationResult<SoftwareInfo>.Ok(new SoftwareInfo { IsInstalled = false });

var key = __Search(Registry.CurrentUser, softwareName);

if (key == null)
key = __Search(Registry.LocalMachine, softwareName);

if (key == null)
return OperationResult<SoftwareInfo>.Ok(new SoftwareInfo { IsInstalled = false });

var result = new SoftwareInfo();
result.IsInstalled = true;
result.DisplayName = key.GetValue("DisplayName")?.ToString();
result.DisplayVersion = key.GetValue("DisplayVersion")?.ToString();
result.InstallLocation = key.GetValue("InstallLocation")?.ToString();
return OperationResult<SoftwareInfo>.Ok(result);
}
catch (Exception ex)
{
return OperationResult<SoftwareInfo>.Fail(ex.ToString());
}
}
#endregion

#endregion

#region - Private helpers -

#region [__Search]
private RegistryKey __Search(RegistryKey key, string softwareName)
{
var baseKey = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");

foreach (var subKeyName in baseKey.GetSubKeyNames())
{
var candidate = baseKey.OpenSubKey(subKeyName);
var displayName = candidate.GetValue("DisplayName")?.ToString();

if (displayName == null)
continue;

displayName = displayName.Replace(" ", string.Empty).Replace("-", string.Empty);
softwareName = softwareName.Replace(" ", string.Empty).Replace("-", string.Empty);

if (displayName.Contains(softwareName))
return candidate;
}

return null;
}
#endregion

#endregion

}
}
10 changes: 7 additions & 3 deletions Leibit.Client.WPF/Leibit.Client.WPF.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<AssemblyName>LeiBIT</AssemblyName>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0-windows10.0.17763.0</TargetFramework>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<SccProjectName>SAK</SccProjectName>
Expand All @@ -18,19 +18,22 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
<NoWarn>1701;1702;WFAC010</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<NoWarn>1701;1702;WFAC010</NoWarn>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>icon.ico</ApplicationIcon>
<Version>0.5.5</Version>
<Version>0.6.0</Version>
<PackageProjectUrl>https://github.com/jannikbecker/leibit</PackageProjectUrl>
<RepositoryUrl>https://github.com/jannikbecker/leibit</RepositoryUrl>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<None Remove="Resources\Fonts\5by7.ttf" />
<None Remove="Resources\Images\bildfpl.png" />
<None Remove="Resources\Images\Dark\bfo.png" />
<None Remove="Resources\Images\Dark\clear.png" />
<None Remove="Resources\Images\Dark\delay.png" />
Expand Down Expand Up @@ -75,6 +78,7 @@
<None Remove="Resources\Images\warning.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Images\bildfpl.png" />
<Resource Include="Resources\Images\Dark\bfo.png" />
<Resource Include="Resources\Images\Dark\clear.png" />
<Resource Include="Resources\Images\Dark\delay.png" />
Expand Down
Binary file added Leibit.Client.WPF/Resources/Images/bildfpl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Leibit.Client.WPF/Resources/ResourceDictionary.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<BitmapImage x:Key="imgBildFpl" UriSource="/Leibit;component/Resources/Images/bildfpl.png" />
<BitmapImage x:Key="imgEstwOnline" UriSource="/Leibit;component/Resources/Images/estw_online.png" />
<BitmapImage x:Key="imgClose" UriSource="/Leibit.Controls.WPF;component/Resources/Images/close.png" />
<BitmapImage x:Key="imgOk" UriSource="/Leibit;component/Resources/Images/ok.png" />
Expand Down
55 changes: 50 additions & 5 deletions Leibit.Client.WPF/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,23 @@ public class MainViewModel : WindowViewModelBase
private readonly LiveDataBLL m_LiveDataBll;
private readonly SettingsBLL m_SettingsBll;
private readonly SerializationBLL m_SerializationBll;
private readonly SoftwareInfoBLL m_SoftwareInfoBll;
private UpdateBLL m_UpdateBll;

private Area m_CurrentArea;
private Thread m_RefreshingThread;
private CancellationTokenSource m_CancellationTokenSource;
private string m_CurrentFilename;
private bool m_ForceClose;
private SoftwareInfo m_BildFplInfo;

private CommandHandler m_NewCommand;
private CommandHandler m_OpenCommand;
private CommandHandler m_SaveCommand;
private CommandHandler m_SaveAsCommand;
private CommandHandler m_SettingsCommand;
private CommandHandler m_EstwOnlineCommand;
private CommandHandler m_BildFplCommand;
private CommandHandler m_ExitCommand;
private CommandHandler m_EstwSelectionCommand;
private CommandHandler m_TrainProgressInformationCommand;
Expand All @@ -98,12 +101,29 @@ public class MainViewModel : WindowViewModelBase
#region - Ctor -
public MainViewModel()
{
m_InitializationBll = new InitializationBLL();
m_LiveDataBll = new LiveDataBLL();
m_SettingsBll = new SettingsBLL();
m_SerializationBll = new SerializationBLL();
m_SoftwareInfoBll = new SoftwareInfoBLL();

var BildFplResult = m_SoftwareInfoBll.GetSoftwareInfo("Bildfahrplan");

if (BildFplResult.Succeeded)
m_BildFplInfo = BildFplResult.Result;
else
{
ShowMessage(BildFplResult);
m_BildFplInfo = new SoftwareInfo { IsInstalled = false };
}

m_NewCommand = new CommandHandler<string>(__New, true);
m_OpenCommand = new CommandHandler(__Open, true);
m_SaveCommand = new CommandHandler(__Save, false);
m_SaveAsCommand = new CommandHandler(__SaveAs, false);
m_SettingsCommand = new CommandHandler(__Settings, true);
m_EstwOnlineCommand = new CommandHandler(__StartEstwOnline, true);
m_BildFplCommand = new CommandHandler(__StartBildFpl, IsBildFplInstalled);
m_ExitCommand = new CommandHandler(__Exit, true);
m_EstwSelectionCommand = new CommandHandler(__ShowEstwSelectionWindow, false);
m_TrainProgressInformationCommand = new CommandHandler(__ShowTrainProgressInformationWindow, false);
Expand All @@ -118,11 +138,6 @@ public MainViewModel()
m_AboutCommand = new CommandHandler(__ShowAboutWindow, true);
m_DebugModeCommand = new CommandHandler(__ToggleDebugMode, true);

m_InitializationBll = new InitializationBLL();
m_LiveDataBll = new LiveDataBLL();
m_SettingsBll = new SettingsBLL();
m_SerializationBll = new SerializationBLL();

ChildWindows = new ObservableCollection<LeibitWindow>();

Runtime.VisibleStationsChanged += __VisibleStationsChanged;
Expand Down Expand Up @@ -336,6 +351,13 @@ public int? TrainScheduleNumber
}
#endregion

#region [IsBildFplInstalled]
public bool IsBildFplInstalled
{
get => m_BildFplInfo?.IsInstalled == true;
}
#endregion

#region - Commands -

#region [NewCommand]
Expand Down Expand Up @@ -398,6 +420,16 @@ public ICommand EstwOnlineCommand
}
#endregion

#region [BildFplCommand]
public ICommand BildFplCommand
{
get
{
return m_BildFplCommand;
}
}
#endregion

#region [ExitCommand]
public ICommand ExitCommand
{
Expand Down Expand Up @@ -983,6 +1015,19 @@ private void __StartEstwOnline()
}
#endregion

#region [__StartBildFpl]
private void __StartBildFpl()
{
if (m_BildFplInfo == null || !m_BildFplInfo.IsInstalled || m_BildFplInfo.InstallLocation.IsNullOrWhiteSpace())
return;

var exePath = Path.Combine(m_BildFplInfo.InstallLocation, "BildFpl_V2.exe");

if (File.Exists(exePath))
Process.Start(exePath);
}
#endregion

#region [__Exit]
private void __Exit()
{
Expand Down
11 changes: 10 additions & 1 deletion Leibit.Client.WPF/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:core="clr-namespace:Leibit.Core.Client.Common;assembly=Leibit.Core.Client.WPF"
xmlns:common="clr-namespace:Leibit.Core.Client.Common;assembly=Leibit.Core.Client.WPF"
xmlns:controls="clr-namespace:Leibit.Controls;assembly=Leibit.Controls.WPF"
xmlns:converter="clr-namespace:Leibit.Core.Client.Converter;assembly=Leibit.Core.Client.WPF"
Title="LeiBIT für ESTWsim">

<Window.InputBindings>
Expand All @@ -18,6 +19,7 @@
<Grid.Resources>
<ResourceDictionary>
<common:BindingProxy x:Key="proxy" Data="{Binding}" />
<converter:VisibilityConverter x:Key="VisibilityConverter"/>
</ResourceDictionary>
</Grid.Resources>

Expand Down Expand Up @@ -71,6 +73,12 @@
</MenuItem.Icon>
</MenuItem>

<MenuItem Header="Bildfahrplan starten" Command="{Binding BildFplCommand}" Visibility="{Binding IsBildFplInstalled, Converter={StaticResource VisibilityConverter}}">
<MenuItem.Icon>
<Image Source="{StaticResource imgBildFpl}" />
</MenuItem.Icon>
</MenuItem>

<Separator Background="{DynamicResource MenuSeparatorColor}" />

<MenuItem Header="Beenden" Command="{Binding ExitCommand}">
Expand Down Expand Up @@ -174,7 +182,8 @@
<controls:ImageButton Image="{DynamicResource imgSave}" Command="{Binding SaveCommand}" ToolTipService.ToolTip="Speichern" />
<Separator />
<controls:ImageButton Image="{DynamicResource imgSettings}" Command="{Binding SettingsCommand}" ToolTipService.ToolTip="Einstellungen" />
<controls:ImageButton Image="{DynamicResource imgEstwOnline}" Command="{Binding EstwOnlineCommand}" ToolTipService.ToolTip="ESTWonline starten"/>
<controls:ImageButton Image="{StaticResource imgEstwOnline}" Command="{Binding EstwOnlineCommand}" ToolTipService.ToolTip="ESTWonline starten"/>
<controls:ImageButton Image="{StaticResource imgBildFpl}" Command="{Binding BildFplCommand}" ToolTipService.ToolTip="Bildfahrplan starten" Visibility="{Binding IsBildFplInstalled, Converter={StaticResource VisibilityConverter}}"/>
<Separator />
<controls:ImageButton Image="{DynamicResource imgZfi}" Command="{Binding TrainProgressInformationCommand}" ToolTipService.ToolTip="Zugfahrtinformation (ZFI)"/>

Expand Down
Loading

0 comments on commit 46f616d

Please sign in to comment.