source: java/installer2/src/net/oni2/aeinstaller/backend/oni/OniSplit.java@ 1025

Last change on this file since 1025 was 767, checked in by alloc, 12 years ago

AEI2 0.99y:

  • Perhaps fixes launching Oni on MacOS
File size: 7.0 KB
RevLine 
[596]1package net.oni2.aeinstaller.backend.oni;
2
3import java.io.File;
4import java.io.IOException;
5import java.util.Vector;
6
[699]7import net.oni2.aeinstaller.backend.CaseInsensitiveFile;
[596]8import net.oni2.aeinstaller.backend.Paths;
[720]9import net.oni2.platformtools.PlatformInformation;
10import net.oni2.platformtools.PlatformInformation.Platform;
11import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
12import net.oni2.platformtools.applicationinvoker.ApplicationInvocationResult;
13import net.oni2.platformtools.applicationinvoker.EExeType;
14import net.oni2.platformtools.applicationinvoker.ERuntimeNotInstalledException;
[596]15
16/**
17 * @author Christian Illy
18 */
19public class OniSplit {
20
21 /**
[602]22 * @return Is Onisplit installed?
23 */
24 public static boolean isOniSplitInstalled() {
25 return getProgramFile().exists();
26 }
27
28 /**
[596]29 * Export given dat-file to target folder
30 *
31 * @param targetFolder
32 * Target folder
33 * @param input
34 * Dat file
[600]35 * @return OniSplit output
[596]36 */
[767]37 public static ApplicationInvocationResult export(File targetFolder,
38 File input) {
[698]39 return export(targetFolder, input, null);
40 }
41
42 /**
43 * Export named resources from given dat-file to target folder
44 *
45 * @param targetFolder
46 * Target folder
47 * @param input
48 * Dat file
[702]49 * @param patterns
50 * Filename patterns for files to export
[698]51 * @return OniSplit output
52 */
[767]53 public static ApplicationInvocationResult export(File targetFolder,
54 File input, Vector<String> patterns) {
[596]55 if (!targetFolder.exists())
56 targetFolder.mkdir();
57
[720]58 Vector<String> params = new Vector<String>();
[702]59 if (patterns == null)
[720]60 params.add("-export");
[702]61 else {
62 for (String p : patterns)
[720]63 params.add("-export:" + p);
[702]64 }
[720]65 params.add(targetFolder.getPath());
66 params.add(input.getPath());
67 ApplicationInvocationResult res = null;
[596]68 try {
[767]69 res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null,
70 getProgramFile(), params, false);
[596]71 } catch (IOException e) {
72 e.printStackTrace();
[720]73 } catch (ERuntimeNotInstalledException e) {
74 e.printStackTrace();
[596]75 }
[600]76 return res;
[596]77 }
78
[597]79 /**
80 * Import given folder to a .dat-file
[598]81 *
82 * @param sourceFolders
83 * Folders containing .oni-files
84 * @param targetFile
85 * Target .dat-file
[600]86 * @return OniSplit output
[597]87 */
[767]88 public static ApplicationInvocationResult importLevel(
89 Vector<File> sourceFolders, File targetFile) {
[720]90 Vector<String> params = new Vector<String>();
91 params.add(getImportParam());
[598]92 for (File f : sourceFolders)
[720]93 params.add(f.getPath());
94 params.add(targetFile.getPath());
95 ApplicationInvocationResult res = null;
[597]96 try {
[767]97 res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null,
98 getProgramFile(), params, false);
[597]99 } catch (IOException e) {
100 e.printStackTrace();
[720]101 } catch (ERuntimeNotInstalledException e) {
102 e.printStackTrace();
[597]103 }
[600]104 return res;
105 }
106
107 /**
108 * Pack a level to a .dat-file. More powerful variant which allows
109 * specifying single .oni/.dat files
110 *
111 * @param sourceFoldersFiles
112 * Folders (for recursive .oni import) or files (.dat and single
113 * .oni) to import
114 * @param targetFile
115 * Target .dat-file
116 * @return OniSplit output
117 */
[767]118 public static ApplicationInvocationResult packLevel(
119 Vector<File> sourceFoldersFiles, File targetFile) {
[720]120 Vector<String> params = new Vector<String>();
121 params.add(getPackParam());
122 params.add(getPackTypeParam());
123 params.add("-out");
124 params.add(targetFile.getPath());
[600]125 for (File f : sourceFoldersFiles)
[720]126 params.add(f.getPath());
127 ApplicationInvocationResult res = null;
[600]128 try {
[767]129 res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null,
130 getProgramFile(), params, false);
[600]131 } catch (IOException e) {
132 e.printStackTrace();
[720]133 } catch (ERuntimeNotInstalledException e) {
134 e.printStackTrace();
[597]135 }
[600]136 return res;
[596]137 }
138
[597]139 /**
140 * Move files from one location to another using OniSplit so relations are
141 * handled
142 *
143 * @param targetFolder
144 * Target folder for files
145 * @param input
146 * Files to move, can contain wildcards
147 * @param moveParameter
148 * e.g. overwrite, delete
[600]149 * @return OniSplit output
[597]150 */
[767]151 public static ApplicationInvocationResult move(File targetFolder,
152 String input, String moveParameter) {
[597]153 if (!targetFolder.exists())
154 targetFolder.mkdir();
155
[720]156 Vector<String> params = new Vector<String>();
[767]157 params.add("-move" + (moveParameter != null ? ":" + moveParameter : ""));
[720]158 params.add(targetFolder.getPath());
159 params.add(input);
160 ApplicationInvocationResult res = null;
[597]161 try {
[767]162 res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null,
163 getProgramFile(), params, false);
[597]164 } catch (IOException e) {
165 e.printStackTrace();
[720]166 } catch (ERuntimeNotInstalledException e) {
167 e.printStackTrace();
[597]168 }
[600]169 return res;
[597]170 }
171
[698]172 /**
173 * Convert given .oni-files to XML and put them in target folder
174 *
175 * @param targetFolder
176 * Target folder
177 * @param inputFiles
178 * .oni files
179 * @return OniSplit output
180 */
[767]181 public static ApplicationInvocationResult convertOniToXML(
182 File targetFolder, Vector<File> inputFiles) {
[698]183 if (!targetFolder.exists())
184 targetFolder.mkdirs();
185
[720]186 Vector<String> params = new Vector<String>();
187 params.add("-extract:xml");
188 params.add(targetFolder.getPath());
[698]189 for (File f : inputFiles) {
[720]190 params.add(f.getPath());
[698]191 }
[720]192 ApplicationInvocationResult res = null;
[698]193 try {
[767]194 res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null,
195 getProgramFile(), params, false);
[698]196 } catch (IOException e) {
197 e.printStackTrace();
[720]198 } catch (ERuntimeNotInstalledException e) {
199 e.printStackTrace();
[698]200 }
201 return res;
202 }
203
204 /**
205 * Convert given XML-files to .oni and put them in target folder
206 *
207 * @param targetFolder
208 * Target folder
209 * @param inputFiles
210 * XML-files
211 * @return OniSplit output
212 */
[767]213 public static ApplicationInvocationResult convertXMLtoOni(
214 File targetFolder, Vector<File> inputFiles) {
[698]215 if (!targetFolder.exists())
216 targetFolder.mkdirs();
217
[720]218 Vector<String> params = new Vector<String>();
219 params.add("-create");
220 params.add(targetFolder.getPath());
[698]221 for (File f : inputFiles) {
[720]222 params.add(f.getPath());
[698]223 }
[720]224 ApplicationInvocationResult res = null;
[698]225 try {
[767]226 res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null,
227 getProgramFile(), params, false);
[698]228 } catch (IOException e) {
229 e.printStackTrace();
[720]230 } catch (ERuntimeNotInstalledException e) {
231 e.printStackTrace();
[698]232 }
233 return res;
234 }
235
[596]236 private static String getImportParam() {
[720]237 if (PlatformInformation.getPlatform() == Platform.MACOS)
[596]238 return "-import:sep";
239 else
240 return "-import:nosep";
241 }
242
[600]243 private static String getPackParam() {
244 return "pack";
245 }
246
247 private static String getPackTypeParam() {
[720]248 if (PlatformInformation.getPlatform() == Platform.MACOS)
[600]249 return "-type:macintel";
250 else
251 return "-type:pc";
252 }
253
[602]254 private static File getProgramFile() {
[702]255 File toolsPath = CaseInsensitiveFile.getCaseInsensitiveFile(
256 Paths.getEditionBasePath(), "Tools");
257 return CaseInsensitiveFile.getCaseInsensitiveFile(toolsPath,
258 "Onisplit.exe");
[602]259 }
[596]260}
Note: See TracBrowser for help on using the repository browser.