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

Last change on this file since 1152 was 1081, checked in by alloc, 7 years ago

AEI2 2.27

File size: 10.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;
[651]7import java.lang.reflect.InvocationTargetException;
8import java.lang.reflect.Method;
9import java.net.MalformedURLException;
[593]10import java.net.URL;
[651]11import java.net.URLClassLoader;
[886]12import java.text.SimpleDateFormat;
13import java.util.Date;
[592]14import java.util.ResourceBundle;
[591]15
[593]16import javax.imageio.ImageIO;
[591]17import javax.swing.JFrame;
[592]18import javax.swing.JOptionPane;
[591]19import javax.swing.JToolBar;
20import javax.swing.SwingUtilities;
[1025]21import javax.swing.ToolTipManager;
[591]22import javax.swing.UIManager;
23import javax.swing.UIManager.LookAndFeelInfo;
24
[852]25import net.oni2.ProxySettings;
[720]26import net.oni2.SettingsManager;
[699]27import net.oni2.aeinstaller.backend.CaseInsensitiveFile;
[886]28import net.oni2.aeinstaller.backend.LogPrintStream;
[596]29import net.oni2.aeinstaller.backend.Paths;
[852]30import net.oni2.aeinstaller.backend.RuntimeOptions;
[599]31import net.oni2.aeinstaller.backend.SizeFormatter;
[596]32import net.oni2.aeinstaller.backend.oni.OniSplit;
[749]33import net.oni2.aeinstaller.backend.oni.management.Installer;
[591]34import net.oni2.aeinstaller.gui.MainWin;
[749]35import net.oni2.moddepot.DepotManager;
[720]36import net.oni2.platformtools.PlatformInformation;
37import net.oni2.platformtools.PlatformInformation.Platform;
[730]38import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
[720]39import net.oni2.platformtools.applicationinvoker.DotNet;
[730]40import net.oni2.platformtools.applicationinvoker.EExeType;
[840]41import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
[730]42import net.oni2.svnaccess.SVN;
[849]43import net.oni2.swingcomponents.HTMLLinkLabel;
[591]44
45import org.javabuilders.swing.SwingJavaBuilder;
[593]46import org.simplericity.macify.eawt.Application;
47import org.simplericity.macify.eawt.DefaultApplication;
[591]48
49/**
50 * @author Christian Illy
51 */
52public class AEInstaller2 {
53
[852]54 private static ResourceBundle imagesBundle = ResourceBundle
55 .getBundle("net.oni2.aeinstaller.Images");
56 private static ResourceBundle basicBundle = ResourceBundle
57 .getBundle("net.oni2.aeinstaller.AEInstaller");
[1024]58 /**
59 * Global localization strings (e.g. non GUI stuff like backend modules)
60 */
[1023]61 public static ResourceBundle globalBundle;
[593]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
[637]71 URL icon = AEInstaller2.class.getResource(imagesBundle
72 .getString("img.ae"));
[593]73 try {
74 BufferedImage img = ImageIO.read(icon);
75 app.setApplicationIconImage(img);
76 } catch (IOException e) {
77 e.printStackTrace();
78 }
79 }
[730]80
[653]81 private static void initBundles() {
[730]82 File localesDir = CaseInsensitiveFile.getCaseInsensitiveFile(
83 Paths.getInstallerPath(), "locales");
[653]84 if (localesDir.isDirectory())
85 addClassPath(localesDir);
[735]86 else {
87 File localesSubDir = CaseInsensitiveFile.getCaseInsensitiveFile(
88 CaseInsensitiveFile.getCaseInsensitiveFile(
89 Paths.getInstallerPath(), "bin"), "locales");
90 if (localesSubDir.isDirectory()) {
91 addClassPath(localesSubDir);
92 }
93 }
[840]94 globalBundle = UTF8ResourceBundleLoader
[653]95 .getBundle("net.oni2.aeinstaller.localization.Global");
96 }
[593]97
[651]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
[591]117 /**
118 * @param args
119 * Command line arguments
120 */
121 public static void main(String[] args) {
[988]122 if (PlatformInformation.getPlatform() == Platform.MACOS)
123 initMacOS();
124
[596]125 Paths.getPrefsPath().mkdirs();
126 Paths.getDownloadPath().mkdirs();
[591]127
[649]128 for (String a : args) {
[591]129 if (a.equalsIgnoreCase("-debug"))
[852]130 RuntimeOptions.setDebug(true);
[649]131 if (a.equalsIgnoreCase("-nocacheupdate"))
[852]132 RuntimeOptions.setNoCacheUpdateMode(true);
[749]133 if (a.equalsIgnoreCase("-offline"))
[852]134 RuntimeOptions.setOfflineMode(true);
[776]135 if (a.equalsIgnoreCase("-usewd"))
[852]136 RuntimeOptions.setUseWorkingDir(true);
[649]137 }
[886]138 LogPrintStream lps = LogPrintStream.getInstance();
[852]139 if (!RuntimeOptions.isDebug()) {
[591]140 try {
[886]141 lps.setFile(new File(Paths.getPrefsPath(), "aei_output.log"));
[591]142 } catch (FileNotFoundException e1) {
143 e1.printStackTrace();
[886]144 } catch (IOException e) {
145 e.printStackTrace();
[591]146 }
147 }
[730]148
[753]149 SettingsManager.deserializeFromFile(Paths.getSettingsFilename());
[886]150
[852]151 if (Paths.getProxySettingsFilename().exists()) {
152 ProxySettings.deserializeFromFile(Paths.getProxySettingsFilename());
153 }
[886]154
[653]155 initBundles();
[591]156
[592]157 SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
158 SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
[640]159 SwingJavaBuilder.getConfig().addResourceBundle(globalBundle);
[591]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");
[596]166
[591]167 try {
[720]168 String laf = SettingsManager.getInstance().get("lookandfeel",
[591]169 (String) null);
170 if (laf == null) {
[720]171 if (PlatformInformation.getPlatform() != Platform.LINUX) {
[593]172 laf = UIManager.getSystemLookAndFeelClassName();
173 } else {
174 for (LookAndFeelInfo lafInfo : UIManager
175 .getInstalledLookAndFeels()) {
176 if (lafInfo.getName().equals("Nimbus"))
177 laf = lafInfo.getClassName();
178 }
[591]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);
[1025]188
189 ToolTipManager.sharedInstance().setDismissDelay (20000);
[591]190
[886]191 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
[772]192 System.out.println(basicBundle.getString("appname")
[637]193 + basicBundle.getString("appversion"));
[886]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"));
[778]203 System.out.println("JarPath: " + Paths.getJarPath());
[596]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());
[612]208 System.out.println("ValidPath: " + Installer.verifyRunningDirectory());
[1032]209 System.out.println("Platform: " + System.getProperty("os.name") +
210 " detected as " + PlatformInformation.getPlatform().toString());
[730]211 System.out.println("Architect: "
212 + PlatformInformation.getArchitecture());
[672]213 System.out.println(".NET: " + DotNet.isInstalled());
[602]214 System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled());
[596]215 System.out.println("Globalized:" + Installer.isEditionInitialized());
[591]216
[624]217 // TODO: Check available space
[600]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));
[634]225 System.out.println();
[600]226
[672]227 if (!DotNet.isInstalled()) {
[612]228 HTMLLinkLabel hll = new HTMLLinkLabel();
229 String dlUrl = "";
[720]230 switch (PlatformInformation.getPlatform()) {
[612]231 case WIN:
[720]232 switch (PlatformInformation.getArchitecture()) {
[612]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;
[1081]239 default:
240 System.err.println("Running Windows but neither on a X86 nor AMD64 system!");
[612]241 }
242 break;
243 default:
244 dlUrl = "http://www.go-mono.com/mono-downloads/download.html";
245 }
[640]246 hll.setText(globalBundle
[634]247 .getString("dotNetMissing.text")
248 .replaceAll(
249 "%1",
250 String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl)));
[612]251 JOptionPane.showMessageDialog(null, hll,
[640]252 globalBundle.getString("dotNetMissing.title"),
[612]253 JOptionPane.ERROR_MESSAGE);
254 return;
255 }
256
[603]257 if (!Installer.verifyRunningDirectory()) {
[592]258 JOptionPane.showMessageDialog(null,
[640]259 globalBundle.getString("invalidPath.text"),
260 globalBundle.getString("invalidPath.title"),
[592]261 JOptionPane.ERROR_MESSAGE);
[852]262 if (!RuntimeOptions.isDebug()) {
[592]263 return;
264 }
265 }
266
[852]267 if (!RuntimeOptions.isOfflineMode()) {
268 RuntimeOptions.setOfflineMode(!DepotManager.getInstance()
269 .checkConnection());
[649]270 }
[852]271 if (RuntimeOptions.isOfflineMode()) {
[621]272 JOptionPane.showMessageDialog(null,
[646]273 globalBundle.getString("offlineModeStartup.text"),
274 globalBundle.getString("offlineModeStartup.title"),
[621]275 JOptionPane.INFORMATION_MESSAGE);
276 }
277
[852]278 if (!RuntimeOptions.isOfflineMode()) {
[730]279 SVN svn = new SVN();
280 try {
281 int x = svn.checkSVN("http://svn.aei.oni2.net",
[776]282 Paths.getJarPath());
[730]283 if (x > 0) {
[766]284 // Update available or missing files
[730]285 int res = JOptionPane.showConfirmDialog(null,
286 globalBundle.getString("aeiUpdateAvailable.text"),
287 globalBundle.getString("aeiUpdateAvailable.title"),
288 JOptionPane.YES_NO_OPTION,
289 JOptionPane.INFORMATION_MESSAGE);
290 if (res == JOptionPane.YES_OPTION) {
291 File updater = new File(Paths.getInstallerPath(),
292 "AEInstaller2Updater.jar");
293 ApplicationInvoker.execute(EExeType.JAR, null, updater,
[767]294 null, false);
[730]295 return;
296 }
297 } else if (x == 0) {
298 // Up to date
299 } else if (x < 0) {
300 // No WC at given path
301 }
302 } catch (Exception e) {
303 e.printStackTrace();
304 }
305 }
306
[591]307 SwingUtilities.invokeLater(new Runnable() {
308 public void run() {
309 try {
[593]310 MainWin mw = new MainWin();
311 if (app != null) {
312 app.addAboutMenuItem();
313 app.setEnabledAboutMenu(true);
314 app.addPreferencesMenuItem();
315 app.setEnabledPreferencesMenu(true);
316 app.addApplicationListener(mw);
317 }
318 mw.setVisible(true);
[591]319 } catch (Exception e) {
320 e.printStackTrace();
321 }
322 }
323 });
324
325 }
326}
Note: See TracBrowser for help on using the repository browser.