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

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

AEI2 0.99y:

  • Fix to layout of Main win lower part
File size: 9.5 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.lang.reflect.InvocationTargetException;
9import java.lang.reflect.Method;
10import java.net.MalformedURLException;
11import java.net.URL;
12import java.net.URLClassLoader;
13import java.util.ResourceBundle;
14
15import javax.imageio.ImageIO;
16import javax.swing.JFrame;
17import javax.swing.JOptionPane;
18import javax.swing.JToolBar;
19import javax.swing.SwingUtilities;
20import javax.swing.UIManager;
21import javax.swing.UIManager.LookAndFeelInfo;
22
23import net.oni2.SettingsManager;
24import net.oni2.aeinstaller.backend.CaseInsensitiveFile;
25import net.oni2.aeinstaller.backend.Paths;
26import net.oni2.aeinstaller.backend.SizeFormatter;
27import net.oni2.aeinstaller.backend.oni.OniSplit;
28import net.oni2.aeinstaller.backend.oni.management.Installer;
29import net.oni2.aeinstaller.gui.HTMLLinkLabel;
30import net.oni2.aeinstaller.gui.MainWin;
31import net.oni2.moddepot.DepotManager;
32import net.oni2.platformtools.PlatformInformation;
33import net.oni2.platformtools.PlatformInformation.Platform;
34import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
35import net.oni2.platformtools.applicationinvoker.DotNet;
36import net.oni2.platformtools.applicationinvoker.EExeType;
37import net.oni2.svnaccess.SVN;
38
39import org.javabuilders.swing.SwingJavaBuilder;
40import org.simplericity.macify.eawt.Application;
41import org.simplericity.macify.eawt.DefaultApplication;
42
43/**
44 * @author Christian Illy
45 */
46public class AEInstaller2 {
47
48 private static ResourceBundle imagesBundle;
49 private static ResourceBundle basicBundle;
50 private static ResourceBundle globalBundle;
51
52 private static Application app = null;
53
54 private static void initMacOS() {
55 System.setProperty("apple.laf.useScreenMenuBar", "true");
56 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
57 basicBundle.getString("appname"));
58 app = new DefaultApplication();
59
60 URL icon = AEInstaller2.class.getResource(imagesBundle
61 .getString("img.ae"));
62 try {
63 BufferedImage img = ImageIO.read(icon);
64 app.setApplicationIconImage(img);
65 } catch (IOException e) {
66 e.printStackTrace();
67 }
68 }
69
70 private static void initBundles() {
71 File localesDir = CaseInsensitiveFile.getCaseInsensitiveFile(
72 Paths.getInstallerPath(), "locales");
73 if (localesDir.isDirectory())
74 addClassPath(localesDir);
75 else {
76 File localesSubDir = CaseInsensitiveFile.getCaseInsensitiveFile(
77 CaseInsensitiveFile.getCaseInsensitiveFile(
78 Paths.getInstallerPath(), "bin"), "locales");
79 if (localesSubDir.isDirectory()) {
80 addClassPath(localesSubDir);
81 }
82 }
83 imagesBundle = ResourceBundle.getBundle("net.oni2.aeinstaller.Images");
84 basicBundle = ResourceBundle
85 .getBundle("net.oni2.aeinstaller.AEInstaller");
86 globalBundle = ResourceBundle
87 .getBundle("net.oni2.aeinstaller.localization.Global");
88 }
89
90 private static void addClassPath(File dir) {
91 try {
92 URL u = dir.toURI().toURL();
93 URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader
94 .getSystemClassLoader();
95 Class<URLClassLoader> urlClass = URLClassLoader.class;
96 Method method = urlClass.getDeclaredMethod("addURL",
97 new Class[] { URL.class });
98 method.setAccessible(true);
99 method.invoke(urlClassLoader, new Object[] { u });
100 } catch (MalformedURLException e) {
101 } catch (SecurityException e) {
102 } catch (NoSuchMethodException e) {
103 } catch (IllegalArgumentException e) {
104 } catch (IllegalAccessException e) {
105 } catch (InvocationTargetException e) {
106 }
107 }
108
109 /**
110 * @param args
111 * Command line arguments
112 */
113 public static void main(String[] args) {
114 Paths.getPrefsPath().mkdirs();
115 Paths.getDownloadPath().mkdirs();
116
117 boolean debug = false;
118 boolean noCacheUpdate = false;
119 boolean offline = false;
120 for (String a : args) {
121 if (a.equalsIgnoreCase("-debug"))
122 debug = true;
123 if (a.equalsIgnoreCase("-nocacheupdate"))
124 noCacheUpdate = true;
125 if (a.equalsIgnoreCase("-offline"))
126 offline = true;
127 }
128 if (!debug) {
129 try {
130 PrintStream ps = new PrintStream(new File(Paths.getPrefsPath(),
131 "aei_output.log"));
132 System.setOut(ps);
133 System.setErr(ps);
134 } catch (FileNotFoundException e1) {
135 e1.printStackTrace();
136 }
137 }
138
139 SettingsManager.setDebug(debug);
140 SettingsManager.deserializeFromFile(Paths.getSettingsFilename());
141 SettingsManager.setDebug(debug);
142 SettingsManager.getInstance().setNoCacheUpdateMode(noCacheUpdate);
143
144 initBundles();
145
146 if (PlatformInformation.getPlatform() == Platform.MACOS)
147 initMacOS();
148
149 SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
150 SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
151 SwingJavaBuilder.getConfig().addResourceBundle(globalBundle);
152 SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true);
153 SwingJavaBuilder.getConfig().addType("JToolBarSeparator",
154 JToolBar.Separator.class);
155
156 System.setProperty("networkaddress.cache.ttl", "5");
157 System.setProperty("networkaddress.cache.negative.ttl", "1");
158
159 try {
160 String laf = SettingsManager.getInstance().get("lookandfeel",
161 (String) null);
162 if (laf == null) {
163 if (PlatformInformation.getPlatform() != Platform.LINUX) {
164 laf = UIManager.getSystemLookAndFeelClassName();
165 } else {
166 for (LookAndFeelInfo lafInfo : UIManager
167 .getInstalledLookAndFeels()) {
168 if (lafInfo.getName().equals("Nimbus"))
169 laf = lafInfo.getClassName();
170 }
171 }
172 }
173 if (laf == null)
174 laf = UIManager.getSystemLookAndFeelClassName();
175 UIManager.setLookAndFeel(laf);
176 } catch (Exception e) {
177 e.printStackTrace();
178 }
179 JFrame.setDefaultLookAndFeelDecorated(true);
180
181 System.out.println(basicBundle.getString("appname") + " "
182 + basicBundle.getString("appversion"));
183 System.out.println("JarPath: " + Paths.getInstallerPath());
184 System.out.println("PrefsPath: " + Paths.getPrefsPath());
185 System.out.println("DataPath: " + Paths.getModsPath());
186 System.out.println("DownPath: " + Paths.getDownloadPath());
187 System.out.println("TempPath: " + Paths.getTempPath());
188 System.out.println("ValidPath: " + Installer.verifyRunningDirectory());
189 System.out.println("Platform: " + PlatformInformation.getPlatform());
190 System.out.println("Architect: "
191 + PlatformInformation.getArchitecture());
192 System.out.println(".NET: " + DotNet.isInstalled());
193 System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled());
194 System.out.println("Globalized:" + Installer.isEditionInitialized());
195
196 // TODO: Check available space
197 System.out
198 .println("Free space on temp: "
199 + SizeFormatter.format(Paths.getTempPath()
200 .getUsableSpace(), 3));
201 System.out.println("Free space on Jar: "
202 + SizeFormatter.format(Paths.getInstallerPath()
203 .getUsableSpace(), 3));
204 System.out.println();
205
206 if (!DotNet.isInstalled()) {
207 HTMLLinkLabel hll = new HTMLLinkLabel();
208 String dlUrl = "";
209 switch (PlatformInformation.getPlatform()) {
210 case WIN:
211 switch (PlatformInformation.getArchitecture()) {
212 case X86:
213 dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe";
214 break;
215 case AMD64:
216 dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x64.exe";
217 break;
218 }
219 break;
220 default:
221 dlUrl = "http://www.go-mono.com/mono-downloads/download.html";
222 }
223 hll.setText(globalBundle
224 .getString("dotNetMissing.text")
225 .replaceAll(
226 "%1",
227 String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl)));
228 JOptionPane.showMessageDialog(null, hll,
229 globalBundle.getString("dotNetMissing.title"),
230 JOptionPane.ERROR_MESSAGE);
231 return;
232 }
233
234 if (!Installer.verifyRunningDirectory()) {
235 JOptionPane.showMessageDialog(null,
236 globalBundle.getString("invalidPath.text"),
237 globalBundle.getString("invalidPath.title"),
238 JOptionPane.ERROR_MESSAGE);
239 if (!SettingsManager.isDebug()) {
240 return;
241 }
242 }
243
244 if (!offline) {
245 offline = !DepotManager.getInstance().checkConnection();
246 }
247 if (offline) {
248 JOptionPane.showMessageDialog(null,
249 globalBundle.getString("offlineModeStartup.text"),
250 globalBundle.getString("offlineModeStartup.title"),
251 JOptionPane.INFORMATION_MESSAGE);
252 }
253 SettingsManager.getInstance().setOfflineMode(offline);
254
255 if (!offline) {
256 SVN svn = new SVN();
257 try {
258 int x = svn.checkSVN("http://svn.aei.oni2.net",
259 new File(Paths.getPrefsPath(), "bin"));
260 if (x > 0) {
261 // Update available
262 int res = JOptionPane.showConfirmDialog(null,
263 globalBundle.getString("aeiUpdateAvailable.text"),
264 globalBundle.getString("aeiUpdateAvailable.title"),
265 JOptionPane.YES_NO_OPTION,
266 JOptionPane.INFORMATION_MESSAGE);
267 if (res == JOptionPane.YES_OPTION) {
268 File updater = new File(Paths.getInstallerPath(),
269 "AEInstaller2Updater.jar");
270 ApplicationInvoker.execute(EExeType.JAR, null, updater,
271 null);
272 return;
273 }
274 } else if (x == 0) {
275 // Up to date
276 } else if (x < 0) {
277 // No WC at given path
278 }
279 } catch (Exception e) {
280 e.printStackTrace();
281 }
282 }
283
284 SwingUtilities.invokeLater(new Runnable() {
285 public void run() {
286 try {
287 MainWin mw = new MainWin();
288 if (app != null) {
289 app.addAboutMenuItem();
290 app.setEnabledAboutMenu(true);
291 app.addPreferencesMenuItem();
292 app.setEnabledPreferencesMenu(true);
293 app.addApplicationListener(mw);
294 }
295 mw.setVisible(true);
296 } catch (Exception e) {
297 e.printStackTrace();
298 }
299 }
300 });
301
302 }
303}
Note: See TracBrowser for help on using the repository browser.