You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Main.java 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (c) 2006-2011 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. package com.dmdirc.installer;
  23. import com.dmdirc.installer.cliparser.BooleanParam;
  24. import com.dmdirc.installer.cliparser.CLIParser;
  25. import com.dmdirc.installer.cliparser.StringParam;
  26. import com.dmdirc.installer.ui.InstallerDialog;
  27. import com.dmdirc.installer.ui.StepConfirm;
  28. import com.dmdirc.installer.ui.StepError;
  29. import com.dmdirc.installer.ui.StepInstall;
  30. import com.dmdirc.installer.ui.StepSettings;
  31. import com.dmdirc.installer.ui.StepWelcome;
  32. /**
  33. * Main installer entry point.
  34. */
  35. public final class Main {
  36. /** Wizard dialog. */
  37. private static InstallerDialog wizardDialog;
  38. /** Installer. */
  39. private static Installer myInstaller;
  40. /** CLI Parser. */
  41. private static CLIParser cli = CLIParser.getCLIParser();
  42. /**
  43. * Creates and Displays the Installer wizard.
  44. */
  45. private Main() {
  46. try {
  47. InstallerDialog.initUISettings();
  48. } catch (UnsupportedOperationException ex) {
  49. //Ignore, revert to default
  50. }
  51. String releaseName = "DMDirc";
  52. if (cli.getParamNumber("-release") > 0) {
  53. releaseName = releaseName + " " + cli.getParam("-release").
  54. getStringValue();
  55. }
  56. setWizardFrame(new InstallerDialog(releaseName + " Installer"));
  57. getWizardFrame().addWizardListener(new InstallerListener(this));
  58. getWizardFrame().addStepListener(new InstallerListener(this));
  59. final String osName = System.getProperty("os.name");
  60. wizardDialog.addStep(new StepWelcome(releaseName));
  61. if (osName.startsWith("Mac OS")) {
  62. wizardDialog.addStep(
  63. new StepError(
  64. "Sorry, OSX Installation should be done using the downloadable dmg file, not this installer.\n\n"));
  65. } else {
  66. if (CLIParser.getCLIParser().getParamNumber("-unattended") == 0) {
  67. wizardDialog.addStep(new StepSettings());
  68. wizardDialog.addStep(new StepConfirm());
  69. }
  70. wizardDialog.addStep(new StepInstall());
  71. }
  72. }
  73. /**
  74. * Disposes of the current installer.
  75. */
  76. public void disposeOfInstaller() {
  77. final Thread temp = myInstaller;
  78. myInstaller = null;
  79. if (temp != null) {
  80. temp.interrupt();
  81. }
  82. }
  83. /**
  84. * Get the Installer object for this OS.
  85. *
  86. * @return The installer for this OS
  87. */
  88. public static synchronized Installer getInstaller() {
  89. if (myInstaller == null) {
  90. final String osName = System.getProperty("os.name");
  91. if (osName.startsWith("Windows")) {
  92. myInstaller = new WindowsInstaller();
  93. } else if(!osName.startsWith("Mac OS")) {
  94. myInstaller = new LinuxInstaller();
  95. }
  96. }
  97. return myInstaller;
  98. }
  99. /**
  100. * Setup the cli parser.
  101. * This clears the current CLIParser params and creates new ones.
  102. */
  103. private static void setupCLIParser() {
  104. cli.clear();
  105. cli.add(new StringParam('h', "help", "Get Help"));
  106. cli.setHelp(cli.getParam("-help"));
  107. cli.add(new BooleanParam((char) 0, "isroot", "Installing as Root"));
  108. cli.add(new StringParam('r', "release", "Release Name"));
  109. cli.add(new StringParam('d', "directory", "Default install directory"));
  110. cli.add(new BooleanParam('u', "unattended",
  111. "Perform an unattended installation"));
  112. cli.add(new BooleanParam((char) 0, "no-shortcut-desktop",
  113. "Don't offer a desktop shortcut as the default"));
  114. cli.add(new BooleanParam((char) 0, "no-shortcut-menu",
  115. "Don't offer a menu shortcut as the default"));
  116. cli.add(new BooleanParam((char) 0, "no-shortcut-quicklaunch",
  117. "Don't offer a quick launch shortcut as the default"));
  118. cli.add(new BooleanParam((char) 0, "no-shortcut-protocol",
  119. "Don't offer to handle irc:// links as the default"));
  120. }
  121. /**
  122. * Get the WizardFrame.
  123. *
  124. * @return The current wizardDialog
  125. */
  126. public static synchronized InstallerDialog getWizardFrame() {
  127. if (wizardDialog == null) {
  128. new Main();
  129. }
  130. return wizardDialog;
  131. }
  132. /**
  133. * Set the WizardFrame.
  134. *
  135. * @param dialog The new WizardDialog
  136. */
  137. private static void setWizardFrame(final InstallerDialog dialog) {
  138. wizardDialog = dialog;
  139. }
  140. /**
  141. * Run the installer.
  142. *
  143. * @param args Command line arguments
  144. */
  145. public static void main(final String[] args) {
  146. setupCLIParser();
  147. if (cli.wantsHelp(args)) {
  148. cli.showHelp("DMDirc installer Help", "[options [--]]");
  149. System.exit(0);
  150. }
  151. cli.parseArgs(args, false);
  152. getWizardFrame().display();
  153. }
  154. }