/// <summary> /// Initializes the AddIn system. /// This loads the AddIns that were added to the list, /// then it executes the <see cref="ICommand">commands</see> /// in <c>/SharpDevelop/Autostart</c>. /// </summary> public void RunInitialization() { addInTree.Load(addInFiles, disabledAddIns); // perform service registration var container = (IServiceContainer)ServiceSingleton.ServiceProvider.GetService(typeof(IServiceContainer)); if (container != null) { addInTree.BuildItems <object>("/SharpDevelop/Services", container, false); } // run workspace autostart commands LoggingService.Info("Running autostart commands..."); foreach (ICommand command in addInTree.BuildItems <ICommand>("/SharpDevelop/Autostart", null, false)) { try { command.Execute(null); } catch (Exception ex) { // allow startup to continue if some commands fail ServiceSingleton.GetRequiredService <IMessageService>().ShowException(ex); } } }
/// <summary> /// Installs the AddIns from AddInInstallTemp to the UserAddInPath. /// In case of installation errors, a error message is displayed to the user /// and the affected AddIn is added to the disabled list. /// </summary> public static void InstallAddIns(List <string> disabled) { if (!Directory.Exists(addInInstallTemp)) { return; } LoggingService.Info("AddInManager.InstallAddIns started"); if (!Directory.Exists(userAddInPath)) { Directory.CreateDirectory(userAddInPath); } string removeFile = Path.Combine(addInInstallTemp, "remove.txt"); bool allOK = true; List <string> notRemoved = new List <string>(); if (File.Exists(removeFile)) { using (StreamReader r = new StreamReader(removeFile)) { string addInName; while ((addInName = r.ReadLine()) != null) { addInName = addInName.Trim(); if (addInName.Length == 0) { continue; } string targetDir = Path.Combine(userAddInPath, addInName); if (!UninstallAddIn(disabled, addInName, targetDir)) { notRemoved.Add(addInName); allOK = false; } } } if (notRemoved.Count == 0) { LoggingService.Info("Deleting remove.txt"); File.Delete(removeFile); } else { LoggingService.Info("Rewriting remove.txt"); using (StreamWriter w = new StreamWriter(removeFile)) { notRemoved.ForEach(w.WriteLine); } } } foreach (string sourceDir in Directory.GetDirectories(addInInstallTemp)) { string addInName = Path.GetFileName(sourceDir); string targetDir = Path.Combine(userAddInPath, addInName); if (notRemoved.Contains(addInName)) { LoggingService.Info("Skipping installation of " + addInName + " because deinstallation failed."); continue; } if (UninstallAddIn(disabled, addInName, targetDir)) { LoggingService.Info("Installing " + addInName + "..."); Directory.Move(sourceDir, targetDir); } else { allOK = false; } } if (allOK) { try { Directory.Delete(addInInstallTemp, false); } catch (Exception ex) { LoggingService.Warn("Error removing install temp", ex); } } LoggingService.Info("AddInManager.InstallAddIns finished"); }
public static void ShowMessage(string message, string caption) { LoggingService.Info(message); ServiceManager.MessageService.ShowMessage(message, caption); }