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