OSDN Git Service

archive-installer,na-get-lib,アーカイブ形式のインストール・アンインストール時にて(使用中のファイルなどで)処理に失敗したっとき異常終了する不...
authorttp <ttp@users.sourceforge.jp>
Sat, 2 Jan 2010 15:48:58 +0000 (00:48 +0900)
committerttp <ttp@users.sourceforge.jp>
Sat, 2 Jan 2010 15:48:58 +0000 (00:48 +0900)
archive-inst/Program.cs
na-get-lib/NaGet.Packages.Install/Uninstallation.cs

index 01a53bd..d191f39 100644 (file)
@@ -70,8 +70,12 @@ namespace ArchiveInstall
                                string filePath = NaGet.Utils.GetRelativePath(fakeTargetDir, file);\r
                                string targetFilePath = Path.Combine(targetDir, filePath);\r
                                if (File.Exists(targetFilePath)) {\r
-                                       File.SetAttributes(targetFilePath, FileAttributes.Normal);\r
-                                       File.Delete(targetFilePath);\r
+                                       try {\r
+                                               File.SetAttributes(targetFilePath, FileAttributes.Normal);\r
+                                               File.Delete(targetFilePath);\r
+                                       } catch (UnauthorizedAccessException e) {\r
+                                               throw new IOException(string.Format("Access denied '{0}'", targetFilePath), e);\r
+                                       }\r
                                }\r
                                File.Move(file, targetFilePath);\r
                        }\r
@@ -220,8 +224,13 @@ namespace ArchiveInstall
                                }\r
                        }\r
                        \r
-                       NaGet.Utils.SetAttributeRecursive(targetDir, FileAttributes.Normal);\r
-                       Directory.Delete(targetDir, true);\r
+                       try {\r
+                               NaGet.Utils.SetAttributeRecursive(targetDir, FileAttributes.Normal);\r
+                               Directory.Delete(targetDir, true);\r
+                       } catch (UnauthorizedAccessException) {\r
+                               Console.Error.WriteLine("W: could not complete to delete '{0}': Permission denied", targetDir);\r
+                               Environment.Exit(1);\r
+                       }\r
                }\r
                \r
                private static void parseMainArguments(string[] args, out string arcFile, out string targetDir, out Package package)\r
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