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

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

AEI2.00:

  • JarPath fix
File size: 9.6 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.oni.OniSplit;
28import net.oni2.aeinstaller.backend.oni.management.Installer;
29import net.oni2.aeinstaller.gui.HTMLLinkLabel;
30import net.oni2.aeinstaller.gui.MainWin;
31import net.oni2.moddepot.DepotManager;
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 else {
76 File localesSubDir = CaseInsensitiveFile.getCaseInsensitiveFile(
77 CaseInsensitiveFile.getCaseInsensitiveFile(
78 Paths.getInstallerPath(), "bin"), "locales");
79 if (localesSubDir.isDirectory()) {
80 addClassPath(localesSubDir);
81 }
82 }
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 }
89
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
109 /**
110 * @param args
111 * Command line arguments
112 */
113 public static void main(String[] args) {
114 Paths.getPrefsPath().mkdirs();
115 Paths.getDownloadPath().mkdirs();
116
117 boolean debug = false;
118 boolean useWd = false;
119 boolean noCacheUpdate = false;
120 boolean offline = false;
121 for (String a : args) {
122 if (a.equalsIgnoreCase("-debug"))
123 debug = true;
124 if (a.equalsIgnoreCase("-nocacheupdate"))
125 noCacheUpdate = true;
126 if (a.equalsIgnoreCase("-offline"))
127 offline = true;
128 if (a.equalsIgnoreCase("-usewd"))
129 useWd = true;
130 }
131 if (!debug) {
132 try {
133 PrintStream ps = new PrintStream(new File(Paths.getPrefsPath(),
134 "aei_output.log"));
135 System.setOut(ps);
136 System.setErr(ps);
137 } catch (FileNotFoundException e1) {
138 e1.printStackTrace();
139 }
140 }
141
142 SettingsManager.setDebug(debug);
143 SettingsManager.deserializeFromFile(Paths.getSettingsFilename());
144 SettingsManager.setDebug(debug);
145 SettingsManager.setUseWorkingDir(useWd);
146 SettingsManager.getInstance().setNoCacheUpdateMode(noCacheUpdate);
147
148 initBundles();
149
150 if (PlatformInformation.getPlatform() == Platform.MACOS)
151 initMacOS();
152
153 SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
154 SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
155 SwingJavaBuilder.getConfig().addResourceBundle(globalBundle);
156 SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true);
157 SwingJavaBuilder.getConfig().addType("JToolBarSeparator",
158 JToolBar.Separator.class);
159
160 System.setProperty("networkaddress.cache.ttl", "5");
161 System.setProperty("networkaddress.cache.negative.ttl", "1");
162
163 try {
164 String laf = SettingsManager.getInstance().get("lookandfeel",
165 (String) null);
166 if (laf == null) {
167 if (PlatformInformation.getPlatform() != Platform.LINUX) {
168 laf = UIManager.getSystemLookAndFeelClassName();
169 } else {
170 for (LookAndFeelInfo lafInfo : UIManager
171 .getInstalledLookAndFeels()) {
172 if (lafInfo.getName().equals("Nimbus"))
173 laf = lafInfo.getClassName();
174 }
175 }
176 }
177 if (laf == null)
178 laf = UIManager.getSystemLookAndFeelClassName();
179 UIManager.setLookAndFeel(laf);
180 } catch (Exception e) {
181 e.printStackTrace();
182 }
183 JFrame.setDefaultLookAndFeelDecorated(true);
184
185 System.out.println(basicBundle.getString("appname")
186 + basicBundle.getString("appversion"));
187 System.out.println("JarPath: " + Paths.getJarPath());
188 System.out.println("PrefsPath: " + Paths.getPrefsPath());
189 System.out.println("DataPath: " + Paths.getModsPath());
190 System.out.println("DownPath: " + Paths.getDownloadPath());
191 System.out.println("TempPath: " + Paths.getTempPath());
192 System.out.println("ValidPath: " + Installer.verifyRunningDirectory());
193 System.out.println("Platform: " + PlatformInformation.getPlatform());
194 System.out.println("Architect: "
195 + PlatformInformation.getArchitecture());
196 System.out.println(".NET: " + DotNet.isInstalled());
197 System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled());
198 System.out.println("Globalized:" + Installer.isEditionInitialized());
199
200 // TODO: Check available space
201 System.out
202 .println("Free space on temp: "
203 + SizeFormatter.format(Paths.getTempPath()
204 .getUsableSpace(), 3));
205 System.out.println("Free space on Jar: "
206 + SizeFormatter.format(Paths.getInstallerPath()
207 .getUsableSpace(), 3));
208 System.out.println();
209
210 if (!DotNet.isInstalled()) {
211 HTMLLinkLabel hll = new HTMLLinkLabel();
212 String dlUrl = "";
213 switch (PlatformInformation.getPlatform()) {
214 case WIN:
215 switch (PlatformInformation.getArchitecture()) {
216 case X86:
217 dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe";
218 break;
219 case AMD64:
220 dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x64.exe";
221 break;
222 }
223 break;
224 default:
225 dlUrl = "http://www.go-mono.com/mono-downloads/download.html";
226 }
227 hll.setText(globalBundle
228 .getString("dotNetMissing.text")
229 .replaceAll(
230 "%1",
231 String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl)));
232 JOptionPane.showMessageDialog(null, hll,
233 globalBundle.getString("dotNetMissing.title"),
234 JOptionPane.ERROR_MESSAGE);
235 return;
236 }
237
238 if (!Installer.verifyRunningDirectory()) {
239 JOptionPane.showMessageDialog(null,
240 globalBundle.getString("invalidPath.text"),
241 globalBundle.getString("invalidPath.title"),
242 JOptionPane.ERROR_MESSAGE);
243 if (!SettingsManager.isDebug()) {
244 return;
245 }
246 }
247
248 if (!offline) {
249 offline = !DepotManager.getInstance().checkConnection();
250 }
251 if (offline) {
252 JOptionPane.showMessageDialog(null,
253 globalBundle.getString("offlineModeStartup.text"),
254 globalBundle.getString("offlineModeStartup.title"),
255 JOptionPane.INFORMATION_MESSAGE);
256 }
257 SettingsManager.getInstance().setOfflineMode(offline);
258
259 if (!offline) {
260 SVN svn = new SVN();
261 try {
262 int x = svn.checkSVN("http://svn.aei.oni2.net",
263 Paths.getJarPath());
264 if (x > 0) {
265 // Update available or missing files
266 int res = JOptionPane.showConfirmDialog(null,
267 globalBundle.getString("aeiUpdateAvailable.text"),
268 globalBundle.getString("aeiUpdateAvailable.title"),
269 JOptionPane.YES_NO_OPTION,
270 JOptionPane.INFORMATION_MESSAGE);
271 if (res == JOptionPane.YES_OPTION) {
272 File updater = new File(Paths.getInstallerPath(),
273 "AEInstaller2Updater.jar");
274 ApplicationInvoker.execute(EExeType.JAR, null, updater,
275 null, false);
276 return;
277 }
278 } else if (x == 0) {
279 // Up to date
280 } else if (x < 0) {
281 // No WC at given path
282 }
283 } catch (Exception e) {
284 e.printStackTrace();
285 }
286 }
287
288 SwingUtilities.invokeLater(new Runnable() {
289 public void run() {
290 try {
291 MainWin mw = new MainWin();
292 if (app != null) {
293 app.addAboutMenuItem();
294 app.setEnabledAboutMenu(true);
295 app.addPreferencesMenuItem();
296 app.setEnabledPreferencesMenu(true);
297 app.addApplicationListener(mw);
298 }
299 mw.setVisible(true);
300 } catch (Exception e) {
301 e.printStackTrace();
302 }
303 }
304 });
305
306 }
307}
Note: See TracBrowser for help on using the repository browser.