From f6c202745fd2e56930ea11e5cb19241548d7c9bd Mon Sep 17 00:00:00 2001 From: Andreas Weizel Date: Thu, 24 Jan 2013 01:11:35 +0100 Subject: [PATCH] - Finished support for external AddIns installed from .addin files. They are shown with a different icon in AddIn list. - Improved error handling and visualization. - Some more refactoring. --- .../Project/AddInManager2.csproj | 3 +- .../Project/Resources/StringResources.resx | 5 +- .../Resources/external_addin_small.png | Bin 0 -> 798 bytes .../Src/Model/AddInExceptionEventArgs.cs | 24 ------ .../Project/Src/Model/AddInManagerEvents.cs | 12 ++- .../Src/Model/AddInOperationErrorEventArgs.cs | 49 ++++++++++++ .../Project/Src/Model/AddInSetup.cs | 74 +++++++++++------- .../Model/Interfaces/IAddInManagerEvents.cs | 5 +- .../Model/Interfaces/ISDAddInManagement.cs | 1 + .../Project/Src/Model/SDAddInManagement.cs | 5 ++ .../Project/Src/View/AddInManagerView.xaml | 22 +++++- .../Project/Src/View/AddInsView.xaml | 18 +++++ .../Src/ViewModel/AddInManagerViewModel.cs | 9 ++- .../ViewModel/AddInPackageViewModelBase.cs | 8 ++ .../Src/ViewModel/InstalledAddInsViewModel.cs | 2 +- .../Src/ViewModel/NuGetPackageViewModel.cs | 12 ++- .../Src/ViewModel/OfflineAddInViewModel.cs | 42 +++++++++- 17 files changed, 221 insertions(+), 70 deletions(-) create mode 100644 src/AddIns/Misc/AddInManager2/Project/Resources/external_addin_small.png delete mode 100644 src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInExceptionEventArgs.cs create mode 100644 src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInOperationErrorEventArgs.cs diff --git a/src/AddIns/Misc/AddInManager2/Project/AddInManager2.csproj b/src/AddIns/Misc/AddInManager2/Project/AddInManager2.csproj index 90eeb233d2..bdcbd9ba89 100644 --- a/src/AddIns/Misc/AddInManager2/Project/AddInManager2.csproj +++ b/src/AddIns/Misc/AddInManager2/Project/AddInManager2.csproj @@ -77,6 +77,7 @@ + @@ -110,7 +111,7 @@ - + diff --git a/src/AddIns/Misc/AddInManager2/Project/Resources/StringResources.resx b/src/AddIns/Misc/AddInManager2/Project/Resources/StringResources.resx index fa78b641fc..b0d2f7ecb2 100644 --- a/src/AddIns/Misc/AddInManager2/Project/Resources/StringResources.resx +++ b/src/AddIns/Misc/AddInManager2/Project/Resources/StringResources.resx @@ -236,7 +236,7 @@ If you do not agree to the license terms click "I Decline". License Agreements - SharpDevelop AddIns|*.sdaddin|All files|*.* + SharpDevelop AddIns|*.sdaddin;*.addin|All files|*.* Package "{0}" needs at least one additional package: @@ -254,4 +254,7 @@ The application will try to download and install them, as well. Do you want to c File name: + + Selected package doesn't contain a valid SharpDevelop AddIn. + \ No newline at end of file diff --git a/src/AddIns/Misc/AddInManager2/Project/Resources/external_addin_small.png b/src/AddIns/Misc/AddInManager2/Project/Resources/external_addin_small.png new file mode 100644 index 0000000000000000000000000000000000000000..ac945975af0b2c60d4b46dcbc34fa9b7f576fec9 GIT binary patch literal 798 zcmV+(1L6FMP)N2bPDNB8 zb~7$DE-^4L^m3s900NpxL_t(IPmPjWNRwe4#=q<8DuOPGh{!I6U=WtH4ptZrIuL27 zSYc#prm|9pGZRM;1u`&6g)k6Dk!H?pDQTr)UFgEp5hkK@ZqqqkJA89+sw-<4ineVX~&KfGHk|6Av)s`B`77_MLt4!<8(pAU0hFU%f~VEy1A zsD?RCjBwo1=EWv)%AHfI^Sx_paI&E0y%T!V5+)ZGV6xdTVYNbMFn~mL%)cP=ruh+h zqeV^gGb&Yqj{#PA9+%qexcJqZrY$|nK!brHn~Pu|INX} z;_@L&XU3yBAd`(R$L#A)Lf1J}T3RRo_C7Gx7Jpb-QhoNiGuvjDuXb3Ft((DxCsVjP z8iIBzjI`$Ocrj{?K?snlRNfE(GL13uaGhzq{G&Hq^45d00Uy+#cvKAWQ1*Lq-QY%z zF@UoT<7hL^2@rbNl%k>{0YKWN8mu_kXqqnRb4BvIUAWxgKyv+8!6zCfkotHMc|A)| zXooT5bPB(7yr7^&jC0(MTm2ih757#oRQ1`i+GnBYTtH&G1G1-!*x6!-ylWXL_lKbW zVu9W5hGTUVM{;wOVq8-El{?zXXJbg$4&j*Q9kv)E*xnmKa!o(F*zxIi=!>aO4(8>O>nBivuUmy^JP_t337?YHcmZqXki?UPX)eqn`+d0TuI}i%3gYaxkwPH-t9)+Tk z03?FYN$5I%Li}t_wPH-t)}$njm={FXp*IPO@3O`mV6Y%tQ>_@2v?)G5ccV;p?|)3S c9LI4#0XA_;gZ~iiW&i*H07*qoM6N<$f<+~0kN^Mx literal 0 HcmV?d00001 diff --git a/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInExceptionEventArgs.cs b/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInExceptionEventArgs.cs deleted file mode 100644 index 9cc0a54d2b..0000000000 --- a/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInExceptionEventArgs.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) -// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) - -using System; - -namespace ICSharpCode.AddInManager2.Model -{ - /// - /// Data for events indicating an exception during package-related operations. - /// - public class AddInExceptionEventArgs : EventArgs - { - public AddInExceptionEventArgs(Exception exception) - { - Exception = exception; - } - - public Exception Exception - { - get; - private set; - } - } -} diff --git a/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInManagerEvents.cs b/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInManagerEvents.cs index 7bf7cddff2..c77bf3bab3 100644 --- a/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInManagerEvents.cs +++ b/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInManagerEvents.cs @@ -13,6 +13,14 @@ namespace ICSharpCode.AddInManager2.Model { public event EventHandler OperationStarted; + public void OnOperationStarted() + { + if (OperationStarted != null) + { + OperationStarted(this, new EventArgs()); + } + } + public void OnOperationStarted(EventArgs e) { if (OperationStarted != null) @@ -41,9 +49,9 @@ namespace ICSharpCode.AddInManager2.Model } } - public event EventHandler AddInOperationError; + public event EventHandler AddInOperationError; - public void OnAddInOperationError(AddInExceptionEventArgs e) + public void OnAddInOperationError(AddInOperationErrorEventArgs e) { if (AddInOperationError != null) { diff --git a/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInOperationErrorEventArgs.cs b/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInOperationErrorEventArgs.cs new file mode 100644 index 0000000000..a65310f4b7 --- /dev/null +++ b/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInOperationErrorEventArgs.cs @@ -0,0 +1,49 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; + +namespace ICSharpCode.AddInManager2.Model +{ + /// + /// Data for events indicating an exception or other errors during package-related operations. + /// + public class AddInOperationErrorEventArgs : EventArgs + { + private string _message = null; + + public AddInOperationErrorEventArgs(Exception exception) + { + Exception = exception; + } + + public AddInOperationErrorEventArgs(string message) + { + Exception = null; + _message = message; + } + + public Exception Exception + { + get; + private set; + } + + public string Message + { + get + { + if (_message != null) + { + return _message; + } + if (Exception != null) + { + return Exception.Message; + } + + return null; + } + } + } +} diff --git a/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInSetup.cs b/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInSetup.cs index af7b03b298..6476c0b050 100644 --- a/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInSetup.cs +++ b/src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInSetup.cs @@ -56,7 +56,7 @@ namespace ICSharpCode.AddInManager2.Model } catch (Exception ex) { - _events.OnAddInOperationError(new AddInExceptionEventArgs(ex)); + _events.OnAddInOperationError(new AddInOperationErrorEventArgs(ex)); } } @@ -71,8 +71,9 @@ namespace ICSharpCode.AddInManager2.Model if (addInEntry != null) { _events.OnAddInOperationError( - new AddInExceptionEventArgs( - new AddInLoadException("The package may only contain one .addin file."))); + new AddInOperationErrorEventArgs( + SD.ResourceService.GetString("AddInManager2.InvalidPackage"))); + return null; } addInEntry = entry; } @@ -80,8 +81,9 @@ namespace ICSharpCode.AddInManager2.Model if (addInEntry == null) { _events.OnAddInOperationError( - new AddInExceptionEventArgs( - new AddInLoadException("The package must contain one .addin file."))); + new AddInOperationErrorEventArgs( + SD.ResourceService.GetString("AddInManager2.InvalidPackage"))); + return null; } using (Stream s = file.GetInputStream(addInEntry)) { @@ -100,22 +102,28 @@ namespace ICSharpCode.AddInManager2.Model { AddIn addIn = null; + bool installAsExternal = false; + switch (Path.GetExtension(fileName).ToLowerInvariant()) { case ".addin": if (FileUtility.IsBaseDirectory(FileUtility.ApplicationRootPath, fileName)) { - // TODO Send around the error message -// MessageService.ShowMessage("${res:AddInManager.CannotInstallIntoApplicationDirectory}"); + // Don't allow to install AddIns from application root path + _events.OnAddInOperationError( + new AddInOperationErrorEventArgs( + SD.ResourceService.GetString("AddInManager.CannotInstallIntoApplicationDirectory"))); return null; } // Load directly from location addIn = _sdAddInManagement.Load(fileName); + installAsExternal = true; break; case ".sdaddin": + case ".zip": // Try to load the *.sdaddin file as ZIP archive ZipFile zipFile = null; try @@ -123,10 +131,12 @@ namespace ICSharpCode.AddInManager2.Model zipFile = new ZipFile(fileName); addIn = LoadAddInFromZip(zipFile); } - catch (Exception ex) + catch (Exception) { - // Report the exception - _events.OnAddInOperationError(new AddInExceptionEventArgs(ex)); + // ZIP file seems not to be valid + _events.OnAddInOperationError( + new AddInOperationErrorEventArgs( + SD.ResourceService.GetString("AddInManager2.InvalidPackage"))); return null; } finally @@ -139,8 +149,10 @@ namespace ICSharpCode.AddInManager2.Model break; default: - // TODO Send around the error message -// MessageService.ShowMessage("${res:AddInManager.UnknownFileFormat} " + Path.GetExtension(file)); + // Unknown format of file + _events.OnAddInOperationError( + new AddInOperationErrorEventArgs( + SD.ResourceService.GetString("AddInManager.UnknownFileFormat") + " " + Path.GetExtension(fileName))); return null; } @@ -149,7 +161,7 @@ namespace ICSharpCode.AddInManager2.Model if ((addIn.Manifest == null) || (addIn.Manifest.PrimaryIdentity == null)) { _events.OnAddInOperationError( - new AddInExceptionEventArgs( + new AddInOperationErrorEventArgs( new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity")))); return null; } @@ -172,18 +184,26 @@ namespace ICSharpCode.AddInManager2.Model _sdAddInManagement.AbortRemoveUserAddInOnNextStart(installedIdentity); } - // Create target directory for AddIn in user profile & copy package contents there - CopyAddInFromZip(addIn, fileName); - - // Install the AddIn using manifest - if (foundAddIn != null) + if (!installAsExternal) { - addIn.Action = AddInAction.Update; + // Create target directory for AddIn in user profile & copy package contents there + CopyAddInFromZip(addIn, fileName); + + // Install the AddIn using manifest + if (foundAddIn != null) + { + addIn.Action = AddInAction.Update; + } + else + { + addIn.Action = AddInAction.Install; + _sdAddInManagement.AddToTree(addIn); + } } else { - addIn.Action = AddInAction.Install; - _sdAddInManagement.AddToTree(addIn); + // Only add a reference to an external manifest + _sdAddInManagement.AddExternalAddIns(new AddIn[] { addIn }); } // Mark this AddIn @@ -202,13 +222,9 @@ namespace ICSharpCode.AddInManager2.Model return addIn; } - else - { - // This is not a valid SharpDevelop AddIn package! - // TODO Show a message to user! - } } + // In successful cases we should have exited somewhere else, in error cases the error event was already fired. return null; } @@ -222,7 +238,7 @@ namespace ICSharpCode.AddInManager2.Model if (addIn.Manifest.PrimaryIdentity == null) { _events.OnAddInOperationError( - new AddInExceptionEventArgs( + new AddInOperationErrorEventArgs( new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity")))); return null; } @@ -278,7 +294,9 @@ namespace ICSharpCode.AddInManager2.Model else { // This is not a valid SharpDevelop AddIn package! - // TODO Throw something. + _events.OnAddInOperationError( + new AddInOperationErrorEventArgs( + SD.ResourceService.GetString("AddInManager2.InvalidPackage"))); } return null; diff --git a/src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/IAddInManagerEvents.cs b/src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/IAddInManagerEvents.cs index 30a7de7441..d774903567 100644 --- a/src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/IAddInManagerEvents.cs +++ b/src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/IAddInManagerEvents.cs @@ -13,6 +13,7 @@ namespace ICSharpCode.AddInManager2.Model { event EventHandler OperationStarted; void OnOperationStarted(EventArgs e); + void OnOperationStarted(); event EventHandler AddInInstalled; void OnAddInInstalled(AddInInstallationEventArgs e); @@ -20,8 +21,8 @@ namespace ICSharpCode.AddInManager2.Model event EventHandler AddInUninstalled; void OnAddInUninstalled(AddInInstallationEventArgs e); - event EventHandler AddInOperationError; - void OnAddInOperationError(AddInExceptionEventArgs e); + event EventHandler AddInOperationError; + void OnAddInOperationError(AddInOperationErrorEventArgs e); event EventHandler AddInPackageDownloaded; void OnAddInPackageDownloaded(PackageOperationEventArgs e); diff --git a/src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/ISDAddInManagement.cs b/src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/ISDAddInManagement.cs index ea814a7371..a56af15da4 100644 --- a/src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/ISDAddInManagement.cs +++ b/src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/ISDAddInManagement.cs @@ -35,5 +35,6 @@ namespace ICSharpCode.AddInManager2.Model void RemoveUserAddInOnNextStart(string identity); AddIn Load(TextReader textReader); AddIn Load(string fileName); + void AddExternalAddIns(IList addIns); } } diff --git a/src/AddIns/Misc/AddInManager2/Project/Src/Model/SDAddInManagement.cs b/src/AddIns/Misc/AddInManager2/Project/Src/Model/SDAddInManagement.cs index 0bde903869..d716c79c39 100644 --- a/src/AddIns/Misc/AddInManager2/Project/Src/Model/SDAddInManagement.cs +++ b/src/AddIns/Misc/AddInManager2/Project/Src/Model/SDAddInManagement.cs @@ -84,5 +84,10 @@ namespace ICSharpCode.AddInManager2.Model { return AddIn.Load(SD.AddInTree, fileName); } + + public void AddExternalAddIns(IList addIns) + { + ICSharpCode.Core.AddInManager.AddExternalAddIns(addIns); + } } } diff --git a/src/AddIns/Misc/AddInManager2/Project/Src/View/AddInManagerView.xaml b/src/AddIns/Misc/AddInManager2/Project/Src/View/AddInManagerView.xaml index db56187271..45f416a5bb 100644 --- a/src/AddIns/Misc/AddInManager2/Project/Src/View/AddInManagerView.xaml +++ b/src/AddIns/Misc/AddInManager2/Project/Src/View/AddInManagerView.xaml @@ -20,6 +20,25 @@ + + + +