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

Last change on this file since 757 was 753, checked in by alloc, 12 years ago

AEI2 0.99y:

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