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

Last change on this file since 846 was 840, checked in by alloc, 12 years ago

AEI2.07:

  • Allow for non-ISO-8859-1 characters in properties files (more exactly require them to be UTF8)
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
[720]23import net.oni2.SettingsManager;
[699]24import net.oni2.aeinstaller.backend.CaseInsensitiveFile;
[596]25import net.oni2.aeinstaller.backend.Paths;
[599]26import net.oni2.aeinstaller.backend.SizeFormatter;
[596]27import net.oni2.aeinstaller.backend.oni.OniSplit;
[749]28import net.oni2.aeinstaller.backend.oni.management.Installer;
[612]29import net.oni2.aeinstaller.gui.HTMLLinkLabel;
[591]30import net.oni2.aeinstaller.gui.MainWin;
[749]31import net.oni2.moddepot.DepotManager;
[720]32import net.oni2.platformtools.PlatformInformation;
33import net.oni2.platformtools.PlatformInformation.Platform;
[730]34import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
[720]35import net.oni2.platformtools.applicationinvoker.DotNet;
[730]36import net.oni2.platformtools.applicationinvoker.EExeType;
[840]37import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
[730]38import net.oni2.svnaccess.SVN;
[591]39
40import org.javabuilders.swing.SwingJavaBuilder;
[593]41import org.simplericity.macify.eawt.Application;
42import org.simplericity.macify.eawt.DefaultApplication;
[591]43
44/**
45 * @author Christian Illy
46 */
47public class AEInstaller2 {
48
[651]49 private static ResourceBundle imagesBundle;
50 private static ResourceBundle basicBundle;
51 private static ResourceBundle globalBundle;
[593]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
[637]61 URL icon = AEInstaller2.class.getResource(imagesBundle
62 .getString("img.ae"));
[593]63 try {
64 BufferedImage img = ImageIO.read(icon);
65 app.setApplicationIconImage(img);
66 } catch (IOException e) {
67 e.printStackTrace();
68 }
69 }
[730]70
[653]71 private static void initBundles() {
[730]72 File localesDir = CaseInsensitiveFile.getCaseInsensitiveFile(
73 Paths.getInstallerPath(), "locales");
[653]74 if (localesDir.isDirectory())
75 addClassPath(localesDir);
[735]76 else {
77 File localesSubDir = CaseInsensitiveFile.getCaseInsensitiveFile(
78 CaseInsensitiveFile.getCaseInsensitiveFile(
79 Paths.getInstallerPath(), "bin"), "locales");
80 if (localesSubDir.isDirectory()) {
81 addClassPath(localesSubDir);
82 }
83 }
[653]84 imagesBundle = ResourceBundle.getBundle("net.oni2.aeinstaller.Images");
85 basicBundle = ResourceBundle
86 .getBundle("net.oni2.aeinstaller.AEInstaller");
[840]87 globalBundle = UTF8ResourceBundleLoader
[653]88 .getBundle("net.oni2.aeinstaller.localization.Global");
89 }
[593]90
[651]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
[591]110 /**
111 * @param args
112 * Command line arguments
113 */
114 public static void main(String[] args) {
[596]115 Paths.getPrefsPath().mkdirs();
116 Paths.getDownloadPath().mkdirs();
[591]117
118 boolean debug = false;
[776]119 boolean useWd = false;
[649]120 boolean noCacheUpdate = false;
[749]121 boolean offline = false;
[649]122 for (String a : args) {
[591]123 if (a.equalsIgnoreCase("-debug"))
124 debug = true;
[649]125 if (a.equalsIgnoreCase("-nocacheupdate"))
126 noCacheUpdate = true;
[749]127 if (a.equalsIgnoreCase("-offline"))
128 offline = true;
[776]129 if (a.equalsIgnoreCase("-usewd"))
130 useWd = true;
[649]131 }
[591]132 if (!debug) {
133 try {
[634]134 PrintStream ps = new PrintStream(new File(Paths.getPrefsPath(),
135 "aei_output.log"));
136 System.setOut(ps);
137 System.setErr(ps);
[591]138 } catch (FileNotFoundException e1) {
139 e1.printStackTrace();
140 }
141 }
[730]142
[753]143 SettingsManager.setDebug(debug);
144 SettingsManager.deserializeFromFile(Paths.getSettingsFilename());
145 SettingsManager.setDebug(debug);
[776]146 SettingsManager.setUseWorkingDir(useWd);
[753]147 SettingsManager.getInstance().setNoCacheUpdateMode(noCacheUpdate);
148
[653]149 initBundles();
[591]150
[720]151 if (PlatformInformation.getPlatform() == Platform.MACOS)
[593]152 initMacOS();
153
[592]154 SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
155 SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
[640]156 SwingJavaBuilder.getConfig().addResourceBundle(globalBundle);
[591]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");
[596]163
[591]164 try {
[720]165 String laf = SettingsManager.getInstance().get("lookandfeel",
[591]166 (String) null);
167 if (laf == null) {
[720]168 if (PlatformInformation.getPlatform() != Platform.LINUX) {
[593]169 laf = UIManager.getSystemLookAndFeelClassName();
170 } else {
171 for (LookAndFeelInfo lafInfo : UIManager
172 .getInstalledLookAndFeels()) {
173 if (lafInfo.getName().equals("Nimbus"))
174 laf = lafInfo.getClassName();
175 }
[591]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
[772]186 System.out.println(basicBundle.getString("appname")
[637]187 + basicBundle.getString("appversion"));
[778]188 System.out.println("JarPath: " + Paths.getJarPath());
[596]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());
[612]193 System.out.println("ValidPath: " + Installer.verifyRunningDirectory());
[720]194 System.out.println("Platform: " + PlatformInformation.getPlatform());
[730]195 System.out.println("Architect: "
196 + PlatformInformation.getArchitecture());
[672]197 System.out.println(".NET: " + DotNet.isInstalled());
[602]198 System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled());
[596]199 System.out.println("Globalized:" + Installer.isEditionInitialized());
[591]200
[624]201 // TODO: Check available space
[600]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));
[634]209 System.out.println();
[600]210
[672]211 if (!DotNet.isInstalled()) {
[612]212 HTMLLinkLabel hll = new HTMLLinkLabel();
213 String dlUrl = "";
[720]214 switch (PlatformInformation.getPlatform()) {
[612]215 case WIN:
[720]216 switch (PlatformInformation.getArchitecture()) {
[612]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 }
[640]228 hll.setText(globalBundle
[634]229 .getString("dotNetMissing.text")
230 .replaceAll(
231 "%1",
232 String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl)));
[612]233 JOptionPane.showMessageDialog(null, hll,
[640]234 globalBundle.getString("dotNetMissing.title"),
[612]235 JOptionPane.ERROR_MESSAGE);
236 return;
237 }
238
[603]239 if (!Installer.verifyRunningDirectory()) {
[592]240 JOptionPane.showMessageDialog(null,
[640]241 globalBundle.getString("invalidPath.text"),
242 globalBundle.getString("invalidPath.title"),
[592]243 JOptionPane.ERROR_MESSAGE);
[720]244 if (!SettingsManager.isDebug()) {
[592]245 return;
246 }
247 }
248
[649]249 if (!offline) {
250 offline = !DepotManager.getInstance().checkConnection();
251 }
252 if (offline) {
[621]253 JOptionPane.showMessageDialog(null,
[646]254 globalBundle.getString("offlineModeStartup.text"),
255 globalBundle.getString("offlineModeStartup.title"),
[621]256 JOptionPane.INFORMATION_MESSAGE);
257 }
[720]258 SettingsManager.getInstance().setOfflineMode(offline);
[621]259
[730]260 if (!offline) {
261 SVN svn = new SVN();
262 try {
263 int x = svn.checkSVN("http://svn.aei.oni2.net",
[776]264 Paths.getJarPath());
[730]265 if (x > 0) {
[766]266 // Update available or missing files
[730]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,
[767]276 null, false);
[730]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
[591]289 SwingUtilities.invokeLater(new Runnable() {
290 public void run() {
291 try {
[593]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);
[591]301 } catch (Exception e) {
302 e.printStackTrace();
303 }
304 }
305 });
306
307 }
308}
Note: See TracBrowser for help on using the repository browser.