1 | package net.oni2.platformtools.applicationinvoker;
|
---|
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.platformtools.PlatformInformation;
|
---|
10 | import net.oni2.platformtools.PlatformInformation.Architecture;
|
---|
11 | import net.oni2.platformtools.PlatformInformation.Platform;
|
---|
12 | import net.oni2.platformtools.WinRegistry;
|
---|
13 | import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
|
---|
14 | import net.oni2.platformtools.applicationinvoker.ApplicationInvocationResult;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * @author Christian Illy
|
---|
18 | */
|
---|
19 | public class DotNet {
|
---|
20 | private static File mono = null;
|
---|
21 | private static int isInst = -1;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * @return is a .NET implementation installed?
|
---|
25 | */
|
---|
26 | public static boolean isInstalled() {
|
---|
27 | if (isInst < 0) {
|
---|
28 | isInst = 0;
|
---|
29 | switch (PlatformInformation.getPlatform()) {
|
---|
30 | case WIN:
|
---|
31 | try {
|
---|
32 | int view = WinRegistry.KEY_WOW64_32KEY;
|
---|
33 | if (PlatformInformation.getArchitecture() == Architecture.AMD64)
|
---|
34 | view = WinRegistry.KEY_WOW64_64KEY;
|
---|
35 |
|
---|
36 | Map<String, String> m = WinRegistry
|
---|
37 | .readStringValues(
|
---|
38 | WinRegistry.HKEY_LOCAL_MACHINE,
|
---|
39 | "Software\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727",
|
---|
40 | view);
|
---|
41 | isInst = (m != null ? 1 : 0);
|
---|
42 | } catch (IllegalArgumentException e) {
|
---|
43 | e.printStackTrace();
|
---|
44 | } catch (IllegalAccessException e) {
|
---|
45 | e.printStackTrace();
|
---|
46 | } catch (InvocationTargetException e) {
|
---|
47 | e.printStackTrace();
|
---|
48 | } catch (Exception e) {
|
---|
49 | if (!e.getMessage()
|
---|
50 | .equals("Registry access not supported (not a Windows OS?)."))
|
---|
51 | e.printStackTrace();
|
---|
52 | }
|
---|
53 | break;
|
---|
54 | case MACOS:
|
---|
55 | case LINUX:
|
---|
56 | Vector<String> params = new Vector<String>();
|
---|
57 | params.add("mono");
|
---|
58 | ApplicationInvocationResult res = null;
|
---|
59 | try {
|
---|
60 | res = ApplicationInvoker.executeAndWait(EExeType.OSBINARY, null, new File("which"), params);
|
---|
61 | } catch (IOException e) {
|
---|
62 | e.printStackTrace();
|
---|
63 | } catch (ERuntimeNotInstalledException e) {
|
---|
64 | e.printStackTrace();
|
---|
65 | }
|
---|
66 | if (res != null) {
|
---|
67 | if (res.output.size() > 0) {
|
---|
68 | if (res.output.get(0).startsWith("/")
|
---|
69 | && res.output.get(0).endsWith("mono")) {
|
---|
70 | isInst = 1;
|
---|
71 | mono = new File(res.output.get(0));
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | break;
|
---|
76 | default:
|
---|
77 | isInst = 0;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | return isInst == 1;
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * @return Get the .Net runtime executable name
|
---|
85 | */
|
---|
86 | public static File getRuntimeExe() {
|
---|
87 | if (PlatformInformation.getPlatform() != Platform.WIN)
|
---|
88 | return mono;
|
---|
89 | return null;
|
---|
90 | }
|
---|
91 |
|
---|
92 | }
|
---|