From fc3f41d879c0a1c48a91d726c4f116ae2a58ec51 Mon Sep 17 00:00:00 2001 From: daredloco Date: Sat, 24 Oct 2020 12:24:43 -0300 Subject: [PATCH] Added ZipSettings --- GitInstaller/GitInstaller/GitInstaller.csproj | 1 + GitInstaller/GitInstaller/Installer.cs | 2 +- .../GitInstaller/Properties/AssemblyInfo.cs | 4 +- .../GitInstaller/ZipArchiveExtensions.cs | 24 +++++++++- GitInstaller/GitInstaller/ZipSettings.cs | 44 +++++++++++++++++++ 5 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 GitInstaller/GitInstaller/ZipSettings.cs diff --git a/GitInstaller/GitInstaller/GitInstaller.csproj b/GitInstaller/GitInstaller/GitInstaller.csproj index f071c08..174179b 100644 --- a/GitInstaller/GitInstaller/GitInstaller.csproj +++ b/GitInstaller/GitInstaller/GitInstaller.csproj @@ -71,6 +71,7 @@ MSBuild:Compile Designer + MSBuild:Compile Designer diff --git a/GitInstaller/GitInstaller/Installer.cs b/GitInstaller/GitInstaller/Installer.cs index 285a790..a31b0ee 100644 --- a/GitInstaller/GitInstaller/Installer.cs +++ b/GitInstaller/GitInstaller/Installer.cs @@ -227,7 +227,7 @@ await Task.Run(() => { { using(ZipArchive archive = new ZipArchive(fs)) { - ZipArchiveExtensions.ExtractToDirectory(archive, fi.DirectoryName, true); + ZipArchiveExtensions.ExtractWithSettings(archive, fi.DirectoryName, true); } } File.Delete(fname); diff --git a/GitInstaller/GitInstaller/Properties/AssemblyInfo.cs b/GitInstaller/GitInstaller/Properties/AssemblyInfo.cs index de53ae1..50e85a7 100644 --- a/GitInstaller/GitInstaller/Properties/AssemblyInfo.cs +++ b/GitInstaller/GitInstaller/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // indem Sie "*" wie unten gezeigt eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.0.0")] -[assembly: AssemblyFileVersion("1.3.0.0")] +[assembly: AssemblyVersion("1.4.0.0")] +[assembly: AssemblyFileVersion("1.4.0.0")] diff --git a/GitInstaller/GitInstaller/ZipArchiveExtensions.cs b/GitInstaller/GitInstaller/ZipArchiveExtensions.cs index af0e156..be9cbf2 100644 --- a/GitInstaller/GitInstaller/ZipArchiveExtensions.cs +++ b/GitInstaller/GitInstaller/ZipArchiveExtensions.cs @@ -26,9 +26,31 @@ public static void ExtractToDirectory(this ZipArchive archive, string destinatio if (!Directory.Exists(directory)) Directory.CreateDirectory(directory); - if (file.Name != "") + if (string.IsNullOrEmpty(file.Name) && file.Name != "zipsettings.json") file.ExtractToFile(completeFileName, true); } } + + //Added by daRedLoCo + public static void ExtractWithSettings(this ZipArchive archive, string destinationDirectoryName, bool overwrite) + { + ZipSettings settings = ZipSettings.FromStream(archive.GetEntry("zipsettings.json").Open()); + if(settings == null) + { + ExtractToDirectory(archive, destinationDirectoryName, overwrite); + return; + } + foreach(ZipArchiveEntry file in archive.Entries) + { + string completeFileName = Path.Combine(destinationDirectoryName, settings.Subfolder, file.FullName); + string directory = Path.GetDirectoryName(completeFileName); + + if (!Directory.Exists(directory)) + Directory.CreateDirectory(directory); + + if (string.IsNullOrEmpty(file.Name) && file.Name != "zipsettings.json") + file.ExtractToFile(completeFileName, overwrite); + } + } } } diff --git a/GitInstaller/GitInstaller/ZipSettings.cs b/GitInstaller/GitInstaller/ZipSettings.cs new file mode 100644 index 0000000..2329dda --- /dev/null +++ b/GitInstaller/GitInstaller/ZipSettings.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace GitInstaller +{ + [Serializable] + public class ZipSettings + { + public string Subfolder; + + public ZipSettings() { } + + public static ZipSettings FromFile(string fname) + { + if (File.Exists(fname)) + { + return JsonConvert.DeserializeObject(File.ReadAllText(fname)); + } + return null; + } + + public static ZipSettings FromStream(Stream stream) + { + using (StreamReader reader = new StreamReader(stream)) + { + try + { + ZipSettings zs = JsonConvert.DeserializeObject(reader.ReadToEnd()); + return zs; + } + catch (Exception ex) + { + System.Windows.Forms.MessageBox.Show("There was an error while reading the ZipSettings! => " + ex.Message); + return null; + } + } + } + } +}