Skip to content

Commit

Permalink
redone the first time start up
Browse files Browse the repository at this point in the history
  • Loading branch information
kruumy committed Mar 12, 2023
1 parent 4acf31f commit f5b4faa
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 23 deletions.
3 changes: 2 additions & 1 deletion EasyZoneBuilder.Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace EasyZoneBuilder.Core
{
public static class Settings
{
public static bool IsTargetExecutablePathValid => Settings.File.Exists && !string.IsNullOrEmpty(Settings.TargetExecutablePath) && System.IO.File.Exists(Settings.TargetExecutablePath);
private static string _TargetExecutablePath = string.Empty;
public static string TargetExecutablePath
{
Expand All @@ -18,7 +19,7 @@ public static string TargetExecutablePath
set
{
_TargetExecutablePath = value;
if ( !string.IsNullOrEmpty(value) )
if ( !string.IsNullOrEmpty(value) && System.IO.File.Exists(value) )
{
FileInfo fileInfo = new FileInfo(value);
if ( fileInfo != null && fileInfo.Exists )
Expand Down
47 changes: 47 additions & 0 deletions EasyZoneBuilder.GUI/AppSettings.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Window x:Class="EasyZoneBuilder.GUI.AppSettings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:EasyZoneBuilder.GUI"
mc:Ignorable="d"
Style="{DynamicResource CustomWindowStyle}"
Title="App Settings" Height="300" Width="450" ResizeMode="NoResize" Icon="/Resources/settings.ico" WindowStartupLocation="CenterOwner">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Label
Content="Hello"
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontSize="36"
Grid.Row="1">
</Label>
<Button
Content="Select Your ZoneBuilder"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Padding="25,10"
Grid.Row="2"
FontSize="16"
Click="Button_Click">
</Button>
<Label
Content="If you're using IW4X, that is your game executable."
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontSize="9"
Grid.Row="3"
FontStyle="Italic">
</Label>
</Grid>

</Window>
46 changes: 46 additions & 0 deletions EasyZoneBuilder.GUI/AppSettings.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Microsoft.Win32;
using System.IO;
using System.Windows;

namespace EasyZoneBuilder.GUI
{
/// <summary>
/// Interaction logic for AppSettings.xaml
/// </summary>
public partial class AppSettings : Window
{
public AppSettings()
{
InitializeComponent();
}

private void Button_Click( object sender, RoutedEventArgs e )
{
OpenFileDialog selectIw4x = new OpenFileDialog
{
Title = "Select your IW4 executable",
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = "exe",
Filter = "Executable files (*.exe)|*.exe",
RestoreDirectory = false,
ReadOnlyChecked = true,
ShowReadOnly = true,
Multiselect = false,
};
selectIw4x.ShowDialog();
string fileName = Path.GetFileNameWithoutExtension(selectIw4x.FileName);
if ( fileName == "iw4x" || fileName == "iw4m" /* TODO add zonebuilder exe name */)
{
Core.Settings.TargetExecutablePath = selectIw4x.FileName;
this.Close();
return;
}
else
{
MessageBox.Show("Please select a supported executable!", "Error");
return;
}
}
}
}
7 changes: 7 additions & 0 deletions EasyZoneBuilder.GUI/EasyZoneBuilder.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="AppSettings.xaml.cs">
<DependentUpon>AppSettings.xaml</DependentUpon>
</Compile>
<Compile Include="DarkTheme.xaml.cs">
<DependentUpon>DarkTheme.xaml</DependentUpon>
</Compile>
Expand All @@ -89,6 +92,10 @@
<Compile Include="Zone.xaml.cs">
<DependentUpon>Zone.xaml</DependentUpon>
</Compile>
<Page Include="AppSettings.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="DarkTheme.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
26 changes: 4 additions & 22 deletions EasyZoneBuilder.GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using EasyZoneBuilder.Core;
using Microsoft.Win32;
using System;
using System.IO;
using System.Windows;

namespace EasyZoneBuilder.GUI
Expand All @@ -14,7 +12,7 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
if ( !Settings.File.Exists || string.IsNullOrEmpty(Settings.TargetExecutablePath) || !File.Exists(Settings.TargetExecutablePath) )
if ( !Settings.IsTargetExecutablePathValid )
{
RunFirstTimeSetup();
}
Expand All @@ -27,28 +25,12 @@ public MainWindow()

private void RunFirstTimeSetup()
{
MessageBox.Show("Please select your IW4 executable after pressing OK...", "First Time Setup");
OpenFileDialog selectIw4x = new OpenFileDialog
AppSettings appSettings = new AppSettings();
appSettings.ShowDialog();
if ( !Settings.IsTargetExecutablePathValid )
{
Title = "Select your IW4 executable",
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = "exe",
Filter = "Executable files (*.exe)|*.exe",
FilterIndex = 2,
RestoreDirectory = false,
ReadOnlyChecked = true,
ShowReadOnly = true,
Multiselect = false,
};
selectIw4x.ShowDialog();
string fileName = Path.GetFileNameWithoutExtension(selectIw4x.FileName);
if ( fileName != "iw4x" && fileName != "iw4m" /* TODO add zonebuilder exe name */)
{
MessageBox.Show("Not legal executable, exiting...", "First Time Setup");
Environment.Exit(0);
}
Settings.TargetExecutablePath = selectIw4x.FileName;
}

private void RunNoDependencyGraph()
Expand Down

0 comments on commit f5b4faa

Please sign in to comment.