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

Last change on this file since 880 was 857, checked in by alloc, 12 years ago

AEI2.10:

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