OSDN Git Service

archive-installer,na-get-lib,アーカイブ形式のインストール・アンインストール時にて(使用中のファイルなどで)処理に失敗したっとき異常終了する不...
[applistation/AppliStation.git] / na-get-lib / NaGet.Packages.Install / Uninstallation.cs
index ecb9098..cccf075 100644 (file)
@@ -81,14 +81,32 @@ namespace NaGet.Packages.Install
                                throw new ApplicationException(string.Format("Could not found {0}install script", Silent? "silent " : ""));\r
                        }\r
                        \r
-                       if (UninstalledPackage.UninstallInfo.WindowsInstaller &&\r
+                       if (UninstalledPackage.Type == InstallerType.ARCHIVE\r
+                          || UninstalledPackage.Type == InstallerType.ITSELF) {\r
+                               \r
+                                       string argument = string.Format("-x \"{0}\"", UninstalledPackage.Name);\r
+                                       using (Process hProcess = createExtractArchiveProcess(argument,\r
+                                                                              this.OutputDataReceived,\r
+                                                                              this.ErrorDataReceived)) {\r
+                                               \r
+                                               if (NaGet.Env.InstallProcessOnBackground) {\r
+                                                       try {\r
+                                                               hProcess.PriorityClass = ProcessPriorityClass.Idle;\r
+                                                       } catch (Exception) {}\r
+                                               }\r
+                                               \r
+                                               hProcess.WaitForExit();\r
+                                               \r
+                                               exitValue = hProcess.ExitCode;\r
+                                       }\r
+                       } else if (UninstalledPackage.UninstallInfo.WindowsInstaller &&\r
                            Regex.Match(uninstallString.Substring("MsiExec.exe /I".Length),\r
                                        @"^\{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}$").Success) {\r
                                string guid = uninstallString.Substring("MsiExec.exe /I".Length);\r
                                using (Process hProcess = NaGet.Utils.ProcessStartWithOutputCapture(\r
                                        new ProcessStartInfo("msiexec", string.Format("/X{0}", guid)),\r
-                                       NaGet.Utils.ConvertToDataReceivedEventHandler(OutputDataReceived),\r
-                                       NaGet.Utils.ConvertToDataReceivedEventHandler(ErrorDataReceived)) ) {\r
+                                       this.OutputDataReceived,\r
+                                       this.ErrorDataReceived) ) {\r
                                        \r
                                        if (NaGet.Env.InstallProcessOnBackground) {\r
                                                try {\r
@@ -104,8 +122,8 @@ namespace NaGet.Packages.Install
                                // 単独のファイルの場合\r
                                using (Process hProcess = NaGet.Utils.ProcessStartWithOutputCapture(\r
                                        new ProcessStartInfo(uninstallString),\r
-                                       NaGet.Utils.ConvertToDataReceivedEventHandler(OutputDataReceived),\r
-                                       NaGet.Utils.ConvertToDataReceivedEventHandler(ErrorDataReceived)) ) {\r
+                                       this.OutputDataReceived,\r
+                                       this.ErrorDataReceived) ) {\r
                                        \r
                                        if (NaGet.Env.InstallProcessOnBackground) {\r
                                                try {\r
@@ -138,6 +156,34 @@ namespace NaGet.Packages.Install
                        return exitValue;\r
                }\r
                \r
+               /// <summary>\r
+               /// アーカイブファイルのアンインストールを行う\r
+               /// </summary>\r
+               /// <param name="archiveInstArgs">"archive-inst.exe"への引数</param>\r
+               /// <param name="outputReceived">標準出力用リスナ(null可)</param>\r
+               /// <param name="errorReceived">エラー出力用リスナ(null可)</param>\r
+               /// <returns>実行プロセス</returns>\r
+               private static Process createExtractArchiveProcess(string archiveInstArgs,\r
+                                                 EventHandler<NaGet.Utils.AnyDataEventArgs<string>> outputReceived,\r
+                                                 EventHandler<NaGet.Utils.AnyDataEventArgs<string>> errorReceived)\r
+               {\r
+                       string archiveInstExe = Path.GetFullPath("archive-inst.exe");\r
+                       if (! File.Exists(archiveInstExe)) {\r
+                               string errMsg = string.Format("\"{0}\" does not found!");\r
+                               throw new ApplicationException(errMsg,\r
+                                                              new FileNotFoundException(errMsg, archiveInstExe));\r
+                       }\r
+                       \r
+                       \r
+                       \r
+                       ProcessStartInfo procInfo = new ProcessStartInfo(archiveInstExe, archiveInstArgs);\r
+                       procInfo.UseShellExecute = false;\r
+                       procInfo.CreateNoWindow = true;\r
+                       procInfo.WorkingDirectory = Environment.CurrentDirectory;\r
+                       \r
+                       return NaGet.Utils.ProcessStartWithOutputCapture(procInfo, outputReceived, errorReceived);\r
+               }\r
+               \r
                public override string ToString()\r
                {\r
                        return string.Format("{0}({1})", UninstalledPackage.Name, UninstalledPackage.Version);\r