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

Last change on this file since 660 was 624, checked in by alloc, 12 years ago

AEI2 0.84:

  • Actually *do* update packages
  • Uninstall backend for tools
File size: 5.5 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.AppExecution;
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 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 = AppExecution.executeAndWait(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 /**
74 * @return Is Onisplit installed?
75 */
76 public static boolean isOniSplitInstalled() {
77 return getProgramFile().exists();
78 }
79
80 /**
81 * Export given dat-file to target folder
82 *
83 * @param targetFolder
84 * Target folder
85 * @param input
86 * Dat file
87 * @return OniSplit output
88 */
89 public static Vector<String> export(File targetFolder, File input) {
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 = AppExecution.executeAndWait(cmdLine);
100 } catch (IOException e) {
101 e.printStackTrace();
102 }
103 return res;
104 }
105
106 /**
107 * Import given folder to a .dat-file
108 *
109 * @param sourceFolders
110 * Folders containing .oni-files
111 * @param targetFile
112 * Target .dat-file
113 * @return OniSplit output
114 */
115 public static Vector<String> importLevel(Vector<File> sourceFolders,
116 File targetFile) {
117 Vector<String> cmdLine = getProgramInvocation();
118 cmdLine.add(getImportParam());
119 for (File f : sourceFolders)
120 cmdLine.add(f.getPath());
121 cmdLine.add(targetFile.getPath());
122 Vector<String> res = null;
123 try {
124 res = AppExecution.executeAndWait(cmdLine);
125 } catch (IOException e) {
126 e.printStackTrace();
127 }
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 = AppExecution.executeAndWait(cmdLine);
154 } catch (IOException e) {
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 = AppExecution.executeAndWait(cmdLine);
185 } catch (IOException e) {
186 e.printStackTrace();
187 }
188 return res;
189 }
190
191 private static String getImportParam() {
192 if (Settings.getPlatform() == Platform.MACOS)
193 return "-import:sep";
194 else
195 return "-import:nosep";
196 }
197
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
209 private static Vector<String> getProgramInvocation() {
210 Vector<String> res = new Vector<String>();
211 if (Settings.getPlatform() != Platform.WIN)
212 res.add("mono");
213 res.add(getProgramFile().getPath());
214 return res;
215 }
216
217 private static File getProgramFile() {
218 return new File(new File(Paths.getEditionBasePath(), "Tools"),
219 "Onisplit.exe");
220 }
221}
Note: See TracBrowser for help on using the repository browser.