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

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

v.25: Added some debug information to mod installation, auto flush log, print detected platform

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