From a44700a86d26a1f888297457b6393cf24b7cd626 Mon Sep 17 00:00:00 2001 From: Junyu Long <877730493@qq.com> Date: Sat, 31 Aug 2024 20:55:33 +0800 Subject: [PATCH] Box64rc: fixed cannot import rcp file. --- .../java/com/winlator/box86_64/rc/RCFile.java | 54 ++++++++++--------- .../com/winlator/box86_64/rc/RCManager.java | 28 +++++----- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/winlator/box86_64/rc/RCFile.java b/app/src/main/java/com/winlator/box86_64/rc/RCFile.java index 4d850c06..fbd4e14d 100644 --- a/app/src/main/java/com/winlator/box86_64/rc/RCFile.java +++ b/app/src/main/java/com/winlator/box86_64/rc/RCFile.java @@ -35,36 +35,38 @@ public void removeGroup(RCGroup group) { groups.remove(group); } - public void save() { - File file = getRCFile(context, id); + public JSONObject toJson() throws JSONException { + JSONObject profileData = new JSONObject(); + profileData.put("id", id); + profileData.put("name", name); + JSONArray groupsJSONArray = new JSONArray(); - try { - JSONObject profileData = new JSONObject(); - profileData.put("id", id); - profileData.put("name", name); - JSONArray groupsJSONArray = new JSONArray(); - - for (RCGroup group : groups) { - JSONObject groupData = new JSONObject(); - groupData.put("name", group.getGroupName()); - groupData.put("desc", group.getGroupDesc()); - groupData.put("enabled", group.isEnabled()); - JSONArray itemsJSONArray = new JSONArray(); - - for (RCItem item : group.getItems()) { - JSONObject itemData = new JSONObject(); - itemData.put("processName", item.getProcessName()); - itemData.put("desc", item.getItemDesc()); - itemData.put("vars", new JSONObject(item.getVarMap())); - itemsJSONArray.put(itemData); - } - groupData.put("items", itemsJSONArray); - groupsJSONArray.put(groupData); + for (RCGroup group : groups) { + JSONObject groupData = new JSONObject(); + groupData.put("name", group.getGroupName()); + groupData.put("desc", group.getGroupDesc()); + groupData.put("enabled", group.isEnabled()); + JSONArray itemsJSONArray = new JSONArray(); + + for (RCItem item : group.getItems()) { + JSONObject itemData = new JSONObject(); + itemData.put("processName", item.getProcessName()); + itemData.put("desc", item.getItemDesc()); + itemData.put("vars", new JSONObject(item.getVarMap())); + itemsJSONArray.put(itemData); } + groupData.put("items", itemsJSONArray); + groupsJSONArray.put(groupData); + } - profileData.put("groups", groupsJSONArray); + profileData.put("groups", groupsJSONArray); + return profileData; + } - FileUtils.writeString(file, profileData.toString()); + public void save() { + File file = getRCFile(context, id); + try { + FileUtils.writeString(file, this.toJson().toString()); } catch (JSONException e) { e.printStackTrace(); } diff --git a/app/src/main/java/com/winlator/box86_64/rc/RCManager.java b/app/src/main/java/com/winlator/box86_64/rc/RCManager.java index db676a77..54499d93 100644 --- a/app/src/main/java/com/winlator/box86_64/rc/RCManager.java +++ b/app/src/main/java/com/winlator/box86_64/rc/RCManager.java @@ -35,29 +35,33 @@ public RCManager(Context context) { } public RCFile duplicateRCFile(RCFile source) { - String newName; - for (int i = 1; ; i++) { - newName = source.getName() + " (" + i + ")"; - boolean found = false; - for (RCFile rcfile : rcfiles) { - if (rcfile.getName().equals(newName)) { - found = true; - break; + String newName = source.getName(); + for (RCFile rcFile : getRCFiles()) { + if (rcFile.getName().equals(newName)) { + for (int i = 1; ; i++) { + newName = source.getName() + " (" + i + ")"; + boolean found = false; + for (RCFile rcfile : rcfiles) { + if (rcfile.getName().equals(newName)) { + found = true; + break; + } + } + if (!found) break; } + break; } - if (!found) break; } int newId = ++maxRCFileId; File newFile = RCFile.getRCFile(context, newId); try { - JSONObject data = new JSONObject(FileUtils.readString(RCFile.getRCFile(context, source.id))); + JSONObject data = source.toJson(); data.put("id", newId); data.put("name", newName); FileUtils.writeString(newFile, data.toString()); - } catch (JSONException e) { - } + } catch (JSONException e) {} RCFile rcfile = loadRCFile(context, newFile); rcfiles.add(rcfile);