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