[596] | 1 | package net.oni2.aeinstaller.backend.oni;
|
---|
| 2 |
|
---|
| 3 | import java.io.File;
|
---|
| 4 | import java.io.IOException;
|
---|
| 5 | import java.lang.reflect.InvocationTargetException;
|
---|
| 6 | import java.util.Map;
|
---|
| 7 | import java.util.Vector;
|
---|
| 8 |
|
---|
| 9 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[600] | 10 | import net.oni2.aeinstaller.backend.QuickAppExecution;
|
---|
[596] | 11 | import net.oni2.aeinstaller.backend.Settings;
|
---|
| 12 | import net.oni2.aeinstaller.backend.Settings.Architecture;
|
---|
| 13 | import net.oni2.aeinstaller.backend.Settings.Platform;
|
---|
| 14 | import net.oni2.aeinstaller.backend.WinRegistry;
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | * @author Christian Illy
|
---|
| 18 | */
|
---|
| 19 | public class OniSplit {
|
---|
| 20 |
|
---|
| 21 | /**
|
---|
| 22 | * @return is a .NET implementation installed?
|
---|
| 23 | */
|
---|
| 24 | public static boolean isDotNETInstalled() {
|
---|
| 25 | switch (Settings.getPlatform()) {
|
---|
| 26 | case WIN:
|
---|
| 27 | try {
|
---|
| 28 | int view = WinRegistry.KEY_WOW64_32KEY;
|
---|
| 29 | if (Settings.getArchitecture() == Architecture.AMD64)
|
---|
| 30 | view = WinRegistry.KEY_WOW64_64KEY;
|
---|
| 31 |
|
---|
| 32 | Map<String, String> m = WinRegistry
|
---|
| 33 | .readStringValues(
|
---|
| 34 | WinRegistry.HKEY_LOCAL_MACHINE,
|
---|
| 35 | "Software\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727",
|
---|
| 36 | view);
|
---|
| 37 | return m != null;
|
---|
| 38 | } catch (IllegalArgumentException e) {
|
---|
| 39 | e.printStackTrace();
|
---|
| 40 | } catch (IllegalAccessException e) {
|
---|
| 41 | e.printStackTrace();
|
---|
| 42 | } catch (InvocationTargetException e) {
|
---|
| 43 | e.printStackTrace();
|
---|
| 44 | } catch (Exception e) {
|
---|
| 45 | if (!e.getMessage()
|
---|
| 46 | .equals("Registry access not supported (not a Windows OS?)."))
|
---|
| 47 | e.printStackTrace();
|
---|
| 48 | }
|
---|
| 49 | return false;
|
---|
| 50 | case MACOS:
|
---|
| 51 | case LINUX:
|
---|
| 52 | Vector<String> cmd = new Vector<String>();
|
---|
| 53 | cmd.add("which");
|
---|
| 54 | cmd.add("mono");
|
---|
| 55 | Vector<String> res = null;
|
---|
| 56 | try {
|
---|
| 57 | res = QuickAppExecution.execute(cmd);
|
---|
| 58 | } catch (IOException e) {
|
---|
| 59 | e.printStackTrace();
|
---|
| 60 | }
|
---|
| 61 | if (res != null) {
|
---|
| 62 | if (res.get(0).startsWith("/")
|
---|
| 63 | && res.get(0).endsWith("mono")) {
|
---|
| 64 | return true;
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | return false;
|
---|
| 68 | default:
|
---|
| 69 | return false;
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | /**
|
---|
[602] | 74 | * @return Is Onisplit installed?
|
---|
| 75 | */
|
---|
| 76 | public static boolean isOniSplitInstalled() {
|
---|
| 77 | return getProgramFile().exists();
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | /**
|
---|
[596] | 81 | * Export given dat-file to target folder
|
---|
| 82 | *
|
---|
| 83 | * @param targetFolder
|
---|
| 84 | * Target folder
|
---|
| 85 | * @param input
|
---|
| 86 | * Dat file
|
---|
[600] | 87 | * @return OniSplit output
|
---|
[596] | 88 | */
|
---|
[600] | 89 | public static Vector<String> export(File targetFolder, File input) {
|
---|
[596] | 90 | if (!targetFolder.exists())
|
---|
| 91 | targetFolder.mkdir();
|
---|
| 92 |
|
---|
| 93 | Vector<String> cmdLine = getProgramInvocation();
|
---|
| 94 | cmdLine.add("-export");
|
---|
| 95 | cmdLine.add(targetFolder.getPath());
|
---|
| 96 | cmdLine.add(input.getPath());
|
---|
| 97 | Vector<String> res = null;
|
---|
| 98 | try {
|
---|
| 99 | res = QuickAppExecution.execute(cmdLine);
|
---|
| 100 | } catch (IOException e) {
|
---|
| 101 | e.printStackTrace();
|
---|
| 102 | }
|
---|
[600] | 103 | return res;
|
---|
[596] | 104 | }
|
---|
| 105 |
|
---|
[597] | 106 | /**
|
---|
| 107 | * Import given folder to a .dat-file
|
---|
[598] | 108 | *
|
---|
| 109 | * @param sourceFolders
|
---|
| 110 | * Folders containing .oni-files
|
---|
| 111 | * @param targetFile
|
---|
| 112 | * Target .dat-file
|
---|
[600] | 113 | * @return OniSplit output
|
---|
[597] | 114 | */
|
---|
[602] | 115 | public static Vector<String> importLevel(Vector<File> sourceFolders,
|
---|
| 116 | File targetFile) {
|
---|
[597] | 117 | Vector<String> cmdLine = getProgramInvocation();
|
---|
| 118 | cmdLine.add(getImportParam());
|
---|
[598] | 119 | for (File f : sourceFolders)
|
---|
| 120 | cmdLine.add(f.getPath());
|
---|
[597] | 121 | cmdLine.add(targetFile.getPath());
|
---|
| 122 | Vector<String> res = null;
|
---|
| 123 | try {
|
---|
| 124 | res = QuickAppExecution.execute(cmdLine);
|
---|
| 125 | } catch (IOException e) {
|
---|
| 126 | e.printStackTrace();
|
---|
| 127 | }
|
---|
[600] | 128 | return res;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /**
|
---|
| 132 | * Pack a level to a .dat-file. More powerful variant which allows
|
---|
| 133 | * specifying single .oni/.dat files
|
---|
| 134 | *
|
---|
| 135 | * @param sourceFoldersFiles
|
---|
| 136 | * Folders (for recursive .oni import) or files (.dat and single
|
---|
| 137 | * .oni) to import
|
---|
| 138 | * @param targetFile
|
---|
| 139 | * Target .dat-file
|
---|
| 140 | * @return OniSplit output
|
---|
| 141 | */
|
---|
| 142 | public static Vector<String> packLevel(Vector<File> sourceFoldersFiles,
|
---|
| 143 | File targetFile) {
|
---|
| 144 | Vector<String> cmdLine = getProgramInvocation();
|
---|
| 145 | cmdLine.add(getPackParam());
|
---|
| 146 | cmdLine.add(getPackTypeParam());
|
---|
| 147 | cmdLine.add("-out");
|
---|
| 148 | cmdLine.add(targetFile.getPath());
|
---|
| 149 | for (File f : sourceFoldersFiles)
|
---|
| 150 | cmdLine.add(f.getPath());
|
---|
| 151 | Vector<String> res = null;
|
---|
| 152 | try {
|
---|
| 153 | res = QuickAppExecution.execute(cmdLine);
|
---|
| 154 | } catch (IOException e) {
|
---|
| 155 | e.printStackTrace();
|
---|
[597] | 156 | }
|
---|
[600] | 157 | return res;
|
---|
[596] | 158 | }
|
---|
| 159 |
|
---|
[597] | 160 | /**
|
---|
| 161 | * Move files from one location to another using OniSplit so relations are
|
---|
| 162 | * handled
|
---|
| 163 | *
|
---|
| 164 | * @param targetFolder
|
---|
| 165 | * Target folder for files
|
---|
| 166 | * @param input
|
---|
| 167 | * Files to move, can contain wildcards
|
---|
| 168 | * @param moveParameter
|
---|
| 169 | * e.g. overwrite, delete
|
---|
[600] | 170 | * @return OniSplit output
|
---|
[597] | 171 | */
|
---|
[600] | 172 | public static Vector<String> move(File targetFolder, String input,
|
---|
[597] | 173 | String moveParameter) {
|
---|
| 174 | if (!targetFolder.exists())
|
---|
| 175 | targetFolder.mkdir();
|
---|
| 176 |
|
---|
| 177 | Vector<String> cmdLine = getProgramInvocation();
|
---|
| 178 | cmdLine.add("-move"
|
---|
| 179 | + (moveParameter != null ? ":" + moveParameter : ""));
|
---|
| 180 | cmdLine.add(targetFolder.getPath());
|
---|
| 181 | cmdLine.add(input);
|
---|
| 182 | Vector<String> res = null;
|
---|
| 183 | try {
|
---|
| 184 | res = QuickAppExecution.execute(cmdLine);
|
---|
| 185 | } catch (IOException e) {
|
---|
| 186 | e.printStackTrace();
|
---|
| 187 | }
|
---|
[600] | 188 | return res;
|
---|
[597] | 189 | }
|
---|
| 190 |
|
---|
[596] | 191 | private static String getImportParam() {
|
---|
| 192 | if (Settings.getPlatform() == Platform.MACOS)
|
---|
| 193 | return "-import:sep";
|
---|
| 194 | else
|
---|
| 195 | return "-import:nosep";
|
---|
| 196 | }
|
---|
| 197 |
|
---|
[600] | 198 | private static String getPackParam() {
|
---|
| 199 | return "pack";
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | private static String getPackTypeParam() {
|
---|
| 203 | if (Settings.getPlatform() == Platform.MACOS)
|
---|
| 204 | return "-type:macintel";
|
---|
| 205 | else
|
---|
| 206 | return "-type:pc";
|
---|
| 207 | }
|
---|
| 208 |
|
---|
[596] | 209 | private static Vector<String> getProgramInvocation() {
|
---|
| 210 | Vector<String> res = new Vector<String>();
|
---|
| 211 | if (Settings.getPlatform() != Platform.WIN)
|
---|
| 212 | res.add("mono");
|
---|
[602] | 213 | res.add(getProgramFile().getPath());
|
---|
[596] | 214 | return res;
|
---|
| 215 | }
|
---|
[602] | 216 |
|
---|
| 217 | private static File getProgramFile() {
|
---|
| 218 | return new File(new File(Paths.getEditionBasePath(), "Tools"),
|
---|
| 219 | "Onisplit.exe");
|
---|
| 220 | }
|
---|
[596] | 221 | }
|
---|