ICSharpCode.Core.AddInManager.UninstallAddIn C# (CSharp) Метод

UninstallAddIn() статический приватный Метод

static private UninstallAddIn ( List disabled, string addInName, string targetDir ) : bool
disabled List
addInName string
targetDir string
Результат bool
        static bool UninstallAddIn(List<string> disabled, string addInName, string targetDir)
        {
            if (Directory.Exists(targetDir)) {
                LoggingService.Info("Removing " + addInName + "...");
                try {
                    Directory.Delete(targetDir, true);
                } catch (Exception ex) {
                    disabled.Add(addInName);
                    MessageService.ShowError("Error removing " + addInName + ":\n" +
                                             ex.Message + "\nThe AddIn will be " +
                                             "removed on the next start of " + MessageService.ProductName +
                                             " and is disabled for now.");
                    return false;
                }
            }
            return true;
        }

Usage Example

Пример #1
0
        public static void InstallAddIns(System.Collections.Generic.List <string> disabled)
        {
            if (!System.IO.Directory.Exists(AddInManager.addInInstallTemp))
            {
                return;
            }
            if (!System.IO.Directory.Exists(AddInManager.userAddInPath))
            {
                System.IO.Directory.CreateDirectory(AddInManager.userAddInPath);
            }
            string path = System.IO.Path.Combine(AddInManager.addInInstallTemp, "remove.txt");
            bool   flag = true;

            System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>();
            if (System.IO.File.Exists(path))
            {
                using (System.IO.StreamReader streamReader = new System.IO.StreamReader(path))
                {
                    string text;
                    while ((text = streamReader.ReadLine()) != null)
                    {
                        text = text.Trim();
                        if (!string.IsNullOrEmpty(text))
                        {
                            string targetDir = System.IO.Path.Combine(AddInManager.userAddInPath, text);
                            if (!AddInManager.UninstallAddIn(disabled, text, targetDir))
                            {
                                list.Add(text);
                                flag = false;
                            }
                        }
                    }
                }
                if (list.Count == 0)
                {
                    System.IO.File.Delete(path);
                }
                else
                {
                    using (System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(path))
                    {
                        list.ForEach(new System.Action <string>(streamWriter.WriteLine));
                    }
                }
            }
            string[] directories = System.IO.Directory.GetDirectories(AddInManager.addInInstallTemp);
            for (int i = 0; i < directories.Length; i++)
            {
                string text2    = directories[i];
                string fileName = System.IO.Path.GetFileName(text2);
                string text3    = System.IO.Path.Combine(AddInManager.userAddInPath, fileName);
                if (!list.Contains(fileName))
                {
                    if (AddInManager.UninstallAddIn(disabled, fileName, text3))
                    {
                        System.IO.Directory.Move(text2, text3);
                    }
                    else
                    {
                        flag = false;
                    }
                }
            }
            if (flag)
            {
                try
                {
                    System.IO.Directory.Delete(AddInManager.addInInstallTemp, false);
                }
                catch (System.Exception)
                {
                }
            }
        }