Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
- Explicitly cleanup the WM_INPUT of RawInput. While there's no leaks happened, still better safe than sorry.
- Disable DoubleBuffering drawing technique of WinForm controls as we handover all the drawing logic to IE or webview rendering engine.
- Put some more explanations about unsafe settings.
  • Loading branch information
Leayal committed Jul 12, 2023
1 parent 43d6827 commit b693318
Show file tree
Hide file tree
Showing 36 changed files with 258 additions and 143 deletions.
28 changes: 0 additions & 28 deletions LauncherCore/UIElements/ConvenientEventHandlers.cs

This file was deleted.

63 changes: 63 additions & 0 deletions LauncherCore/UIElements/ConvenientMembers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;

namespace Leayal.PSO2Launcher.Core.UIElements
{
static class ConvenientMembers
{
/// <summary>Identifies extension property "PaddingLeft".</summary>
/// <remarks>This property allows caller to change only "Left" padding, the rest remains unchanged.</remarks>
public static readonly DependencyProperty PaddingLeftProperty = DependencyProperty.RegisterAttached("PaddingLeft", typeof(double), typeof(Control), new PropertyMetadata(default(double), (obj, e) =>
{
if (obj is Control control)
{
var newPaddingLeft = Unsafe.Unbox<double>(e.NewValue);
var thickness = control.Padding;
if (thickness.Left != newPaddingLeft)
{
thickness.Left = newPaddingLeft;
control.Padding = thickness;
}
}
}, (obj, coerceValue) =>
{
if (obj is Control control)
{
// var myOwnValue = Unsafe.Unbox<double>(coerceValue);
return control.Padding.Left;
}
return coerceValue;
}));

/// <summary>Sets the left padding of a control while leaving other padding values unchanged.</summary>
/// <param name="control">The control to set the left padding value.</param>
/// <param name="value">The thickness value.</param>
public static void SetPaddingLeft(Control control, double value) => control.SetValue(PaddingLeftProperty, value);

/// <summary>Gets the left padding of a control.</summary>
/// <param name="control">The control to get the padding value.</param>
/// <returns>The thickness of left padding.</returns>
public static double GetPaddingLeft(Control control) => Unsafe.Unbox<double>(control.GetValue(PaddingLeftProperty));

/// <summary>When this method is added to a <seealso cref="System.Windows.Controls.Primitives.Selector.SelectionChanged"/>, prevent the control from selecting no items.</summary>
/// <remarks>
/// <para>You can also just pass-through the event handler to this handler.</para>
/// <para>Currently supports only <seealso cref="TabControl"/>.</para>
/// </remarks>
/// <param name="sender">The element which raised this event. May be <see langword="null"/>.</param>
/// <param name="e">The event parameters which associated with the event.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void TabControl_SelectionChanged_PreventSelectingNothing(object? sender, SelectionChangedEventArgs e)
{
if (e.AddedItems == null || e.AddedItems.Count == 0)
{
if (e.RemovedItems[0] is TabItem tab)
{
e.Handled = true;
tab.IsSelected = true;
}
}
}
}
}
7 changes: 4 additions & 3 deletions LauncherCore/Windows/DataManagerWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,11 @@
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="2" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="Allow launcher to disable in-game file integrity validation (which allows client mods)" VerticalAlignment="Center" />
<iconPacks:PackIconFontAwesome Grid.Column="1" Kind="ExclamationCircleSolid" VerticalAlignment="Center" />
<iconPacks:PackIconFontAwesome Grid.Column="2" Kind="ExclamationCircleSolid" VerticalAlignment="Center" localui:ConvenientMembers.PaddingLeft="3" />
</Grid>
</CheckBox>
<CheckBox Grid.Row="1" Margin="1" x:Name="checkbox_allowDlssModding" ToolTipService.InitialShowDelay="0" >
Expand All @@ -212,8 +213,8 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="Don't redownload Nvidia DLSS binary files if it's already existed" VerticalAlignment="Center" />
<iconPacks:PackIconFontAwesome Grid.Column="1" Kind="ExclamationCircleSolid" VerticalAlignment="Center" />
<TextBlock Text="Don't redownload Nvidia DLSS binary files if it's already existed (which allows DLSS version override) " VerticalAlignment="Center" />
<iconPacks:PackIconFontAwesome Grid.Column="1" Kind="ExclamationCircleSolid" VerticalAlignment="Center" localui:ConvenientMembers.PaddingLeft="3" />
</Grid>
</CheckBox>
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion LauncherCore/Windows/DataManagerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private void Numberbox_throttledownload_PreviewTextInput(object sender, TextComp
}

private void TabControl_SelectionChanged_PreventSelectingNone(object sender, SelectionChangedEventArgs e)
=> ConvenientEventHandlers.TabControl_SelectionChanged_PreventSelectingNothing(sender, e);
=> ConvenientMembers.TabControl_SelectionChanged_PreventSelectingNothing(sender, e);

