1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 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.Windows.Forms;
|
---|
24 | using System.Text;
|
---|
25 | using System.Linq;
|
---|
26 | using HeuristicLab.PluginInfrastructure.Starter;
|
---|
27 | using System.IO;
|
---|
28 | using HeuristicLab.PluginInfrastructure.Advanced;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.PluginInfrastructure {
|
---|
31 | public static class Main {
|
---|
32 | public static void Run(string[] args) {
|
---|
33 | if (args.Length == 0) { // normal mode
|
---|
34 | try {
|
---|
35 | Application.EnableVisualStyles();
|
---|
36 | Application.SetCompatibleTextRenderingDefault(false);
|
---|
37 | Application.Run(new StarterForm());
|
---|
38 | }
|
---|
39 | catch (Exception ex) {
|
---|
40 | ShowErrorMessageBox(ex);
|
---|
41 | }
|
---|
42 |
|
---|
43 | } else {
|
---|
44 | var cmd = args[0].ToUpperInvariant();
|
---|
45 | string pluginDir = Path.GetFullPath(Application.StartupPath);
|
---|
46 | switch (cmd) {
|
---|
47 | case "START": {
|
---|
48 | if (args.Length != 2) {
|
---|
49 | PrintUsage();
|
---|
50 | } else {
|
---|
51 | Application.EnableVisualStyles();
|
---|
52 | Application.SetCompatibleTextRenderingDefault(false);
|
---|
53 | Application.Run(new StarterForm(args[1]));
|
---|
54 | }
|
---|
55 | break;
|
---|
56 | }
|
---|
57 | case "SHOW": {
|
---|
58 | InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
|
---|
59 | managerConsole.Show(args.Skip(1));
|
---|
60 | break;
|
---|
61 | }
|
---|
62 | case "INSTALL": {
|
---|
63 | InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
|
---|
64 | managerConsole.Install(args.Skip(1));
|
---|
65 | break;
|
---|
66 | }
|
---|
67 | case "UPDATE": {
|
---|
68 | InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
|
---|
69 | managerConsole.Update(args.Skip(1));
|
---|
70 | break;
|
---|
71 | }
|
---|
72 | case "REMOVE": {
|
---|
73 | InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
|
---|
74 | managerConsole.Remove(args.Skip(1));
|
---|
75 | break;
|
---|
76 | }
|
---|
77 | default: PrintUsage(); break;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | private static void PrintUsage() {
|
---|
83 | Console.WriteLine("Usage: HeuristicLab.exe <command> <args>");
|
---|
84 | Console.WriteLine("Commands:");
|
---|
85 | Console.WriteLine("\tstart <application name>");
|
---|
86 | Console.WriteLine("\tshow <plugin name(s)>");
|
---|
87 | Console.WriteLine("\tupdate <plugin name(s)>");
|
---|
88 | Console.WriteLine("\tremove <plugin name(s)>");
|
---|
89 | Console.WriteLine("\tinstall <plugin name(s)>");
|
---|
90 | }
|
---|
91 |
|
---|
92 | private static void ShowErrorMessageBox(Exception ex) {
|
---|
93 | MessageBox.Show(null,
|
---|
94 | BuildErrorMessage(ex),
|
---|
95 | "Error - " + ex.GetType().Name,
|
---|
96 | MessageBoxButtons.OK,
|
---|
97 | MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
|
---|
98 | }
|
---|
99 |
|
---|
100 | private static string BuildErrorMessage(Exception ex) {
|
---|
101 | StringBuilder sb = new StringBuilder();
|
---|
102 | sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
|
---|
103 |
|
---|
104 | while (ex.InnerException != null) {
|
---|
105 | ex = ex.InnerException;
|
---|
106 | sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
|
---|
107 | }
|
---|
108 | return sb.ToString();
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|