source: java/PlatformTools/src/net/oni2/platformtools/applicationinvoker/DotNet.java@ 835

Last change on this file since 835 was 767, checked in by alloc, 12 years ago

AEI2 0.99y:

  • Perhaps fixes launching Oni on MacOS
File size: 2.5 KB
Line 
1package net.oni2.platformtools.applicationinvoker;
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.platformtools.PlatformInformation;
10import net.oni2.platformtools.PlatformInformation.Architecture;
11import net.oni2.platformtools.PlatformInformation.Platform;
12import net.oni2.platformtools.WinRegistry;
13import net.oni2.platformtools.applicationinvoker.ApplicationInvoker;
14import net.oni2.platformtools.applicationinvoker.ApplicationInvocationResult;
15
16/**
17 * @author Christian Illy
18 */
19public 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, false);
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}
Note: See TracBrowser for help on using the repository browser.