From 4628e6b161d6278458e26810babf3d8b2b082df3 Mon Sep 17 00:00:00 2001 From: polyethene Date: Sun, 14 Nov 2010 09:13:52 +0000 Subject: [PATCH] Use GNU zip if 7-zip is not available, then recompress with advzip. --- Deploy/Deploy.csproj | 1 + Deploy/Program.cs | 32 ------------- Deploy/Zip.cs | 104 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 32 deletions(-) create mode 100644 Deploy/Zip.cs diff --git a/Deploy/Deploy.csproj b/Deploy/Deploy.csproj index d4f1dcbc..65abea13 100644 --- a/Deploy/Deploy.csproj +++ b/Deploy/Deploy.csproj @@ -70,6 +70,7 @@ + diff --git a/Deploy/Program.cs b/Deploy/Program.cs index 42b7a529..e6d5a33e 100644 --- a/Deploy/Program.cs +++ b/Deploy/Program.cs @@ -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]; } diff --git a/Deploy/Zip.cs b/Deploy/Zip.cs new file mode 100644 index 00000000..fe216f2b --- /dev/null +++ b/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); + } + } + } + } +}