1 | package net.oni2.aeinstaller;
|
---|
2 |
|
---|
3 | import java.awt.image.BufferedImage;
|
---|
4 | import java.io.File;
|
---|
5 | import java.io.FileNotFoundException;
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.io.PrintStream;
|
---|
8 | import java.lang.reflect.InvocationTargetException;
|
---|
9 | import java.lang.reflect.Method;
|
---|
10 | import java.net.MalformedURLException;
|
---|
11 | import java.net.URL;
|
---|
12 | import java.net.URLClassLoader;
|
---|
13 | import java.util.ResourceBundle;
|
---|
14 |
|
---|
15 | import javax.imageio.ImageIO;
|
---|
16 | import javax.swing.JFrame;
|
---|
17 | import javax.swing.JOptionPane;
|
---|
18 | import javax.swing.JToolBar;
|
---|
19 | import javax.swing.SwingUtilities;
|
---|
20 | import javax.swing.UIManager;
|
---|
21 | import javax.swing.UIManager.LookAndFeelInfo;
|
---|
22 |
|
---|
23 | import net.oni2.SettingsManager;
|
---|
24 | import net.oni2.aeinstaller.backend.CaseInsensitiveFile;
|
---|
25 | import net.oni2.aeinstaller.backend.Paths;
|
---|
26 | import net.oni2.aeinstaller.backend.SizeFormatter;
|
---|
27 | import net.oni2.aeinstaller.backend.depot.DepotManager;
|
---|
28 | import net.oni2.aeinstaller.backend.oni.Installer;
|
---|
29 | import net.oni2.aeinstaller.backend.oni.OniSplit;
|
---|
30 | import net.oni2.aeinstaller.gui.HTMLLinkLabel;
|
---|
31 | import net.oni2.aeinstaller.gui.MainWin;
|
---|
32 | import net.oni2.platformtools.PlatformInformation;
|
---|
33 | import net.oni2.platformtools.PlatformInformation.Platform;
|
---|
34 | import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
|
---|
35 | import net.oni2.platformtools.applicationinvoker.DotNet;
|
---|
36 | import net.oni2.platformtools.applicationinvoker.EExeType;
|
---|
37 | import net.oni2.svnaccess.SVN;
|
---|
38 |
|
---|
39 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
40 | import org.simplericity.macify.eawt.Application;
|
---|
41 | import org.simplericity.macify.eawt.DefaultApplication;
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * @author Christian Illy
|
---|
45 | */
|
---|
46 | public 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 noCacheUpdate = false;
|
---|
119 | for (String a : args) {
|
---|
120 | if (a.equalsIgnoreCase("-debug"))
|
---|
121 | debug = true;
|
---|
122 | if (a.equalsIgnoreCase("-nocacheupdate"))
|
---|
123 | noCacheUpdate = true;
|
---|
124 | }
|
---|
125 | if (!debug) {
|
---|
126 | try {
|
---|
127 | PrintStream ps = new PrintStream(new File(Paths.getPrefsPath(),
|
---|
128 | "aei_output.log"));
|
---|
129 | System.setOut(ps);
|
---|
130 | System.setErr(ps);
|
---|
131 | } catch (FileNotFoundException e1) {
|
---|
132 | e1.printStackTrace();
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | initBundles();
|
---|
137 |
|
---|
138 | if (PlatformInformation.getPlatform() == Platform.MACOS)
|
---|
139 | initMacOS();
|
---|
140 |
|
---|
141 | SettingsManager.setDebug(debug);
|
---|
142 | SettingsManager.deserializeFromFile(Paths.getSettingsFilename());
|
---|
143 | SettingsManager.setDebug(debug);
|
---|
144 | SettingsManager.getInstance().setNoCacheUpdateMode(noCacheUpdate);
|
---|
145 |
|
---|
146 | SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
|
---|
147 | SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
|
---|
148 | SwingJavaBuilder.getConfig().addResourceBundle(globalBundle);
|
---|
149 | SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true);
|
---|
150 | SwingJavaBuilder.getConfig().addType("JToolBarSeparator",
|
---|
151 | JToolBar.Separator.class);
|
---|
152 |
|
---|
153 | System.setProperty("networkaddress.cache.ttl", "5");
|
---|
154 | System.setProperty("networkaddress.cache.negative.ttl", "1");
|
---|
155 |
|
---|
156 | try {
|
---|
157 | String laf = SettingsManager.getInstance().get("lookandfeel",
|
---|
158 | (String) null);
|
---|
159 | if (laf == null) {
|
---|
160 | if (PlatformInformation.getPlatform() != Platform.LINUX) {
|
---|
161 | laf = UIManager.getSystemLookAndFeelClassName();
|
---|
162 | } else {
|
---|
163 | for (LookAndFeelInfo lafInfo : UIManager
|
---|
164 | .getInstalledLookAndFeels()) {
|
---|
165 | if (lafInfo.getName().equals("Nimbus"))
|
---|
166 | laf = lafInfo.getClassName();
|
---|
167 | }
|
---|
168 | }
|
---|
169 | }
|
---|
170 | if (laf == null)
|
---|
171 | laf = UIManager.getSystemLookAndFeelClassName();
|
---|
172 | UIManager.setLookAndFeel(laf);
|
---|
173 | } catch (Exception e) {
|
---|
174 | e.printStackTrace();
|
---|
175 | }
|
---|
176 | JFrame.setDefaultLookAndFeelDecorated(true);
|
---|
177 |
|
---|
178 | System.out.println(basicBundle.getString("appname") + " "
|
---|
179 | + basicBundle.getString("appversion"));
|
---|
180 | System.out.println("JarPath: " + Paths.getInstallerPath());
|
---|
181 | System.out.println("PrefsPath: " + Paths.getPrefsPath());
|
---|
182 | System.out.println("DataPath: " + Paths.getModsPath());
|
---|
183 | System.out.println("DownPath: " + Paths.getDownloadPath());
|
---|
184 | System.out.println("TempPath: " + Paths.getTempPath());
|
---|
185 | System.out.println("ValidPath: " + Installer.verifyRunningDirectory());
|
---|
186 | System.out.println("Platform: " + PlatformInformation.getPlatform());
|
---|
187 | System.out.println("Architect: "
|
---|
188 | + PlatformInformation.getArchitecture());
|
---|
189 | System.out.println(".NET: " + DotNet.isInstalled());
|
---|
190 | System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled());
|
---|
191 | System.out.println("Globalized:" + Installer.isEditionInitialized());
|
---|
192 |
|
---|
193 | // TODO: Check available space
|
---|
194 | System.out
|
---|
195 | .println("Free space on temp: "
|
---|
196 | + SizeFormatter.format(Paths.getTempPath()
|
---|
197 | .getUsableSpace(), 3));
|
---|
198 | System.out.println("Free space on Jar: "
|
---|
199 | + SizeFormatter.format(Paths.getInstallerPath()
|
---|
200 | .getUsableSpace(), 3));
|
---|
201 | System.out.println();
|
---|
202 |
|
---|
203 | if (!DotNet.isInstalled()) {
|
---|
204 | HTMLLinkLabel hll = new HTMLLinkLabel();
|
---|
205 | String dlUrl = "";
|
---|
206 | switch (PlatformInformation.getPlatform()) {
|
---|
207 | case WIN:
|
---|
208 | switch (PlatformInformation.getArchitecture()) {
|
---|
209 | case X86:
|
---|
210 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe";
|
---|
211 | break;
|
---|
212 | case AMD64:
|
---|
213 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x64.exe";
|
---|
214 | break;
|
---|
215 | }
|
---|
216 | break;
|
---|
217 | default:
|
---|
218 | dlUrl = "http://www.go-mono.com/mono-downloads/download.html";
|
---|
219 | }
|
---|
220 | hll.setText(globalBundle
|
---|
221 | .getString("dotNetMissing.text")
|
---|
222 | .replaceAll(
|
---|
223 | "%1",
|
---|
224 | String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl)));
|
---|
225 | JOptionPane.showMessageDialog(null, hll,
|
---|
226 | globalBundle.getString("dotNetMissing.title"),
|
---|
227 | JOptionPane.ERROR_MESSAGE);
|
---|
228 | return;
|
---|
229 | }
|
---|
230 |
|
---|
231 | if (!Installer.verifyRunningDirectory()) {
|
---|
232 | JOptionPane.showMessageDialog(null,
|
---|
233 | globalBundle.getString("invalidPath.text"),
|
---|
234 | globalBundle.getString("invalidPath.title"),
|
---|
235 | JOptionPane.ERROR_MESSAGE);
|
---|
236 | if (!SettingsManager.isDebug()) {
|
---|
237 | return;
|
---|
238 | }
|
---|
239 | }
|
---|
240 |
|
---|
241 | boolean offline = false;
|
---|
242 | for (String a : args)
|
---|
243 | if (a.equalsIgnoreCase("-offline"))
|
---|
244 | offline = true;
|
---|
245 | if (!offline) {
|
---|
246 | offline = !DepotManager.getInstance().checkConnection();
|
---|
247 | }
|
---|
248 | if (offline) {
|
---|
249 | JOptionPane.showMessageDialog(null,
|
---|
250 | globalBundle.getString("offlineModeStartup.text"),
|
---|
251 | globalBundle.getString("offlineModeStartup.title"),
|
---|
252 | JOptionPane.INFORMATION_MESSAGE);
|
---|
253 | }
|
---|
254 | SettingsManager.getInstance().setOfflineMode(offline);
|
---|
255 |
|
---|
256 | if (!offline) {
|
---|
257 | SVN svn = new SVN();
|
---|
258 | try {
|
---|
259 | int x = svn.checkSVN("http://svn.aei.oni2.net",
|
---|
260 | new File(Paths.getPrefsPath(), "bin"));
|
---|
261 | if (x > 0) {
|
---|
262 | // Update available
|
---|
263 | int res = JOptionPane.showConfirmDialog(null,
|
---|
264 | globalBundle.getString("aeiUpdateAvailable.text"),
|
---|
265 | globalBundle.getString("aeiUpdateAvailable.title"),
|
---|
266 | JOptionPane.YES_NO_OPTION,
|
---|
267 | JOptionPane.INFORMATION_MESSAGE);
|
---|
268 | if (res == JOptionPane.YES_OPTION) {
|
---|
269 | File updater = new File(Paths.getInstallerPath(),
|
---|
270 | "AEInstaller2Updater.jar");
|
---|
271 | ApplicationInvoker.execute(EExeType.JAR, null, updater,
|
---|
272 | null);
|
---|
273 | return;
|
---|
274 | }
|
---|
275 | } else if (x == 0) {
|
---|
276 | // Up to date
|
---|
277 | } else if (x < 0) {
|
---|
278 | // No WC at given path
|
---|
279 | }
|
---|
280 | } catch (Exception e) {
|
---|
281 | e.printStackTrace();
|
---|
282 | }
|
---|
283 | }
|
---|
284 |
|
---|
285 | SwingUtilities.invokeLater(new Runnable() {
|
---|
286 | public void run() {
|
---|
287 | try {
|
---|
288 | MainWin mw = new MainWin();
|
---|
289 | if (app != null) {
|
---|
290 | app.addAboutMenuItem();
|
---|
291 | app.setEnabledAboutMenu(true);
|
---|
292 | app.addPreferencesMenuItem();
|
---|
293 | app.setEnabledPreferencesMenu(true);
|
---|
294 | app.addApplicationListener(mw);
|
---|
295 | }
|
---|
296 | mw.setVisible(true);
|
---|
297 | } catch (Exception e) {
|
---|
298 | e.printStackTrace();
|
---|
299 | }
|
---|
300 | }
|
---|
301 | });
|
---|
302 |
|
---|
303 | }
|
---|
304 | }
|
---|