From 308ea92267ceaaebf10ed1c6e51a23f3bd612dce Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Sun, 1 Aug 2021 15:12:22 -0400 Subject: [PATCH] add patchclient, update other projects, blah --- Patcher/PatchClient/App.xaml | 9 ++ Patcher/PatchClient/App.xaml.cs | 17 +++ Patcher/PatchClient/AssemblyInfo.cs | 10 ++ .../Extensions/ControlExtensions.cs | 48 ++++++ Patcher/PatchClient/MainWindow.xaml | 36 +++++ Patcher/PatchClient/MainWindow.xaml.cs | 82 ++++++++++ Patcher/PatchClient/PatchClient.csproj | 13 ++ .../Extensions/ControlExtensions.cs | 48 ++++++ Patcher/PatchGenerator/MainWindow.xaml | 31 ++-- Patcher/PatchGenerator/MainWindow.xaml.cs | 141 ++++++++++++------ Patcher/PatchGenerator/PatchGenerator.csproj | 8 - Patcher/Patcher.sln | 6 + Patcher/PatcherUtils/FileCompare.cs | 2 +- Patcher/PatcherUtils/FilePatcher.cs | 4 +- Patcher/PatcherUtils/LazyOperations.cs | 34 +++-- Patcher/PatcherUtils/PatcherUtils.csproj | 10 ++ .../Resources/7za.exe | Bin .../PatcherUtils/Resources/PatchClient.exe | Bin 0 -> 1957623 bytes 18 files changed, 418 insertions(+), 81 deletions(-) create mode 100644 Patcher/PatchClient/App.xaml create mode 100644 Patcher/PatchClient/App.xaml.cs create mode 100644 Patcher/PatchClient/AssemblyInfo.cs create mode 100644 Patcher/PatchClient/Extensions/ControlExtensions.cs create mode 100644 Patcher/PatchClient/MainWindow.xaml create mode 100644 Patcher/PatchClient/MainWindow.xaml.cs create mode 100644 Patcher/PatchClient/PatchClient.csproj create mode 100644 Patcher/PatchGenerator/Extensions/ControlExtensions.cs rename Patcher/{PatchGenerator => PatcherUtils}/Resources/7za.exe (100%) create mode 100644 Patcher/PatcherUtils/Resources/PatchClient.exe diff --git a/Patcher/PatchClient/App.xaml b/Patcher/PatchClient/App.xaml new file mode 100644 index 0000000..58657c0 --- /dev/null +++ b/Patcher/PatchClient/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Patcher/PatchClient/App.xaml.cs b/Patcher/PatchClient/App.xaml.cs new file mode 100644 index 0000000..2a36935 --- /dev/null +++ b/Patcher/PatchClient/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace PatchClient +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/Patcher/PatchClient/AssemblyInfo.cs b/Patcher/PatchClient/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/Patcher/PatchClient/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/Patcher/PatchClient/Extensions/ControlExtensions.cs b/Patcher/PatchClient/Extensions/ControlExtensions.cs new file mode 100644 index 0000000..bf6b129 --- /dev/null +++ b/Patcher/PatchClient/Extensions/ControlExtensions.cs @@ -0,0 +1,48 @@ +using System.Windows; +using System.Windows.Controls; + +namespace PatchClient.Extensions +{ + public static class ControlExtensions + { + public static void DispatcherSetValue(this ProgressBar pb, int Value) + { + Application.Current.Dispatcher.Invoke(() => + { + pb.Value = Value; + }); + } + + public static void DispatcherSetIndetermination(this ProgressBar pb, bool Indeterminate) + { + Application.Current.Dispatcher.Invoke(() => + { + pb.IsIndeterminate = Indeterminate; + }); + } + + public static void DispaatcherSetContent(this ContentControl cc, object content) + { + Application.Current.Dispatcher.Invoke(() => + { + cc.Content = content; + }); + } + + public static void DispatcherSetText(this TextBlock tb, string Text) + { + Application.Current.Dispatcher.Invoke(() => + { + tb.Text = Text; + }); + } + + public static void DispatcherSetEnabled(this UIElement uie, bool Enabled) + { + Application.Current.Dispatcher.Invoke(() => + { + uie.IsEnabled = Enabled; + }); + } + } +} diff --git a/Patcher/PatchClient/MainWindow.xaml b/Patcher/PatchClient/MainWindow.xaml new file mode 100644 index 0000000..f7d83e5 --- /dev/null +++ b/Patcher/PatchClient/MainWindow.xaml @@ -0,0 +1,36 @@ + + + + + + diff --git a/Patcher/PatchClient/MainWindow.xaml.cs b/Patcher/PatchClient/MainWindow.xaml.cs new file mode 100644 index 0000000..3610ca5 --- /dev/null +++ b/Patcher/PatchClient/MainWindow.xaml.cs @@ -0,0 +1,82 @@ +using PatchClient.Extensions; +using PatcherUtils; +using System; +using System.Threading.Tasks; +using System.Windows; + +namespace PatchClient +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + + private void RunPatcher() + { + Task.Run(() => + { + FilePatcher bp = new FilePatcher() + { + TargetBase = Environment.CurrentDirectory, + PatchBase = LazyOperations.PatchFolder.FromCwd() + }; + + bp.ProgressChanged += Bp_ProgressChanged; + + try + { + if (bp.Run()) + { + MessageBox.Show("Patch completed without issues", "Patching Successful"); + } + else + { + MessageBox.Show("Failed to patch client.", "Patching Failed", MessageBoxButton.OK, MessageBoxImage.Error); + } + } + catch(Exception ex) + { + MessageBox.Show(ex.Message); + } + finally + { + Application.Current.Dispatcher.Invoke(() => + { + Application.Current.Shutdown(0); + }); + } + }); + } + + private void Bp_ProgressChanged(object Sender, int Progress, int Total, int Percent, string Message = "", params LineItem[] AdditionalLineItems) + { + string additionalInfo = ""; + foreach (LineItem item in AdditionalLineItems) + { + additionalInfo += $"{item.ItemText}: {item.ItemValue}\n"; + } + + + PatchProgressBar.DispatcherSetValue(Percent); + + if (!string.IsNullOrWhiteSpace(Message)) + { + PatchMessageLabel.DispaatcherSetContent(Message); + } + + PatchProgressInfoLabel.DispaatcherSetContent($"[{Progress}/{Total}]"); + + AdditionalInfoBlock.DispatcherSetText(additionalInfo); + } + + private void Window_Loaded(object sender, RoutedEventArgs e) + { + RunPatcher(); + } + } +} diff --git a/Patcher/PatchClient/PatchClient.csproj b/Patcher/PatchClient/PatchClient.csproj new file mode 100644 index 0000000..50f77b1 --- /dev/null +++ b/Patcher/PatchClient/PatchClient.csproj @@ -0,0 +1,13 @@ + + + + WinExe + net5.0-windows + true + + + + + + + diff --git a/Patcher/PatchGenerator/Extensions/ControlExtensions.cs b/Patcher/PatchGenerator/Extensions/ControlExtensions.cs new file mode 100644 index 0000000..e91824b --- /dev/null +++ b/Patcher/PatchGenerator/Extensions/ControlExtensions.cs @@ -0,0 +1,48 @@ +using System.Windows; +using System.Windows.Controls; + +namespace PatchGenerator.Extensions +{ + public static class ControlExtensions + { + public static void DispatcherSetValue(this ProgressBar pb, int Value) + { + Application.Current.Dispatcher.Invoke(() => + { + pb.Value = Value; + }); + } + + public static void DispatcherSetIndetermination(this ProgressBar pb, bool Indeterminate) + { + Application.Current.Dispatcher.Invoke(() => + { + pb.IsIndeterminate = Indeterminate; + }); + } + + public static void DispaatcherSetContent(this ContentControl cc, object content) + { + Application.Current.Dispatcher.Invoke(() => + { + cc.Content = content; + }); + } + + public static void DispatcherSetText(this TextBlock tb, string Text) + { + Application.Current.Dispatcher.Invoke(() => + { + tb.Text = Text; + }); + } + + public static void DispatcherSetEnabled(this UIElement uie, bool Enabled) + { + Application.Current.Dispatcher.Invoke(() => + { + uie.IsEnabled = Enabled; + }); + } + } +} diff --git a/Patcher/PatchGenerator/MainWindow.xaml b/Patcher/PatchGenerator/MainWindow.xaml index b01a1a2..0bd37ad 100644 --- a/Patcher/PatchGenerator/MainWindow.xaml +++ b/Patcher/PatchGenerator/MainWindow.xaml @@ -5,7 +5,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:PatchGenerator" mc:Ignorable="d" - Title="MainWindow" Height="450" Width="800"> + Title="Patch Generator" Height="450" Width="800" + WindowStartupLocation="CenterScreen"> @@ -14,30 +15,41 @@ + + + + +