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.OniSplit;
|
---|
20 | import net.oni2.aeinstaller.backend.Settings;
|
---|
21 | import net.oni2.aeinstaller.backend.Settings.Platform;
|
---|
22 | import net.oni2.aeinstaller.backend.StuffToRefactorLater;
|
---|
23 | import net.oni2.aeinstaller.backend.depot.DepotManager;
|
---|
24 | import net.oni2.aeinstaller.gui.MainWin;
|
---|
25 |
|
---|
26 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
27 | import org.simplericity.macify.eawt.Application;
|
---|
28 | import org.simplericity.macify.eawt.DefaultApplication;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * @author Christian Illy
|
---|
32 | */
|
---|
33 | public class AEInstaller2 {
|
---|
34 |
|
---|
35 | private static ResourceBundle imagesBundle = ResourceBundle
|
---|
36 | .getBundle(AEInstaller2.class.getPackage().getName() + ".Images");
|
---|
37 | private static ResourceBundle basicBundle = ResourceBundle
|
---|
38 | .getBundle(AEInstaller2.class.getPackage().getName()
|
---|
39 | + ".AEInstaller");
|
---|
40 |
|
---|
41 | private static Application app = null;
|
---|
42 |
|
---|
43 | private static void initMacOS() {
|
---|
44 | System.setProperty("apple.laf.useScreenMenuBar", "true");
|
---|
45 | System.setProperty("com.apple.mrj.application.apple.menu.about.name",
|
---|
46 | basicBundle.getString("appname"));
|
---|
47 | app = new DefaultApplication();
|
---|
48 |
|
---|
49 | URL icon = AEInstaller2.class.getResource("images/AElogo.png");
|
---|
50 | try {
|
---|
51 | BufferedImage img = ImageIO.read(icon);
|
---|
52 | app.setApplicationIconImage(img);
|
---|
53 | } catch (IOException e) {
|
---|
54 | // TODO Auto-generated catch block
|
---|
55 | e.printStackTrace();
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * @param args
|
---|
61 | * Command line arguments
|
---|
62 | */
|
---|
63 | public static void main(String[] args) {
|
---|
64 | new File(Settings.getPrefsPath()).mkdirs();
|
---|
65 | new File(Settings.getDownloadPath()).mkdirs();
|
---|
66 |
|
---|
67 | boolean debug = false;
|
---|
68 | for (String a : args)
|
---|
69 | if (a.equalsIgnoreCase("-debug"))
|
---|
70 | debug = true;
|
---|
71 | if (!debug) {
|
---|
72 | try {
|
---|
73 | System.setOut(new PrintStream(Settings.getPrefsPath()
|
---|
74 | + "aei_output.log"));
|
---|
75 | System.setErr(new PrintStream(Settings.getPrefsPath()
|
---|
76 | + "aei_error.log"));
|
---|
77 | } catch (FileNotFoundException e1) {
|
---|
78 | e1.printStackTrace();
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | if (Settings.getPlatform() == Platform.MACOS)
|
---|
83 | initMacOS();
|
---|
84 |
|
---|
85 | Settings.deserializeFromFile();
|
---|
86 | Settings.setDebug(debug);
|
---|
87 | DepotManager.getInstance().loadFromFile(
|
---|
88 | new File(Settings.getDepotCacheFilename()));
|
---|
89 |
|
---|
90 | SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
|
---|
91 | SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
|
---|
92 | SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true);
|
---|
93 | SwingJavaBuilder.getConfig().addType("JToolBarSeparator",
|
---|
94 | JToolBar.Separator.class);
|
---|
95 |
|
---|
96 | System.setProperty("networkaddress.cache.ttl", "5");
|
---|
97 | System.setProperty("networkaddress.cache.negative.ttl", "1");
|
---|
98 |
|
---|
99 | try {
|
---|
100 | String laf = Settings.getInstance().get("lookandfeel",
|
---|
101 | (String) null);
|
---|
102 | if (laf == null) {
|
---|
103 | if (Settings.getPlatform() == Platform.MACOS) {
|
---|
104 | laf = UIManager.getSystemLookAndFeelClassName();
|
---|
105 | } else {
|
---|
106 | for (LookAndFeelInfo lafInfo : UIManager
|
---|
107 | .getInstalledLookAndFeels()) {
|
---|
108 | if (lafInfo.getName().equals("Nimbus"))
|
---|
109 | laf = lafInfo.getClassName();
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|
113 | if (laf == null)
|
---|
114 | laf = UIManager.getSystemLookAndFeelClassName();
|
---|
115 | UIManager.setLookAndFeel(laf);
|
---|
116 | } catch (Exception e) {
|
---|
117 | e.printStackTrace();
|
---|
118 | }
|
---|
119 | JFrame.setDefaultLookAndFeelDecorated(true);
|
---|
120 |
|
---|
121 | // TODO
|
---|
122 | System.out.println("JarPath: " + Settings.getJarPath());
|
---|
123 | System.out.println("PrefsPath: " + Settings.getPrefsPath());
|
---|
124 | System.out.println("DataPath: " + Settings.getDataPath());
|
---|
125 | System.out.println("DownPath: " + Settings.getDownloadPath());
|
---|
126 | System.out.println("TempPath: " + Settings.getTempPath());
|
---|
127 | System.out.println("ValidPath: "
|
---|
128 | + StuffToRefactorLater.verifyRunningDirectory());
|
---|
129 | System.out.println("Platform: " + Settings.getPlatform());
|
---|
130 | System.out.println("Architect: " + Settings.getArchitecture());
|
---|
131 | System.out.println(".NET: " + OniSplit.isDotNETInstalled());
|
---|
132 |
|
---|
133 | if (!StuffToRefactorLater.verifyRunningDirectory()) {
|
---|
134 | JOptionPane.showMessageDialog(null,
|
---|
135 | basicBundle.getString("invalidPath.text"),
|
---|
136 | basicBundle.getString("invalidPath.title"),
|
---|
137 | JOptionPane.ERROR_MESSAGE);
|
---|
138 | if (!Settings.getDebug()) {
|
---|
139 | return;
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | SwingUtilities.invokeLater(new Runnable() {
|
---|
144 |
|
---|
145 | public void run() {
|
---|
146 | try {
|
---|
147 | MainWin mw = new MainWin();
|
---|
148 | if (app != null) {
|
---|
149 | app.addAboutMenuItem();
|
---|
150 | app.setEnabledAboutMenu(true);
|
---|
151 | app.addPreferencesMenuItem();
|
---|
152 | app.setEnabledPreferencesMenu(true);
|
---|
153 | app.addApplicationListener(mw);
|
---|
154 | }
|
---|
155 | mw.setVisible(true);
|
---|
156 | } catch (Exception e) {
|
---|
157 | e.printStackTrace();
|
---|
158 | }
|
---|
159 | }
|
---|
160 | });
|
---|
161 |
|
---|
162 | }
|
---|
163 | }
|
---|