source: AE/installer2/src/net/oni2/aeinstaller/AEInstaller2.java@ 628

Last change on this file since 628 was 628, checked in by alloc, 12 years ago

AEI2:

  • Minor UI changes
File size: 6.5 KB
RevLine 
[591]1package net.oni2.aeinstaller;
2
[593]3import java.awt.image.BufferedImage;
[591]4import java.io.File;
5import java.io.FileNotFoundException;
[593]6import java.io.IOException;
[591]7import java.io.PrintStream;
[593]8import java.net.URL;
[592]9import java.util.ResourceBundle;
[591]10
[593]11import javax.imageio.ImageIO;
[591]12import javax.swing.JFrame;
[592]13import javax.swing.JOptionPane;
[591]14import javax.swing.JToolBar;
15import javax.swing.SwingUtilities;
16import javax.swing.UIManager;
17import javax.swing.UIManager.LookAndFeelInfo;
18
[596]19import net.oni2.aeinstaller.backend.Paths;
[591]20import net.oni2.aeinstaller.backend.Settings;
[600]21import net.oni2.aeinstaller.backend.Settings.Platform;
[599]22import net.oni2.aeinstaller.backend.SizeFormatter;
[591]23import net.oni2.aeinstaller.backend.depot.DepotManager;
[596]24import net.oni2.aeinstaller.backend.oni.Installer;
25import net.oni2.aeinstaller.backend.oni.OniSplit;
[612]26import net.oni2.aeinstaller.gui.HTMLLinkLabel;
[591]27import net.oni2.aeinstaller.gui.MainWin;
28
29import org.javabuilders.swing.SwingJavaBuilder;
[593]30import org.simplericity.macify.eawt.Application;
31import org.simplericity.macify.eawt.DefaultApplication;
[591]32
33/**
34 * @author Christian Illy
35 */
36public class AEInstaller2 {
37
[593]38 private static ResourceBundle imagesBundle = ResourceBundle
39 .getBundle(AEInstaller2.class.getPackage().getName() + ".Images");
40 private static ResourceBundle basicBundle = ResourceBundle
41 .getBundle(AEInstaller2.class.getPackage().getName()
42 + ".AEInstaller");
43
44 private static Application app = null;
45
46 private static void initMacOS() {
47 System.setProperty("apple.laf.useScreenMenuBar", "true");
48 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
49 basicBundle.getString("appname"));
50 app = new DefaultApplication();
51
52 URL icon = AEInstaller2.class.getResource("images/AElogo.png");
53 try {
54 BufferedImage img = ImageIO.read(icon);
55 app.setApplicationIconImage(img);
56 } catch (IOException e) {
57 e.printStackTrace();
58 }
59 }
60
[591]61 /**
62 * @param args
63 * Command line arguments
64 */
65 public static void main(String[] args) {
[596]66 Paths.getPrefsPath().mkdirs();
67 Paths.getDownloadPath().mkdirs();
[591]68
69 boolean debug = false;
70 for (String a : args)
71 if (a.equalsIgnoreCase("-debug"))
72 debug = true;
73 if (!debug) {
74 try {
[596]75 System.setOut(new PrintStream(new File(Paths.getPrefsPath(),
76 "aei_output.log")));
77 System.setErr(new PrintStream(new File(Paths.getPrefsPath(),
78 "aei_error.log")));
[591]79 } catch (FileNotFoundException e1) {
80 e1.printStackTrace();
81 }
82 }
83
[593]84 if (Settings.getPlatform() == Platform.MACOS)
85 initMacOS();
86
[591]87 Settings.deserializeFromFile();
88 Settings.setDebug(debug);
89 DepotManager.getInstance().loadFromFile(
[596]90 Settings.getDepotCacheFilename());
[591]91
[592]92 SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
93 SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
[591]94 SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true);
95 SwingJavaBuilder.getConfig().addType("JToolBarSeparator",
96 JToolBar.Separator.class);
97
98 System.setProperty("networkaddress.cache.ttl", "5");
99 System.setProperty("networkaddress.cache.negative.ttl", "1");
[596]100
[591]101 try {
102 String laf = Settings.getInstance().get("lookandfeel",
103 (String) null);
104 if (laf == null) {
[628]105 if (Settings.getPlatform() != Platform.LINUX) {
[593]106 laf = UIManager.getSystemLookAndFeelClassName();
107 } else {
108 for (LookAndFeelInfo lafInfo : UIManager
109 .getInstalledLookAndFeels()) {
110 if (lafInfo.getName().equals("Nimbus"))
111 laf = lafInfo.getClassName();
112 }
[591]113 }
114 }
115 if (laf == null)
116 laf = UIManager.getSystemLookAndFeelClassName();
117 UIManager.setLookAndFeel(laf);
118 } catch (Exception e) {
119 e.printStackTrace();
120 }
121 JFrame.setDefaultLookAndFeelDecorated(true);
122
[624]123 // TODO: Remove debug output
[596]124 System.out.println("JarPath: " + Paths.getInstallerPath());
125 System.out.println("PrefsPath: " + Paths.getPrefsPath());
126 System.out.println("DataPath: " + Paths.getModsPath());
127 System.out.println("DownPath: " + Paths.getDownloadPath());
128 System.out.println("TempPath: " + Paths.getTempPath());
[612]129 System.out.println("ValidPath: " + Installer.verifyRunningDirectory());
[594]130 System.out.println("Platform: " + Settings.getPlatform());
131 System.out.println("Architect: " + Settings.getArchitecture());
132 System.out.println(".NET: " + OniSplit.isDotNETInstalled());
[602]133 System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled());
[596]134 System.out.println("Globalized:" + Installer.isEditionInitialized());
[591]135
[624]136 // TODO: Check available space
[600]137 System.out
138 .println("Free space on temp: "
139 + SizeFormatter.format(Paths.getTempPath()
140 .getUsableSpace(), 3));
141 System.out.println("Free space on Jar: "
142 + SizeFormatter.format(Paths.getInstallerPath()
143 .getUsableSpace(), 3));
144
[612]145 if (!OniSplit.isDotNETInstalled()) {
146 HTMLLinkLabel hll = new HTMLLinkLabel();
147 String dlUrl = "";
148 switch (Settings.getPlatform()) {
149 case WIN:
150 switch (Settings.getArchitecture()) {
151 case X86:
152 dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe";
153 break;
154 case AMD64:
155 dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x64.exe";
156 break;
157 }
158 break;
159 default:
160 dlUrl = "http://www.go-mono.com/mono-downloads/download.html";
161 }
162 hll.setText(basicBundle.getString("dotNetMissing.text").replaceAll(
163 "%1", String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl)));
164 JOptionPane.showMessageDialog(null, hll,
165 basicBundle.getString("dotNetMissing.title"),
166 JOptionPane.ERROR_MESSAGE);
167 return;
168 }
169
[603]170 if (!Installer.verifyRunningDirectory()) {
[592]171 JOptionPane.showMessageDialog(null,
172 basicBundle.getString("invalidPath.text"),
173 basicBundle.getString("invalidPath.title"),
174 JOptionPane.ERROR_MESSAGE);
[625]175 if (!Settings.isDebug()) {
[592]176 return;
177 }
178 }
179
[621]180 boolean offline = !DepotManager.getInstance().checkConnection();
181 if (offline) {
182 JOptionPane.showMessageDialog(null,
183 basicBundle.getString("offlineMode.text"),
184 basicBundle.getString("offlineMode.title"),
185 JOptionPane.INFORMATION_MESSAGE);
186 }
187 Settings.getInstance().setOfflineMode(offline);
188
[591]189 SwingUtilities.invokeLater(new Runnable() {
190 public void run() {
191 try {
[593]192 MainWin mw = new MainWin();
193 if (app != null) {
194 app.addAboutMenuItem();
195 app.setEnabledAboutMenu(true);
196 app.addPreferencesMenuItem();
197 app.setEnabledPreferencesMenu(true);
198 app.addApplicationListener(mw);
199 }
200 mw.setVisible(true);
[591]201 } catch (Exception e) {
202 e.printStackTrace();
203 }
204 }
205 });
206
207 }
208}
Note: See TracBrowser for help on using the repository browser.