source: AE/installer2/src/net/oni2/aeinstaller/backend/oni/OniSplit.java@ 601

Last change on this file since 601 was 600, checked in by alloc, 12 years ago
File size: 5.7 KB
Line 
1package net.oni2.aeinstaller.backend.oni;
2
3import java.io.File;
4import java.io.IOException;
5import java.lang.reflect.InvocationTargetException;
6import java.util.Map;
7import java.util.Vector;
8
9import net.oni2.aeinstaller.backend.Paths;
10import net.oni2.aeinstaller.backend.QuickAppExecution;
11import net.oni2.aeinstaller.backend.Settings;
12import net.oni2.aeinstaller.backend.Settings.Architecture;
13import net.oni2.aeinstaller.backend.Settings.Platform;
14import net.oni2.aeinstaller.backend.WinRegistry;
15
16/**
17 * @author Christian Illy
18 */
19public 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 * @return OniSplit output
86 */
87 public static Vector<String> export(File targetFolder, File input) {
88 if (!targetFolder.exists())
89 targetFolder.mkdir();
90
91 Vector<String> cmdLine = getProgramInvocation();
92 cmdLine.add("-export");
93 cmdLine.add(targetFolder.getPath());
94 cmdLine.add(input.getPath());
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 return res;
103 }
104
105 /**
106 * Import given folder to a .dat-file
107 *
108 * @param sourceFolders
109 * Folders containing .oni-files
110 * @param targetFile
111 * Target .dat-file
112 * @return OniSplit output
113 */
114 public static Vector<String> importLevel(Vector<File> sourceFolders, File targetFile) {
115 Vector<String> cmdLine = getProgramInvocation();
116 cmdLine.add(getImportParam());
117 for (File f : sourceFolders)
118 cmdLine.add(f.getPath());
119 cmdLine.add(targetFile.getPath());
120 Vector<String> res = null;
121 try {
122 res = QuickAppExecution.execute(cmdLine);
123 } catch (IOException e) {
124 // TODO Auto-generated catch block
125 e.printStackTrace();
126 }
127 return res;
128 }
129
130 /**
131 * Pack a level to a .dat-file. More powerful variant which allows
132 * specifying single .oni/.dat files
133 *
134 * @param sourceFoldersFiles
135 * Folders (for recursive .oni import) or files (.dat and single
136 * .oni) to import
137 * @param targetFile
138 * Target .dat-file
139 * @return OniSplit output
140 */
141 public static Vector<String> packLevel(Vector<File> sourceFoldersFiles,
142 File targetFile) {
143 Vector<String> cmdLine = getProgramInvocation();
144 cmdLine.add(getPackParam());
145 cmdLine.add(getPackTypeParam());
146 cmdLine.add("-out");
147 cmdLine.add(targetFile.getPath());
148 for (File f : sourceFoldersFiles)
149 cmdLine.add(f.getPath());
150 Vector<String> res = null;
151 try {
152 res = QuickAppExecution.execute(cmdLine);
153 } catch (IOException e) {
154 // TODO Auto-generated catch block
155 e.printStackTrace();
156 }
157 return res;
158 }
159
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
170 * @return OniSplit output
171 */
172 public static Vector<String> move(File targetFolder, String input,
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 // TODO Auto-generated catch block
187 e.printStackTrace();
188 }
189 return res;
190 }
191
192 private static String getImportParam() {
193 if (Settings.getPlatform() == Platform.MACOS)
194 return "-import:sep";
195 else
196 return "-import:nosep";
197 }
198
199 private static String getPackParam() {
200 return "pack";
201 }
202
203 private static String getPackTypeParam() {
204 if (Settings.getPlatform() == Platform.MACOS)
205 return "-type:macintel";
206 else
207 return "-type:pc";
208 }
209
210 private static Vector<String> getProgramInvocation() {
211 Vector<String> res = new Vector<String>();
212 if (Settings.getPlatform() != Platform.WIN)
213 res.add("mono");
214 res.add(new File(new File(Paths.getEditionBasePath(), "Tools"),
215 "Onisplit.exe").getPath());
216 return res;
217 }
218}
Note: See TracBrowser for help on using the repository browser.