X-Git-Url: http://git.sourceforge.jp/view?p=applistation%2FAppliStation.git;a=blobdiff_plain;f=all-get%2FMain.cs;h=876d8aa2b6a5823c301caff7339891e0844761a0;hp=98b1a44873b298c6b490dec085dc4c370b573e78;hb=a8463953e348242dc94c5617dcf496ec9fb652d5;hpb=81aca369e40a261359eade384ccf68ab2bee04a6 diff --git a/all-get/Main.cs b/all-get/Main.cs index 98b1a44..876d8aa 100644 --- a/all-get/Main.cs +++ b/all-get/Main.cs @@ -68,6 +68,11 @@ namespace AllGet private PackageListsManager pkgListMan; + /// + /// サイレントインストールをするか否か + /// + private bool silent = false; + public MainClass() { downloader = new Downloader(); @@ -75,6 +80,7 @@ namespace AllGet downloader.DownloadEventRaised += new EventHandler(dl.OnDownload); pkgListMan = new PackageListsManager(); + pkgListMan.LoadPackageLists(); } public void Update() @@ -90,7 +96,6 @@ namespace AllGet public void update(bool downloadPackageListFlag) { NaGet.SubCommands.NaGetUpdate tasks = new NaGet.SubCommands.NaGetUpdate(pkgListMan, downloadPackageListFlag); - tasks.Downloader = this.downloader; tasks.TaskSetRaised += delegate(object sender, NaGetTaskSetEventArgs e) { switch (e.Type) { // case NaGetTaskSetEventType.COMPLETED_TASKSET @@ -113,6 +118,8 @@ namespace AllGet break; } }; + DownloadListener dl = new DownloadListener(); + tasks.Downloader.DownloadEventRaised += dl.OnDownload; tasks.Run(); } @@ -123,7 +130,7 @@ namespace AllGet VersionComparetor verComp = new VersionComparetor(); - foreach (InstalledPackage pkg in pkgListMan.InstalledPkgList.Packages) { + foreach (InstalledPackage pkg in pkgListMan.InstalledPkgList) { Package avaiablePkg = packageList.GetPackageForName(pkg.Name); if (avaiablePkg != null) { @@ -136,7 +143,7 @@ namespace AllGet Console.ResetColor(); } } - foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList.Packages) { + foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList) { Package avaiablePkg = packageList.GetPackageForName(pkg.Name); if (avaiablePkg != null) { @@ -274,6 +281,8 @@ namespace AllGet for (int i = 0; i < installations.Length; i++) { installations[i] = new Installation((Package) downloadList[i]); + installations[i].Silent = silent; // サイレントインストールのフラグの設定 + if (! installations[i].IsInstallablePackage()) { Console.WriteLine("E: Can not install package {0} to your PC.", installations[i].ToString()); Environment.Exit(1); @@ -281,6 +290,13 @@ namespace AllGet } } + Installation[] depInstallations; + { + Installation[] resolved; + DependeciesResolver.ResolveInstallations(installations, pkgListMan, out resolved, out depInstallations); + installations = resolved; + } + Console.WriteLine("The following packages will be downloaded:"); Console.WriteLine(" {0}", Installation.ToString(installations)); if (AllGet.Util.Confirm("Do you want to continue [Y/n]?", true) == false) { @@ -289,7 +305,6 @@ namespace AllGet } NaGet.SubCommands.NaGetInstall tasks = new NaGet.SubCommands.NaGetInstall(pkgListMan, installations); - tasks.Downloader = this.downloader; tasks.TaskQueryRaised += delegate(object sender, NaGetTaskQueryArgs e) { char result = '\u0000'; if (e.SelectionFlag == (NaGetTaskQueryResult.CONTINUE | NaGetTaskQueryResult.RETRY | NaGetTaskQueryResult.CANCEL)) { @@ -335,6 +350,8 @@ namespace AllGet break; } }; + DownloadListener dl = new DownloadListener(); + tasks.Downloader.DownloadEventRaised += dl.OnDownload; tasks.Run(); } @@ -428,7 +445,7 @@ namespace AllGet Console.WriteLine("\t{0} search|show pkg1 [pkg2 ...]", executeFileName); Console.WriteLine("\t{0} cleancache [pkg ...]", executeFileName); Console.WriteLine("\t{0} download pkg1 [pkg2 ...]", executeFileName); - Console.WriteLine("\t{0} install|uninstall pkg1 [pkg2 ...]", executeFileName); + Console.WriteLine("\t{0} [--quiet] install|uninstall pkg1 [pkg2 ...]", executeFileName); Console.WriteLine(); Console.WriteLine("{0} is a simple command line interface for downloading and "+ "installing packages. The most frequently used commands are update "+ @@ -449,7 +466,7 @@ namespace AllGet public void FooBar() { - foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList.Packages) { + foreach (InstalledPackage pkg in pkgListMan.SystemInstalledPkgList) { Console.WriteLine("{0} : {1}", pkg.Name, pkg.UninstallInfo.UninstallString); } } @@ -471,6 +488,7 @@ namespace AllGet Console.WriteLine("誰か {0} をスーパー牛さんパワー化してくれ", executeFileName); } + [STAThread] public static void Main(string[] args) { // アーカイブSYSTEM32をパスに足す @@ -480,81 +498,113 @@ namespace AllGet if (args.Length == 0) { mc.Help(); - } else if (args[0] == "update") { - if (args.Length != 1) { - Console.WriteLine("E: The update command takes no arguments"); - Environment.Exit(1); - } - mc.Update(); - } else if (args[0] == "localupdate") { - if (args.Length != 1) { - Console.WriteLine("E: The update command takes no arguments"); - Environment.Exit(1); - } - mc.LocalUpdate(); - } else if (args[0] == "search") { - if (args.Length <= 1) { - Console.WriteLine("E: You must give exactly one pattern"); - Environment.Exit(1); - } - mc.Search(string.Join(" ", args, 1, args.Length - 1)); - } else if (args[0] == "show") { - if (args.Length <= 1) { - Console.WriteLine("E: You must give exactly one pattern"); - Environment.Exit(1); - } - - for (int i = 1; i < args.Length; i++) { - mc.Show(args[i]); - } - } else if (args[0] == "download") { - if (args.Length <= 1) { - Console.WriteLine("E: Invalid operation download"); - Environment.Exit(1); - } - - string[] packages = new string[args.Length - 1]; - Array.Copy(args, 1, packages, 0, packages.Length); - - mc.Download(packages); - } else if (args[0] == "install") { - if (args.Length <= 1) { - Console.WriteLine("E: Invalid operation install"); + Environment.Exit(1); + } else { + try { + NaGet.ArgParser argParser = new NaGet.ArgParser(); + argParser["quiet"] = false; + args = argParser.Parse(args); + mc.silent = (bool) argParser["quiet"]; + } catch (ApplicationException e) { + Console.WriteLine(e.Message); Environment.Exit(1); } - - string[] packages = new string[args.Length - 1]; - Array.Copy(args, 1, packages, 0, packages.Length); - - mc.Install(packages); - } else if (args[0] == "checkupgrade") { - mc.CheckUpgrade(); - } else if (args[0] == "remove") { - if (args.Length <= 1) { - Console.WriteLine("E: Invalid operation remove"); + } + + // 引数ごとに操作を決定 + switch (args[0]) + { + case "update": + if (args.Length != 1) { + Console.WriteLine("E: The update command takes no arguments"); + Environment.Exit(1); + } + mc.Update(); + break; + case "localupate": + if (args.Length != 1) { + Console.WriteLine("E: The update command takes no arguments"); + Environment.Exit(1); + } + mc.LocalUpdate(); + break; + case "search": + if (args.Length <= 1) { + Console.WriteLine("E: You must give exactly one pattern"); + Environment.Exit(1); + } + + mc.Search(string.Join(" ", args, 1, args.Length - 1)); + break; + case "show": + if (args.Length <= 1) { + Console.WriteLine("E: You must give exactly one pattern"); + Environment.Exit(1); + } + + for (int i = 1; i < args.Length; i++) { + mc.Show(args[i]); + } + break; + case "download": + if (args.Length <= 1) { + Console.WriteLine("E: Invalid operation download"); + Environment.Exit(1); + } else { + string[] packages = new string[args.Length - 1]; + Array.Copy(args, 1, packages, 0, packages.Length); + + mc.Download(packages); + } + break; + case "install": + if (args.Length <= 1) { + Console.WriteLine("E: Invalid operation install"); + Environment.Exit(1); + } else { + string[] packages = new string[args.Length - 1]; + Array.Copy(args, 1, packages, 0, packages.Length); + + mc.Install(packages); + } + break; + case "checkupgrade": + mc.CheckUpgrade(); + break; + case "remove": + if (args.Length <= 1) { + Console.WriteLine("E: Invalid operation remove"); + Environment.Exit(1); + } else { + string[] packages = new string[args.Length - 1]; + Array.Copy(args, 1, packages, 0, packages.Length); + + mc.Remove(packages); + } + break; + case "cleancache": + { + string[] packages = new string[args.Length - 1]; + Array.Copy(args, 1, packages, 0, packages.Length); + + mc.CleanCache(packages); + } + break; + case "foobar": + mc.FooBar(); + break; + case "hoge": + mc.Hoge(); + break; + case "moo": + mc.Moo(); + break; + default: + mc.Help(); + Environment.Exit(1); - } - - string[] packages = new string[args.Length - 1]; - Array.Copy(args, 1, packages, 0, packages.Length); - - mc.Remove(packages); - } else if (args[0] == "cleancache") { - string[] packages = new string[args.Length - 1]; - Array.Copy(args, 1, packages, 0, packages.Length); - - mc.CleanCache(packages); - } else if (args[0] == "foobar") { - mc.FooBar(); - } else if (args[0] == "hoge") { - mc.Hoge(); - } else if (args[0] == "moo") { - mc.Moo(); - } else { - mc.Help(); - - Environment.Exit(1); + break; } } }