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

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

AEI2 0.99w:

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