[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 |
|
---|
[672] | 7 | import net.oni2.aeinstaller.backend.DotNet;
|
---|
[596] | 8 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[624] | 9 | import net.oni2.aeinstaller.backend.AppExecution;
|
---|
[596] | 10 | import net.oni2.aeinstaller.backend.Settings;
|
---|
| 11 | import net.oni2.aeinstaller.backend.Settings.Platform;
|
---|
| 12 |
|
---|
| 13 | /**
|
---|
| 14 | * @author Christian Illy
|
---|
| 15 | */
|
---|
| 16 | public class OniSplit {
|
---|
| 17 |
|
---|
| 18 | /**
|
---|
[602] | 19 | * @return Is Onisplit installed?
|
---|
| 20 | */
|
---|
| 21 | public static boolean isOniSplitInstalled() {
|
---|
| 22 | return getProgramFile().exists();
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | /**
|
---|
[596] | 26 | * Export given dat-file to target folder
|
---|
| 27 | *
|
---|
| 28 | * @param targetFolder
|
---|
| 29 | * Target folder
|
---|
| 30 | * @param input
|
---|
| 31 | * Dat file
|
---|
[600] | 32 | * @return OniSplit output
|
---|
[596] | 33 | */
|
---|
[600] | 34 | public static Vector<String> export(File targetFolder, File input) {
|
---|
[596] | 35 | if (!targetFolder.exists())
|
---|
| 36 | targetFolder.mkdir();
|
---|
| 37 |
|
---|
| 38 | Vector<String> cmdLine = getProgramInvocation();
|
---|
| 39 | cmdLine.add("-export");
|
---|
| 40 | cmdLine.add(targetFolder.getPath());
|
---|
| 41 | cmdLine.add(input.getPath());
|
---|
| 42 | Vector<String> res = null;
|
---|
| 43 | try {
|
---|
[624] | 44 | res = AppExecution.executeAndWait(cmdLine);
|
---|
[596] | 45 | } catch (IOException e) {
|
---|
| 46 | e.printStackTrace();
|
---|
| 47 | }
|
---|
[600] | 48 | return res;
|
---|
[596] | 49 | }
|
---|
| 50 |
|
---|
[597] | 51 | /**
|
---|
| 52 | * Import given folder to a .dat-file
|
---|
[598] | 53 | *
|
---|
| 54 | * @param sourceFolders
|
---|
| 55 | * Folders containing .oni-files
|
---|
| 56 | * @param targetFile
|
---|
| 57 | * Target .dat-file
|
---|
[600] | 58 | * @return OniSplit output
|
---|
[597] | 59 | */
|
---|
[602] | 60 | public static Vector<String> importLevel(Vector<File> sourceFolders,
|
---|
| 61 | File targetFile) {
|
---|
[597] | 62 | Vector<String> cmdLine = getProgramInvocation();
|
---|
| 63 | cmdLine.add(getImportParam());
|
---|
[598] | 64 | for (File f : sourceFolders)
|
---|
| 65 | cmdLine.add(f.getPath());
|
---|
[597] | 66 | cmdLine.add(targetFile.getPath());
|
---|
| 67 | Vector<String> res = null;
|
---|
| 68 | try {
|
---|
[624] | 69 | res = AppExecution.executeAndWait(cmdLine);
|
---|
[597] | 70 | } catch (IOException e) {
|
---|
| 71 | e.printStackTrace();
|
---|
| 72 | }
|
---|
[600] | 73 | return res;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | /**
|
---|
| 77 | * Pack a level to a .dat-file. More powerful variant which allows
|
---|
| 78 | * specifying single .oni/.dat files
|
---|
| 79 | *
|
---|
| 80 | * @param sourceFoldersFiles
|
---|
| 81 | * Folders (for recursive .oni import) or files (.dat and single
|
---|
| 82 | * .oni) to import
|
---|
| 83 | * @param targetFile
|
---|
| 84 | * Target .dat-file
|
---|
| 85 | * @return OniSplit output
|
---|
| 86 | */
|
---|
| 87 | public static Vector<String> packLevel(Vector<File> sourceFoldersFiles,
|
---|
| 88 | File targetFile) {
|
---|
| 89 | Vector<String> cmdLine = getProgramInvocation();
|
---|
| 90 | cmdLine.add(getPackParam());
|
---|
| 91 | cmdLine.add(getPackTypeParam());
|
---|
| 92 | cmdLine.add("-out");
|
---|
| 93 | cmdLine.add(targetFile.getPath());
|
---|
| 94 | for (File f : sourceFoldersFiles)
|
---|
| 95 | cmdLine.add(f.getPath());
|
---|
| 96 | Vector<String> res = null;
|
---|
| 97 | try {
|
---|
[624] | 98 | res = AppExecution.executeAndWait(cmdLine);
|
---|
[600] | 99 | } catch (IOException e) {
|
---|
| 100 | e.printStackTrace();
|
---|
[597] | 101 | }
|
---|
[600] | 102 | return res;
|
---|
[596] | 103 | }
|
---|
| 104 |
|
---|
[597] | 105 | /**
|
---|
| 106 | * Move files from one location to another using OniSplit so relations are
|
---|
| 107 | * handled
|
---|
| 108 | *
|
---|
| 109 | * @param targetFolder
|
---|
| 110 | * Target folder for files
|
---|
| 111 | * @param input
|
---|
| 112 | * Files to move, can contain wildcards
|
---|
| 113 | * @param moveParameter
|
---|
| 114 | * e.g. overwrite, delete
|
---|
[600] | 115 | * @return OniSplit output
|
---|
[597] | 116 | */
|
---|
[600] | 117 | public static Vector<String> move(File targetFolder, String input,
|
---|
[597] | 118 | String moveParameter) {
|
---|
| 119 | if (!targetFolder.exists())
|
---|
| 120 | targetFolder.mkdir();
|
---|
| 121 |
|
---|
| 122 | Vector<String> cmdLine = getProgramInvocation();
|
---|
| 123 | cmdLine.add("-move"
|
---|
| 124 | + (moveParameter != null ? ":" + moveParameter : ""));
|
---|
| 125 | cmdLine.add(targetFolder.getPath());
|
---|
| 126 | cmdLine.add(input);
|
---|
| 127 | Vector<String> res = null;
|
---|
| 128 | try {
|
---|
[624] | 129 | res = AppExecution.executeAndWait(cmdLine);
|
---|
[597] | 130 | } catch (IOException e) {
|
---|
| 131 | e.printStackTrace();
|
---|
| 132 | }
|
---|
[600] | 133 | return res;
|
---|
[597] | 134 | }
|
---|
| 135 |
|
---|
[596] | 136 | private static String getImportParam() {
|
---|
| 137 | if (Settings.getPlatform() == Platform.MACOS)
|
---|
| 138 | return "-import:sep";
|
---|
| 139 | else
|
---|
| 140 | return "-import:nosep";
|
---|
| 141 | }
|
---|
| 142 |
|
---|
[600] | 143 | private static String getPackParam() {
|
---|
| 144 | return "pack";
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | private static String getPackTypeParam() {
|
---|
| 148 | if (Settings.getPlatform() == Platform.MACOS)
|
---|
| 149 | return "-type:macintel";
|
---|
| 150 | else
|
---|
| 151 | return "-type:pc";
|
---|
| 152 | }
|
---|
| 153 |
|
---|
[596] | 154 | private static Vector<String> getProgramInvocation() {
|
---|
| 155 | Vector<String> res = new Vector<String>();
|
---|
[672] | 156 | if (DotNet.getRuntimeExe().length() > 0)
|
---|
| 157 | res.add(DotNet.getRuntimeExe());
|
---|
[602] | 158 | res.add(getProgramFile().getPath());
|
---|
[596] | 159 | return res;
|
---|
| 160 | }
|
---|
[602] | 161 |
|
---|
| 162 | private static File getProgramFile() {
|
---|
| 163 | return new File(new File(Paths.getEditionBasePath(), "Tools"),
|
---|
| 164 | "Onisplit.exe");
|
---|
| 165 | }
|
---|
[596] | 166 | }
|
---|