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

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

AEI2.08:

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