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.aeinstaller.backend.CaseInsensitiveFile;
|
---|
24 | import net.oni2.aeinstaller.backend.DotNet;
|
---|
25 | import net.oni2.aeinstaller.backend.Paths;
|
---|
26 | import net.oni2.aeinstaller.backend.Settings;
|
---|
27 | import net.oni2.aeinstaller.backend.Settings.Platform;
|
---|
28 | import net.oni2.aeinstaller.backend.SizeFormatter;
|
---|
29 | import net.oni2.aeinstaller.backend.depot.DepotManager;
|
---|
30 | import net.oni2.aeinstaller.backend.oni.Installer;
|
---|
31 | import net.oni2.aeinstaller.backend.oni.OniSplit;
|
---|
32 | import net.oni2.aeinstaller.gui.HTMLLinkLabel;
|
---|
33 | import net.oni2.aeinstaller.gui.MainWin;
|
---|
34 |
|
---|
35 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
36 | import org.simplericity.macify.eawt.Application;
|
---|
37 | import org.simplericity.macify.eawt.DefaultApplication;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * @author Christian Illy
|
---|
41 | */
|
---|
42 | public class AEInstaller2 {
|
---|
43 |
|
---|
44 | private static ResourceBundle imagesBundle;
|
---|
45 | private static ResourceBundle basicBundle;
|
---|
46 | private static ResourceBundle globalBundle;
|
---|
47 |
|
---|
48 | private static Application app = null;
|
---|
49 |
|
---|
50 | private static void initMacOS() {
|
---|
51 | System.setProperty("apple.laf.useScreenMenuBar", "true");
|
---|
52 | System.setProperty("com.apple.mrj.application.apple.menu.about.name",
|
---|
53 | basicBundle.getString("appname"));
|
---|
54 | app = new DefaultApplication();
|
---|
55 |
|
---|
56 | URL icon = AEInstaller2.class.getResource(imagesBundle
|
---|
57 | .getString("img.ae"));
|
---|
58 | try {
|
---|
59 | BufferedImage img = ImageIO.read(icon);
|
---|
60 | app.setApplicationIconImage(img);
|
---|
61 | } catch (IOException e) {
|
---|
62 | e.printStackTrace();
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | private static void initBundles() {
|
---|
67 | File localesDir = CaseInsensitiveFile.getCaseInsensitiveFile(Paths.getInstallerPath(), "locales");
|
---|
68 | if (localesDir.isDirectory())
|
---|
69 | addClassPath(localesDir);
|
---|
70 | imagesBundle = ResourceBundle.getBundle("net.oni2.aeinstaller.Images");
|
---|
71 | basicBundle = ResourceBundle
|
---|
72 | .getBundle("net.oni2.aeinstaller.AEInstaller");
|
---|
73 | globalBundle = ResourceBundle
|
---|
74 | .getBundle("net.oni2.aeinstaller.localization.Global");
|
---|
75 | }
|
---|
76 |
|
---|
77 | private static void addClassPath(File dir) {
|
---|
78 | try {
|
---|
79 | URL u = dir.toURI().toURL();
|
---|
80 | URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader
|
---|
81 | .getSystemClassLoader();
|
---|
82 | Class<URLClassLoader> urlClass = URLClassLoader.class;
|
---|
83 | Method method = urlClass.getDeclaredMethod("addURL",
|
---|
84 | new Class[] { URL.class });
|
---|
85 | method.setAccessible(true);
|
---|
86 | method.invoke(urlClassLoader, new Object[] { u });
|
---|
87 | } catch (MalformedURLException e) {
|
---|
88 | } catch (SecurityException e) {
|
---|
89 | } catch (NoSuchMethodException e) {
|
---|
90 | } catch (IllegalArgumentException e) {
|
---|
91 | } catch (IllegalAccessException e) {
|
---|
92 | } catch (InvocationTargetException e) {
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * @param args
|
---|
98 | * Command line arguments
|
---|
99 | */
|
---|
100 | public static void main(String[] args) {
|
---|
101 | Paths.getPrefsPath().mkdirs();
|
---|
102 | Paths.getDownloadPath().mkdirs();
|
---|
103 |
|
---|
104 | boolean debug = false;
|
---|
105 | boolean noCacheUpdate = false;
|
---|
106 | for (String a : args) {
|
---|
107 | if (a.equalsIgnoreCase("-debug"))
|
---|
108 | debug = true;
|
---|
109 | if (a.equalsIgnoreCase("-nocacheupdate"))
|
---|
110 | noCacheUpdate = true;
|
---|
111 | }
|
---|
112 | if (!debug) {
|
---|
113 | try {
|
---|
114 | PrintStream ps = new PrintStream(new File(Paths.getPrefsPath(),
|
---|
115 | "aei_output.log"));
|
---|
116 | System.setOut(ps);
|
---|
117 | System.setErr(ps);
|
---|
118 | } catch (FileNotFoundException e1) {
|
---|
119 | e1.printStackTrace();
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | initBundles();
|
---|
124 |
|
---|
125 | if (Settings.getPlatform() == Platform.MACOS)
|
---|
126 | initMacOS();
|
---|
127 |
|
---|
128 | Settings.setDebug(debug);
|
---|
129 | Settings.deserializeFromFile();
|
---|
130 | Settings.setDebug(debug);
|
---|
131 | Settings.getInstance().setNoCacheUpdateMode(noCacheUpdate);
|
---|
132 |
|
---|
133 | SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
|
---|
134 | SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
|
---|
135 | SwingJavaBuilder.getConfig().addResourceBundle(globalBundle);
|
---|
136 | SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true);
|
---|
137 | SwingJavaBuilder.getConfig().addType("JToolBarSeparator",
|
---|
138 | JToolBar.Separator.class);
|
---|
139 |
|
---|
140 | System.setProperty("networkaddress.cache.ttl", "5");
|
---|
141 | System.setProperty("networkaddress.cache.negative.ttl", "1");
|
---|
142 |
|
---|
143 | try {
|
---|
144 | String laf = Settings.getInstance().get("lookandfeel",
|
---|
145 | (String) null);
|
---|
146 | if (laf == null) {
|
---|
147 | if (Settings.getPlatform() != Platform.LINUX) {
|
---|
148 | laf = UIManager.getSystemLookAndFeelClassName();
|
---|
149 | } else {
|
---|
150 | for (LookAndFeelInfo lafInfo : UIManager
|
---|
151 | .getInstalledLookAndFeels()) {
|
---|
152 | if (lafInfo.getName().equals("Nimbus"))
|
---|
153 | laf = lafInfo.getClassName();
|
---|
154 | }
|
---|
155 | }
|
---|
156 | }
|
---|
157 | if (laf == null)
|
---|
158 | laf = UIManager.getSystemLookAndFeelClassName();
|
---|
159 | UIManager.setLookAndFeel(laf);
|
---|
160 | } catch (Exception e) {
|
---|
161 | e.printStackTrace();
|
---|
162 | }
|
---|
163 | JFrame.setDefaultLookAndFeelDecorated(true);
|
---|
164 |
|
---|
165 | System.out.println(basicBundle.getString("appname") + " "
|
---|
166 | + basicBundle.getString("appversion"));
|
---|
167 | System.out.println("JarPath: " + Paths.getInstallerPath());
|
---|
168 | System.out.println("PrefsPath: " + Paths.getPrefsPath());
|
---|
169 | System.out.println("DataPath: " + Paths.getModsPath());
|
---|
170 | System.out.println("DownPath: " + Paths.getDownloadPath());
|
---|
171 | System.out.println("TempPath: " + Paths.getTempPath());
|
---|
172 | System.out.println("ValidPath: " + Installer.verifyRunningDirectory());
|
---|
173 | System.out.println("Platform: " + Settings.getPlatform());
|
---|
174 | System.out.println("Architect: " + Settings.getArchitecture());
|
---|
175 | System.out.println(".NET: " + DotNet.isInstalled());
|
---|
176 | System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled());
|
---|
177 | System.out.println("Globalized:" + Installer.isEditionInitialized());
|
---|
178 |
|
---|
179 | // TODO: Check available space
|
---|
180 | System.out
|
---|
181 | .println("Free space on temp: "
|
---|
182 | + SizeFormatter.format(Paths.getTempPath()
|
---|
183 | .getUsableSpace(), 3));
|
---|
184 | System.out.println("Free space on Jar: "
|
---|
185 | + SizeFormatter.format(Paths.getInstallerPath()
|
---|
186 | .getUsableSpace(), 3));
|
---|
187 | System.out.println();
|
---|
188 |
|
---|
189 | if (!DotNet.isInstalled()) {
|
---|
190 | HTMLLinkLabel hll = new HTMLLinkLabel();
|
---|
191 | String dlUrl = "";
|
---|
192 | switch (Settings.getPlatform()) {
|
---|
193 | case WIN:
|
---|
194 | switch (Settings.getArchitecture()) {
|
---|
195 | case X86:
|
---|
196 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe";
|
---|
197 | break;
|
---|
198 | case AMD64:
|
---|
199 | dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x64.exe";
|
---|
200 | break;
|
---|
201 | }
|
---|
202 | break;
|
---|
203 | default:
|
---|
204 | dlUrl = "http://www.go-mono.com/mono-downloads/download.html";
|
---|
205 | }
|
---|
206 | hll.setText(globalBundle
|
---|
207 | .getString("dotNetMissing.text")
|
---|
208 | .replaceAll(
|
---|
209 | "%1",
|
---|
210 | String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl)));
|
---|
211 | JOptionPane.showMessageDialog(null, hll,
|
---|
212 | globalBundle.getString("dotNetMissing.title"),
|
---|
213 | JOptionPane.ERROR_MESSAGE);
|
---|
214 | return;
|
---|
215 | }
|
---|
216 |
|
---|
217 | if (!Installer.verifyRunningDirectory()) {
|
---|
218 | JOptionPane.showMessageDialog(null,
|
---|
219 | globalBundle.getString("invalidPath.text"),
|
---|
220 | globalBundle.getString("invalidPath.title"),
|
---|
221 | JOptionPane.ERROR_MESSAGE);
|
---|
222 | if (!Settings.isDebug()) {
|
---|
223 | return;
|
---|
224 | }
|
---|
225 | }
|
---|
226 |
|
---|
227 | boolean offline = false;
|
---|
228 | for (String a : args)
|
---|
229 | if (a.equalsIgnoreCase("-offline"))
|
---|
230 | offline = true;
|
---|
231 | if (!offline) {
|
---|
232 | offline = !DepotManager.getInstance().checkConnection();
|
---|
233 | }
|
---|
234 | if (offline) {
|
---|
235 | JOptionPane.showMessageDialog(null,
|
---|
236 | globalBundle.getString("offlineModeStartup.text"),
|
---|
237 | globalBundle.getString("offlineModeStartup.title"),
|
---|
238 | JOptionPane.INFORMATION_MESSAGE);
|
---|
239 | }
|
---|
240 | Settings.getInstance().setOfflineMode(offline);
|
---|
241 |
|
---|
242 | SwingUtilities.invokeLater(new Runnable() {
|
---|
243 | public void run() {
|
---|
244 | try {
|
---|
245 | MainWin mw = new MainWin();
|
---|
246 | if (app != null) {
|
---|
247 | app.addAboutMenuItem();
|
---|
248 | app.setEnabledAboutMenu(true);
|
---|
249 | app.addPreferencesMenuItem();
|
---|
250 | app.setEnabledPreferencesMenu(true);
|
---|
251 | app.addApplicationListener(mw);
|
---|
252 | }
|
---|
253 | mw.setVisible(true);
|
---|
254 | } catch (Exception e) {
|
---|
255 | e.printStackTrace();
|
---|
256 | }
|
---|
257 | }
|
---|
258 | });
|
---|
259 |
|
---|
260 | }
|
---|
261 | }
|
---|