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;
|
---|
10 | import net.oni2.aeinstaller.backend.QuickAppExecution;
|
---|
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 | // TODO Auto-generated catch block
|
---|
40 | e.printStackTrace();
|
---|
41 | } catch (IllegalAccessException e) {
|
---|
42 | // TODO Auto-generated catch block
|
---|
43 | e.printStackTrace();
|
---|
44 | } catch (InvocationTargetException e) {
|
---|
45 | // TODO Auto-generated catch block
|
---|
46 | e.printStackTrace();
|
---|
47 | } catch (Exception e) {
|
---|
48 | if (!e.getMessage()
|
---|
49 | .equals("Registry access not supported (not a Windows OS?)."))
|
---|
50 | // TODO Auto-generated catch block
|
---|
51 | e.printStackTrace();
|
---|
52 | }
|
---|
53 | return false;
|
---|
54 | case MACOS:
|
---|
55 | case LINUX:
|
---|
56 | Vector<String> cmd = new Vector<String>();
|
---|
57 | cmd.add("which");
|
---|
58 | cmd.add("mono");
|
---|
59 | Vector<String> res = null;
|
---|
60 | try {
|
---|
61 | res = QuickAppExecution.execute(cmd);
|
---|
62 | } catch (IOException e) {
|
---|
63 | // TODO Auto-generated catch block
|
---|
64 | e.printStackTrace();
|
---|
65 | }
|
---|
66 | if (res != null) {
|
---|
67 | if (res.get(0).startsWith("/")
|
---|
68 | && res.get(0).endsWith("mono")) {
|
---|
69 | return true;
|
---|
70 | }
|
---|
71 | }
|
---|
72 | return false;
|
---|
73 | default:
|
---|
74 | return false;
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * @return Is Onisplit installed?
|
---|
80 | */
|
---|
81 | public static boolean isOniSplitInstalled() {
|
---|
82 | return getProgramFile().exists();
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Export given dat-file to target folder
|
---|
87 | *
|
---|
88 | * @param targetFolder
|
---|
89 | * Target folder
|
---|
90 | * @param input
|
---|
91 | * Dat file
|
---|
92 | * @return OniSplit output
|
---|
93 | */
|
---|
94 | public static Vector<String> export(File targetFolder, File input) {
|
---|
95 | if (!targetFolder.exists())
|
---|
96 | targetFolder.mkdir();
|
---|
97 |
|
---|
98 | Vector<String> cmdLine = getProgramInvocation();
|
---|
99 | cmdLine.add("-export");
|
---|
100 | cmdLine.add(targetFolder.getPath());
|
---|
101 | cmdLine.add(input.getPath());
|
---|
102 | Vector<String> res = null;
|
---|
103 | try {
|
---|
104 | res = QuickAppExecution.execute(cmdLine);
|
---|
105 | } catch (IOException e) {
|
---|
106 | // TODO Auto-generated catch block
|
---|
107 | e.printStackTrace();
|
---|
108 | }
|
---|
109 | return res;
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Import given folder to a .dat-file
|
---|
114 | *
|
---|
115 | * @param sourceFolders
|
---|
116 | * Folders containing .oni-files
|
---|
117 | * @param targetFile
|
---|
118 | * Target .dat-file
|
---|
119 | * @return OniSplit output
|
---|
120 | */
|
---|
121 | public static Vector<String> importLevel(Vector<File> sourceFolders,
|
---|
122 | File targetFile) {
|
---|
123 | Vector<String> cmdLine = getProgramInvocation();
|
---|
124 | cmdLine.add(getImportParam());
|
---|
125 | for (File f : sourceFolders)
|
---|
126 | cmdLine.add(f.getPath());
|
---|
127 | cmdLine.add(targetFile.getPath());
|
---|
128 | Vector<String> res = null;
|
---|
129 | try {
|
---|
130 | res = QuickAppExecution.execute(cmdLine);
|
---|
131 | } catch (IOException e) {
|
---|
132 | // TODO Auto-generated catch block
|
---|
133 | e.printStackTrace();
|
---|
134 | }
|
---|
135 | return res;
|
---|
136 | }
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Pack a level to a .dat-file. More powerful variant which allows
|
---|
140 | * specifying single .oni/.dat files
|
---|
141 | *
|
---|
142 | * @param sourceFoldersFiles
|
---|
143 | * Folders (for recursive .oni import) or files (.dat and single
|
---|
144 | * .oni) to import
|
---|
145 | * @param targetFile
|
---|
146 | * Target .dat-file
|
---|
147 | * @return OniSplit output
|
---|
148 | */
|
---|
149 | public static Vector<String> packLevel(Vector<File> sourceFoldersFiles,
|
---|
150 | File targetFile) {
|
---|
151 | Vector<String> cmdLine = getProgramInvocation();
|
---|
152 | cmdLine.add(getPackParam());
|
---|
153 | cmdLine.add(getPackTypeParam());
|
---|
154 | cmdLine.add("-out");
|
---|
155 | cmdLine.add(targetFile.getPath());
|
---|
156 | for (File f : sourceFoldersFiles)
|
---|
157 | cmdLine.add(f.getPath());
|
---|
158 | Vector<String> res = null;
|
---|
159 | try {
|
---|
160 | res = QuickAppExecution.execute(cmdLine);
|
---|
161 | } catch (IOException e) {
|
---|
162 | // TODO Auto-generated catch block
|
---|
163 | e.printStackTrace();
|
---|
164 | }
|
---|
165 | return res;
|
---|
166 | }
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Move files from one location to another using OniSplit so relations are
|
---|
170 | * handled
|
---|
171 | *
|
---|
172 | * @param targetFolder
|
---|
173 | * Target folder for files
|
---|
174 | * @param input
|
---|
175 | * Files to move, can contain wildcards
|
---|
176 | * @param moveParameter
|
---|
177 | * e.g. overwrite, delete
|
---|
178 | * @return OniSplit output
|
---|
179 | */
|
---|
180 | public static Vector<String> move(File targetFolder, String input,
|
---|
181 | String moveParameter) {
|
---|
182 | if (!targetFolder.exists())
|
---|
183 | targetFolder.mkdir();
|
---|
184 |
|
---|
185 | Vector<String> cmdLine = getProgramInvocation();
|
---|
186 | cmdLine.add("-move"
|
---|
187 | + (moveParameter != null ? ":" + moveParameter : ""));
|
---|
188 | cmdLine.add(targetFolder.getPath());
|
---|
189 | cmdLine.add(input);
|
---|
190 | Vector<String> res = null;
|
---|
191 | try {
|
---|
192 | res = QuickAppExecution.execute(cmdLine);
|
---|
193 | } catch (IOException e) {
|
---|
194 | // TODO Auto-generated catch block
|
---|
195 | e.printStackTrace();
|
---|
196 | }
|
---|
197 | return res;
|
---|
198 | }
|
---|
199 |
|
---|
200 | private static String getImportParam() {
|
---|
201 | if (Settings.getPlatform() == Platform.MACOS)
|
---|
202 | return "-import:sep";
|
---|
203 | else
|
---|
204 | return "-import:nosep";
|
---|
205 | }
|
---|
206 |
|
---|
207 | private static String getPackParam() {
|
---|
208 | return "pack";
|
---|
209 | }
|
---|
210 |
|
---|
211 | private static String getPackTypeParam() {
|
---|
212 | if (Settings.getPlatform() == Platform.MACOS)
|
---|
213 | return "-type:macintel";
|
---|
214 | else
|
---|
215 | return "-type:pc";
|
---|
216 | }
|
---|
217 |
|
---|
218 | private static Vector<String> getProgramInvocation() {
|
---|
219 | Vector<String> res = new Vector<String>();
|
---|
220 | if (Settings.getPlatform() != Platform.WIN)
|
---|
221 | res.add("mono");
|
---|
222 | res.add(getProgramFile().getPath());
|
---|
223 | return res;
|
---|
224 | }
|
---|
225 |
|
---|
226 | private static File getProgramFile() {
|
---|
227 | return new File(new File(Paths.getEditionBasePath(), "Tools"),
|
---|
228 | "Onisplit.exe");
|
---|
229 | }
|
---|
230 | }
|
---|