[596] | 1 | package net.oni2.aeinstaller.backend.oni;
|
---|
| 2 |
|
---|
| 3 | import java.io.File;
|
---|
| 4 | import java.io.IOException;
|
---|
| 5 | import java.util.Vector;
|
---|
| 6 |
|
---|
[699] | 7 | import net.oni2.aeinstaller.backend.CaseInsensitiveFile;
|
---|
[596] | 8 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[720] | 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;
|
---|
[596] | 15 |
|
---|
| 16 | /**
|
---|
| 17 | * @author Christian Illy
|
---|
| 18 | */
|
---|
| 19 | public 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 | */
|
---|
[720] | 37 | public static ApplicationInvocationResult export(File targetFolder, File input) {
|
---|
[698] | 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
|
---|
[702] | 48 | * @param patterns
|
---|
| 49 | * Filename patterns for files to export
|
---|
[698] | 50 | * @return OniSplit output
|
---|
| 51 | */
|
---|
[720] | 52 | public static ApplicationInvocationResult export(File targetFolder, File input,
|
---|
[702] | 53 | Vector<String> patterns) {
|
---|
[596] | 54 | if (!targetFolder.exists())
|
---|
| 55 | targetFolder.mkdir();
|
---|
| 56 |
|
---|
[720] | 57 | Vector<String> params = new Vector<String>();
|
---|
[702] | 58 | if (patterns == null)
|
---|
[720] | 59 | params.add("-export");
|
---|
[702] | 60 | else {
|
---|
| 61 | for (String p : patterns)
|
---|
[720] | 62 | params.add("-export:" + p);
|
---|
[702] | 63 | }
|
---|
[720] | 64 | params.add(targetFolder.getPath());
|
---|
| 65 | params.add(input.getPath());
|
---|
| 66 | ApplicationInvocationResult res = null;
|
---|
[596] | 67 | try {
|
---|
[720] | 68 | res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null, getProgramFile(), params);
|
---|
[596] | 69 | } catch (IOException e) {
|
---|
| 70 | e.printStackTrace();
|
---|
[720] | 71 | } catch (ERuntimeNotInstalledException e) {
|
---|
| 72 | e.printStackTrace();
|
---|
[596] | 73 | }
|
---|
[600] | 74 | return res;
|
---|
[596] | 75 | }
|
---|
| 76 |
|
---|
[597] | 77 | /**
|
---|
| 78 | * Import given folder to a .dat-file
|
---|
[598] | 79 | *
|
---|
| 80 | * @param sourceFolders
|
---|
| 81 | * Folders containing .oni-files
|
---|
| 82 | * @param targetFile
|
---|
| 83 | * Target .dat-file
|
---|
[600] | 84 | * @return OniSplit output
|
---|
[597] | 85 | */
|
---|
[720] | 86 | public static ApplicationInvocationResult importLevel(Vector<File> sourceFolders,
|
---|
[602] | 87 | File targetFile) {
|
---|
[720] | 88 | Vector<String> params = new Vector<String>();
|
---|
| 89 | params.add(getImportParam());
|
---|
[598] | 90 | for (File f : sourceFolders)
|
---|
[720] | 91 | params.add(f.getPath());
|
---|
| 92 | params.add(targetFile.getPath());
|
---|
| 93 | ApplicationInvocationResult res = null;
|
---|
[597] | 94 | try {
|
---|
[720] | 95 | res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null, getProgramFile(), params);
|
---|
[597] | 96 | } catch (IOException e) {
|
---|
| 97 | e.printStackTrace();
|
---|
[720] | 98 | } catch (ERuntimeNotInstalledException e) {
|
---|
| 99 | e.printStackTrace();
|
---|
[597] | 100 | }
|
---|
[600] | 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 | */
|
---|
[720] | 115 | public static ApplicationInvocationResult packLevel(Vector<File> sourceFoldersFiles,
|
---|
[600] | 116 | File targetFile) {
|
---|
[720] | 117 | Vector<String> params = new Vector<String>();
|
---|
| 118 | params.add(getPackParam());
|
---|
| 119 | params.add(getPackTypeParam());
|
---|
| 120 | params.add("-out");
|
---|
| 121 | params.add(targetFile.getPath());
|
---|
[600] | 122 | for (File f : sourceFoldersFiles)
|
---|
[720] | 123 | params.add(f.getPath());
|
---|
| 124 | ApplicationInvocationResult res = null;
|
---|
[600] | 125 | try {
|
---|
[720] | 126 | res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null, getProgramFile(), params);
|
---|
[600] | 127 | } catch (IOException e) {
|
---|
| 128 | e.printStackTrace();
|
---|
[720] | 129 | } catch (ERuntimeNotInstalledException e) {
|
---|
| 130 | e.printStackTrace();
|
---|
[597] | 131 | }
|
---|
[600] | 132 | return res;
|
---|
[596] | 133 | }
|
---|
| 134 |
|
---|
[597] | 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
|
---|
[600] | 145 | * @return OniSplit output
|
---|
[597] | 146 | */
|
---|
[720] | 147 | public static ApplicationInvocationResult move(File targetFolder, String input,
|
---|
[597] | 148 | String moveParameter) {
|
---|
| 149 | if (!targetFolder.exists())
|
---|
| 150 | targetFolder.mkdir();
|
---|
| 151 |
|
---|
[720] | 152 | Vector<String> params = new Vector<String>();
|
---|
| 153 | params.add("-move"
|
---|
[597] | 154 | + (moveParameter != null ? ":" + moveParameter : ""));
|
---|
[720] | 155 | params.add(targetFolder.getPath());
|
---|
| 156 | params.add(input);
|
---|
| 157 | ApplicationInvocationResult res = null;
|
---|
[597] | 158 | try {
|
---|
[720] | 159 | res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null, getProgramFile(), params);
|
---|
[597] | 160 | } catch (IOException e) {
|
---|
| 161 | e.printStackTrace();
|
---|
[720] | 162 | } catch (ERuntimeNotInstalledException e) {
|
---|
| 163 | e.printStackTrace();
|
---|
[597] | 164 | }
|
---|
[600] | 165 | return res;
|
---|
[597] | 166 | }
|
---|
| 167 |
|
---|
[698] | 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 | */
|
---|
[720] | 177 | public static ApplicationInvocationResult convertOniToXML(File targetFolder,
|
---|
[698] | 178 | Vector<File> inputFiles) {
|
---|
| 179 | if (!targetFolder.exists())
|
---|
| 180 | targetFolder.mkdirs();
|
---|
| 181 |
|
---|
[720] | 182 | Vector<String> params = new Vector<String>();
|
---|
| 183 | params.add("-extract:xml");
|
---|
| 184 | params.add(targetFolder.getPath());
|
---|
[698] | 185 | for (File f : inputFiles) {
|
---|
[720] | 186 | params.add(f.getPath());
|
---|
[698] | 187 | }
|
---|
[720] | 188 | ApplicationInvocationResult res = null;
|
---|
[698] | 189 | try {
|
---|
[720] | 190 | res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null, getProgramFile(), params);
|
---|
[698] | 191 | } catch (IOException e) {
|
---|
| 192 | e.printStackTrace();
|
---|
[720] | 193 | } catch (ERuntimeNotInstalledException e) {
|
---|
| 194 | e.printStackTrace();
|
---|
[698] | 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 | */
|
---|
[720] | 208 | public static ApplicationInvocationResult convertXMLtoOni(File targetFolder,
|
---|
[698] | 209 | Vector<File> inputFiles) {
|
---|
| 210 | if (!targetFolder.exists())
|
---|
| 211 | targetFolder.mkdirs();
|
---|
| 212 |
|
---|
[720] | 213 | Vector<String> params = new Vector<String>();
|
---|
| 214 | params.add("-create");
|
---|
| 215 | params.add(targetFolder.getPath());
|
---|
[698] | 216 | for (File f : inputFiles) {
|
---|
[720] | 217 | params.add(f.getPath());
|
---|
[698] | 218 | }
|
---|
[720] | 219 | ApplicationInvocationResult res = null;
|
---|
[698] | 220 | try {
|
---|
[720] | 221 | res = ApplicationInvoker.executeAndWait(EExeType.DOTNET, null, getProgramFile(), params);
|
---|
[698] | 222 | } catch (IOException e) {
|
---|
| 223 | e.printStackTrace();
|
---|
[720] | 224 | } catch (ERuntimeNotInstalledException e) {
|
---|
| 225 | e.printStackTrace();
|
---|
[698] | 226 | }
|
---|
| 227 | return res;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
[596] | 230 | private static String getImportParam() {
|
---|
[720] | 231 | if (PlatformInformation.getPlatform() == Platform.MACOS)
|
---|
[596] | 232 | return "-import:sep";
|
---|
| 233 | else
|
---|
| 234 | return "-import:nosep";
|
---|
| 235 | }
|
---|
| 236 |
|
---|
[600] | 237 | private static String getPackParam() {
|
---|
| 238 | return "pack";
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | private static String getPackTypeParam() {
|
---|
[720] | 242 | if (PlatformInformation.getPlatform() == Platform.MACOS)
|
---|
[600] | 243 | return "-type:macintel";
|
---|
| 244 | else
|
---|
| 245 | return "-type:pc";
|
---|
| 246 | }
|
---|
| 247 |
|
---|
[602] | 248 | private static File getProgramFile() {
|
---|
[702] | 249 | File toolsPath = CaseInsensitiveFile.getCaseInsensitiveFile(
|
---|
| 250 | Paths.getEditionBasePath(), "Tools");
|
---|
| 251 | return CaseInsensitiveFile.getCaseInsensitiveFile(toolsPath,
|
---|
| 252 | "Onisplit.exe");
|
---|
[602] | 253 | }
|
---|
[596] | 254 | }
|
---|