Skip to content

Commit

Permalink
rc: add support to manage .rcp file
Browse files Browse the repository at this point in the history
  • Loading branch information
longjunyu2 committed Aug 9, 2024
1 parent 681b1ff commit 3ea9d07
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 102 deletions.
1 change: 1 addition & 0 deletions app/src/main/assets/box86_64/rcfiles/box86_64rc-1.rcp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":1,"name":"Default","groups":[{"name":"Steam","desc":"","enabled":true,"items":[{"processName":"steam.exe","desc":"","vars":{"BOX64_CEFDISABLEGPU":"1","BOX64_DYNAREC_STRONGMEM":"1"}},{"processName":"steamwebhelper.exe","desc":"","vars":{"BOX64_DYNAREC_STRONGMEM":"1"}}]},{"name":"Flatout","desc":"","enabled":true,"items":[{"processName":"flatout.exe","desc":"","vars":{"BOX64_DYNAREC_BIGBLOCK":"3","BOX64_DYNAREC_CALLRET":"1"}}]}]}
224 changes: 134 additions & 90 deletions app/src/main/java/com/winlator/Box86_64RCFragment.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/src/main/java/com/winlator/InputControlsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
((AppCompatActivity)getActivity()).getSupportActionBar().setTitle(R.string.input_controls);
((AppCompatActivity)getActivity()).getSupportActionBar().setTitle(R.string.group_edit);
}

