OSDN Git Service

AppliStation,サイレントインストールのロジック部分とall-get.exeからの部分を書いた
authorttp <ttp@users.sourceforge.jp>
Sun, 18 May 2008 11:07:47 +0000 (11:07 +0000)
committerttp <ttp@users.sourceforge.jp>
Sun, 18 May 2008 11:07:47 +0000 (11:07 +0000)
git-svn-id: http://localhost/svn/AppliStation/trunk@910 34ed2c89-c49f-4a4b-abdb-c318350108cf

AppliStation/AppliStation.csproj
AppliStation/Program.cs
all-get/Main.cs
na-get-lib/NaGet.Packages.Install/Installation.cs
na-get-lib/NaGet/ArgParse.cs [moved from AppliStation/ArgParse.cs with 90% similarity]
na-get-lib/na-get-lib.csproj

index 93be75b..b3200ba 100644 (file)
@@ -70,7 +70,6 @@
     <Compile Include="AppliStation.Util\PackageUtils.cs" />\r
     <Compile Include="AppliStation.Util\ToolStripWeb2LikeTextBox.cs" />\r
     <Compile Include="AssemblyInfo.cs" />\r
-    <Compile Include="ArgParse.cs" />\r
     <Compile Include="InstallerInfoForm.cs" />\r
     <Compile Include="InstallerInfoForm.Designer.cs">\r
       <DependentUpon>InstallerInfoForm.cs</DependentUpon>\r
index 9b16164..9b007df 100644 (file)
@@ -98,7 +98,7 @@ namespace AppliStation
                \r
                private void parseArgs(string[] args)\r
                {\r
-                       ArgParse parser = new ArgParse(appArgs);\r
+                       NaGet.ArgParser parser = new NaGet.ArgParser(appArgs);\r
                        restAppArgs = parser.Parse(args);\r
                }\r
                \r
index 98b1a44..42d4bfe 100644 (file)
@@ -68,6 +68,11 @@ namespace AllGet
                \r
                private PackageListsManager pkgListMan;\r
                \r
