Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * Copyright (c) 2006-2008 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;
  23. import com.dmdirc.actions.ActionManager;
  24. import com.dmdirc.actions.CoreActionType;
  25. import com.dmdirc.commandline.CommandLineParser;
  26. import com.dmdirc.commandparser.CommandManager;
  27. import com.dmdirc.config.IdentityManager;
  28. import com.dmdirc.logger.DMDircExceptionHandler;
  29. import com.dmdirc.plugins.PluginManager;
  30. import com.dmdirc.themes.ThemeManager;
  31. import com.dmdirc.ui.dummy.DummyController;
  32. import com.dmdirc.ui.swing.SwingController;
  33. import com.dmdirc.ui.interfaces.UIController;
  34. import com.dmdirc.updater.UpdateChannel;
  35. import com.dmdirc.updater.UpdateChecker;
  36. import java.awt.GraphicsEnvironment;
  37. import java.util.Timer;
  38. import java.util.TimerTask;
  39. /**
  40. * Main class, handles initialisation.
  41. *
  42. * @author chris
  43. */
  44. public final class Main {
  45. /**
  46. * Stores the current textual program version.
  47. */
  48. public static final String VERSION = "SVN";
  49. /**
  50. * Stores the release date of this version.
  51. */
  52. public static final int RELEASE_DATE = 0;
  53. /**
  54. * Stores the update channel that this version came from, if any.
  55. */
  56. public static final UpdateChannel UPDATE_CHANNEL = UpdateChannel.NONE;
  57. /**
  58. * A revision number for actions and core plugins. If this is increased,
  59. * users will be prompted to re-extract them.
  60. *
  61. * @Deprecated No longer needed, remove post-0.6
  62. */
  63. @Deprecated
  64. private static final int ADDON_REVISION = 10;
  65. /**
  66. * Feedback nag delay.
  67. */
  68. private static final int FEEDBACK_DELAY = 30 * 60 * 1000;
  69. /**
  70. * The UI to use for the client.
  71. */
  72. private static UIController controller;
  73. /**
  74. * The config dir to use for the client.
  75. */
  76. private static String configdir;
  77. /**
  78. * Prevents creation of main.
  79. */
  80. private Main() {
  81. }
  82. /**
  83. * Entry procedure.
  84. *
  85. * @param args the command line arguments
  86. */
  87. public static void main(final String[] args) {
  88. Thread.setDefaultUncaughtExceptionHandler(new DMDircExceptionHandler());
  89. final CommandLineParser clp = new CommandLineParser(args);
  90. IdentityManager.load();
  91. clp.applySettings();
  92. CommandManager.initCommands();
  93. getUI().initUISettings();
  94. ActionManager.init();
  95. PluginManager.getPluginManager();
  96. ActionManager.loadActions();
  97. new ThemeManager().loadDefaultTheme();
  98. getUI().getMainWindow();
  99. if (IdentityManager.getGlobalConfig().getOptionBool("general", "firstRun", true)) {
  100. IdentityManager.getConfigIdentity().setOption("general", "firstRun", "false");
  101. IdentityManager.getConfigIdentity().setOption("general", "addonrevision", ADDON_REVISION);
  102. getUI().showFirstRunWizard();
  103. new Timer().schedule(new TimerTask(){
  104. /** {@inheritDoc} */
  105. @Override
  106. public void run() {
  107. getUI().showFeedbackNag();
  108. }
  109. }, FEEDBACK_DELAY);
  110. } else if (IdentityManager.getGlobalConfig().getOptionInt("general", "addonrevision", -1) < ADDON_REVISION) {
  111. IdentityManager.getConfigIdentity().setOption("general", "addonrevision", ADDON_REVISION);
  112. getUI().showMigrationWizard();
  113. }
  114. ActionManager.processEvent(CoreActionType.CLIENT_OPENED, null);
  115. UpdateChecker.init();
  116. clp.processArguments();
  117. if (IdentityManager.getGlobalConfig().getOptionBool("general", "showglobalwindow", false)) {
  118. new GlobalWindow();
  119. }
  120. Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
  121. public void run() {
  122. ActionManager.processEvent(CoreActionType.CLIENT_CLOSED, null);
  123. ServerManager.getServerManager().disconnectAll("Unexpected shutdown");
  124. IdentityManager.save();
  125. }
  126. }, "Shutdown thread"));
  127. }
  128. /**
  129. * Quits the client nicely, with the default closing message.
  130. */
  131. public static void quit() {
  132. quit(IdentityManager.getGlobalConfig().getOption("general", "closemessage"));
  133. }
  134. /**
  135. * Quits the client nicely.
  136. *
  137. * @param reason The quit reason to send
  138. */
  139. public static void quit(final String reason) {
  140. ServerManager.getServerManager().disconnectAll(reason);
  141. System.exit(0);
  142. }
  143. /**
  144. * Retrieves the UI controller that's being used by the client.
  145. *
  146. * @return The client's UI controller
  147. */
  148. public static UIController getUI() {
  149. if (controller == null) {
  150. if (GraphicsEnvironment.isHeadless()) {
  151. controller = new DummyController();
  152. } else {
  153. controller = new SwingController();
  154. }
  155. }
  156. return controller;
  157. }
  158. /**
  159. * Sets the UI controller that should be used by this client.
  160. *
  161. * @param newController The new UI Controller
  162. */
  163. public static void setUI(final UIController newController) {
  164. controller = newController;
  165. }
  166. /**
  167. * Returns the application's config directory.
  168. *
  169. * @return configuration directory
  170. */
  171. public static String getConfigDir() {
  172. if (configdir == null) {
  173. final String fs = System.getProperty("file.separator");
  174. final String osName = System.getProperty("os.name");
  175. if (osName.startsWith("Mac OS")) {
  176. configdir = System.getProperty("user.home") + fs + "Library" + fs + "Preferences" + fs + "DMDirc" + fs;
  177. } else if (osName.startsWith("Windows")) {
  178. if (System.getenv("APPDATA") == null) {
  179. configdir = System.getProperty("user.home") + fs + "DMDirc" + fs;
  180. } else {
  181. configdir = System.getenv("APPDATA") + fs + "DMDirc" + fs;
  182. }
  183. } else {
  184. configdir = System.getProperty("user.home") + fs + ".DMDirc" + fs;
  185. }
  186. }
  187. return configdir;
  188. }
  189. /**
  190. * Sets the config directory for this client.
  191. *
  192. * @param newdir The new configuration directory
  193. */
  194. public static void setConfigDir(final String newdir) {
  195. configdir = newdir;
  196. }
  197. }