source: java/installer2/src/net/oni2/aeinstaller/backend/oni/OniLauncher.java@ 1012

Last change on this file since 1012 was 1012, checked in by alloc, 10 years ago

Fixes #78 (hopefully, untested)

File size: 2.6 KB
Line 
1package net.oni2.aeinstaller.backend.oni;
2
3import java.io.File;
4import java.io.FileNotFoundException;
5import java.io.IOException;
6import java.util.Vector;
7
8import org.apache.commons.io.FileUtils;
9
10import net.oni2.aeinstaller.backend.CaseInsensitiveFile;
11import net.oni2.aeinstaller.backend.Paths;
12import net.oni2.platformtools.PlatformInformation;
13import net.oni2.platformtools.PlatformInformation.Platform;
14import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
15import net.oni2.platformtools.applicationinvoker.EExeType;
16import net.oni2.platformtools.applicationinvoker.ERuntimeNotInstalledException;
17
18/**
19 * @author Christian Illy
20 */
21public class OniLauncher {
22
23 private static File getOniExe() throws FileNotFoundException {
24 File exe = null;
25 switch (PlatformInformation.getPlatform()) {
26 case WIN:
27 case LINUX:
28 exe = new File(Paths.getEditionBasePath(), "Oni.exe");
29 break;
30 case MACOS:
31 exe = new File(Paths.getEditionBasePath(),
32 "Oni.app/Contents/MacOS/Oni");
33 break;
34 default:
35 }
36 if (exe.exists())
37 return exe;
38 else
39 throw new FileNotFoundException("Oni's executable was not found");
40 }
41
42 private static EExeType getOniExeType() {
43 switch (PlatformInformation.getPlatform()) {
44 case MACOS:
45 return EExeType.OSBINARY;
46 default:
47 return EExeType.WINEXE;
48 }
49 }
50
51 private static Vector<String> getLaunchArgs () {
52 Vector<String> res = new Vector<String>();
53 if (PlatformInformation.getPlatform() == Platform.MACOS) {
54 File launchArgs = CaseInsensitiveFile.getCaseInsensitiveFile(Paths.getEditionBasePath(), "launch_args.txt");
55 if (launchArgs.exists()) {
56 try {
57 String[] argsStrings = FileUtils.readFileToString(launchArgs).split(" ");
58 for (int i = 0; i < argsStrings.length; i++) {
59 argsStrings [i] = argsStrings [i].trim();
60 if (argsStrings [i].length() > 0) {
61 res.add(argsStrings [i]);
62 }
63 }
64 } catch (IOException e) {
65 e.printStackTrace();
66 }
67 }
68 }
69 return res;
70 }
71
72 /**
73 * @param windowed
74 * Run in windowed mode
75 * @throws FileNotFoundException
76 * If Oni's executable was not found
77 * @throws ERuntimeNotInstalledException
78 * If Linux and Wine not found
79 */
80 public static void launch(boolean windowed) throws FileNotFoundException,
81 ERuntimeNotInstalledException {
82 File exe = getOniExe();
83 Vector<String> params = getLaunchArgs();
84 params.add("-debugfiles");
85 if (windowed)
86 params.add("-noswitch");
87 else
88 params.remove("-noswitch");
89 ApplicationInvoker.execute(getOniExeType(), Paths.getEditionBasePath(),
90 exe, params, true);
91 }
92
93}
Note: See TracBrowser for help on using the repository browser.