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

Last change on this file since 927 was 886, checked in by alloc, 11 years ago

AEI2.16:

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