[596] | 1 | package net.oni2.aeinstaller.backend.oni;
|
---|
| 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.aeinstaller.backend.Paths;
|
---|
| 10 | import net.oni2.aeinstaller.backend.Settings;
|
---|
| 11 | import net.oni2.aeinstaller.backend.Settings.Architecture;
|
---|
| 12 | import net.oni2.aeinstaller.backend.Settings.Platform;
|
---|
| 13 | import net.oni2.aeinstaller.backend.WinRegistry;
|
---|
| 14 | import net.oni2.aeinstaller.backend.app_launcher.QuickAppExecution;
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | * @author Christian Illy
|
---|
| 18 | */
|
---|
| 19 | public 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 | System.out.println(res.toString());
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | public static void importLevel() {
|
---|
| 108 | getImportParam();
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | private static String getImportParam() {
|
---|
| 112 | if (Settings.getPlatform() == Platform.MACOS)
|
---|
| 113 | return "-import:sep";
|
---|
| 114 | else
|
---|
| 115 | return "-import:nosep";
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | private static Vector<String> getProgramInvocation() {
|
---|
| 119 | Vector<String> res = new Vector<String>();
|
---|
| 120 | if (Settings.getPlatform() != Platform.WIN)
|
---|
| 121 | res.add("mono");
|
---|
| 122 | res.add(new File(Paths.getInstallerPath(), "Onisplit.exe").getPath());
|
---|
| 123 | return res;
|
---|
| 124 | }
|
---|
| 125 | }
|
---|