Skip to content

Commit

Permalink
Checking for errors when doing the UAC check and when opening the con…
Browse files Browse the repository at this point in the history
…fig folder.

Some small color changes.
  • Loading branch information
tstavrianos committed Apr 20, 2020
1 parent b125cd5 commit 703d51f
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 47 deletions.
1 change: 1 addition & 0 deletions BannerLord.Common/IModManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public interface IModManager : IEnableLogger
{
bool Initialize(string configPath, string gamePath, out string errorMessage);

bool OpenConfig(out string errorMessage);

bool Save(out string errorMessage);
bool Run(out string errorMessage);
Expand Down
34 changes: 25 additions & 9 deletions BannerLord.Common/ModManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,33 @@ public bool Run(out string errorMessage)
return true;
}

public void OpenConfig()
public bool OpenConfig(out string errorMessage)
{
if (string.IsNullOrEmpty(this._basePath) || !Directory.Exists(this._basePath)) return;
var info = new ProcessStartInfo
errorMessage = default;
try
{
Arguments = this._basePath,
FileName = "explorer.exe",
WorkingDirectory = this._basePath,
UseShellExecute = false
};
Process.Start(info);
if (string.IsNullOrEmpty(this._basePath) || !Directory.Exists(this._basePath))
{
errorMessage = $"{this._basePath} is invalid";
return false;
}
var info = new ProcessStartInfo
{
Arguments = this._basePath,
FileName = "explorer.exe",
WorkingDirectory = this._basePath,
UseShellExecute = false
};
Process.Start(info);
}
catch (Exception e)
{
this.Log().Error(e);
errorMessage = e.Message;
return false;
}

return true;
}

public bool Save(out string errorMessage)
Expand Down
3 changes: 0 additions & 3 deletions BannerLordLauncher/BannerLordLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
<ApplicationIcon>BLLicon.ico</ApplicationIcon>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<RootNamespace>BannerLordLauncher</RootNamespace>
<AssemblyVersion>0.1.14.0</AssemblyVersion>
<FileVersion>0.1.14.0</FileVersion>
<PackageProjectUrl>https://www.nexusmods.com/mountandblade2bannerlord/mods/265</PackageProjectUrl>
<RepositoryUrl>https://github.com/tstavrianos/BannerLordLauncher</RepositoryUrl>
<Version>0.1.14</Version>
<StartupObject>BannerLordLauncher.Program</StartupObject>

</PropertyGroup>
Expand Down
35 changes: 20 additions & 15 deletions BannerLordLauncher/Dictionary.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
<GradientStop Color="#462e22" Offset="1"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="PackIconMaterialBorderBrush1" Color="#513a29"/>
<SolidColorBrush x:Key="StackPanelBackground1" Color="#FF17110B"/>
<SolidColorBrush x:Key="ModListItemCommunity" Color="#ffbe9d81"/>
<SolidColorBrush x:Key="ModListItemNative" Color="#ff684d36"/>
<SolidColorBrush x:Key="PackIconMaterialBorderBrush2" Color="#a96f46"/>
<SolidColorBrush x:Key="StackPanelBackground1" Color="#17110B"/>
<SolidColorBrush x:Key="ModListItemCommunity" Color="#be9d81"/>
<SolidColorBrush x:Key="ModListItemNative" Color="#684d36"/>
<SolidColorBrush x:Key="ModListCheckEmpty" Color="#231A11" />
<SolidColorBrush x:Key="TitleButtonInactive" Color="#3e2c20" />
<SolidColorBrush x:Key="TitleButtonActive" Color="#4e3827" />
<SolidColorBrush x:Key="TitleButtonPressed" Color="#4e3827" />
<Style x:Key="MyButton" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="#c48129" />
<Setter Property="Foreground" Value="{StaticResource PackIconMaterialForeground1}" />
<Setter Property="FontFamily" Value="/Assets/Fonts/#Candara" />
<Setter Property="FontSize" Value="20" />
<Setter Property="Background" Value="{StaticResource PackIconMaterialBackground1}"/>
Expand All @@ -40,12 +45,12 @@
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource PackIconMaterialBackground2}"/>
<Setter Property="BorderBrush" Value="{StaticResource PackIconMaterialBorderBrush2}"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="MoveBtn" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="#c48129" />
<Setter Property="Foreground" Value="{StaticResource PackIconMaterialForeground1}" />
<Setter Property="Background" Value="{StaticResource PackIconMaterialBackground1}"/>
<Setter Property="Padding" Value="0,0,0,0"/>
<Setter Property="BorderThickness" Value="2,2,2,2"/>
Expand All @@ -63,7 +68,7 @@
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource PackIconMaterialBackground2}"/>
<Setter Property="BorderBrush" Value="{StaticResource PackIconMaterialBorderBrush2}"/>
</Trigger>
</Style.Triggers>
</Style>
Expand All @@ -82,10 +87,10 @@
</BulletDecorator>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter Property="Opacity" TargetName="CheckedMark" Value="1"/>
<Setter Property="Foreground" TargetName="CheckedMark" Value="{StaticResource ModListItemCommunity}"/>
</Trigger>
<Trigger Property="IsChecked" Value="false">
<Setter Property="Opacity" TargetName="CheckedMark" Value="0"/>
<Setter Property="Foreground" TargetName="CheckedMark" Value="{StaticResource ModListCheckEmpty}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Expand All @@ -103,7 +108,7 @@
<ControlTemplate TargetType="{x:Type Button}">
<Border
x:Name="border"
Background="#3e2c20"
Background="{StaticResource TitleButtonInactive}"
BorderThickness="0"
SnapsToDevicePixels="true">
<ContentPresenter
Expand All @@ -116,10 +121,10 @@
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#4e3827" />
<Setter TargetName="border" Property="Background" Value="{StaticResource TitleButtonActive}" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#4e3827" />
<Setter TargetName="border" Property="Background" Value="{StaticResource TitleButtonPressed}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Expand All @@ -137,7 +142,7 @@
<ControlTemplate TargetType="{x:Type Button}">
<Border
x:Name="border"
Background="#3e2c20"
Background="{StaticResource TitleButtonInactive}"
BorderThickness="0"
SnapsToDevicePixels="true">
<ContentPresenter
Expand All @@ -150,10 +155,10 @@
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#4e3827" />
<Setter TargetName="border" Property="Background" Value="{StaticResource TitleButtonActive}" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#4e3827" />
<Setter TargetName="border" Property="Background" Value="{StaticResource TitleButtonPressed}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Expand Down
45 changes: 29 additions & 16 deletions BannerLordLauncher/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public MainWindowViewModel(MainWindow window)
this.UncheckAll = ReactiveCommand.Create(this.UncheckAllCmd);
this.InvertCheck = ReactiveCommand.Create(this.InvertCheckCmd);
this.Run = ReactiveCommand.Create(this.RunCmd);
this.Config = ReactiveCommand.Create(() => this.Manager.OpenConfig());
this.Config = ReactiveCommand.Create(this.OpenConfigCmd);
}

