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

Last change on this file since 597 was 596, checked in by alloc, 12 years ago

AEI: OniSplit / globalization

File size: 5.0 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;
10
11import javax.imageio.ImageIO;
12import javax.swing.JFrame;
13import javax.swing.JOptionPane;
14import javax.swing.JToolBar;
15import javax.swing.SwingUtilities;
16import javax.swing.UIManager;
17import javax.swing.UIManager.LookAndFeelInfo;
18
19import net.oni2.aeinstaller.backend.Paths;
20import net.oni2.aeinstaller.backend.Settings;
21import net.oni2.aeinstaller.backend.Settings.Platform;
22import net.oni2.aeinstaller.backend.StuffToRefactorLater;
23import net.oni2.aeinstaller.backend.depot.DepotManager;
24import net.oni2.aeinstaller.backend.oni.Installer;
25import net.oni2.aeinstaller.backend.oni.OniSplit;
26import net.oni2.aeinstaller.gui.MainWin;
27
28import org.javabuilders.swing.SwingJavaBuilder;
29import org.simplericity.macify.eawt.Application;
30import org.simplericity.macify.eawt.DefaultApplication;
31
32/**
33 * @author Christian Illy
34 */
35public class AEInstaller2 {
36
37 private static ResourceBundle imagesBundle = ResourceBundle
38 .getBundle(AEInstaller2.class.getPackage().getName() + ".Images");
39 private static ResourceBundle basicBundle = ResourceBundle
40 .getBundle(AEInstaller2.class.getPackage().getName()
41 + ".AEInstaller");
42
43 private static Application app = null;
44
45 private static void initMacOS() {
46 System.setProperty("apple.laf.useScreenMenuBar", "true");
47 System.setProperty("com.apple.mrj.application.apple.menu.about.name",
48 basicBundle.getString("appname"));
49 app = new DefaultApplication();
50
51 URL icon = AEInstaller2.class.getResource("images/AElogo.png");
52 try {
53 BufferedImage img = ImageIO.read(icon);
54 app.setApplicationIconImage(img);
55 } catch (IOException e) {
56 // TODO Auto-generated catch block
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: "
130 + StuffToRefactorLater.verifyRunningDirectory());
131 System.out.println("Platform: " + Settings.getPlatform());
132 System.out.println("Architect: " + Settings.getArchitecture());
133 System.out.println(".NET: " + OniSplit.isDotNETInstalled());
134 System.out.println("Globalized:" + Installer.isEditionInitialized());
135
136 if (!StuffToRefactorLater.verifyRunningDirectory()) {
137 JOptionPane.showMessageDialog(null,
138 basicBundle.getString("invalidPath.text"),
139 basicBundle.getString("invalidPath.title"),
140 JOptionPane.ERROR_MESSAGE);
141 if (!Settings.getDebug()) {
142 return;
143 }
144 } else {
145 Installer.initializeEdition();
146 }
147
148 SwingUtilities.invokeLater(new Runnable() {
149
150 public void run() {
151 try {
152 MainWin mw = new MainWin();
153 if (app != null) {
154 app.addAboutMenuItem();
155 app.setEnabledAboutMenu(true);
156 app.addPreferencesMenuItem();
157 app.setEnabledPreferencesMenu(true);
158 app.addApplicationListener(mw);
159 }
160 mw.setVisible(true);
161 } catch (Exception e) {
162 e.printStackTrace();
163 }
164 }
165 });
166
167 }
168}
Note: See TracBrowser for help on using the repository browser.