OSDN Git Service

na-get,archive-inst.exeの呼び出しルーチンを一本化
authorttp <ttp@users.sourceforge.jp>
Sun, 18 May 2008 10:21:28 +0000 (10:21 +0000)
committerttp <ttp@users.sourceforge.jp>
Sun, 18 May 2008 10:21:28 +0000 (10:21 +0000)
git-svn-id: http://localhost/svn/AppliStation/trunk@909 34ed2c89-c49f-4a4b-abdb-c318350108cf

na-get-lib/NaGet.Packages.Install/Installation.cs

index 359146b..6f3ee93 100644 (file)
@@ -153,20 +153,11 @@ namespace NaGet.Packages.Install
                                        hProcess.WaitForExit();\r
                                        break;\r
                                case InstallerType.ARCHIVE:\r
                                        hProcess.WaitForExit();\r
                                        break;\r
                                case InstallerType.ARCHIVE:\r
-                                       // TODO ハックな実装?\r
-                                       if (File.Exists("archive-inst.exe")) {\r
-                                               string argument = string.Format("-i \"{0}\" \"{1}\"", installerfile, this.InstalledPackage.Name);\r
-                                               ProcessStartInfo procInfo = new ProcessStartInfo(Path.GetFullPath("archive-inst.exe"), argument);\r
-                                               procInfo.UseShellExecute = false;\r
-                                               procInfo.CreateNoWindow = true;\r
-                                               procInfo.WorkingDirectory = Environment.CurrentDirectory;\r
-                                               \r
-                                               hProcess = NaGet.Utils.ProcessStartWithOutputCapture(procInfo, this.OutputDataReceived, this.ErrorDataReceived);\r
-                                               hProcess.WaitForExit();\r
-                                               break;\r
-                                       }\r
-                                       throw new NotImplementedException("Not implemented archive installation yet");\r
-                                       //break;\r
+                                       string argument = string.Format("-i \"{0}\" \"{1}\"", installerfile, this.InstalledPackage.Name);\r
+                                       hProcess = createExtractArchiveProcess(argument,\r
+                                                                              this.OutputDataReceived,\r
+                                                                              this.ErrorDataReceived);\r
+                                       break;\r
                                default:\r
                                        throw new NotImplementedException("Not implemented archive installation yet");\r
                                }\r
                                default:\r
                                        throw new NotImplementedException("Not implemented archive installation yet");\r
                                }\r
@@ -178,7 +169,7 @@ namespace NaGet.Packages.Install
                                }\r
                        }\r
                }\r
                                }\r
                        }\r
                }\r
-\r
+               \r
                /// <summary>\r
                /// インストーラ等を起動してインストール作業を行う\r
                /// </summary>\r
                /// <summary>\r
                /// インストーラ等を起動してインストール作業を行う\r
                /// </summary>\r
@@ -192,23 +183,15 @@ namespace NaGet.Packages.Install
                        if (InstalledPackage.ArchivedInstaller) {\r
                                Directory.CreateDirectory(tempDir);\r
                                \r
                        if (InstalledPackage.ArchivedInstaller) {\r
                                Directory.CreateDirectory(tempDir);\r
                                \r
-                               // 64bit対策で展開も別プロセスで\r
-                               // TODO エラーとかの出力を取得できたりとかできるように\r
-                               if (File.Exists("archive-inst.exe")) {\r
-                                       string argument = string.Format("-t \"{0}\" \"{1}\"", installerFile, tempDir);\r
-                                       ProcessStartInfo info = new ProcessStartInfo(Path.GetFullPath("archive-inst.exe"), argument);\r
-                                       info.UseShellExecute = false;\r
-                                       info.WorkingDirectory = Environment.CurrentDirectory;\r
-                                       \r
-                                       using (Process hProcess = Process.Start(info)) {\r
-                                               hProcess.WaitForExit();\r
-                                       \r
-                                               if (hProcess.ExitCode != 0) {\r
-                                                       throw new ApplicationException("Extract error " + installerFile + " to " + tempDir);\r
-                                               }\r
+                               string argument = string.Format("-t \"{0}\" \"{1}\"", installerFile, tempDir);\r
+                               using (Process hProcess = createExtractArchiveProcess(argument,\r
+                                                                                     this.OutputDataReceived,\r
+                                                                                     this.ErrorDataReceived)) {\r
+                                       hProcess.WaitForExit();\r
+                               \r
+                                       if (hProcess.ExitCode != 0) {\r
+                                               throw new ApplicationException("Extract error " + installerFile + " to " + tempDir);\r
                                        }\r
                                        }\r
-                               } else {\r
-                                       throw new ApplicationException(string.Format("archive-inst.exe not found in {0}!", Environment.CurrentDirectory));\r
                                }\r
                                \r
 //                             System.Text.StringBuilder output = new System.Text.StringBuilder(1024);\r
                                }\r
                                \r
 //                             System.Text.StringBuilder output = new System.Text.StringBuilder(1024);\r
@@ -379,6 +362,33 @@ namespace NaGet.Packages.Install
                        return (list.Count > 0)? list[0] : null;\r
                }\r
                \r
                        return (list.Count > 0)? list[0] : null;\r
                }\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 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
+                       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})", InstalledPackage.Name, InstalledPackage.Version);\r
                public override string ToString()\r
                {\r
                        return string.Format("{0}({1})", InstalledPackage.Name, InstalledPackage.Version);\r