Skip to content

Commit

Permalink
Box64rc: fixed cannot import rcp file.
Browse files Browse the repository at this point in the history
  • Loading branch information
longjunyu2 committed Aug 31, 2024
1 parent 65efe18 commit a44700a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 38 deletions.
54 changes: 28 additions & 26 deletions app/src/main/java/com/winlator/box86_64/rc/RCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
28 changes: 16 additions & 12 deletions app/src/main/java/com/winlator/box86_64/rc/RCManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a44700a

Please sign in to comment.