private void Combobox_downloadselection_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
Expand Down
8 changes: 4 additions & 4 deletions LauncherCore/Windows/GameClientUpdateResultLogDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Leayal.PSO2Launcher.Core.Windows"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:leacontrols="clr-namespace:Leayal.PSO2Launcher.Core.UIElements"
xmlns:localui="clr-namespace:Leayal.PSO2Launcher.Core.UIElements"
xmlns:leawindow="clr-namespace:Leayal.Shared.Windows;assembly=Leayal.Shared.Windows"
mc:Ignorable="d" x:Name="thisSelf"
ShowTitleBar="False" TitleCharacterCasing="Normal" ShowMaxRestoreButton="False" ShowMinButton="False" WindowStartupLocation="CenterOwner"
Expand Down Expand Up @@ -93,7 +93,7 @@
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Text="Filter by name matching pattern" mah:VisibilityHelper.IsCollapsed="{Binding ElementName=ListOfSuccessItemsLabel,Path=IsVisible,Mode=OneWay}" VerticalAlignment="Center" />
<leacontrols:TextBoxDelayedTextChange Grid.Column="1" TextChanged="TextBoxDelayedTextChange_TextChanged" Tag="{Binding ElementName=ListOfSuccessItems,BindsDirectlyToSource=True,Path=ItemsSource, Mode=OneWay}"
<localui:TextBoxDelayedTextChange Grid.Column="1" TextChanged="TextBoxDelayedTextChange_TextChanged" Tag="{Binding ElementName=ListOfSuccessItems,BindsDirectlyToSource=True,Path=ItemsSource, Mode=OneWay}"
mah:VisibilityHelper.IsCollapsed="{Binding ElementName=ListOfSuccessItemsLabel,Path=IsVisible,Mode=OneWay}" />
<ListBox Margin="0,1,0,0" Grid.ColumnSpan="2" Grid.Row="1" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" VirtualizingPanel.CacheLengthUnit="Page" VirtualizingPanel.CacheLength="3" VirtualizingPanel.ScrollUnit="Item"
mah:VisibilityHelper.IsCollapsed="{Binding ElementName=ListOfSuccessItemsLabel,Path=IsVisible,Mode=OneWay}" SelectionMode="Extended"
Expand Down Expand Up @@ -139,7 +139,7 @@
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Text="Filter by name matching pattern" mah:VisibilityHelper.IsCollapsed="{Binding ElementName=ListOfFailureItemsLabel,Path=IsVisible,Mode=OneWay}" VerticalAlignment="Center" />
<leacontrols:TextBoxDelayedTextChange Grid.Column="1" TextChanged="TextBoxDelayedTextChange_TextChanged" Tag="{Binding ElementName=ListOfFailureItems,BindsDirectlyToSource=True,Path=ItemsSource, Mode=OneWay}"
<localui:TextBoxDelayedTextChange Grid.Column="1" TextChanged="TextBoxDelayedTextChange_TextChanged" Tag="{Binding ElementName=ListOfFailureItems,BindsDirectlyToSource=True,Path=ItemsSource, Mode=OneWay}"
mah:VisibilityHelper.IsCollapsed="{Binding ElementName=ListOfFailureItemsLabel,Path=IsVisible,Mode=OneWay}" />
<ListBox Margin="0,1,0,0" Grid.ColumnSpan="2" Grid.Row="1" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" VirtualizingPanel.CacheLengthUnit="Page" VirtualizingPanel.CacheLength="3" VirtualizingPanel.ScrollUnit="Item"
mah:VisibilityHelper.IsCollapsed="{Binding ElementName=ListOfFailureItemsLabel,Path=IsVisible,Mode=OneWay}" SelectionMode="Extended"
Expand Down Expand Up @@ -185,7 +185,7 @@
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Text="Filter by name matching pattern" mah:VisibilityHelper.IsCollapsed="{Binding ElementName=ListOfCancelledItemsLabel,Path=IsVisible,Mode=OneWay}" VerticalAlignment="Center" />
<leacontrols:TextBoxDelayedTextChange Grid.Column="1" TextChanged="TextBoxDelayedTextChange_TextChanged" Tag="{Binding ElementName=ListOfCancelledItems,BindsDirectlyToSource=True,Path=ItemsSource, Mode=OneWay}"
<localui:TextBoxDelayedTextChange Grid.Column="1" TextChanged="TextBoxDelayedTextChange_TextChanged" Tag="{Binding ElementName=ListOfCancelledItems,BindsDirectlyToSource=True,Path=ItemsSource, Mode=OneWay}"
mah:VisibilityHelper.IsCollapsed="{Binding ElementName=ListOfCancelledItemsLabel,Path=IsVisible,Mode=OneWay}" />
<ListBox Margin="0,1,0,0" Grid.ColumnSpan="2" Grid.Row="1" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" VirtualizingPanel.CacheLengthUnit="Page" VirtualizingPanel.CacheLength="3" VirtualizingPanel.ScrollUnit="Item"
mah:VisibilityHelper.IsCollapsed="{Binding ElementName=ListOfCancelledItemsLabel,Path=IsVisible,Mode=OneWay}" SelectionMode="Extended"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public Eyy()
}

