diff --git a/src/jni_driver.cpp b/src/jni_driver.cpp index 9df7c067..fbfae8ff 100644 --- a/src/jni_driver.cpp +++ b/src/jni_driver.cpp @@ -89,6 +89,7 @@ AlberFunction(void, Finalize)(JNIEnv* env, jobject obj) { emulator = nullptr; hidService = nullptr; renderer = nullptr; + romLoaded = false; } AlberFunction(jboolean, HasRomLoaded)(JNIEnv* env, jobject obj) { return romLoaded; } diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java index eebe354f..503684ac 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java @@ -15,6 +15,7 @@ import android.renderscript.Matrix3f; import android.renderscript.Matrix4f; import android.util.Log; import android.util.Rational; +import android.view.Display; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.Surface; @@ -209,6 +210,9 @@ public class GameActivity extends BaseActivity implements EmulatorCallback, Sens } private float getDeviceRotationAngle() { + if (getWindow().getDecorView() == null || getWindow().getDecorView().getDisplay() == null) + return 0.0f; + int rotation = getWindow().getDecorView().getDisplay().getRotation(); switch (rotation) { case Surface.ROTATION_90: return 90.0f; diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/BasePreferenceFragment.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/BasePreferenceFragment.java index 9426c098..ae8d49ad 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/BasePreferenceFragment.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/BasePreferenceFragment.java @@ -26,6 +26,10 @@ public abstract class BasePreferenceFragment extends PreferenceFragmentCompat { ((SwitchPreferenceCompat)findPreference(id)).setChecked(value); } + protected void setSummaryValue(String id,String text) { + findPreference(id).setSummary(text); + } + protected void setActivityTitle(@StringRes int titleId) { ActionBar header = ((AppCompatActivity) requireActivity()).getSupportActionBar(); if (header != null) { diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/preferences/GeneralPreferences.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/preferences/GeneralPreferences.java index 0b003db9..cf16bc50 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/preferences/GeneralPreferences.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/preferences/GeneralPreferences.java @@ -1,7 +1,13 @@ package com.panda3ds.pandroid.app.preferences; +import android.net.Uri; import android.os.Bundle; +import android.util.Log; +import android.widget.Toast; +import androidx.activity.result.ActivityResultCallback; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.Nullable; import androidx.preference.SwitchPreferenceCompat; @@ -10,8 +16,11 @@ import com.panda3ds.pandroid.app.PreferenceActivity; import com.panda3ds.pandroid.app.base.BasePreferenceFragment; import com.panda3ds.pandroid.app.preferences.screen_editor.ScreenLayoutsPreference; import com.panda3ds.pandroid.data.config.GlobalConfig; +import com.panda3ds.pandroid.utils.FileUtils; -public class GeneralPreferences extends BasePreferenceFragment { +public class GeneralPreferences extends BasePreferenceFragment implements ActivityResultCallback { + private final ActivityResultContracts.OpenDocument openFolderContract = new ActivityResultContracts.OpenDocument(); + private ActivityResultLauncher pickFileRequest; @Override public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) { setPreferencesFromResource(R.xml.general_preference, rootKey); @@ -21,6 +30,11 @@ public class GeneralPreferences extends BasePreferenceFragment { setItemClick("behavior.pictureInPicture", (pref)-> GlobalConfig.set(GlobalConfig.KEY_PICTURE_IN_PICTURE, ((SwitchPreferenceCompat)pref).isChecked())); setActivityTitle(R.string.general); refresh(); + + setItemClick("games.aes_key", pref -> pickFileRequest.launch(new String[]{ "text/plain" })); + setItemClick("games.seed_db", pref -> pickFileRequest.launch(new String[]{ "application/octet-stream" })); + + pickFileRequest = registerForActivityResult(openFolderContract, this); } @Override @@ -31,5 +45,45 @@ public class GeneralPreferences extends BasePreferenceFragment { private void refresh() { setSwitchValue("behavior.pictureInPicture", GlobalConfig.get(GlobalConfig.KEY_PICTURE_IN_PICTURE)); + setSummaryValue("games.aes_key", String.format(getString(FileUtils.exists(FileUtils.getPrivatePath()+"/sysdata/aes_keys.txt") ? R.string.file_available : R.string.file_not_available), "aes_key.txt")); + setSummaryValue("games.seed_db", String.format(getString(FileUtils.exists(FileUtils.getPrivatePath()+"/sysdata/seeddb.bin") ? R.string.file_available : R.string.file_not_available), "seeddb.bin")); } + + @Override + public void onDestroy() { + super.onDestroy(); + if (pickFileRequest != null) { + pickFileRequest.unregister(); + pickFileRequest = null; + } + } + + @Override + public void onActivityResult(Uri result) { + if (result != null) { + String path = result.toString(); + Log.w("File", path + " -> " + FileUtils.getName(path)); + switch (String.valueOf(FileUtils.getName(path))) { + case "aes_keys.txt": + case "seeddb.bin": { + String name = FileUtils.getName(path); + if (FileUtils.getLength(path) < 1024 * 256) { + String sysdataFolder = FileUtils.getPrivatePath() + "/sysdata"; + if (!FileUtils.exists(sysdataFolder)) { + FileUtils.createDir(FileUtils.getPrivatePath(), "sysdata"); + } + if (FileUtils.exists(sysdataFolder + "/" + name)) { + FileUtils.delete(sysdataFolder + "/" + name); + } + FileUtils.copyFile(path, FileUtils.getPrivatePath() + "/sysdata/", name); + Toast.makeText(getActivity(), String.format(getString(R.string.file_imported), name), Toast.LENGTH_LONG).show(); + } else { + Toast.makeText(getActivity(), R.string.invalid_file, Toast.LENGTH_LONG).show(); + } + } break; + default: Toast.makeText(getActivity(), R.string.invalid_file, Toast.LENGTH_LONG).show(); break; + } + refresh(); + } + } } diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/FileUtils.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/FileUtils.java index 85245454..26b029d9 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/FileUtils.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/FileUtils.java @@ -230,6 +230,10 @@ public class FileUtils { return parseFile(path).lastModified(); } + public static long getLength(String path) { + return parseFile(path).length(); + } + public static String[] listFiles(String path) { DocumentFile folder = parseFile(path); DocumentFile[] files = folder.listFiles(); diff --git a/src/pandroid/app/src/main/res/values-pt-rBR/strings.xml b/src/pandroid/app/src/main/res/values-pt-rBR/strings.xml index 0ecb1280..521f199e 100644 --- a/src/pandroid/app/src/main/res/values-pt-rBR/strings.xml +++ b/src/pandroid/app/src/main/res/values-pt-rBR/strings.xml @@ -92,4 +92,10 @@ Ferramentas Multiplicação precisa de shader Usar calculos mais precisos para shaders + Importar chaves + %s disponível + %s não disponível + Importar SeedDB + Arquivo inválido + %s Importado diff --git a/src/pandroid/app/src/main/res/values/strings.xml b/src/pandroid/app/src/main/res/values/strings.xml index 6f15e6dd..63a6c246 100644 --- a/src/pandroid/app/src/main/res/values/strings.xml +++ b/src/pandroid/app/src/main/res/values/strings.xml @@ -98,4 +98,10 @@ Invalid game Accurate shader multiplication Can improve rendering at a small performance loss + Import keys + %s imported + %s available + %s not available + Import SeedDB + Invalid file diff --git a/src/pandroid/app/src/main/res/xml/general_preference.xml b/src/pandroid/app/src/main/res/xml/general_preference.xml index 3e2d93c8..4352ee54 100644 --- a/src/pandroid/app/src/main/res/xml/general_preference.xml +++ b/src/pandroid/app/src/main/res/xml/general_preference.xml @@ -23,6 +23,16 @@ app:title="@string/pref_game_folders" app:summary="@string/pref_game_folders_summary" app:iconSpaceReserved="false"/> + +