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

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

AEI2 0.92a:

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