private void MetroAnimatedTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
=> ConvenientEventHandlers.TabControl_SelectionChanged_PreventSelectingNothing(sender, e);
=> ConvenientMembers.TabControl_SelectionChanged_PreventSelectingNothing(sender, e);

private static readonly string CharLookout = "?#*[]";
private void TextBoxDelayedTextChange_TextChanged(object sender, TextChangedEventArgs e)
Expand Down
60 changes: 43 additions & 17 deletions LauncherCore/Windows/LauncherBehaviorManagerWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<leawindow:MetroWindowEx x:Class="Leayal.PSO2Launcher.Core.Windows.LauncherBehaviorManagerWindow"
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:Leayal.PSO2Launcher.Core.Windows"
xmlns:localui="clr-namespace:Leayal.PSO2Launcher.Core.UIElements"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:leawindow="clr-namespace:Leayal.Shared.Windows;assembly=Leayal.Shared.Windows" xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
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:Leayal.PSO2Launcher.Core.Windows"
xmlns:localui="clr-namespace:Leayal.PSO2Launcher.Core.UIElements"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:leawindow="clr-namespace:Leayal.Shared.Windows;assembly=Leayal.Shared.Windows" xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
mc:Ignorable="d" x:Name="thisSelf"
TitleCharacterCasing="Normal" ShowTitleBar="False" ShowMinButton="False" ShowMaxRestoreButton="False"
ResizeMode="NoResize"
Loaded="ThisSelf_Loaded"
SizeToContent="Height"
Title="Launcher Behavior Manager" Height="450" Width="800" WindowStartupLocation="CenterOwner">
TitleCharacterCasing="Normal" ShowTitleBar="False" ShowMinButton="False" ShowMaxRestoreButton="False"
ResizeMode="NoResize"
Loaded="ThisSelf_Loaded"
SizeToContent="Height"
Title="Launcher Behavior Manager" Height="450" Width="800" WindowStartupLocation="CenterOwner">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
Expand Down Expand Up @@ -47,7 +47,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="5" />
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition MinHeight="100"/>
</Grid.RowDefinitions>

<CheckBox Grid.Row="0" Grid.ColumnSpan="2" Content="Load the launcher website at startup" Margin="1" x:Name="checkbox_loadweblauncher" />
Expand Down Expand Up @@ -91,7 +91,7 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="Allow launcher to disable in-game file integrity validation (which allows client mods)" VerticalAlignment="Center" />
<iconPacks:PackIconFontAwesome Grid.Column="1" Kind="ExclamationCircleSolid" VerticalAlignment="Center" />
<iconPacks:PackIconFontAwesome Grid.Column="1" Kind="ExclamationCircleSolid" VerticalAlignment="Center" localui:ConvenientMembers.PaddingLeft="3" />
</Grid>
</CheckBox>

Expand Down Expand Up @@ -134,8 +134,34 @@
</TextBlock>
</CheckBox.ToolTip>
</CheckBox>

<CheckBox Grid.Row="13" Grid.ColumnSpan="2" Content="Launch this launcher as Admin by default (Not recommended)" Margin="1" x:Name="checkbox_lauchlauncherasadmin" />

<CheckBox Grid.Row="13" Grid.ColumnSpan="2" Margin="1" x:Name="checkbox_lauchlauncherasadmin" ToolTipService.InitialShowDelay="0">
<CheckBox.ToolTip>
<TextBlock>
<Run Text="Do NOT enable this feature unless you know what this is." TextDecorations="Underline" />
<LineBreak />
<Run Text="All features of this launcher are operational without administrator privileges unless your PC has abnormal or special circumstance." />
<LineBreak />
<Run Text="This feature will force the launcher to require Adminstration Access, which grants a lot of privileges that can modify your Admin-only settings or files, regardless whether you do &quot;Run as administrator&quot; or not." />
<LineBreak />
<Run Text="You can run the launcher as Admin by yourself without this feature by right-click on the launcher's icon and select &quot;Run as administrator&quot;." />
<LineBreak />
<Run Text="This feature is only helpful when you installed your PSO2 game client in Admin-only locations or questionable locations." />
<LineBreak />
<Run Text="In those cases, it is likely that you get" />
<Run Text="UnauthorizedAccessException" TextDecorations="Underline" />
<Run Text="error while updating PSO2 game client, you can try running this launcher as administrator to see if it can fix this error." />
</TextBlock>
</CheckBox.ToolTip>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="Launch this launcher as Admin by default (Not recommended)" VerticalAlignment="Center" />
<iconPacks:PackIconFontAwesome Grid.Column="1" Kind="ExclamationTriangleSolid" VerticalAlignment="Center" localui:ConvenientMembers.PaddingLeft="3" />
</Grid>
</CheckBox>
</Grid>

<Grid Grid.Row="2" Grid.ColumnSpan="2" Margin="1">
Expand Down
Loading

0 comments on commit b693318

Please sign in to comment.