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

Last change on this file since 598 was 598, checked in by alloc, 12 years ago
File size: 4.8 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.Settings;
11import net.oni2.aeinstaller.backend.Settings.Architecture;
12import net.oni2.aeinstaller.backend.Settings.Platform;
13import net.oni2.aeinstaller.backend.WinRegistry;
14import net.oni2.aeinstaller.backend.app_launcher.QuickAppExecution;
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 */
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 *
111 * @param sourceFolders
112 * Folders containing .oni-files
113 * @param targetFile
114 * Target .dat-file
115 */
116 public static void importLevel(Vector<File> sourceFolders, 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 // System.out.println(cmdLine.toString());
123 Vector<String> res = null;
124 try {
125 res = QuickAppExecution.execute(cmdLine);
126 } catch (IOException e) {
127 // TODO Auto-generated catch block
128 e.printStackTrace();
129 }
130 if (res != null) {
131 // check for errors
132 System.out.println(res.toString());
133 }
134 }
135
136 /**
137 * Move files from one location to another using OniSplit so relations are
138 * handled
139 *
140 * @param targetFolder
141 * Target folder for files
142 * @param input
143 * Files to move, can contain wildcards
144 * @param moveParameter
145 * e.g. overwrite, delete
146 */
147 public static void move(File targetFolder, String input,
148 String moveParameter) {
149 if (!targetFolder.exists())
150 targetFolder.mkdir();
151
152 Vector<String> cmdLine = getProgramInvocation();
153 cmdLine.add("-move"
154 + (moveParameter != null ? ":" + moveParameter : ""));
155 cmdLine.add(targetFolder.getPath());
156 cmdLine.add(input);
157 Vector<String> res = null;
158 try {
159 res = QuickAppExecution.execute(cmdLine);
160 } catch (IOException e) {
161 // TODO Auto-generated catch block
162 e.printStackTrace();
163 }
164 if (res != null && res.size() > 0) {
165 // TODO: errors
166 System.out.println(res.toString());
167 }
168 }
169
170 private static String getImportParam() {
171 if (Settings.getPlatform() == Platform.MACOS)
172 return "-import:sep";
173 else
174 return "-import:nosep";
175 }
176
177 private static Vector<String> getProgramInvocation() {
178 Vector<String> res = new Vector<String>();
179 if (Settings.getPlatform() != Platform.WIN)
180 res.add("mono");
181 res.add(new File(Paths.getInstallerPath(), "Onisplit.exe").getPath());
182 return res;
183 }
184}
Note: See TracBrowser for help on using the repository browser.