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

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

Fixes #78 (hopefully, untested)

File size: 2.6 KB
RevLine 
[720]1package net.oni2.aeinstaller.backend.oni;
2
3import java.io.File;
4import java.io.FileNotFoundException;
[1012]5import java.io.IOException;
[720]6import java.util.Vector;
7
[1012]8import org.apache.commons.io.FileUtils;
9
10import net.oni2.aeinstaller.backend.CaseInsensitiveFile;
[720]11import net.oni2.aeinstaller.backend.Paths;
12import net.oni2.platformtools.PlatformInformation;
[1012]13import net.oni2.platformtools.PlatformInformation.Platform;
[720]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
[767]23 private static File getOniExe() throws FileNotFoundException {
[720]24 File exe = null;
25 switch (PlatformInformation.getPlatform()) {
26 case WIN:
[767]27 case LINUX:
[720]28 exe = new File(Paths.getEditionBasePath(), "Oni.exe");
[772]29 break;
[720]30 case MACOS:
[785]31 exe = new File(Paths.getEditionBasePath(),
32 "Oni.app/Contents/MacOS/Oni");
[772]33 break;
[720]34 default:
35 }
[772]36 if (exe.exists())
37 return exe;
38 else
[785]39 throw new FileNotFoundException("Oni's executable was not found");
[720]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 }
[1012]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 }
[766]71
[720]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();
[1012]83 Vector<String> params = getLaunchArgs();
[720]84 params.add("-debugfiles");
85 if (windowed)
86 params.add("-noswitch");
[1012]87 else
88 params.remove("-noswitch");
[766]89 ApplicationInvoker.execute(getOniExeType(), Paths.getEditionBasePath(),
[767]90 exe, params, true);
[720]91 }
92
93}
Note: See TracBrowser for help on using the repository browser.