source: AE/installer2/src/net/oni2/aeinstaller/AEInstaller2.java@ 598

Last change on this file since 598 was 598, checked in by alloc, 12 years ago
File size: 5.1 KB
Line 
1package net.oni2.aeinstaller;
2
3import java.awt.image.BufferedImage;
4import java.io.File;
5import java.io.FileNotFoundException;
6import java.io.IOException;
7import java.io.PrintStream;
8import java.net.URL;
9import java.util.ResourceBundle;
10import java.util.TreeSet;
11
12import javax.imageio.ImageIO;
13import javax.swing.JFrame;
14import javax.swing.JOptionPane;
15import javax.swing.JToolBar;
16import javax.swing.SwingUtilities;
17import javax.swing.UIManager;
18import javax.swing.UIManager.LookAndFeelInfo;
19
20import net.oni2.aeinstaller.backend.Paths;
21import net.oni2.aeinstaller.backend.Settings;
22import net.oni2.aeinstaller.backend.Settings.Platform;
23import net.oni2.aeinstaller.backend.StuffToRefactorLater;
24import net.oni2.aeinstaller.backend.depot.DepotManager;
25import net.oni2.aeinstaller.backend.mods.Mod;
26import net.oni2.aeinstaller.backend.oni.Installer;
27import net.oni2.aeinstaller.backend.oni.OniSplit;
28import net.oni2.aeinstaller.gui.MainWin;
29
30import org.javabuilders.swing.SwingJavaBuilder;
31import org.simplericity.macify.eawt.Application;
32import org.simplericity.macify.eawt.DefaultApplication;
33
34/**
35 * @author Christian Illy
36 */
37public class AEInstaller2 {
38
39 private static ResourceBundle imagesBundle = ResourceBundle
40 .getBundle(AEInstaller2.class.getPackage().getName() + ".Images");
41 private static ResourceBundle basicBundle = ResourceBundle
42 .getBundle(AEInstaller2.class.getPackage().getName()
43 + ".AEInstaller");
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("images/AElogo.png");
54 try {
55 BufferedImage img = ImageIO.read(icon);
56 app.setApplicationIconImage(img);
57 } catch (IOException e) {
58 // TODO Auto-generated catch block
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 System.setOut(new PrintStream(new File(Paths.getPrefsPath(),
78 "aei_output.log")));
79 System.setErr(new PrintStream(new File(Paths.getPrefsPath(),
80 "aei_error.log")));
81 } catch (FileNotFoundException e1) {
82 e1.printStackTrace();
83 }
84 }
85
86 if (Settings.getPlatform() == Platform.MACOS)
87 initMacOS();
88
89 Settings.deserializeFromFile();
90 Settings.setDebug(debug);
91 DepotManager.getInstance().loadFromFile(
92 Settings.getDepotCacheFilename());
93
94 SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
95 SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
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.MACOS) {
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 // TODO
126 System.out.println("JarPath: " + Paths.getInstallerPath());
127 System.out.println("PrefsPath: " + Paths.getPrefsPath());
128 System.out.println("DataPath: " + Paths.getModsPath());
129 System.out.println("DownPath: " + Paths.getDownloadPath());
130 System.out.println("TempPath: " + Paths.getTempPath());
131 System.out.println("ValidPath: "
132 + StuffToRefactorLater.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("Globalized:" + Installer.isEditionInitialized());
137
138 if (!StuffToRefactorLater.verifyRunningDirectory()) {
139 JOptionPane.showMessageDialog(null,
140 basicBundle.getString("invalidPath.text"),
141 basicBundle.getString("invalidPath.title"),
142 JOptionPane.ERROR_MESSAGE);
143 if (!Settings.getDebug()) {
144 return;
145 }
146 } else {
147// Installer.initializeEdition();
148 Installer.install(new TreeSet<Mod>());
149 }
150
151 SwingUtilities.invokeLater(new Runnable() {
152
153 public void run() {
154 try {
155 MainWin mw = new MainWin();
156 if (app != null) {
157 app.addAboutMenuItem();
158 app.setEnabledAboutMenu(true);
159 app.addPreferencesMenuItem();
160 app.setEnabledPreferencesMenu(true);
161 app.addApplicationListener(mw);
162 }
163 mw.setVisible(true);
164 } catch (Exception e) {
165 e.printStackTrace();
166 }
167 }
168 });
169
170 }
171}
Note: See TracBrowser for help on using the repository browser.