This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Use GNU zip if 7-zip is not available, then recompress with advzip.

  • Loading branch information...
polyethene
polyethene committed Nov 14, 2010
1 parent 66315c8 commit 4628e6b161d6278458e26810babf3d8b2b082df3
Showing with 105 additions and 32 deletions.
  1. +1 −0 Deploy/Deploy.csproj
  2. +0 −32 Deploy/Program.cs
  3. +104 −0 Deploy/Zip.cs
View
@@ -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" />
View
@@ -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]; }
View
@@ -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.