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

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

AEI2 2.27

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