+               /// <summary>\r
+               /// サイレントインストールをするか否か\r
+               /// </summary>\r
+               private bool silent = false;\r
+               \r
                public MainClass()\r
                {\r
                        downloader = new Downloader();\r
@@ -274,6 +279,8 @@ namespace AllGet
                                for (int i = 0; i < installations.Length; i++) {\r
                                        installations[i] = new Installation((Package) downloadList[i]);\r
                                        \r
+                                       installations[i].Silent = silent; // サイレントインストールのフラグの設定\r
+                                       \r
                                        if (! installations[i].IsInstallablePackage()) {\r
                                                Console.WriteLine("E: Can not install package {0} to your PC.", installations[i].ToString());\r
                                                Environment.Exit(1);\r
@@ -480,7 +487,21 @@ namespace AllGet
                        \r
                        if (args.Length == 0) {\r
                                mc.Help();\r
-                       } else if (args[0] == "update") {\r
+                               \r
+                               Environment.Exit(1);\r
+                       } else {\r
+                               try {\r
+                                       NaGet.ArgParser argParser = new NaGet.ArgParser();\r
+                                       argParser["quiet"] = false;\r
+                                       args = argParser.Parse(args);\r
+                                       mc.silent = (bool) argParser["quiet"];\r
+                               } catch (ApplicationException e) {\r
+                                       Console.WriteLine(e.Message);\r
+                                       Environment.Exit(1);\r
+                               }\r
+                       }\r
+                       \r
+                       if (args[0] == "update") {\r
                                if (args.Length != 1) {\r
                                        Console.WriteLine("E: The update command takes no arguments");\r
                                        Environment.Exit(1);\r
index 6f3ee93..9711c93 100644 (file)
@@ -26,6 +26,11 @@ namespace NaGet.Packages.Install
                /// インストールが完了されたか否かのフラグ\r
                /// </summary>\r
                private bool installed = false;\r
+               \r
+               /// <summary>\r
+               /// サイレントインストールを行うか否か\r
+               /// </summary>\r
+               private bool silent = false;\r
          \r
                /// <summary>\r
                /// 起動するインストーラのインデックス番号\r
@@ -74,17 +79,70 @@ namespace NaGet.Packages.Install
                }\r
                \r
                /// <summary>\r
-               /// ã\81\99ã\81§ã\81«ã\82¤ã\83³ã\82¹ã\83\88ã\83¼ã\83«ã\81\95ã\82\8cã\81¦ã\81\84ã\82\8bã\83\91ã\83\83ã\82±ã\83¼ã\82¸ã\82\92å\8f\96å¾\97ã\81\99ã\82\8b\r
+               /// ã\83\80ã\82¦ã\83³ã\83­ã\83¼ã\83\89æ¸\88ã\81¿ã\81§ã\81\82ã\82\8bã\81\8bå\90¦ã\81\8b\r
                /// </summary>\r
-               /// <param name="installedPkgs">\r
-               /// インストールドリスト\r
-               /// </param>\r
-               /// <returns>\r
-               /// インストールされているパッケージの情報。インストールされたパッケージが見つからないならばnullを返す  \r
-               /// </returns>\r
-               public InstalledPackage GetInstalledPackage(PackageList<InstalledPackage> installedPkgs)\r
-               {\r
-                       return installedPkgs.GetPackageForName(InstalledPackage.Name);\r
+               public bool Downloaded {\r
+                       get {\r
+                               return File.Exists(InstallerFile) && ((File.GetAttributes(InstallerFile) & FileAttributes.Hidden) != FileAttributes.Hidden);\r
+                       }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// インストール作業済みであるか否か。実際にインストールされたかどうかではありません。\r
+               /// </summary>\r
+               public bool Installed {\r
+                       get { return installed; }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// インストーラの処理が成功してインストールされたプログラムが確認できるか否か。\r
+               /// </summary>\r
+               public bool InstallSuccessed {\r
+                       get {\r
+                               switch (InstalledPackage.Type) {\r
+                                       case InstallerType.ARCHIVE: // アーカイブインストーラはフォルダの確認\r
+                                               return Directory.Exists(Path.Combine(NaGet.Env.ArchiveProgramFiles, InstalledPackage.Name));\r
+                                       case InstallerType.EXEC_INSTALLER:\r
+                                       case InstallerType.MSI_PACKAGE:\r
+                                               return RegistriedUninstallers.GetInstalledPackageFor(InstalledPackage) != null;\r
+                                       default:\r
+                                               return false;\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// サイレントインストールを行うかのフラグ。\r
+               /// </summary>\r
+               public bool Silent {\r
+                       get {\r
+                               return (IsSupportsSilentOnly)? true :\r
+                                       (IsSupportsSilent)? silent :\r
+                                       false;\r
+                       }\r
+                       set { silent = value; }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// サイレントインストールをサポートしているか否か\r
+               /// </summary>\r
+               public bool IsSupportsSilent {\r
+                       get {\r
+                               switch (InstalledPackage.Type) {\r
+                                       case InstallerType.ARCHIVE:\r
+                                       case InstallerType.MSI_PACKAGE:\r
+                                               return true;\r
+                                       default:\r
+                                               return false;\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// サイレントインストールだけをサポートしているか否か\r
+               /// </summary>\r
+               public bool IsSupportsSilentOnly {\r
+                       get { return InstalledPackage.Type == InstallerType.ARCHIVE; }\r
                }\r
                \r
                /// <summary>\r
@@ -145,12 +203,14 @@ namespace NaGet.Packages.Install
                                switch (type) {\r
                                case InstallerType.EXEC_INSTALLER:\r
                                        hProcess = Process.Start(installerfile);\r
-                                       hProcess.WaitForExit();\r
                                        \r
                                        break;\r
                                case InstallerType.MSI_PACKAGE:\r
-                                       hProcess = Process.Start("msiexec", string.Format("/i \"{0}\"", installerfile));\r
-                                       hProcess.WaitForExit();\r
+                                       string msiexecArgs = string.Format("{0} /i \"{1}\"",\r
+                                                                   (Silent)? "/passive" : string.Empty,\r
+                                                                   installerfile);\r
+                                       \r
+                                       hProcess = Process.Start("msiexec", msiexecArgs);\r
                                        break;\r
                                case InstallerType.ARCHIVE:\r
                                        string argument = string.Format("-i \"{0}\" \"{1}\"", installerfile, this.InstalledPackage.Name);\r
@@ -161,6 +221,7 @@ namespace NaGet.Packages.Install
                                default:\r
                                        throw new NotImplementedException("Not implemented archive installation yet");\r
                                }\r
+                               hProcess.WaitForExit();\r
                                \r
                                return hProcess.ExitCode;\r
                        } finally {\r
@@ -194,12 +255,6 @@ namespace NaGet.Packages.Install
                                        }\r
                                }\r
                                \r
-//                             System.Text.StringBuilder output = new System.Text.StringBuilder(1024);\r
-//                             int res = NaGet.InteropServices.CommonArchiverExtracter.ExtractArchive(installerFile, tempDir, output, IntPtr.Zero);\r
-//                             if (res != 0) {\r
-//                                     throw new ApplicationException("Extract error\n" + output.ToString());\r
-//                             }\r
-                               \r
                                installerFile = seekInstallerFile(tempDir, InstalledPackage.Type);\r
                                if (installerFile == null && Directory.GetDirectories(tempDir).Length == 1) {\r
                                        installerFile = seekInstallerFile(Path.Combine(tempDir, Directory.GetDirectories(tempDir)[0]), InstalledPackage.Type);\r
@@ -215,48 +270,6 @@ namespace NaGet.Packages.Install
                }\r
                \r
                /// <summary>\r
-               /// ダウンロード済みであるか否か\r
-               /// </summary>\r
-               public bool Downloaded {\r
-                       get {\r
-                               return File.Exists(InstallerFile) && ((File.GetAttributes(InstallerFile) & FileAttributes.Hidden) != FileAttributes.Hidden);\r
-                       }\r
-               }\r
-               \r
-               /// <summary>\r
-               /// インストール作業済みであるか否か。実際にインストールされたかどうかではありません。\r
-               /// </summary>\r
-               public bool Installed {\r
-                       get { return installed; }\r
-               }\r
-               \r
-               /// <summary>\r
-               /// インストーラの処理が成功してインストールされたプログラムが確認できるか否か。\r
-               /// </summary>\r
-               public bool InstallSuccessed {\r
-                       get {\r
-                               switch (Type) {\r
-                                       case InstallerType.ARCHIVE: // アーカイブインストーラはフォルダの確認\r
-                                               return Directory.Exists(Path.Combine(NaGet.Env.ArchiveProgramFiles, InstalledPackage.Name));\r
-                                       case InstallerType.EXEC_INSTALLER:\r
-                                       case InstallerType.MSI_PACKAGE:\r
-                                               return RegistriedUninstallers.GetInstalledPackageFor(InstalledPackage) != null;\r
-                                       default:\r
-                                               return false;\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               /// <summary>\r
-               /// インストーラの種類を返す\r
-               /// </summary>\r
-               public InstallerType Type {\r
-                       get {\r
-                               return InstalledPackage.Type;\r
-                       }\r
-               }\r
-               \r
-               /// <summary>\r
                /// もっともふさわしいインストーラ番号を返す\r
                /// </summary>\r
                /// <returns></returns>\r
@@ -314,6 +327,20 @@ namespace NaGet.Packages.Install
                }\r
                \r
                /// <summary>\r
+               /// すでにインストールされているパッケージを取得する\r
+               /// </summary>\r
+               /// <param name="installedPkgs">\r
+               /// インストールドリスト\r
+               /// </param>\r
+               /// <returns>\r
+               /// インストールされているパッケージの情報。インストールされたパッケージが見つからないならばnullを返す  \r
+               /// </returns>\r
+               public InstalledPackage GetInstalledPackage(PackageList<InstalledPackage> installedPkgs)\r
+               {\r
+                       return installedPkgs.GetPackageForName(InstalledPackage.Name);\r
+               }\r
+               \r
+               /// <summary>\r
                /// インストーラファイルを探す\r
                /// </summary>\r
                /// <param name="basedir">探すフォルダ</param>\r
similarity index 90%
rename from AppliStation/ArgParse.cs
rename to na-get-lib/NaGet/ArgParse.cs
index 5754ffa..a30f5c1 100644 (file)
@@ -2,12 +2,12 @@ using System;
 using System.Collections.Generic;\r
 using System.Text.RegularExpressions;\r
 \r
-namespace AppliStation\r
+namespace NaGet\r
 {\r
        /// <summary>\r
        /// \92á\8b@\94\\82È\88ø\90\94\89ð\90Í\82ð\82·\82é\81B\r
        /// </summary>\r
-       public class ArgParse\r
+       public class ArgParser\r
        {\r
                /// <summary>\r
                /// \89ð\90Í\8c\8b\89Ê\r
@@ -25,7 +25,7 @@ namespace AppliStation
                        }\r
                }\r
                \r
-               public ArgParse()\r
+               public ArgParser()\r
                        : this(new Dictionary<string,object>())\r
                {\r
                }\r
@@ -34,7 +34,7 @@ namespace AppliStation
                /// \8f\89\8aú\89»\r
                /// </summary>\r
                /// <param name="hashDefault">\8f\89\8aú\82Ì\8e«\8f\91</param>\r
-               public ArgParse(Dictionary<string,object> hashDefault)\r
+               public ArgParser(Dictionary<string,object> hashDefault)\r
                {\r
                        opts = hashDefault;\r
                }\r
index 7369c9e..7788e6c 100644 (file)
@@ -64,6 +64,7 @@
     <Compile Include="NaGet.SubCommands\NaGetTask.cs" />\r
     <Compile Include="NaGet.SubCommands\NaGetTaskSet.cs" />\r
     <Compile Include="NaGet.SubCommands\NaGetUninstall.cs" />\r
+    <Compile Include="NaGet\ArgParse.cs" />\r
     <Compile Include="NaGet\Env.cs" />\r
     <Compile Include="NaGet\Utils.cs" />\r
     <Compile Include="NaGet.Net\Downloader.cs" />\r