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 |
boolean noCacheUpdate = false; |
73 |
for (String a : args) { |
74 |
if (a.equalsIgnoreCase("-debug")) |
75 |
debug = true; |
76 |
if (a.equalsIgnoreCase("-nocacheupdate")) |
77 |
noCacheUpdate = true; |
78 |
} |
79 |
if (!debug) { |
80 |
try { |
81 |
PrintStream ps = new PrintStream(new File(Paths.getPrefsPath(), |
82 |
"aei_output.log")); |
83 |
System.setOut(ps); |
84 |
System.setErr(ps); |
85 |
} catch (FileNotFoundException e1) { |
86 |
e1.printStackTrace(); |
87 |
} |
88 |
} |
89 |
|
90 |
if (Settings.getPlatform() == Platform.MACOS) |
91 |
initMacOS(); |
92 |
|
93 |
Settings.setDebug(debug); |
94 |
Settings.deserializeFromFile(); |
95 |
Settings.setDebug(debug); |
96 |
Settings.getInstance().setNoCacheUpdateMode(noCacheUpdate); |
97 |
|
98 |
SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle); |
99 |
SwingJavaBuilder.getConfig().addResourceBundle(basicBundle); |
100 |
SwingJavaBuilder.getConfig().addResourceBundle(globalBundle); |
101 |
SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true); |
102 |
SwingJavaBuilder.getConfig().addType("JToolBarSeparator", |
103 |
JToolBar.Separator.class); |
104 |
|
105 |
System.setProperty("networkaddress.cache.ttl", "5"); |
106 |
System.setProperty("networkaddress.cache.negative.ttl", "1"); |
107 |
|
108 |
try { |
109 |
String laf = Settings.getInstance().get("lookandfeel", |
110 |
(String) null); |
111 |
if (laf == null) { |
112 |
if (Settings.getPlatform() != Platform.LINUX) { |
113 |
laf = UIManager.getSystemLookAndFeelClassName(); |
114 |
} else { |
115 |
for (LookAndFeelInfo lafInfo : UIManager |
116 |
.getInstalledLookAndFeels()) { |
117 |
if (lafInfo.getName().equals("Nimbus")) |
118 |
laf = lafInfo.getClassName(); |
119 |
} |
120 |
} |
121 |
} |
122 |
if (laf == null) |
123 |
laf = UIManager.getSystemLookAndFeelClassName(); |
124 |
UIManager.setLookAndFeel(laf); |
125 |
} catch (Exception e) { |
126 |
e.printStackTrace(); |
127 |
} |
128 |
JFrame.setDefaultLookAndFeelDecorated(true); |
129 |
|
130 |
System.out.println(basicBundle.getString("appname") + " " |
131 |
+ basicBundle.getString("appversion")); |
132 |
System.out.println("JarPath: " + Paths.getInstallerPath()); |
133 |
System.out.println("PrefsPath: " + Paths.getPrefsPath()); |
134 |
System.out.println("DataPath: " + Paths.getModsPath()); |
135 |
System.out.println("DownPath: " + Paths.getDownloadPath()); |
136 |
System.out.println("TempPath: " + Paths.getTempPath()); |
137 |
System.out.println("ValidPath: " + Installer.verifyRunningDirectory()); |
138 |
System.out.println("Platform: " + Settings.getPlatform()); |
139 |
System.out.println("Architect: " + Settings.getArchitecture()); |
140 |
System.out.println(".NET: " + OniSplit.isDotNETInstalled()); |
141 |
System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled()); |
142 |
System.out.println("Globalized:" + Installer.isEditionInitialized()); |
143 |
|
144 |
// TODO: Check available space |
145 |
System.out |
146 |
.println("Free space on temp: " |
147 |
+ SizeFormatter.format(Paths.getTempPath() |
148 |
.getUsableSpace(), 3)); |
149 |
System.out.println("Free space on Jar: " |
150 |
+ SizeFormatter.format(Paths.getInstallerPath() |
151 |
.getUsableSpace(), 3)); |
152 |
System.out.println(); |
153 |
|
154 |
if (!OniSplit.isDotNETInstalled()) { |
155 |
HTMLLinkLabel hll = new HTMLLinkLabel(); |
156 |
String dlUrl = ""; |
157 |
switch (Settings.getPlatform()) { |
158 |
case WIN: |
159 |
switch (Settings.getArchitecture()) { |
160 |
case X86: |
161 |
dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x86.exe"; |
162 |
break; |
163 |
case AMD64: |
164 |
dlUrl = "http://download.microsoft.com/download/c/6/e/c6e88215-0178-4c6c-b5f3-158ff77b1f38/NetFx20SP2_x64.exe"; |
165 |
break; |
166 |
} |
167 |
break; |
168 |
default: |
169 |
dlUrl = "http://www.go-mono.com/mono-downloads/download.html"; |
170 |
} |
171 |
hll.setText(globalBundle |
172 |
.getString("dotNetMissing.text") |
173 |
.replaceAll( |
174 |
"%1", |
175 |
String.format("<a href=\"%s\">%s</a>", dlUrl, dlUrl))); |
176 |
JOptionPane.showMessageDialog(null, hll, |
177 |
globalBundle.getString("dotNetMissing.title"), |
178 |
JOptionPane.ERROR_MESSAGE); |
179 |
return; |
180 |
} |
181 |
|
182 |
if (!Installer.verifyRunningDirectory()) { |
183 |
JOptionPane.showMessageDialog(null, |
184 |
globalBundle.getString("invalidPath.text"), |
185 |
globalBundle.getString("invalidPath.title"), |
186 |
JOptionPane.ERROR_MESSAGE); |
187 |
if (!Settings.isDebug()) { |
188 |
return; |
189 |
} |
190 |
} |
191 |
|
192 |
boolean offline = false; |
193 |
for (String a : args) |
194 |
if (a.equalsIgnoreCase("-offline")) |
195 |
offline = true; |
196 |
if (!offline) { |
197 |
offline = !DepotManager.getInstance().checkConnection(); |
198 |
} |
199 |
if (offline) { |
200 |
JOptionPane.showMessageDialog(null, |
201 |
globalBundle.getString("offlineModeStartup.text"), |
202 |
globalBundle.getString("offlineModeStartup.title"), |
203 |
JOptionPane.INFORMATION_MESSAGE); |
204 |
} |
205 |
Settings.getInstance().setOfflineMode(offline); |
206 |
|
207 |
SwingUtilities.invokeLater(new Runnable() { |
208 |
public void run() { |
209 |
try { |
210 |
MainWin mw = new MainWin(); |
211 |
if (app != null) { |
212 |
app.addAboutMenuItem(); |
213 |
app.setEnabledAboutMenu(true); |
214 |
app.addPreferencesMenuItem(); |
215 |
app.setEnabledPreferencesMenu(true); |
216 |
app.addApplicationListener(mw); |
217 |
} |
218 |
mw.setVisible(true); |
219 |
} catch (Exception e) { |
220 |
e.printStackTrace(); |
221 |
} |
222 |
} |
223 |
}); |
224 |
|
225 |
} |
226 |
} |