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

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

AEI2 0.99u:

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