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

Last change on this file since 607 was 603, checked in by alloc, 12 years ago

AEI2

File size: 5.2 KB
RevLine 
[591]1package net.oni2.aeinstaller;
2
[593]3import java.awt.image.BufferedImage;
[591]4import java.io.File;
5import java.io.FileNotFoundException;
[593]6import java.io.IOException;
[591]7import java.io.PrintStream;
[593]8import java.net.URL;
[592]9import java.util.ResourceBundle;
[591]10
[593]11import javax.imageio.ImageIO;
[591]12import javax.swing.JFrame;
[592]13import javax.swing.JOptionPane;
[591]14import javax.swing.JToolBar;
15import javax.swing.SwingUtilities;
16import javax.swing.UIManager;
17import javax.swing.UIManager.LookAndFeelInfo;
18
[596]19import net.oni2.aeinstaller.backend.Paths;
[591]20import net.oni2.aeinstaller.backend.Settings;
[600]21import net.oni2.aeinstaller.backend.Settings.Platform;
[599]22import net.oni2.aeinstaller.backend.SizeFormatter;
[591]23import net.oni2.aeinstaller.backend.depot.DepotManager;
[596]24import net.oni2.aeinstaller.backend.oni.Installer;
25import net.oni2.aeinstaller.backend.oni.OniSplit;
[591]26import net.oni2.aeinstaller.gui.MainWin;
27
28import org.javabuilders.swing.SwingJavaBuilder;
[593]29import org.simplericity.macify.eawt.Application;
30import org.simplericity.macify.eawt.DefaultApplication;
[591]31
32/**
33 * @author Christian Illy
34 */
35public class AEInstaller2 {
36
[593]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 e.printStackTrace();
57 }
58 }
59
[591]60 /**
61 * @param args
62 * Command line arguments
63 */
64 public static void main(String[] args) {
[596]65 Paths.getPrefsPath().mkdirs();
66 Paths.getDownloadPath().mkdirs();
[591]67
68 boolean debug = false;
69 for (String a : args)
70 if (a.equalsIgnoreCase("-debug"))
71 debug = true;
72 if (!debug) {
73 try {
[596]74 System.setOut(new PrintStream(new File(Paths.getPrefsPath(),
75 "aei_output.log")));
76 System.setErr(new PrintStream(new File(Paths.getPrefsPath(),
77 "aei_error.log")));
[591]78 } catch (FileNotFoundException e1) {
79 e1.printStackTrace();
80 }
81 }
82
[593]83 if (Settings.getPlatform() == Platform.MACOS)
84 initMacOS();
85
[591]86 Settings.deserializeFromFile();
87 Settings.setDebug(debug);
88 DepotManager.getInstance().loadFromFile(
[596]89 Settings.getDepotCacheFilename());
[591]90
[592]91 SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle);
92 SwingJavaBuilder.getConfig().addResourceBundle(basicBundle);
[591]93 SwingJavaBuilder.getConfig().setMarkInvalidResourceBundleKeys(true);
94 SwingJavaBuilder.getConfig().addType("JToolBarSeparator",
95 JToolBar.Separator.class);
96
97 System.setProperty("networkaddress.cache.ttl", "5");
98 System.setProperty("networkaddress.cache.negative.ttl", "1");
[596]99
[591]100 try {
101 String laf = Settings.getInstance().get("lookandfeel",
102 (String) null);
103 if (laf == null) {
[593]104 if (Settings.getPlatform() == Platform.MACOS) {
105 laf = UIManager.getSystemLookAndFeelClassName();
106 } else {
107 for (LookAndFeelInfo lafInfo : UIManager
108 .getInstalledLookAndFeels()) {
109 if (lafInfo.getName().equals("Nimbus"))
110 laf = lafInfo.getClassName();
111 }
[591]112 }
113 }
114 if (laf == null)
115 laf = UIManager.getSystemLookAndFeelClassName();
116 UIManager.setLookAndFeel(laf);
117 } catch (Exception e) {
118 e.printStackTrace();
119 }
120 JFrame.setDefaultLookAndFeelDecorated(true);
121
122 // TODO
[596]123 System.out.println("JarPath: " + Paths.getInstallerPath());
124 System.out.println("PrefsPath: " + Paths.getPrefsPath());
125 System.out.println("DataPath: " + Paths.getModsPath());
126 System.out.println("DownPath: " + Paths.getDownloadPath());
127 System.out.println("TempPath: " + Paths.getTempPath());
[591]128 System.out.println("ValidPath: "
[603]129 + Installer.verifyRunningDirectory());
[594]130 System.out.println("Platform: " + Settings.getPlatform());
131 System.out.println("Architect: " + Settings.getArchitecture());
132 System.out.println(".NET: " + OniSplit.isDotNETInstalled());
[602]133 System.out.println("OniSplit: " + OniSplit.isOniSplitInstalled());
[596]134 System.out.println("Globalized:" + Installer.isEditionInitialized());
[591]135
[600]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
[603]144 if (!Installer.verifyRunningDirectory()) {
[592]145 JOptionPane.showMessageDialog(null,
146 basicBundle.getString("invalidPath.text"),
147 basicBundle.getString("invalidPath.title"),
148 JOptionPane.ERROR_MESSAGE);
149 if (!Settings.getDebug()) {
150 return;
151 }
152 }
153
[591]154 SwingUtilities.invokeLater(new Runnable() {
155 public void run() {
156 try {
[593]157 MainWin mw = new MainWin();
158 if (app != null) {
159 app.addAboutMenuItem();
160 app.setEnabledAboutMenu(true);
161 app.addPreferencesMenuItem();
162 app.setEnabledPreferencesMenu(true);
163 app.addApplicationListener(mw);
164 }
165 mw.setVisible(true);
[591]166 } catch (Exception e) {
167 e.printStackTrace();
168 }
169 }
170 });
171
172 }
173}
Note: See TracBrowser for help on using the repository browser.