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

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

AEI2 0.99y:

  • Perhaps fixes launching Oni on MacOS
File size: 7.0 KB
Line 
1package net.oni2.aeinstaller.backend.oni;
2
3import java.io.File;
4import java.io.IOException;
5import java.util.Vector;
6
7import net.oni2.aeinstaller.backend.CaseInsensitiveFile;
8import net.oni2.aeinstaller.backend.Paths;
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;
15
16/**
17 * @author Christian Illy
18 */
19public 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,
38 File input) {
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
49 * @param patterns
50 * Filename patterns for files to export
51 * @return OniSplit output
52 */
53 public static ApplicationInvocationResult export(File targetFolder,
54 File input, Vector<String> patterns) {
55 if (!targetFolder.exists())
56 targetFolder.mkdir();
57
58 Vector<String> params = new Vector<String>();
59 if (patterns == null)
60 params.add("-export");
61 else {
62 for (String p : patterns)
63 params.add("-export:" + p);
64 }
65 params.add(targetFolder.getPath());
66 params.add(input.getPath());
67 ApplicationInvocationResult res = null;
68 try {
69 res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null,
70 getProgramFile(), params, false);
71 } catch (IOException e) {
72 e.printStackTrace();
73 } catch (ERuntimeNotInstalledException e) {
74 e.printStackTrace();
75 }
76 return res;
77 }
78
79 /**
80 * Import given folder to a .dat-file
81 *
82 * @param sourceFolders
83 * Folders containing .oni-files
84 * @param targetFile
85 * Target .dat-file
86 * @return OniSplit output
87 */
88 public static ApplicationInvocationResult importLevel(
89 Vector<File> sourceFolders, File targetFile) {
90 Vector<String> params = new Vector<String>();
91 params.add(getImportParam());
92 for (File f : sourceFolders)
93 params.add(f.getPath());
94 params.add(targetFile.getPath());
95 ApplicationInvocationResult res = null;
96 try {
97 res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null,
98 getProgramFile(), params, false);
99 } catch (IOException e) {
100 e.printStackTrace();
101 } catch (ERuntimeNotInstalledException e) {
102 e.printStackTrace();
103 }
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 */
118 public static ApplicationInvocationResult packLevel(
119 Vector<File> sourceFoldersFiles, File targetFile) {
120 Vector<String> params = new Vector<String>();
121 params.add(getPackParam());
122 params.add(getPackTypeParam());
123 params.add("-out");
124 params.add(targetFile.getPath());
125 for (File f : sourceFoldersFiles)
126 params.add(f.getPath());
127 ApplicationInvocationResult res = null;
128 try {
129 res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null,
130 getProgramFile(), params, false);
131 } catch (IOException e) {
132 e.printStackTrace();
133 } catch (ERuntimeNotInstalledException e) {
134 e.printStackTrace();
135 }
136 return res;
137 }
138
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
149 * @return OniSplit output
150 */
151 public static ApplicationInvocationResult move(File targetFolder,
152 String input, String moveParameter) {
153 if (!targetFolder.exists())
154 targetFolder.mkdir();
155
156 Vector<String> params = new Vector<String>();
157 params.add("-move" + (moveParameter != null ? ":" + moveParameter : ""));
158 params.add(targetFolder.getPath());
159 params.add(input);
160 ApplicationInvocationResult res = null;
161 try {
162 res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null,
163 getProgramFile(), params, false);
164 } catch (IOException e) {
165 e.printStackTrace();
166 } catch (ERuntimeNotInstalledException e) {
167 e.printStackTrace();
168 }
169 return res;
170 }
171
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 */
181 public static ApplicationInvocationResult convertOniToXML(
182 File targetFolder, Vector<File> inputFiles) {
183 if (!targetFolder.exists())
184 targetFolder.mkdirs();
185
186 Vector<String> params = new Vector<String>();
187 params.add("-extract:xml");
188 params.add(targetFolder.getPath());
189 for (File f : inputFiles) {
190 params.add(f.getPath());
191 }
192 ApplicationInvocationResult res = null;
193 try {
194 res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null,
195 getProgramFile(), params, false);
196 } catch (IOException e) {
197 e.printStackTrace();
198 } catch (ERuntimeNotInstalledException e) {
199 e.printStackTrace();
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 */
213 public static ApplicationInvocationResult convertXMLtoOni(
214 File targetFolder, Vector<File> inputFiles) {
215 if (!targetFolder.exists())
216 targetFolder.mkdirs();
217
218 Vector<String> params = new Vector<String>();
219 params.add("-create");
220 params.add(targetFolder.getPath());
221 for (File f : inputFiles) {
222 params.add(f.getPath());
223 }
224 ApplicationInvocationResult res = null;
225 try {
226 res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null,
227 getProgramFile(), params, false);
228 } catch (IOException e) {
229 e.printStackTrace();
230 } catch (ERuntimeNotInstalledException e) {
231 e.printStackTrace();
232 }
233 return res;
234 }
235
236 private static String getImportParam() {
237 if (PlatformInformation.getPlatform() == Platform.MACOS)
238 return "-import:sep";
239 else
240 return "-import:nosep";
241 }
242
243 private static String getPackParam() {
244 return "pack";
245 }
246
247 private static String getPackTypeParam() {
248 if (PlatformInformation.getPlatform() == Platform.MACOS)
249 return "-type:macintel";
250 else
251 return "-type:pc";
252 }
253
254 private static File getProgramFile() {
255 File toolsPath = CaseInsensitiveFile.getCaseInsensitiveFile(
256 Paths.getEditionBasePath(), "Tools");
257 return CaseInsensitiveFile.getCaseInsensitiveFile(toolsPath,
258 "Onisplit.exe");
259 }
260}
Note: See TracBrowser for help on using the repository browser.