[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Windows.Forms;
|
---|
| 25 | using System.Xml;
|
---|
| 26 | using System.Threading;
|
---|
[1107] | 27 | using System.Text;
|
---|
[2513] | 28 | using System.Linq;
|
---|
[2] | 29 | using HeuristicLab.PluginInfrastructure;
|
---|
[2513] | 30 | using HeuristicLab.PluginInfrastructure.Advanced;
|
---|
[2517] | 31 | using System.Runtime.InteropServices;
|
---|
[2528] | 32 | using HeuristicLab.PluginInfrastructure.Starter;
|
---|
| 33 | using System.IO;
|
---|
[2] | 34 |
|
---|
| 35 | namespace HeuristicLab {
|
---|
| 36 | static class Program {
|
---|
| 37 | [STAThread]
|
---|
[877] | 38 | static void Main(string[] args) {
|
---|
[2513] | 39 | if (args.Length == 0) { // normal mode
|
---|
| 40 | try {
|
---|
[877] | 41 | Application.EnableVisualStyles();
|
---|
| 42 | Application.SetCompatibleTextRenderingDefault(false);
|
---|
[2508] | 43 | Application.Run(new StarterForm());
|
---|
[877] | 44 | }
|
---|
[2513] | 45 | catch (Exception ex) {
|
---|
| 46 | ShowErrorMessageBox(ex);
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | } else {
|
---|
| 50 | var cmd = args[0].ToUpperInvariant();
|
---|
[2528] | 51 | string pluginDir = Path.GetFullPath(Application.StartupPath);
|
---|
[2513] | 52 | switch (cmd) {
|
---|
| 53 | case "START": {
|
---|
| 54 | if (args.Length != 2) {
|
---|
| 55 | PrintUsage();
|
---|
| 56 | } else {
|
---|
| 57 | Application.EnableVisualStyles();
|
---|
| 58 | Application.SetCompatibleTextRenderingDefault(false);
|
---|
| 59 | Application.Run(new StarterForm(args[1]));
|
---|
| 60 | }
|
---|
| 61 | break;
|
---|
| 62 | }
|
---|
| 63 | case "SHOW": {
|
---|
[2528] | 64 | InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
|
---|
[2517] | 65 | managerConsole.Show(args.Skip(1));
|
---|
[2513] | 66 | break;
|
---|
| 67 | }
|
---|
| 68 | case "INSTALL": {
|
---|
[2528] | 69 | InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
|
---|
[2517] | 70 | managerConsole.Install(args.Skip(1));
|
---|
[2513] | 71 | break;
|
---|
| 72 | }
|
---|
| 73 | case "UPDATE": {
|
---|
[2528] | 74 | InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
|
---|
[2517] | 75 | managerConsole.Update(args.Skip(1));
|
---|
[2513] | 76 | break;
|
---|
| 77 | }
|
---|
| 78 | case "REMOVE": {
|
---|
[2528] | 79 | InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
|
---|
[2517] | 80 | managerConsole.Remove(args.Skip(1));
|
---|
[2513] | 81 | break;
|
---|
| 82 | }
|
---|
| 83 | default: PrintUsage(); break;
|
---|
| 84 | }
|
---|
[877] | 85 | }
|
---|
[2] | 86 | }
|
---|
[1107] | 87 |
|
---|
[2513] | 88 | private static void PrintUsage() {
|
---|
| 89 | Console.WriteLine("Usage: HeuristicLab.exe <command> <args>");
|
---|
| 90 | Console.WriteLine("Commands:");
|
---|
| 91 | Console.WriteLine("\tstart <application name>");
|
---|
| 92 | Console.WriteLine("\tshow <plugin name(s)>");
|
---|
| 93 | Console.WriteLine("\tupdate <plugin name(s)>");
|
---|
| 94 | Console.WriteLine("\tremove <plugin name(s)>");
|
---|
| 95 | Console.WriteLine("\tinstall <plugin name(s)>");
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[2504] | 98 | private static void ShowErrorMessageBox(Exception ex) {
|
---|
| 99 | MessageBox.Show(null,
|
---|
| 100 | BuildErrorMessage(ex),
|
---|
| 101 | "Error - " + ex.GetType().Name,
|
---|
| 102 | MessageBoxButtons.OK,
|
---|
| 103 | MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
|
---|
[1107] | 104 | }
|
---|
| 105 |
|
---|
| 106 | private static string BuildErrorMessage(Exception ex) {
|
---|
| 107 | StringBuilder sb = new StringBuilder();
|
---|
| 108 | sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
|
---|
| 109 |
|
---|
| 110 | while (ex.InnerException != null) {
|
---|
| 111 | ex = ex.InnerException;
|
---|
| 112 | sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
|
---|
| 113 | }
|
---|
| 114 | return sb.ToString();
|
---|
| 115 | }
|
---|
[2] | 116 | }
|
---|
| 117 | }
|
---|