From 0b3514bf46c141836f038a96c367de0653539b5f Mon Sep 17 00:00:00 2001 From: WeeXnes Date: Tue, 13 Dec 2022 11:45:42 +0100 Subject: [PATCH] Rewrote Updater --- Update/App.config | 6 ++ Update/App.xaml | 10 +++ Update/App.xaml.cs | 88 +++++++++++++++++++++++ Update/MainWindow.xaml | 12 ++++ Update/MainWindow.xaml.cs | 13 ++++ Update/Properties/Resources.resx | 117 +++++++++++++++++++++++++++++++ 6 files changed, 246 insertions(+) create mode 100644 Update/App.config create mode 100644 Update/App.xaml create mode 100644 Update/App.xaml.cs create mode 100644 Update/MainWindow.xaml create mode 100644 Update/MainWindow.xaml.cs create mode 100644 Update/Properties/Resources.resx diff --git a/Update/App.config b/Update/App.config new file mode 100644 index 0000000..aee9adf --- /dev/null +++ b/Update/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Update/App.xaml b/Update/App.xaml new file mode 100644 index 0000000..501eb9e --- /dev/null +++ b/Update/App.xaml @@ -0,0 +1,10 @@ + + + + + diff --git a/Update/App.xaml.cs b/Update/App.xaml.cs new file mode 100644 index 0000000..03caf72 --- /dev/null +++ b/Update/App.xaml.cs @@ -0,0 +1,88 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Windows; + +namespace Update +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App + { + private void App_OnStartup(object sender, StartupEventArgs e) + { + RunUpdater(e.Args[0],e.Args[1],e.Args[2],e.Args[3]); + } + private void RunUpdater(string Path, string FileName, string ProcessId, string NewFile) + { + if(String.IsNullOrEmpty(Path)) + return; + if(String.IsNullOrEmpty(FileName)) + return; + if(String.IsNullOrEmpty(ProcessId)) + return; + if(String.IsNullOrEmpty(NewFile)) + return; + + Process p = Process.GetProcessById(Convert.ToInt32(ProcessId)); + p.Kill(); + p.WaitForExit(); + try + { + ZipArchiveHelper.ExtractToDirectory(NewFile, Path, true); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + ZipArchiveHelper.ExtractToDirectory(NewFile, Path, true); + } + Process.Start(Path + "\\" + FileName); + if (File.Exists(NewFile)) + { + File.Delete(NewFile); + } + + Environment.Exit(0); + } + } + public static class ZipArchiveHelper + { + public static void ExtractToDirectory(string archiveFileName, string destinationDirectoryName, bool overwrite) + { + if (!overwrite) + { + ZipFile.ExtractToDirectory(archiveFileName, destinationDirectoryName); + } + else + { + using (var archive = ZipFile.OpenRead(archiveFileName)) + { + + foreach (var file in archive.Entries) + { + try + { + var completeFileName = Path.Combine(destinationDirectoryName, file.FullName); + var directory = Path.GetDirectoryName(completeFileName); + + if (!Directory.Exists(directory) && !string.IsNullOrEmpty(directory)) + Directory.CreateDirectory(directory); + + if (file.Name != "") + file.ExtractToFile(completeFileName, true); + } + catch (IOException ex) + { + Console.WriteLine(ex); + var completeFileName = Path.Combine(destinationDirectoryName, file.FullName + ".new"); + file.ExtractToFile(completeFileName); + } + } + + } + } + } + } +} \ No newline at end of file diff --git a/Update/MainWindow.xaml b/Update/MainWindow.xaml new file mode 100644 index 0000000..55f3455 --- /dev/null +++ b/Update/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/Update/MainWindow.xaml.cs b/Update/MainWindow.xaml.cs new file mode 100644 index 0000000..8465659 --- /dev/null +++ b/Update/MainWindow.xaml.cs @@ -0,0 +1,13 @@ +namespace Update +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow + { + public MainWindow() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/Update/Properties/Resources.resx b/Update/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Update/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file