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