Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 12, 2018. It is now read-only.

Commit

Permalink
Use GNU zip if 7-zip is not available, then recompress with advzip.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paris committed Nov 14, 2010
1 parent 66315c8 commit 4628e6b
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 32 deletions.
1 change: 1 addition & 0 deletions Deploy/Deploy.csproj
Expand Up @@ -70,6 +70,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Bundle.cs" />
<Compile Include="Zip.cs" />
<Compile Include="Portable.cs" />
<Compile Include="Package.cs" />
<Compile Include="Docs.cs" />
Expand Down
32 changes: 0 additions & 32 deletions Deploy/Program.cs
Expand Up @@ -71,38 +71,6 @@ static void Metadata()
File.WriteAllText(path, Version);
}

static void Zip(string output, string paths, string working)
{
if (File.Exists(output))
File.Delete(output);

using (var sz = new Process())
{
sz.StartInfo = new ProcessStartInfo { FileName = "7za", UseShellExecute = false };

if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
string exe = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "7-Zip\\7z.exe");

if (File.Exists(exe))
sz.StartInfo.FileName = exe;
}

sz.StartInfo.WorkingDirectory = working;
sz.StartInfo.Arguments = string.Format("a \"{0}\" \"{1}\" -mx=9", output, paths);

try
{
sz.Start();
sz.WaitForExit();
}
catch (Win32Exception e)
{
Console.Error.WriteLine(ExecFailed, sz.StartInfo.FileName, e.Message);
}
}
}

static string Name
{
get { return typeof(Program).Namespace.Split(new[] { '.' }, 2)[0]; }
Expand Down
104 changes: 104 additions & 0 deletions Deploy/Zip.cs
@@ -0,0 +1,104 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using Microsoft.Win32;

namespace IronAHK.Setup
{
partial class Program
{
static void Zip(string output, string paths, string working)
{
if (File.Exists(output))
File.Delete(output);

SevenZip(output, paths, working);

if (!File.Exists(output))
GnuZip(output, paths, working);

if (File.Exists(output))
AdvZip(output);
}

static void AdvZip(string output)
{
using (var adv = new Process())
{
adv.StartInfo = new ProcessStartInfo { FileName = "advzip", UseShellExecute = true, Arguments = string.Format("-z -4 \"{0}\"", output) };

try
{
adv.Start();
adv.WaitForExit();
}
catch (Win32Exception)
{

}
}
}

static void GnuZip(string output, string paths, string working)
{
using (var zip = new Process())
{
zip.StartInfo = new ProcessStartInfo
{
FileName = "zip",
UseShellExecute = true,
Arguments = string.Format("-9 -r -X \"{0}\" \"{1}\"", output, paths),
WorkingDirectory = working
};

try
{
zip.Start();
zip.WaitForExit();
}
catch (Win32Exception e)
{
Console.Error.WriteLine(ExecFailed, zip.StartInfo.FileName, e.Message);
}
}
}

static void SevenZip(string output, string paths, string working)
{
using (var sz = new Process())
{
sz.StartInfo = new ProcessStartInfo
{
FileName = "7za",
UseShellExecute = true,
Arguments = string.Format("a \"{0}\" \"{1}\" -mx=9", output, paths),
WorkingDirectory = working
};

if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
var install = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "7-Zip");
var dir = (string)Registry.CurrentUser.OpenSubKey("SOFTWARE\\7-Zip").GetValue("Path", install);
var exe = Path.Combine(dir, "7z.exe");

if (File.Exists(exe))
{
sz.StartInfo.FileName = exe;
sz.StartInfo.UseShellExecute = false;
}
}

try
{
sz.Start();
sz.WaitForExit();
}
catch (Win32Exception e)
{
Console.Error.WriteLine(ExecFailed, sz.StartInfo.FileName, e.Message);
}
}
}
}
}

0 comments on commit 4628e6b

Please sign in to comment.