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.Settings; |
11 |
import net.oni2.aeinstaller.backend.Settings.Architecture; |
12 |
import net.oni2.aeinstaller.backend.Settings.Platform; |
13 |
import net.oni2.aeinstaller.backend.WinRegistry; |
14 |
import net.oni2.aeinstaller.backend.app_launcher.QuickAppExecution; |
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 |
* Export given dat-file to target folder |
80 |
* |
81 |
* @param targetFolder |
82 |
* Target folder |
83 |
* @param input |
84 |
* Dat file |
85 |
*/ |
86 |
public static void export(File targetFolder, File input) { |
87 |
if (!targetFolder.exists()) |
88 |
targetFolder.mkdir(); |
89 |
|
90 |
Vector<String> cmdLine = getProgramInvocation(); |
91 |
cmdLine.add("-export"); |
92 |
cmdLine.add(targetFolder.getPath()); |
93 |
cmdLine.add(input.getPath()); |
94 |
// System.out.println(cmdLine.toString()); |
95 |
Vector<String> res = null; |
96 |
try { |
97 |
res = QuickAppExecution.execute(cmdLine); |
98 |
} catch (IOException e) { |
99 |
// TODO Auto-generated catch block |
100 |
e.printStackTrace(); |
101 |
} |
102 |
if (res != null) { |
103 |
// check for errors |
104 |
System.out.println(res.toString()); |
105 |
} |
106 |
} |
107 |
|
108 |
/** |
109 |
* Import given folder to a .dat-file |
110 |
* @param sourceFolder Folder containing .oni-files |
111 |
* @param targetFile Target .dat-file |
112 |
*/ |
113 |
public static void importLevel(File sourceFolder, File targetFile) { |
114 |
Vector<String> cmdLine = getProgramInvocation(); |
115 |
cmdLine.add(getImportParam()); |
116 |
cmdLine.add(sourceFolder.getPath()); |
117 |
cmdLine.add(targetFile.getPath()); |
118 |
// System.out.println(cmdLine.toString()); |
119 |
Vector<String> res = null; |
120 |
try { |
121 |
res = QuickAppExecution.execute(cmdLine); |
122 |
} catch (IOException e) { |
123 |
// TODO Auto-generated catch block |
124 |
e.printStackTrace(); |
125 |
} |
126 |
if (res != null) { |
127 |
// check for errors |
128 |
System.out.println(res.toString()); |
129 |
} |
130 |
} |
131 |
|
132 |
/** |
133 |
* Move files from one location to another using OniSplit so relations are |
134 |
* handled |
135 |
* |
136 |
* @param targetFolder |
137 |
* Target folder for files |
138 |
* @param input |
139 |
* Files to move, can contain wildcards |
140 |
* @param moveParameter |
141 |
* e.g. overwrite, delete |
142 |
*/ |
143 |
public static void move(File targetFolder, String input, |
144 |
String moveParameter) { |
145 |
if (!targetFolder.exists()) |
146 |
targetFolder.mkdir(); |
147 |
|
148 |
Vector<String> cmdLine = getProgramInvocation(); |
149 |
cmdLine.add("-move" |
150 |
+ (moveParameter != null ? ":" + moveParameter : "")); |
151 |
cmdLine.add(targetFolder.getPath()); |
152 |
cmdLine.add(input); |
153 |
Vector<String> res = null; |
154 |
try { |
155 |
res = QuickAppExecution.execute(cmdLine); |
156 |
} catch (IOException e) { |
157 |
// TODO Auto-generated catch block |
158 |
e.printStackTrace(); |
159 |
} |
160 |
if (res != null && res.size() > 0) { |
161 |
// TODO: errors |
162 |
System.out.println(res.toString()); |
163 |
} |
164 |
} |
165 |
|
166 |
private static String getImportParam() { |
167 |
if (Settings.getPlatform() == Platform.MACOS) |
168 |
return "-import:sep"; |
169 |
else |
170 |
return "-import:nosep"; |
171 |
} |
172 |
|
173 |
private static Vector<String> getProgramInvocation() { |
174 |
Vector<String> res = new Vector<String>(); |
175 |
if (Settings.getPlatform() != Platform.WIN) |
176 |
res.add("mono"); |
177 |
res.add(new File(Paths.getInstallerPath(), "Onisplit.exe").getPath()); |
178 |
return res; |
179 |
} |
180 |
} |