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