private void SafeMessage(string message)
Expand Down Expand Up @@ -321,6 +321,13 @@ private void SaveCmd()
if (this.Manager.Save(out var error)) return;
if (!string.IsNullOrEmpty(error)) this.SafeMessage(error);
}

private void OpenConfigCmd()
{

if (this.Manager.OpenConfig(out var error)) return;
if (!string.IsNullOrEmpty(error)) this.SafeMessage(error);
}

public void DragOver(IDropInfo dropInfo)
{
Expand Down Expand Up @@ -390,35 +397,41 @@ public bool CanRun()
return false;
}

if (UACChecker.RequiresElevation(this.Manager.GameExe))
try
{
if (!UacUtil.IsElevated)
if (UACChecker.RequiresElevation(this.Manager.GameExe))
{
this.SafeMessage("The application must be run as admin, to allow launching the game");
return false;
if (!UacUtil.IsElevated)
{
this.SafeMessage("The application must be run as admin, to allow launching the game");
return false;
}
}
}
catch (Exception e)
{
this.Log().Error(e);
SafeMessage(e.Message);
}

return true;
}

public bool CanSave()
{
this._ignoredWarning = false;
if (this.Manager.Mods.Any(x => x.HasConflicts))
if (!this.Manager.Mods.Any(x => x.HasConflicts)) return true;
if (MessageBox.Show(
this._window,
"Your mod list has existing conflicts, are you sure that you want to save it?",
"Warning",
MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
{
if (MessageBox.Show(
this._window,
"Your mod list has existing conflicts, are you sure that you want to save it?",
"Warning",
MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
{
return false;
}

this._ignoredWarning = true;
return false;
}

this._ignoredWarning = true;

return true;
}

Expand Down
7 changes: 3 additions & 4 deletions BannerLordLauncher/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
</WindowChrome.WindowChrome>

<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down Expand Up @@ -106,7 +106,7 @@
RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
StrokeThickness="1" />
</Button>
</Grid>
</Grid>
<StackPanel DockPanel.Dock="Left" Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Center" RenderTransformOrigin="0.534,0.517">
<Button Style="{StaticResource MoveBtn}" Name="MoveToTop" Command="{Binding MoveToTop}" ClickMode="Release" ToolTip="Move selection to top" Margin="5,2,2,1">
<iconPacks:PackIconMaterial Kind="ChevronDoubleUp" Width="32" Height="32"/>
Expand Down Expand Up @@ -167,12 +167,11 @@
ScrollViewer.VerticalScrollBarVisibility="Visible"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
Background="#FF191311"
BorderBrush="{DynamicResource PackIconMaterialBorderBrush1}"
dd:DragDrop.DropHandler="{Binding}"
HorizontalContentAlignment="Stretch"
ItemTemplate="{StaticResource ModListEntry}"
SelectionMode="Single">
SelectionMode="Single" Background="{x:Null}">
<ListBox.Resources>
<Style TargetType="{x:Type ScrollBar}">
<Setter Property="SnapsToDevicePixels" Value="True" />
Expand Down
7 changes: 7 additions & 0 deletions BannerLordLauncher/package.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off

dotnet publish -c Release -p:PublishSingleFile=true -p:AssemblyVersion=%1.0 -p:FileVersion=%1.0 -p:Version=%1
cd bin\Release\netcoreapp3.1\win-x64\publish\
if exist BannerLordLauncher.7z del BannerLordLauncher.7z
if exist BannerLordLauncher.exe "c:\Program Files\7-Zip\7z.exe" a BannerLordLauncher.7z BannerLordLauncher.exe BannerLordLauncher.pdb
cd ..\..\..\..\..

0 comments on commit 703d51f

Please sign in to comment.