From 21b1b21aa503a1756a7b799b167535eb600d0c21 Mon Sep 17 00:00:00 2001 From: Ender's Games Date: Thu, 2 Aug 2018 19:27:16 -0400 Subject: [PATCH 1/5] Android: Android: reimplement stop as an actual "stop" --- .../src/main/java/com/reicast/emulator/emu/JNIdc.java | 1 + shell/android-studio/reicast/src/main/jni/src/Android.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/emu/JNIdc.java b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/emu/JNIdc.java index 716a2f006..f99168104 100644 --- a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/emu/JNIdc.java +++ b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/emu/JNIdc.java @@ -8,6 +8,7 @@ public final class JNIdc public static native void config(String dirName); public static native void init(String fileName); public static native void run(Object track); + public static native void stop(); public static native void terminate(); public static native int send(int cmd, int opt); diff --git a/shell/android-studio/reicast/src/main/jni/src/Android.cpp b/shell/android-studio/reicast/src/main/jni/src/Android.cpp index 0d6b5bddd..b62e3df84 100644 --- a/shell/android-studio/reicast/src/main/jni/src/Android.cpp +++ b/shell/android-studio/reicast/src/main/jni/src/Android.cpp @@ -25,6 +25,7 @@ extern "C" JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_config(JNIEnv *env,jobject obj,jstring dirName) __attribute__((visibility("default"))); JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_init(JNIEnv *env,jobject obj,jstring fileName) __attribute__((visibility("default"))); JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_run(JNIEnv *env,jobject obj,jobject emu_thread) __attribute__((visibility("default"))); + JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_stop(JNIEnv *env,jobject obj) __attribute__((visibility("default"))); JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_terminate(JNIEnv *env,jobject obj) __attribute__((visibility("default"))); JNIEXPORT jint JNICALL Java_com_reicast_emulator_emu_JNIdc_send(JNIEnv *env,jobject obj,jint id, jint v) __attribute__((visibility("default"))); @@ -158,6 +159,7 @@ void egl_stealcntx(); void SetApplicationPath(wchar *path); int dc_init(int argc,wchar* argv[]); void dc_run(); +void dc_stop(); void dc_term(); void mcfg_Create(MapleDeviceType type,u32 bus,u32 port); @@ -368,6 +370,11 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setupVmu(JNIEnv *env, //jpix=env->NewByteArray(1536); } +JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_stop(JNIEnv *env,jobject obj) +{ + dc_stop(); +} + JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_terminate(JNIEnv *env,jobject obj) { dc_term(); From 869cc5649a922ee01961dbff3085f77485295059 Mon Sep 17 00:00:00 2001 From: Ender's Games Date: Thu, 2 Aug 2018 19:27:25 -0400 Subject: [PATCH 2/5] Android: always touch the file (appropriately) --- .../reicast/src/main/java/com/reicast/emulator/FileBrowser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/FileBrowser.java b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/FileBrowser.java index 23042e977..06c8b739a 100644 --- a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/FileBrowser.java +++ b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/FileBrowser.java @@ -196,6 +196,7 @@ public class FileBrowser extends Fragment { buttons = new File(theme); } File file = new File(home_directory, "data/buttons.png"); + org.apache.commons.io.FileUtils.touch(file); if (buttons != null && buttons.exists()) { InputStream in = new FileInputStream(buttons); OutputStream out = new FileOutputStream(file); @@ -209,7 +210,6 @@ public class FileBrowser extends Fragment { in.close(); out.close(); } else if (!file.exists()) { - org.apache.commons.io.FileUtils.touch(file); InputStream png = getActivity().getAssets().open("buttons.png"); OutputStream fo = new FileOutputStream(file); byte[] buffer = new byte[4096]; From e38513a17ee248e84dd28fd40a71daa0ba22efc1 Mon Sep 17 00:00:00 2001 From: Ender's Games Date: Thu, 2 Aug 2018 19:46:03 -0400 Subject: [PATCH 3/5] Android: TODO: gain access to stop conservatively --- shell/android-studio/reicast/src/main/jni/src/Android.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/android-studio/reicast/src/main/jni/src/Android.cpp b/shell/android-studio/reicast/src/main/jni/src/Android.cpp index b62e3df84..827ce3fdb 100644 --- a/shell/android-studio/reicast/src/main/jni/src/Android.cpp +++ b/shell/android-studio/reicast/src/main/jni/src/Android.cpp @@ -159,7 +159,7 @@ void egl_stealcntx(); void SetApplicationPath(wchar *path); int dc_init(int argc,wchar* argv[]); void dc_run(); -void dc_stop(); +//void dc_stop(); void dc_term(); void mcfg_Create(MapleDeviceType type,u32 bus,u32 port); @@ -372,7 +372,7 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_setupVmu(JNIEnv *env, JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_stop(JNIEnv *env,jobject obj) { - dc_stop(); +// dc_stop(); } JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_terminate(JNIEnv *env,jobject obj) From a5fffb9e6c7c9f4a402440ab73c874abb60d4566 Mon Sep 17 00:00:00 2001 From: Ender's Games Date: Thu, 2 Aug 2018 21:46:38 -0400 Subject: [PATCH 4/5] Android: dump async to avoid lost write process --- .../reicast/src/main/assets/build | 2 +- .../com/reicast/emulator/FileBrowser.java | 73 ++++++++----------- 2 files changed, 33 insertions(+), 42 deletions(-) diff --git a/shell/android-studio/reicast/src/main/assets/build b/shell/android-studio/reicast/src/main/assets/build index 28a55ddd6..97c87766d 100644 --- a/shell/android-studio/reicast/src/main/assets/build +++ b/shell/android-studio/reicast/src/main/assets/build @@ -1 +1 @@ -9891979f2c0e9e9e8a8975e16aea9b4e943bd3aa \ No newline at end of file +33a3f7638836bf2529902d1521f97e8a24e565b5 \ No newline at end of file diff --git a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/FileBrowser.java b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/FileBrowser.java index 06c8b739a..d35b4a6ec 100644 --- a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/FileBrowser.java +++ b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/FileBrowser.java @@ -176,7 +176,7 @@ public class FileBrowser extends Fragment { if (!home.exists() || !home.isDirectory()) { showToastMessage(getActivity().getString(R.string.config_home), Snackbar.LENGTH_LONG); } else { - (new installGraphics()).execute(); + installButtons(); } if (!ImgBrowse && !games) { @@ -186,47 +186,38 @@ public class FileBrowser extends Fragment { } } - private class installGraphics extends AsyncTask { - @Override - protected String doInBackground(String... params) { - try { - File buttons = null; - String theme = mPrefs.getString(Config.pref_theme, null); - if (theme != null) { - buttons = new File(theme); - } - File file = new File(home_directory, "data/buttons.png"); - org.apache.commons.io.FileUtils.touch(file); - if (buttons != null && buttons.exists()) { - InputStream in = new FileInputStream(buttons); - OutputStream out = new FileOutputStream(file); - - // Transfer bytes from in to out - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - in.close(); - out.close(); - } else if (!file.exists()) { - InputStream png = getActivity().getAssets().open("buttons.png"); - OutputStream fo = new FileOutputStream(file); - byte[] buffer = new byte[4096]; - int read; - while ((read = png.read(buffer)) != -1) { - fo.write(buffer, 0, read); - } - png.close(); - fo.flush(); - fo.close(); - } - } catch (FileNotFoundException fnf) { - fnf.printStackTrace(); - } catch (IOException ioe) { - ioe.printStackTrace(); + private void installButtons() { + try { + File buttons = null; + String theme = mPrefs.getString(Config.pref_theme, null); + if (theme != null) { + buttons = new File(theme); } - return null; + File file = new File(home_directory, "data/buttons.png"); + org.apache.commons.io.FileUtils.touch(file); + InputStream in = null; + if (buttons != null && buttons.exists()) { + in = new FileInputStream(buttons); + } else if (!file.exists()) { + in = getActivity().getAssets().open("buttons.png"); + } + if (in != null) { + OutputStream out = new FileOutputStream(file); + + // Transfer bytes from in to out + byte[] buf = new byte[4096]; + int len; + while ((len = in.read(buf)) != -1) { + out.write(buf, 0, len); + } + in.close(); + out.flush(); + out.close(); + } + } catch (FileNotFoundException fnf) { + fnf.printStackTrace(); + } catch (IOException ioe) { + ioe.printStackTrace(); } } From f0f1190ddc25e053992460c6045588cf11413757 Mon Sep 17 00:00:00 2001 From: Ender's Games Date: Thu, 2 Aug 2018 22:11:13 -0400 Subject: [PATCH 5/5] Android: retry writing buttons if file is empty --- shell/android-studio/reicast/src/main/assets/build | 1 - .../src/main/java/com/reicast/emulator/FileBrowser.java | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 shell/android-studio/reicast/src/main/assets/build diff --git a/shell/android-studio/reicast/src/main/assets/build b/shell/android-studio/reicast/src/main/assets/build deleted file mode 100644 index 97c87766d..000000000 --- a/shell/android-studio/reicast/src/main/assets/build +++ /dev/null @@ -1 +0,0 @@ -33a3f7638836bf2529902d1521f97e8a24e565b5 \ No newline at end of file diff --git a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/FileBrowser.java b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/FileBrowser.java index d35b4a6ec..5b8c375ab 100644 --- a/shell/android-studio/reicast/src/main/java/com/reicast/emulator/FileBrowser.java +++ b/shell/android-studio/reicast/src/main/java/com/reicast/emulator/FileBrowser.java @@ -194,11 +194,10 @@ public class FileBrowser extends Fragment { buttons = new File(theme); } File file = new File(home_directory, "data/buttons.png"); - org.apache.commons.io.FileUtils.touch(file); InputStream in = null; if (buttons != null && buttons.exists()) { in = new FileInputStream(buttons); - } else if (!file.exists()) { + } else if (!file.exists() || file.length() == 0) { in = getActivity().getAssets().open("buttons.png"); } if (in != null) {