@Override
Expand Down
25 changes: 21 additions & 4 deletions app/src/main/java/com/winlator/box86_64/rc/RCField.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public enum RCField {
BOX64_DYNAREC_TRACE("BOX64_DYNAREC_TRACE", false),
BOX64_NODYNAREC("BOX64_NODYNAREC", false),
BOX64_DYNAREC_TEST("BOX64_DYNAREC_TEST", false),
BOX64_DYNAREC_BIGBLOCK("BOX64_DYNAREC_BIGBLOCK", true),
BOX64_DYNAREC_BIGBLOCK("BOX64_DYNAREC_BIGBLOCK", true, S.S4),
BOX64_DYNAREC_FORWARD("BOX64_DYNAREC_FORWARD", true),
BOX64_DYNAREC_STRONGMEM("BOX64_DYNAREC_STRONGMEM", true),
BOX64_DYNAREC_STRONGMEM("BOX64_DYNAREC_STRONGMEM", true, S.S4),
BOX64_DYNAREC_X87DOUBLE("BOX64_DYNAREC_X87DOUBLE", true),
BOX64_DYNAREC_FASTNAN("BOX64_DYNAREC_FASTNAN", true),
BOX64_DYNAREC_FASTROUND("BOX64_DYNAREC_FASTROUND", true),
BOX64_DYNAREC_SAFEFLAGS("BOX64_DYNAREC_SAFEFLAGS", true),
BOX64_DYNAREC_SAFEFLAGS("BOX64_DYNAREC_SAFEFLAGS", true, S.S3),
BOX64_DYNAREC_CALLRET("BOX64_DYNAREC_CALLRET", true),
BOX64_DYNAREC_ALIGNED_ATOMICS("BOX64_DYNAREC_ALIGNED_ATOMICS", false),
BOX64_DYNAREC_BLEEDING_EDGE("BOX64_DYNAREC_BLEEDING_EDGE", false),
Expand Down Expand Up @@ -82,18 +82,29 @@ public enum RCField {
BOX64_CEFDISABLEGPUCOMPOSITOR("BOX64_CEFDISABLEGPUCOMPOSITOR", true),
BOX64_AVX("BOX64_AVX", true);


private final String fieldName;
private final boolean enabled;
private final String[] selections;

RCField(String name, boolean enabled) {
this(name, enabled, S.S2);
}

RCField(String name, boolean enabled, String[] selections) {
this.fieldName = name;
this.enabled = enabled;
this.selections = selections;
}

public boolean isEnabled() {
return enabled;
}

public String[] getSelections() {
return selections;
}

@NonNull
@Override
public String toString() {
Expand All @@ -109,5 +120,11 @@ public static String[] getEnabledField() {
return list.toArray(new String[0]);
}


private static class S {
public static final String[] S2 = {"0", "1"};
public static final String[] S3 = {"0", "1", "2"};
public static final String[] S4 = {"0", "1", "2", "3"};
}
}


32 changes: 32 additions & 0 deletions app/src/main/java/com/winlator/box86_64/rc/RCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class RCFile implements Comparable<RCFile> {
public final int id;
Expand Down Expand Up @@ -80,6 +82,36 @@ public void setName(String name) {
this.name = name;
}

public String generateBox86_64rc() {
TreeMap<String, TreeMap<String, String>> rcMap = new TreeMap<>();
for (RCGroup group : groups) {
if (!group.isEnabled())
continue;
for (RCItem item : group.getItems()) {
TreeMap<String, String> varMap;
String processName = item.getProcessName();
if (rcMap.containsKey(processName))
varMap = rcMap.get(processName);
else {
varMap = new TreeMap<>();
rcMap.put(processName, varMap);
}
varMap.putAll(item.getVarMap());
}
}

StringBuilder strBuilder = new StringBuilder();
for (String processName : rcMap.keySet()) {
Map<String, String> varMap = rcMap.get(processName);
strBuilder.append('[').append(processName).append(']').append('\n');
for (String varName : varMap.keySet())
strBuilder.append(varName).append('=').append(varMap.get(varName)).append('\n');
strBuilder.append('\n');
}

return strBuilder.toString();
}

@NonNull
@Override
public String toString() {
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/com/winlator/box86_64/rc/RCManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,15 @@ public static RCFile loadRCFile(Context context, File file) {

public static RCFile loadRCFile(Context context, String json) {
try {
JSONObject rcfileJSONObject = new JSONObject(json);
return loadRCFile(context, new JSONObject(json));
} catch (JSONException e) {
return null;
}
}

public static RCFile loadRCFile(Context context, JSONObject obj) {
try {
JSONObject rcfileJSONObject = obj;
int rcfileId = rcfileJSONObject.getInt("id");
String rcfileName = rcfileJSONObject.getString("name");
LinkedList<RCGroup> groups = new LinkedList<>();
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/com/winlator/contentdialog/ContentDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -179,18 +180,19 @@ public static void showMultipleChoiceList(Context context, int titleResId, final

public static void showSingleChoiceList(Context context, int titleResId, final String[] items, Callback<Integer> callback) {
ContentDialog dialog = new ContentDialog(context);
dialog.getContentView().findViewById(R.id.BTConfirm).setVisibility(View.GONE);

final ListView listView = dialog.findViewById(R.id.ListView);
final ListView listView = dialog.findViewById(R.id.ListView);
listView.getLayoutParams().width = AppUtils.getPreferredDialogWidth(context);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setChoiceMode(ListView.CHOICE_MODE_NONE);
listView.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_list_item_single_choice, items));
listView.setVisibility(View.VISIBLE);

dialog.setTitle(titleResId);
dialog.setOnConfirmCallback(() -> {
callback.call(listView.getCheckedItemPosition());
listView.setOnItemClickListener((parent, view, position, id) -> {
callback.call(position);
dialog.dismiss();
});

dialog.setTitle(titleResId);
dialog.show();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.winlator.contentdialog;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;

import com.winlator.R;
import com.winlator.box86_64.rc.RCFile;
import com.winlator.box86_64.rc.RCGroup;
import com.winlator.box86_64.rc.RCManager;
import com.winlator.core.Callback;

import java.util.ArrayList;
import java.util.List;

public class ImportGroupDialog extends ContentDialog {
public ImportGroupDialog(View anchor, RCManager manager, Callback<RCGroup> callback) {
super(anchor.getContext(), R.layout.box86_64_rc_groups_dialog);
setIcon(R.drawable.icon_settings);
setTitle(anchor.getContext().getString(R.string.import_group));

final Spinner sProfile = findViewById(R.id.SProfile);
final ListView lvGroup = findViewById(R.id.LVGroup);

findViewById(R.id.BTConfirm).setVisibility(View.GONE);

List<RCFile> rcfiles = manager.getRCFiles();
List<String> rcfilesName = new ArrayList<>();
for (RCFile rcfile : rcfiles)
rcfilesName.add(rcfile.getName());
sProfile.setAdapter(new ArrayAdapter<>(anchor.getContext(), android.R.layout.simple_spinner_dropdown_item, rcfilesName));
sProfile.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
List<RCGroup> groups = rcfiles.get(position).getGroups();
List<String> groupsName = new ArrayList<>();
for (RCGroup group : groups)
groupsName.add(group.getGroupName());
lvGroup.setAdapter(new ArrayAdapter<>(anchor.getContext(), android.R.layout.simple_list_item_1, groupsName));
lvGroup.setOnItemClickListener((parent1, view1, position1, id1) -> {
RCGroup group = RCGroup.copy(groups.get(position1));
callback.call(group);
dismiss();
});
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
sProfile.setSelection(0, false);
}
}
22 changes: 22 additions & 0 deletions app/src/main/res/layout/box86_64_rc_groups_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="200dp"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/profile" />

<Spinner
android:id="@+id/SProfile"
style="@style/ComboBox"
android:layout_width="match_parent" />

<ListView
android:id="@+id/LVGroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp" />
</LinearLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/layout/box86_64_rc_var.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
android:layout_marginEnd="5dp"
android:layout_weight="2" />

<ImageButton
android:id="@+id/BTValueMenu"
style="@style/ListMenuButton"
android:layout_gravity="center"
android:src="@drawable/icon_menu" />

<EditText
android:id="@+id/ETValue"
style="@style/EditText"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,7 @@
<string name="do_you_want_to_remove_this_variable">Do you want to remove this variable?</string>
<string name="variable_name">Variable Name</string>
<string name="variable_already_exists">Variable already exists</string>
<string name="cannot_remove_default_profile">Cannot remove default profile.</string>
<string name="cannot_edit_default_profile">Cannot edit default profile.</string>
<string name="do_you_want_to_restore_default_profile">Do you want to restore default profile?</string>
</resources>

0 comments on commit 3ea9d07

Please sign in to comment.