diff --git a/Q3E/src/main/java/com/n0n3m4/q3e/karin/KidTechCommand.java b/Q3E/src/main/java/com/n0n3m4/q3e/karin/KidTechCommand.java index 85af922c2..45a9620ec 100644 --- a/Q3E/src/main/java/com/n0n3m4/q3e/karin/KidTechCommand.java +++ b/Q3E/src/main/java/com/n0n3m4/q3e/karin/KidTechCommand.java @@ -485,7 +485,7 @@ public String Param(String name, String...def) private static final int CMD_PART_SET = 3; // +set private static final int CMD_PART_NAME = 4; // r_shadows private static final int CMD_PART_VALUE = 5; // 1 - private static class CmdPart + public static class CmdPart { public int type; public String str; @@ -506,7 +506,7 @@ public String toString() return String.format("{%s|%s}", tname, str); } } - private final List cmdParts = new ArrayList<>(); + public final List cmdParts = new ArrayList<>(); private void Parse() { @@ -518,11 +518,32 @@ private void Parse() while(i < m_cmd.length()) { char c = m_cmd.charAt(i); - if(c == '+' || c == '-') + if (c == '"') + { + if(readingSet) + { + readingSet = false; + String val = ReadWordWithQuotes(m_cmd, i); + AddPart(CMD_PART_NAME, val); + i += val.length(); + } + else + { + String val = ReadUtil(m_cmd, i, argPrefix); + if(!hasArg0) + AddPart(CMD_PART_EXECUTION, val); + else + AddPart(CMD_PART_VALUE, val); + i += val.length(); + } + hasArg0 = true; + } + else if(c == '+' || c == '-') { readingSet = false; - String cmd = ReadWord(m_cmd, i); - boolean isSet = cmd.substring(1).equals("set"); + String cmd = ReadWord(m_cmd, i + 1); + boolean isSet = cmd.equals("set") || cmd.equals("\"set\""); + cmd = c + cmd; if(isSet) AddPart(CMD_PART_SET, cmd); else @@ -602,6 +623,11 @@ private String SkipBlank(String str, int start) private String ReadWord(String str, int start) { + if(str.charAt(start) == '\"') + { + return ReadWordWithQuotes(str, start); + } + StringBuilder ret = new StringBuilder(); int i = start; while(i < str.length()) @@ -615,6 +641,23 @@ private String ReadWord(String str, int start) return ret.toString(); } + private String ReadWordWithQuotes(String str, int start) + { + char quoteStart = str.charAt(start); + StringBuilder ret = new StringBuilder(); + ret.append(quoteStart); + int i = start + 1; + char lastp = 0; + while(i < str.length() && ( str.charAt(i) != quoteStart || lastp == '\\' )) + { + lastp = str.charAt(i); + ret.append(lastp); + i++; + } + ret.append(quoteStart); + return ret.toString(); // with quotes + } + private String ReadUtil(String str, int start, String chars) { StringBuilder ret = new StringBuilder(); @@ -622,6 +665,14 @@ private String ReadUtil(String str, int start, String chars) while(i < str.length()) { char c = str.charAt(i); + if(c == '"') + { + String val = ReadWordWithQuotes(str, i); + ret.append(val); + i += val.length(); + continue; + } + if(Character.isSpaceChar(c)) { if(i + 1 < str.length()) diff --git a/idTech4Amm/src/main/java/com/karin/idTech4Amm/misc/TextHelper.java b/idTech4Amm/src/main/java/com/karin/idTech4Amm/misc/TextHelper.java index a96573d91..cda6ad95f 100644 --- a/idTech4Amm/src/main/java/com/karin/idTech4Amm/misc/TextHelper.java +++ b/idTech4Amm/src/main/java/com/karin/idTech4Amm/misc/TextHelper.java @@ -193,7 +193,7 @@ public static CharSequence GetHelpText() " " + GenLinkText("https://store.steampowered.com/agecheck/app/208200/", "DOOM3 BFG: doom3bfg/base"), " " + GenLinkText("https://github.com/ZDoom/gzdoom", "GZDOOM: gzdoom"), " " + GenLinkText("https://www.etlegacy.com", "ET-Legacy: etmain legacy"), - " " + GenLinkText("https://github.com/wolfetplayer/RealRTCW", "RealRTCW"), + " " + GenLinkText("https://github.com/wolfetplayer/RealRTCW", "RealRTCW: main"), null, "For playing Prey(2006)(Based on `" + GenLinkText("https://github.com/jmarshall23", "jmarshall") + "`'s `" + GenLinkText("https://github.com/jmarshall23/PreyDoom", "PreyDoom") + "`): ", " 1. Putting PC Prey game data file to `preybase` folder and START directly.", diff --git a/idTech4Amm/src/main/java/com/n0n3m4/DIII4A/GameLauncher.java b/idTech4Amm/src/main/java/com/n0n3m4/DIII4A/GameLauncher.java index 82e56b494..f4f7fa257 100644 --- a/idTech4Amm/src/main/java/com/n0n3m4/DIII4A/GameLauncher.java +++ b/idTech4Amm/src/main/java/com/n0n3m4/DIII4A/GameLauncher.java @@ -572,11 +572,11 @@ public void onClick(View view) int id = view.getId(); if (id == R.id.launcher_tab1_edit_autoexec) { - EditFile("autoexec.cfg"); + EditFile("autoexec.cfg", false); } else if (id == R.id.launcher_tab1_edit_doomconfig) { - EditFile(Q3EUtils.q3ei.config_name); + EditFile(Q3EUtils.q3ei.config_name, true); } else if (id == R.id.launcher_tab1_game_lib_button) { @@ -1767,7 +1767,7 @@ private boolean IsProp(String name) // return KidTech4Command.IsProp(GetCmdText(), name); } - private void EditFile(String file) + private void EditFile(String file, boolean findInHome) { if (null == m_editConfigFileFunc) m_editConfigFileFunc = new EditConfigFileFunc(this, CONST_RESULT_CODE_REQUEST_EXTERNAL_STORAGE_FOR_EDIT_CONFIG_FILE); @@ -1776,7 +1776,9 @@ private void EditFile(String file) String game = GetGameModFromCommand(); if (game == null || game.isEmpty()) game = Q3EUtils.q3ei.game_base; - String path = KStr.AppendPath(V.edt_path.getText().toString(), Q3EUtils.q3ei.subdatadir, Q3EUtils.q3ei.GetGameHomeDirectoryPath()); + String path = KStr.AppendPath(V.edt_path.getText().toString(), Q3EUtils.q3ei.subdatadir); + if(findInHome) + path = KStr.AppendPath(path, Q3EUtils.q3ei.GetGameHomeDirectoryPath()); bundle.putString("game", game); bundle.putString("path", path); bundle.putString("file", file); @@ -2475,11 +2477,11 @@ private void OpenDirectoryHelper() private void OpenShortcutCreator() { - if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) +/* if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) { Toast.makeText(this, R.string.only_support_on_android_version_7_1, Toast.LENGTH_LONG).show(); return; - } + }*/ if (null == m_createShortcutFunc) { m_createShortcutFunc = new CreateShortcutFunc(this, CONST_RESULT_CODE_REQUEST_CREATE_SHORTCUT); @@ -2490,11 +2492,11 @@ private void OpenShortcutCreator() private void OpenShortcutWithCommandCreator() { - if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) +/* if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) { Toast.makeText(this, R.string.only_support_on_android_version_7_1, Toast.LENGTH_LONG).show(); return; - } + }*/ if (null == m_createCommandShortcutFunc) { m_createCommandShortcutFunc = new CreateCommandShortcutFunc(this, CONST_RESULT_CODE_REQUEST_CREATE_SHORTCUT_WITH_COMMAND); diff --git a/idTech4Amm/src/main/java/com/n0n3m4/DIII4A/launcher/CreateCommandShortcutFunc.java b/idTech4Amm/src/main/java/com/n0n3m4/DIII4A/launcher/CreateCommandShortcutFunc.java index c78307723..c038d4de0 100644 --- a/idTech4Amm/src/main/java/com/n0n3m4/DIII4A/launcher/CreateCommandShortcutFunc.java +++ b/idTech4Amm/src/main/java/com/n0n3m4/DIII4A/launcher/CreateCommandShortcutFunc.java @@ -104,49 +104,58 @@ private boolean CheckPinnedShortcut(String game, String command) private void CreateShortcut(String game, String name, String command) { - if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) - return; + Class activity = Q3EMain.class; + String gameName = name; + String longName = gameName; + int iconId = GameManager.GetGameIcon(game); - ShortcutManager shortcutManager = (ShortcutManager) m_gameLauncher.getSystemService(Context.SHORTCUT_SERVICE); - if (null != shortcutManager && shortcutManager.isRequestPinShortcutSupported()) + if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - int iconId = GameManager.GetGameIcon(game); - Class activity = Q3EMain.class; - String shortcutId = GenShortcutId(game, command); - String gameName = name; - String longName = gameName; - - Intent intent = new Intent(m_gameLauncher, activity) - .putExtra("game", game) - .putExtra("command", command) - .setAction(Intent.ACTION_VIEW) - ; - ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(m_gameLauncher, shortcutId) - .setShortLabel(gameName) - .setLongLabel(longName) - .setIcon(Icon.createWithResource(m_gameLauncher, iconId)) - .setIntent(intent) - .build(); - - Intent pinnedShortcutCallbackIntent = shortcutManager.createShortcutResultIntent(shortcutInfo); - PendingIntent successCallback = PendingIntent.getBroadcast(m_gameLauncher, 0, pinnedShortcutCallbackIntent, 0); - - try - { - if(shortcutManager.requestPinShortcut(shortcutInfo, successCallback.getIntentSender())) - Toast_long(Tr(R.string.create_desktop_shortcut_success, gameName, command)); - else - Toast_long(Tr(R.string.create_desktop_shortcut_fail, gameName, command)); - } - catch(Exception e) + ShortcutManager shortcutManager = (ShortcutManager) m_gameLauncher.getSystemService(Context.SHORTCUT_SERVICE); + if (null != shortcutManager && shortcutManager.isRequestPinShortcutSupported()) { - e.printStackTrace(); - Toast_long(Tr(R.string.create_desktop_shortcut_fail, gameName, command) + ": " + e.getMessage()); + String shortcutId = GenShortcutId(game, command); + + Intent intent = new Intent(m_gameLauncher, activity) + .putExtra("game", game) + .putExtra("command", command) + .setAction(Intent.ACTION_VIEW) + ; + ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(m_gameLauncher, shortcutId) + .setShortLabel(gameName) + .setLongLabel(longName) + .setIcon(Icon.createWithResource(m_gameLauncher, iconId)) + .setIntent(intent) + .build(); + + Intent pinnedShortcutCallbackIntent = shortcutManager.createShortcutResultIntent(shortcutInfo); + PendingIntent successCallback = PendingIntent.getBroadcast(m_gameLauncher, 0, pinnedShortcutCallbackIntent, 0); + + try + { + if(shortcutManager.requestPinShortcut(shortcutInfo, successCallback.getIntentSender())) + Toast_long(Tr(R.string.create_desktop_shortcut_success, gameName, command)); + else + Toast_long(Tr(R.string.create_desktop_shortcut_fail, gameName, command)); + } + catch(Exception e) + { + e.printStackTrace(); + Toast_long(Tr(R.string.create_desktop_shortcut_fail, gameName, command) + ": " + e.getMessage()); + } + return; } } - else - { - Toast_long(R.string.unsupport_create_desktop_shortcut); - } + + Intent intent = new Intent(m_gameLauncher, activity); + + Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); + shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, gameName); + shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(m_gameLauncher, iconId)); + //shortcutIntent.putExtra("duplicate", false); + shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); + m_gameLauncher.sendBroadcast(shortcutIntent); + Toast_long(Tr(R.string.create_desktop_shortcut_success, gameName, command)); + //Toast_long(R.string.unsupport_create_desktop_shortcut); } } diff --git a/idTech4Amm/src/main/java/com/n0n3m4/DIII4A/launcher/CreateShortcutFunc.java b/idTech4Amm/src/main/java/com/n0n3m4/DIII4A/launcher/CreateShortcutFunc.java index a297e4991..ee8f94b4e 100644 --- a/idTech4Amm/src/main/java/com/n0n3m4/DIII4A/launcher/CreateShortcutFunc.java +++ b/idTech4Amm/src/main/java/com/n0n3m4/DIII4A/launcher/CreateShortcutFunc.java @@ -252,53 +252,63 @@ else if("game".equals(type)) @SuppressLint("NewApi") private void CreateShortcut(String game, int type) { - if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) - return; + boolean isLauncher = TYPE_LAUNCHER == type; + Class activity = isLauncher ? GameLauncher.class : Q3EMain.class; + int iconId = GameManager.GetGameIcon(game); + String gameName = Tr(GameManager.GetGameNameRS(game)); + String typeName = isLauncher ? Tr(R.string.launcher) : Tr(R.string.game); - ShortcutManager shortcutManager = (ShortcutManager) m_gameLauncher.getSystemService(Context.SHORTCUT_SERVICE); - if (null != shortcutManager && shortcutManager.isRequestPinShortcutSupported()) + if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) { - boolean isLauncher = TYPE_LAUNCHER == type; - int iconId = GameManager.GetGameIcon(game); - Class activity = isLauncher ? GameLauncher.class : Q3EMain.class; - String shortcutId = "idTech4Amm_" + game + "_" + (isLauncher ? "launcher" : "game"); - String gameName = Tr(GameManager.GetGameNameRS(game)); - String longName = gameName; - if(isLauncher) - longName += " " + Tr(R.string.launcher); - String typeName = isLauncher ? Tr(R.string.launcher) : Tr(R.string.game); + ShortcutManager shortcutManager = (ShortcutManager) m_gameLauncher.getSystemService(Context.SHORTCUT_SERVICE); + if (null != shortcutManager && shortcutManager.isRequestPinShortcutSupported()) + { + String shortcutId = "idTech4Amm_" + game + "_" + (isLauncher ? "launcher" : "game"); + String longName = gameName; + if(isLauncher) + longName += " " + Tr(R.string.launcher); - Intent intent = new Intent(m_gameLauncher, activity) - .putExtra("game", game) - .setAction(Intent.ACTION_VIEW) - ; - ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(m_gameLauncher, shortcutId) - .setShortLabel(gameName) - .setLongLabel(longName) - .setIcon(Icon.createWithResource(m_gameLauncher, iconId)) - .setIntent(intent) - .build(); + Intent intent = new Intent(m_gameLauncher, activity) + .putExtra("game", game) + .setAction(Intent.ACTION_VIEW) + ; + ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(m_gameLauncher, shortcutId) + .setShortLabel(gameName) + .setLongLabel(longName) + .setIcon(Icon.createWithResource(m_gameLauncher, iconId)) + .setIntent(intent) + .build(); - Intent pinnedShortcutCallbackIntent = shortcutManager.createShortcutResultIntent(shortcutInfo); - PendingIntent successCallback = PendingIntent.getBroadcast(m_gameLauncher, 0, pinnedShortcutCallbackIntent, 0); + Intent pinnedShortcutCallbackIntent = shortcutManager.createShortcutResultIntent(shortcutInfo); + PendingIntent successCallback = PendingIntent.getBroadcast(m_gameLauncher, 0, pinnedShortcutCallbackIntent, 0); - try - { - if(shortcutManager.requestPinShortcut(shortcutInfo, successCallback.getIntentSender())) - Toast_long(Tr(R.string.create_desktop_shortcut_success, gameName, typeName)); - else - Toast_long(Tr(R.string.create_desktop_shortcut_fail, gameName, typeName)); - } - catch(Exception e) - { - e.printStackTrace(); - Toast_long(Tr(R.string.create_desktop_shortcut_fail, gameName, typeName) + ": " + e.getMessage()); + try + { + if(shortcutManager.requestPinShortcut(shortcutInfo, successCallback.getIntentSender())) + Toast_long(Tr(R.string.create_desktop_shortcut_success, gameName, typeName)); + else + Toast_long(Tr(R.string.create_desktop_shortcut_fail, gameName, typeName)); + } + catch(Exception e) + { + e.printStackTrace(); + Toast_long(Tr(R.string.create_desktop_shortcut_fail, gameName, typeName) + ": " + e.getMessage()); + } + run(); + return; } - run(); - } - else - { - Toast_long(R.string.unsupport_create_desktop_shortcut); } + + Intent intent = new Intent(m_gameLauncher, activity); + + Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); + shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, gameName); + shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(m_gameLauncher, iconId)); + //shortcutIntent.putExtra("duplicate", false); + shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); + m_gameLauncher.sendBroadcast(shortcutIntent); + Toast_long(Tr(R.string.create_desktop_shortcut_success, gameName, typeName)); + //Toast_long(R.string.unsupport_create_desktop_shortcut); + run(); } }