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