Skip to content

Commit

Permalink
Added ZipSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
daredloco committed Oct 24, 2020
1 parent 158c204 commit fc3f41d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
1 change: 1 addition & 0 deletions GitInstaller/GitInstaller/GitInstaller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ZipSettings.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
2 changes: 1 addition & 1 deletion GitInstaller/GitInstaller/Installer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions GitInstaller/GitInstaller/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
24 changes: 23 additions & 1 deletion GitInstaller/GitInstaller/ZipArchiveExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
44 changes: 44 additions & 0 deletions GitInstaller/GitInstaller/ZipSettings.cs
Original file line number Diff line number Diff line change
@@ -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<ZipSettings>(File.ReadAllText(fname));
}
return null;
}

public static ZipSettings FromStream(Stream stream)
{
using (StreamReader reader = new StreamReader(stream))
{
try
{
ZipSettings zs = JsonConvert.DeserializeObject<ZipSettings>(reader.ReadToEnd());
return zs;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("There was an error while reading the ZipSettings! => " + ex.Message);
return null;
}
}
}
}
}

0 comments on commit fc3f41d

Please sign in to comment.