1 | package net.oni2.aeinstaller.backend;
|
---|
2 |
|
---|
3 | import java.io.IOException;
|
---|
4 | import java.lang.reflect.InvocationTargetException;
|
---|
5 | import java.util.Map;
|
---|
6 | import java.util.Vector;
|
---|
7 |
|
---|
8 | import net.oni2.applicationinvoker.AppExecution;
|
---|
9 | import net.oni2.applicationinvoker.AppExecutionResult;
|
---|
10 | import net.oni2.settingsmanager.Settings;
|
---|
11 | import net.oni2.settingsmanager.Settings.Architecture;
|
---|
12 | import net.oni2.settingsmanager.Settings.Platform;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * @author Christian Illy
|
---|
16 | */
|
---|
17 | public class DotNet {
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * @return is a .NET implementation installed?
|
---|
21 | */
|
---|
22 | public static boolean isInstalled() {
|
---|
23 | switch (Settings.getPlatform()) {
|
---|
24 | case WIN:
|
---|
25 | try {
|
---|
26 | int view = WinRegistry.KEY_WOW64_32KEY;
|
---|
27 | if (Settings.getArchitecture() == Architecture.AMD64)
|
---|
28 | view = WinRegistry.KEY_WOW64_64KEY;
|
---|
29 |
|
---|
30 | Map<String, String> m = WinRegistry
|
---|
31 | .readStringValues(
|
---|
32 | WinRegistry.HKEY_LOCAL_MACHINE,
|
---|
33 | "Software\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727",
|
---|
34 | view);
|
---|
35 | return m != null;
|
---|
36 | } catch (IllegalArgumentException e) {
|
---|
37 | e.printStackTrace();
|
---|
38 | } catch (IllegalAccessException e) {
|
---|
39 | e.printStackTrace();
|
---|
40 | } catch (InvocationTargetException e) {
|
---|
41 | e.printStackTrace();
|
---|
42 | } catch (Exception e) {
|
---|
43 | if (!e.getMessage()
|
---|
44 | .equals("Registry access not supported (not a Windows OS?)."))
|
---|
45 | e.printStackTrace();
|
---|
46 | }
|
---|
47 | return false;
|
---|
48 | case MACOS:
|
---|
49 | case LINUX:
|
---|
50 | Vector<String> cmd = new Vector<String>();
|
---|
51 | cmd.add("which");
|
---|
52 | cmd.add("mono");
|
---|
53 | AppExecutionResult res = null;
|
---|
54 | try {
|
---|
55 | res = AppExecution.executeAndWait(cmd);
|
---|
56 | } catch (IOException e) {
|
---|
57 | e.printStackTrace();
|
---|
58 | }
|
---|
59 | if (res != null) {
|
---|
60 | if (res.output.get(0).startsWith("/")
|
---|
61 | && res.output.get(0).endsWith("mono")) {
|
---|
62 | return true;
|
---|
63 | }
|
---|
64 | }
|
---|
65 | return false;
|
---|
66 | default:
|
---|
67 | return false;
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * @return Get the .Net runtime executable name
|
---|
73 | */
|
---|
74 | public static String getRuntimeExe() {
|
---|
75 | if (Settings.getPlatform() != Platform.WIN)
|
---|
76 | return "mono";
|
---|
77 | return "";
|
---|
78 | }
|
---|
79 |
|
---|
80 | }
|
---|