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