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

Last change on this file since 1024 was 1024, checked in by alloc, 9 years ago

AEI: Fixed a Javadoc compiler warning

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