From 63a2b16c323d7b7bda60678c28da6b7a68d5a5c2 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 16 May 2017 05:14:39 +0100 Subject: [PATCH] DotNetZip is currently unusable with Xamarin.Mac so disable it until upstream corrects. --- osrepodbmgr.Core/Context.cs | 1 + osrepodbmgr.Core/Workers.cs | 25 ++++++++++++++++++------- osrepodbmgr.Eto.Desktop/Program.cs | 2 ++ osrepodbmgr.Eto.XamMac2/Program.cs | 1 + osrepodbmgr.Eto/frmMain.xeto | 2 +- osrepodbmgr.Eto/frmMain.xeto.cs | 17 ++++++++++++----- osrepodbmgr/Program.cs | 1 + osrepodbmgr/gtk-gui/generated.cs | 8 ++++---- 8 files changed, 40 insertions(+), 17 deletions(-) diff --git a/osrepodbmgr.Core/Context.cs b/osrepodbmgr.Core/Context.cs index 52602da..8a80fe8 100644 --- a/osrepodbmgr.Core/Context.cs +++ b/osrepodbmgr.Core/Context.cs @@ -51,6 +51,7 @@ namespace osrepodbmgr.Core public static BlockMediaType workingDisk; public static CICMMetadataType metadata; public static bool userExtracting; + public static bool usableDotNetZip; public delegate void UnarChangeStatusDelegate(); public static event UnarChangeStatusDelegate UnarChangeStatus; diff --git a/osrepodbmgr.Core/Workers.cs b/osrepodbmgr.Core/Workers.cs index 403106e..7b3be14 100644 --- a/osrepodbmgr.Core/Workers.cs +++ b/osrepodbmgr.Core/Workers.cs @@ -1151,14 +1151,18 @@ namespace osrepodbmgr.Core if(Context.archiveFormat == "Zip") { Context.unzipWithUnAr = true; - ZipFile zf = ZipFile.Read(Context.path, new ReadOptions { Encoding = Encoding.UTF8 }); - foreach(ZipEntry ze in zf) + + if(Context.usableDotNetZip) { - // ZIP created with Mac OS X, need to be extracted with The UnArchiver to get correct ResourceFork structure - if(ze.FileName.StartsWith("__MACOSX", StringComparison.CurrentCulture)) + ZipFile zf = ZipFile.Read(Context.path, new ReadOptions { Encoding = Encoding.UTF8 }); + foreach(ZipEntry ze in zf) { - Context.unzipWithUnAr = false; - break; + // ZIP created with Mac OS X, need to be extracted with The UnArchiver to get correct ResourceFork structure + if(ze.FileName.StartsWith("__MACOSX", StringComparison.CurrentCulture)) + { + Context.unzipWithUnAr = false; + break; + } } } } @@ -1215,7 +1219,7 @@ namespace osrepodbmgr.Core try { // If it's a ZIP file not created by Mac OS X, use DotNetZip to uncompress (unar freaks out or corrupts certain ZIP features) - if(Context.archiveFormat == "Zip" && !Context.unzipWithUnAr) + if(Context.archiveFormat == "Zip" && !Context.unzipWithUnAr && Context.usableDotNetZip) { try { @@ -1591,6 +1595,13 @@ namespace osrepodbmgr.Core return; } + if(!Context.usableDotNetZip) + { + if(Failed != null) + Failed("Cannot create ZIP files"); + return; + } + ZipFile zf = new ZipFile(Context.path, Encoding.UTF8); zf.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression; zf.CompressionMethod = CompressionMethod.Deflate; diff --git a/osrepodbmgr.Eto.Desktop/Program.cs b/osrepodbmgr.Eto.Desktop/Program.cs index 8b160a5..b91ece8 100644 --- a/osrepodbmgr.Eto.Desktop/Program.cs +++ b/osrepodbmgr.Eto.Desktop/Program.cs @@ -39,6 +39,8 @@ namespace osrepodbmgr.Eto.Desktop { Settings.LoadSettings(); Context.CheckUnar(); + Context.usableDotNetZip = !Platform.Detect.IsMac && !Platform.Detect.IsIos; + new Application(Platform.Detect).Run(new frmMain()); } } diff --git a/osrepodbmgr.Eto.XamMac2/Program.cs b/osrepodbmgr.Eto.XamMac2/Program.cs index 9e2a704..a62b0c8 100644 --- a/osrepodbmgr.Eto.XamMac2/Program.cs +++ b/osrepodbmgr.Eto.XamMac2/Program.cs @@ -39,6 +39,7 @@ namespace osrepodbmgr.Eto.XamMac2 { Settings.LoadSettings(); Context.CheckUnar(); + Context.usableDotNetZip = false; new Application(Platforms.XamMac2).Run(new frmMain()); } } diff --git a/osrepodbmgr.Eto/frmMain.xeto b/osrepodbmgr.Eto/frmMain.xeto index d9ba5ce..f75079b 100644 --- a/osrepodbmgr.Eto/frmMain.xeto +++ b/osrepodbmgr.Eto/frmMain.xeto @@ -39,7 +39,7 @@ - + diff --git a/osrepodbmgr.Eto/frmMain.xeto.cs b/osrepodbmgr.Eto/frmMain.xeto.cs index 4c6e83e..414c571 100644 --- a/osrepodbmgr.Eto/frmMain.xeto.cs +++ b/osrepodbmgr.Eto/frmMain.xeto.cs @@ -55,6 +55,7 @@ namespace osrepodbmgr.Eto Button btnStop; ButtonMenuItem btnSettings; ButtonMenuItem btnHelp; + ButtonMenuItem mnuCompress; #pragma warning restore 0649 #endregion XAML UI elements @@ -144,6 +145,12 @@ namespace osrepodbmgr.Eto prgProgress.Indeterminate = true; + if(!Context.usableDotNetZip) + { + btnCompress.Visible = false; + mnuCompress.Enabled = false; + } + Workers.Failed += LoadOSesFailed; Workers.Finished += LoadOSesFinished; Workers.UpdateProgress += UpdateProgress; @@ -187,7 +194,7 @@ namespace osrepodbmgr.Eto treeOSes.Enabled = true; btnAdd.Visible = true; btnRemove.Visible = true; - btnCompress.Visible = true; + btnCompress.Visible = Context.usableDotNetZip; btnSave.Visible = true; btnHelp.Enabled = true; btnSettings.Enabled = true; @@ -318,7 +325,7 @@ namespace osrepodbmgr.Eto treeOSes.Enabled = true; btnAdd.Visible = true; btnRemove.Visible = true; - btnCompress.Visible = true; + btnCompress.Visible = Context.usableDotNetZip; btnSave.Visible = true; btnHelp.Enabled = true; btnSettings.Enabled = true; @@ -350,7 +357,7 @@ namespace osrepodbmgr.Eto treeOSes.Enabled = true; btnAdd.Visible = true; btnRemove.Visible = true; - btnCompress.Visible = true; + btnCompress.Visible = Context.usableDotNetZip; btnSave.Visible = true; btnHelp.Enabled = true; btnSettings.Enabled = true; @@ -461,7 +468,7 @@ namespace osrepodbmgr.Eto treeOSes.Enabled = true; btnAdd.Visible = true; btnRemove.Visible = true; - btnCompress.Visible = true; + btnCompress.Visible = Context.usableDotNetZip; btnSave.Visible = true; btnHelp.Enabled = true; btnSettings.Enabled = true; @@ -493,7 +500,7 @@ namespace osrepodbmgr.Eto treeOSes.Enabled = true; btnAdd.Visible = true; btnRemove.Visible = true; - btnCompress.Visible = true; + btnCompress.Visible = Context.usableDotNetZip; btnSave.Visible = true; btnHelp.Enabled = true; btnSettings.Enabled = true; diff --git a/osrepodbmgr/Program.cs b/osrepodbmgr/Program.cs index 54b2c7b..ba39894 100644 --- a/osrepodbmgr/Program.cs +++ b/osrepodbmgr/Program.cs @@ -36,6 +36,7 @@ namespace osrepodbmgr { Core.Settings.LoadSettings(); Context.CheckUnar(); + Context.usableDotNetZip = true; Application.Init(); frmMain win = new frmMain(); win.Show(); diff --git a/osrepodbmgr/gtk-gui/generated.cs b/osrepodbmgr/gtk-gui/generated.cs index aa4161e..f692d75 100644 --- a/osrepodbmgr/gtk-gui/generated.cs +++ b/osrepodbmgr/gtk-gui/generated.cs @@ -8,7 +8,7 @@ namespace Stetic internal static void Initialize(Gtk.Widget iconRenderer) { - if ((Stetic.Gui.initialized == false)) + if((Stetic.Gui.initialized == false)) { Stetic.Gui.initialized = true; } @@ -20,7 +20,7 @@ namespace Stetic public static Gdk.Pixbuf LoadIcon(Gtk.Widget widget, string name, Gtk.IconSize size) { Gdk.Pixbuf res = widget.RenderIcon(name, size, null); - if ((res != null)) + if((res != null)) { return res; } @@ -33,9 +33,9 @@ namespace Stetic { return Gtk.IconTheme.Default.LoadIcon(name, sz, 0); } - catch (System.Exception) + catch(System.Exception) { - if ((name != "gtk-missing-image")) + if((name != "gtk-missing-image")) { return Stetic.IconLoader.LoadIcon(widget, "gtk-missing-image", size); }