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

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

AEI: Fixed a Javadoc compiler warning

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