File Source: Main.java
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.installer;
24
25 import com.dmdirc.installer.cliparser.BooleanParam;
26 import com.dmdirc.installer.cliparser.CLIParser;
27 import com.dmdirc.installer.cliparser.StringParam;
28
29 import com.dmdirc.installer.ui.InstallerDialog;
30 import com.dmdirc.installer.ui.StepWelcome;
31 import com.dmdirc.installer.ui.StepError;
32 import com.dmdirc.installer.ui.StepSettings;
33 import com.dmdirc.installer.ui.StepConfirm;
34 import com.dmdirc.installer.ui.StepInstall;
35
36 /**
37 * Main installer entry point.
38 */
39 public final class Main {
40
41 /** Wizard dialog. */
42 private static InstallerDialog wizardDialog;
43 /** Installer. */
44 private static Installer myInstaller;
45 /** CLI Parser. */
/*
P/P * Method: com.dmdirc.installer.Main__static_init
*
* Preconditions:
* init'ed(com/dmdirc/installer/cliparser/CLIParser.me)
*
* Postconditions:
* cli == One-of{old com/dmdirc/installer/cliparser/CLIParser.me, &new CLIParser(getCLIParser#1)}
* cli != null
* com/dmdirc/installer/cliparser/CLIParser.me == cli
* new ArrayList(CLIParser#2) num objects <= 1
* new ArrayList(CLIParser#3) num objects == new ArrayList(CLIParser#2) num objects
* new CLIParser(getCLIParser#1) num objects == new ArrayList(CLIParser#2) num objects
* new Hashtable(CLIParser#1) num objects == new ArrayList(CLIParser#2) num objects
* new CLIParser(getCLIParser#1).helpParam == null
* new CLIParser(getCLIParser#1).paramList == &new ArrayList(CLIParser#2)
* new CLIParser(getCLIParser#1).params == &new Hashtable(CLIParser#1)
* ...
*/
46 private static CLIParser cli = CLIParser.getCLIParser();
47
48 /**
49 * Creates and Displays the Installer wizard.
50 */
/*
P/P * Method: void com.dmdirc.installer.Main()
*
* Preconditions:
* cli != null
* cli.params != null
* (soft) init'ed(com/dmdirc/installer/cliparser/CLIParser.me)
* (soft) init'ed(myInstaller)
*
* Presumptions:
* getCLIParser(...).params != null
* java.lang.System:getProperty(...)@68 != null
*
* Postconditions:
* com/dmdirc/installer/cliparser/CLIParser.me == One-of{old com/dmdirc/installer/cliparser/CLIParser.me, &new CLIParser(getCLIParser#1)}
* init'ed(com/dmdirc/installer/cliparser/CLIParser.me)
* myInstaller == One-of{old myInstaller, &new WindowsInstaller(getInstaller#1), &new LinuxInstaller(getInstaller#2)}
* init'ed(myInstaller)
* wizardDialog == &new InstallerDialog(Main#2)
* wizardDialog.wizard.dialog == &new InstallerDialog(Main#2)
* new ArrayList(CLIParser#2) num objects <= 1
* new ArrayList(CLIParser#3) num objects <= 1
* new ArrayList(StepLayout#1) num objects == 1
* new InstallerDialog(Main#2) num objects == 1
* ...
*
* Test Vectors:
* java.lang.String:startsWith(...)@70: {0}, {1}
*/
51 private Main() {
52 try {
53 InstallerDialog.initUISettings();
54 } catch (UnsupportedOperationException ex) {
55 //Ignore, revert to default
56 }
57
58 String releaseName = "DMDirc";
59 if (cli.getParamNumber("-release") > 0) {
60 releaseName = releaseName + " " + cli.getParam("-release").
61 getStringValue();
62 }
63
64 setWizardFrame(new InstallerDialog(releaseName + " Installer"));
65 getWizardFrame().addWizardListener(new InstallerListener(this));
66 getWizardFrame().addStepListener(new InstallerListener(this));
67
68 final String osName = System.getProperty("os.name");
69 wizardDialog.addStep(new StepWelcome(releaseName));
70 if (osName.startsWith("Mac OS")) {
71 wizardDialog.addStep(
72 new StepError(
73 "Sorry, OSX Installation should be done using the downloadable dmg file, not this installer.\n\n"));
74 } else {
75 if (CLIParser.getCLIParser().getParamNumber("-unattended") == 0) {
76 wizardDialog.addStep(new StepSettings());
77 wizardDialog.addStep(new StepConfirm());
78 }
79 wizardDialog.addStep(new StepInstall());
80 }
81 }
82
83 /**
84 * Disposes of the current installer.
85 */
86 public void disposeOfInstaller() {
/*
P/P * Method: void disposeOfInstaller()
*
* Preconditions:
* init'ed(myInstaller)
*
* Postconditions:
* myInstaller == null
*
* Test Vectors:
* myInstaller: Addr_Set{null}, Inverse{null}
*/
87 final Thread temp = myInstaller;
88 myInstaller = null;
89 if (temp != null) {
90 temp.interrupt();
91 }
92 }
93
94 /**
95 * Get the Installer object for this OS.
96 *
97 * @return The installer for this OS
98 */
99 public static synchronized Installer getInstaller() {
/*
P/P * Method: Installer getInstaller()
*
* Preconditions:
* init'ed(myInstaller)
*
* Presumptions:
* java.lang.System:getProperty(...)@101 != null
*
* Postconditions:
* myInstaller == One-of{old myInstaller, &new WindowsInstaller(getInstaller#1), &new LinuxInstaller(getInstaller#2)}
* init'ed(myInstaller)
* return_value == myInstaller
* new LinuxInstaller(getInstaller#2) num objects <= 1
* new WindowsInstaller(getInstaller#1) num objects <= 1
*
* Test Vectors:
* myInstaller: Inverse{null}, Addr_Set{null}
* java.lang.String:startsWith(...)@104: {0}, {1}
*/
100 if (myInstaller == null) {
101 final String osName = System.getProperty("os.name");
102 if (osName.startsWith("Mac OS")) {
103 // myInstaller = new MacInstaller();
104 } else if (osName.startsWith("Windows")) {
105 myInstaller = new WindowsInstaller();
106 } else {
107 myInstaller = new LinuxInstaller();
108 }
109 }
110
111 return myInstaller;
112 }
113
114 /**
115 * Setup the cli parser.
116 * This clears the current CLIParser params and creates new ones.
117 */
118 private static void setupCLIParser() {
/*
P/P * Method: void setupCLIParser()
*
* Preconditions:
* cli != null
* cli.paramList != null
* cli.params != null
* cli.redundant != null
*
* Postconditions:
* init'ed(cli.helpParam)
*/
119 cli.clear();
120 cli.add(new StringParam('h', "help", "Get Help"));
121 cli.setHelp(cli.getParam("-help"));
122 cli.add(new BooleanParam((char) 0, "isroot", "Installing as Root"));
123 cli.add(new StringParam('r', "release", "Release Name"));
124 cli.add(new StringParam('d', "directory", "Default install directory"));
125 cli.add(new BooleanParam('u', "unattended",
126 "Perform an unattended installation"));
127 cli.add(new BooleanParam((char) 0, "no-shortcut-desktop",
128 "Don't offer a desktop shortcut as the default"));
129 cli.add(new BooleanParam((char) 0, "no-shortcut-menu",
130 "Don't offer a menu shortcut as the default"));
131 cli.add(new BooleanParam((char) 0, "no-shortcut-quicklaunch",
132 "Don't offer a quick launch shortcut as the default"));
133 cli.add(new BooleanParam((char) 0, "no-shortcut-protocol",
134 "Don't offer to handle irc:// links as the default"));
135 }
136
137 /**
138 * Get the WizardFrame.
139 *
140 * @return The current wizardDialog
141 */
142 public static synchronized InstallerDialog getWizardFrame() {
/*
P/P * Method: InstallerDialog getWizardFrame()
*
* Preconditions:
* init'ed(wizardDialog)
*
* Postconditions:
* return_value == wizardDialog
* init'ed(return_value)
*
* Test Vectors:
* wizardDialog: Inverse{null}, Addr_Set{null}
*/
143 if (wizardDialog == null) {
144 new Main();
145 }
146 return wizardDialog;
147 }
148
149 /**
150 * Set the WizardFrame.
151 *
152 * @param dialog The new WizardDialog
153 */
154 private static void setWizardFrame(final InstallerDialog dialog) {
/*
P/P * Method: void setWizardFrame(InstallerDialog)
*
* Postconditions:
* wizardDialog == dialog
* init'ed(wizardDialog)
*/
155 wizardDialog = dialog;
156 }
157
158 /**
159 * Run the installer.
160 *
161 * @param args Command line arguments
162 */
163 public static void main(final String[] args) {
/*
P/P * Method: void main(String[])
*
* Preconditions:
* args != null
* args.length <= 232-1
* args[...] != null
* cli != null
* cli.paramList != null
* cli.params != null
* cli.redundant != null
* init'ed(wizardDialog.control.step)
* init'ed(wizardDialog.wizard.layout.currentStep)
* wizardDialog != null
* ...
*
* Presumptions:
* cli.helpParam.stringFlag@165 != null
*
* Postconditions:
* init'ed(cli.helpParam)
* init'ed(java.lang.String:substring(...)._tainted)
* wizardDialog.control.step >= -231+1
* init'ed(wizardDialog.control.total)
* wizardDialog.wizard.layout.currentStep <= 232-2
*/
164 setupCLIParser();
165 if (cli.wantsHelp(args)) {
166 cli.showHelp("DMDirc installer Help", "[options [--]]");
167 System.exit(0);
168 }
169 cli.parseArgs(args, false);
170 getWizardFrame().display();
171 }
172 }
SofCheck Inspector Build Version : 2.17854
| Main.java |
2009-Jun-25 01:54:24 |
| Main.class |
2009-Sep-02 17:04:16 |