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