From e42c16ba6d51bfd7514078268178790854a7e6fe Mon Sep 17 00:00:00 2001 From: gabriel Date: Wed, 13 Mar 2024 12:26:32 -0400 Subject: [PATCH 01/38] zip builder --- .../panda3ds/pandroid/utils/FileUtils.java | 9 ++- .../panda3ds/pandroid/utils/ZipBuilder.java | 61 +++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java 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 852454545..b5ff8cbab 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 @@ -2,11 +2,7 @@ import android.content.Context; import android.content.Intent; -import android.database.Cursor; import android.net.Uri; -import android.os.ParcelFileDescriptor; -import android.provider.DocumentsContract; -import android.system.Os; import android.util.Log; import androidx.documentfile.provider.DocumentFile; @@ -19,7 +15,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.StandardCharsets; -import java.util.Objects; public class FileUtils { public static final String MODE_READ = "r"; @@ -41,6 +36,10 @@ private static DocumentFile parseFile(String path) { return singleFile; } + public static long getLength(String path) { + return parseFile(path).length(); + } + private static Context getContext() { return PandroidApplication.getAppContext(); } diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java new file mode 100644 index 000000000..760e32f93 --- /dev/null +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java @@ -0,0 +1,61 @@ +package com.panda3ds.pandroid.utils; + +import java.io.InputStream; +import java.io.OutputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +public class ZipBuilder { + private final String outputPath, outputName; + private ZipOutputStream zip; + private OutputStream output; + + public ZipBuilder(String path, String name) { + outputPath = path; + outputName = name; + } + + public void begin() throws Exception { + String path = outputPath + "/" + outputName; + if (FileUtils.exists(path)) { + FileUtils.delete(path); + FileUtils.createFile(outputPath, outputName); + } + this.output = FileUtils.getOutputStream(path); + this.zip = new ZipOutputStream(output); + zip.setLevel(ZipOutputStream.DEFLATED); + } + + public void append(String path) throws Exception { + append(path, "/"); + } + + private void append(String path, String parent) throws Exception { + String name = FileUtils.getName(path); + if (FileUtils.isDirectory(path)) { + for (String child : FileUtils.listFiles(path)) { + append(path + "/" + child, parent + "/" + child); + } + } else { + ZipEntry entry = new ZipEntry((parent + "/" + name).replaceAll("//", "/")); + entry.setTime(FileUtils.getLastModified(path)); + entry.setSize(FileUtils.getLength(path)); + zip.putNextEntry(entry); + InputStream input = FileUtils.getInputStream(path); + byte[] buffer = new byte[1024 * 64]; + int len; + while ((len = input.read(buffer)) != -1) { + output.write(buffer, 0, len); + } + input.close(); + zip.flush(); + zip.closeEntry(); + } + } + + public void end() throws Exception { + zip.flush(); + zip.close(); + output.close(); + } +} \ No newline at end of file From 126169ef5f777fede66598475be7f087bea43ecb Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Fri, 15 Mar 2024 22:58:14 +0530 Subject: [PATCH 02/38] add an option to share log file (#38) --- src/config.cpp | 5 +- src/pandroid/app/src/main/AndroidManifest.xml | 10 +++ .../panda3ds/pandroid/app/GameActivity.java | 1 + .../pandroid/app/main/SettingsFragment.java | 2 +- .../app/preferences/AdvancedPreferences.java | 35 ++++++++ .../app/src/main/res/drawable/ic_share.xml | 11 +++ .../src/main/res/values-pt-rBR/strings.xml | 1 - .../app/src/main/res/values/strings.xml | 80 ++++++++++--------- .../src/main/res/xml/advanced_preferences.xml | 29 +++++-- .../app/src/main/res/xml/file_paths.xml | 4 + .../src/main/res/xml/start_preferences.xml | 2 +- src/pandroid/build.gradle.kts | 4 +- 12 files changed, 131 insertions(+), 53 deletions(-) create mode 100644 src/pandroid/app/src/main/res/drawable/ic_share.xml create mode 100644 src/pandroid/app/src/main/res/xml/file_paths.xml diff --git a/src/config.cpp b/src/config.cpp index f19ff06dd..299ef5946 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include "helpers.hpp" @@ -99,13 +100,13 @@ void EmulatorConfig::load() { } void EmulatorConfig::save() { - toml::basic_value data; + toml::basic_value data; const std::filesystem::path& path = filePath; std::error_code error; if (std::filesystem::exists(path, error)) { try { - data = toml::parse(path); + data = toml::parse(path); } catch (const std::exception& ex) { Helpers::warn("Exception trying to parse config file. Exception: %s\n", ex.what()); return; diff --git a/src/pandroid/app/src/main/AndroidManifest.xml b/src/pandroid/app/src/main/AndroidManifest.xml index d47ae2bb2..18120f338 100644 --- a/src/pandroid/app/src/main/AndroidManifest.xml +++ b/src/pandroid/app/src/main/AndroidManifest.xml @@ -23,6 +23,16 @@ + + + + PreferenceActivity.launch(requireContext(), GeneralPreferences.class)); setItemClick("advanced", (item)-> PreferenceActivity.launch(requireContext(), AdvancedPreferences.class)); } - + private String getVersionName() { try { Context context = PandroidApplication.getAppContext(); diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/preferences/AdvancedPreferences.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/preferences/AdvancedPreferences.java index 176bab14d..76fd9dce2 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/preferences/AdvancedPreferences.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/preferences/AdvancedPreferences.java @@ -4,15 +4,22 @@ import android.content.Intent; import android.os.Bundle; import android.os.Build; +import androidx.core.content.FileProvider; +import android.widget.Toast; +import android.content.Intent; +import android.net.Uri; import androidx.annotation.Nullable; import androidx.preference.SwitchPreferenceCompat; +import androidx.preference.Preference; +import androidx.preference.PreferenceFragmentCompat; import com.panda3ds.pandroid.R; import com.panda3ds.pandroid.app.PandroidApplication; import com.panda3ds.pandroid.app.base.BasePreferenceFragment; import com.panda3ds.pandroid.app.services.LoggerService; import com.panda3ds.pandroid.data.config.GlobalConfig; +import java.io.File; public class AdvancedPreferences extends BasePreferenceFragment { @Override @@ -20,14 +27,19 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable S setPreferencesFromResource(R.xml.advanced_preferences, rootKey); setActivityTitle(R.string.advanced_options); + setItemClick("shareLog", pref -> { + shareLogFile(); + }); setItemClick("performanceMonitor", pref -> GlobalConfig.set(GlobalConfig.KEY_SHOW_PERFORMANCE_OVERLAY, ((SwitchPreferenceCompat) pref).isChecked())); setItemClick("shaderJit", pref -> GlobalConfig.set(GlobalConfig.KEY_SHADER_JIT, ((SwitchPreferenceCompat) pref).isChecked())); setItemClick("loggerService", pref -> { boolean checked = ((SwitchPreferenceCompat) pref).isChecked(); Context ctx = PandroidApplication.getAppContext(); if (checked) { + findPreference("shareLog").setVisible(true); ctx.startService(new Intent(ctx, LoggerService.class)); } else { + findPreference("shareLog").setVisible(false); ctx.stopService(new Intent(ctx, LoggerService.class)); } GlobalConfig.set(GlobalConfig.KEY_LOGGER_SERVICE, checked); @@ -43,8 +55,31 @@ public void onResume() { } private void refresh() { + if (GlobalConfig.get(GlobalConfig.KEY_LOGGER_SERVICE)) { + findPreference("shareLog").setVisible(true); + } else { + findPreference("shareLog").setVisible(false); + } ((SwitchPreferenceCompat) findPreference("performanceMonitor")).setChecked(GlobalConfig.get(GlobalConfig.KEY_SHOW_PERFORMANCE_OVERLAY)); ((SwitchPreferenceCompat) findPreference("loggerService")).setChecked(GlobalConfig.get(GlobalConfig.KEY_LOGGER_SERVICE)); ((SwitchPreferenceCompat) findPreference("shaderJit")).setChecked(GlobalConfig.get(GlobalConfig.KEY_SHADER_JIT)); } + + private void shareLogFile() { + String filePath = "/storage/emulated/0/Android/media/com.panda3ds.pandroid/logs/current.txt"; + File file = new File(filePath); + + // Check if the log file exists and then share + if (file.exists()) { + Uri uri = FileProvider.getUriForFile(requireContext(), "com.panda3ds.pandroid.fileprovider", file); + + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_STREAM, uri); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + startActivity(Intent.createChooser(intent, "Share Log File")); + } else { + Toast.makeText(requireContext(), getString(R.string.no_log_file_found), Toast.LENGTH_SHORT).show(); + } + } } diff --git a/src/pandroid/app/src/main/res/drawable/ic_share.xml b/src/pandroid/app/src/main/res/drawable/ic_share.xml new file mode 100644 index 000000000..5c9ff4702 --- /dev/null +++ b/src/pandroid/app/src/main/res/drawable/ic_share.xml @@ -0,0 +1,11 @@ + + + + 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 f2e144c3e..0a61f29ec 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 @@ -89,5 +89,4 @@ Taiwan Comportamento Jogo invalido - Ferramentas diff --git a/src/pandroid/app/src/main/res/values/strings.xml b/src/pandroid/app/src/main/res/values/strings.xml index 255695286..15c93d6f6 100644 --- a/src/pandroid/app/src/main/res/values/strings.xml +++ b/src/pandroid/app/src/main/res/values/strings.xml @@ -1,6 +1,6 @@ - pandroid + pandroid Load ROM Games Settings @@ -26,7 +26,8 @@ Screen gamepad layouts Default screen gamepad layout Invalid name - + + General Theme Set application theme Appearance @@ -34,34 +35,38 @@ Light Dark Black - - Actions - Exit - Resume - Hacks - Lua script - Scripts - File type isn\'t supported - Save and exit - Exit without saving - Exit without saving \"%s\"? - Open file - Create new - Running \"%s\" ... - Rotate + General application configuration. + Screen layouts + Change layout of console screens. + Click to change + Folders for importing games + Game folders + Import folder + %d Games + Directory + Remove + Behavior + Picture In Picture + Minimize window when placed in the background. + + Maintain aspect ratio + Bottom Display + Top Display Advanced options Logger, performance statistics, etc. + Display Performance monitor Show overlay with fps, memory, etc. - Picture In Picture - Minimize window when placed in the background. Graphics Shader JIT Use shader recompiler. - Tools + Debug Logger Store application logs to file. + Share Log + Share Pandroid\'s log to check issues. + No log file found Loading Apply Set application theme @@ -69,23 +74,6 @@ Failed to load ROM Make sure it\'s a valid 3DS ROM and that storage permissions are configured properly. System - General - General application configuration. - Screen layouts - Change layout of console screens. - Click to change - Swap screen - Folders for importing games - Game folders - Import folder - %d Games - Directory - Remove - Play - - Maintain aspect ratio - Bottom Display - Top Display Region North American @@ -94,6 +82,22 @@ Australia Korean Taiwan - Behavior Invalid game + Play + + Actions + Resume + Swap screen + Exit + Hacks + Lua script + Scripts + File type isn\'t supported + Save and exit + Exit without saving + Exit without saving \"%s\"? + Open file + Create new + Running \"%s\" ... + Rotate diff --git a/src/pandroid/app/src/main/res/xml/advanced_preferences.xml b/src/pandroid/app/src/main/res/xml/advanced_preferences.xml index 6602fdfdc..04a614abc 100644 --- a/src/pandroid/app/src/main/res/xml/advanced_preferences.xml +++ b/src/pandroid/app/src/main/res/xml/advanced_preferences.xml @@ -3,19 +3,15 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> + - - + + + + + + + + - \ No newline at end of file + diff --git a/src/pandroid/app/src/main/res/xml/file_paths.xml b/src/pandroid/app/src/main/res/xml/file_paths.xml new file mode 100644 index 000000000..4ff893110 --- /dev/null +++ b/src/pandroid/app/src/main/res/xml/file_paths.xml @@ -0,0 +1,4 @@ + + + + diff --git a/src/pandroid/app/src/main/res/xml/start_preferences.xml b/src/pandroid/app/src/main/res/xml/start_preferences.xml index 788000d61..b0ed28245 100644 --- a/src/pandroid/app/src/main/res/xml/start_preferences.xml +++ b/src/pandroid/app/src/main/res/xml/start_preferences.xml @@ -31,4 +31,4 @@ app:summary="@string/pref_advanced_summary" app:layout="@layout/preference_start_item"/> - \ No newline at end of file + diff --git a/src/pandroid/build.gradle.kts b/src/pandroid/build.gradle.kts index c21801c71..ad48b9cdb 100644 --- a/src/pandroid/build.gradle.kts +++ b/src/pandroid/build.gradle.kts @@ -1,4 +1,4 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. +// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id("com.android.application") version "8.1.2" apply false -} \ No newline at end of file +} From 8309f2fdba2bb7f21033d2019df9a86913ddb241 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sat, 16 Mar 2024 14:31:37 +0530 Subject: [PATCH 03/38] add ui for save import and export --- .../src/main/res/layout/dialog_game_about.xml | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml index 3a91ae2ca..28ca1d368 100644 --- a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml +++ b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml @@ -81,6 +81,41 @@ android:text="@string/app_name" android:alpha="0.76" android:textSize="15sp"/> + + + + + + + + + - \ No newline at end of file + From 447bf21decef0d6c887ab4c6ad6f7be641ff2d81 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sat, 16 Mar 2024 14:44:00 +0530 Subject: [PATCH 04/38] add strings for the button --- src/pandroid/app/src/main/res/values/strings.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pandroid/app/src/main/res/values/strings.xml b/src/pandroid/app/src/main/res/values/strings.xml index 15c93d6f6..e6cb855e1 100644 --- a/src/pandroid/app/src/main/res/values/strings.xml +++ b/src/pandroid/app/src/main/res/values/strings.xml @@ -84,6 +84,9 @@ Taiwan Invalid game Play + Save Management + Import + Export Actions Resume From 460c71c24565782d04b398f0216ec66a4f21f4aa Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sat, 16 Mar 2024 15:51:33 +0530 Subject: [PATCH 05/38] fixes colors --- .../app/src/main/res/layout/dialog_game_about.xml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml index 28ca1d368..6fb15a5fe 100644 --- a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml +++ b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml @@ -104,7 +104,10 @@ android:layout_height="wrap_content" android:contentDescription="@string/import_save" android:text="@string/import_save" - app:icon="@drawable/ic_add" /> + app:icon="@drawable/ic_add" + app:iconTint="?colorOnSurfaceVariant" + android:textColor="?colorOnSurfaceVariant" + android:backgroundTint="?colorSurfaceVariant" /> + app:icon="@drawable/ic_share" + app:iconTint="?colorOnSurfaceVariant" + android:textColor="?colorOnSurfaceVariant" + android:backgroundTint="?colorSurfaceVariant"/> From c43716fcd0d39498d977a142b21c22ec969f75f7 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sat, 16 Mar 2024 17:57:58 +0530 Subject: [PATCH 06/38] more ui things --- .../src/main/res/layout/dialog_game_about.xml | 36 ++++--------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml index 6fb15a5fe..a34268ec7 100644 --- a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml +++ b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml @@ -91,37 +91,15 @@ android:textStyle="bold" android:layout_marginTop="20dp" /> - - - - - - + android:contentDescription="@string/manage_save" + android:text="@string/manage_save" + android:textSize="15sp" + android:textColor="?colorOnSurfaceVariant" /> Date: Sat, 16 Mar 2024 21:25:09 +0530 Subject: [PATCH 07/38] fix strings --- src/pandroid/app/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pandroid/app/src/main/res/values/strings.xml b/src/pandroid/app/src/main/res/values/strings.xml index e6cb855e1..25a462bf5 100644 --- a/src/pandroid/app/src/main/res/values/strings.xml +++ b/src/pandroid/app/src/main/res/values/strings.xml @@ -87,6 +87,7 @@ Save Management Import Export + Manage Save Data Actions Resume From 4293e4420b2ca350cd048679dccbeb628a5adfbd Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sun, 17 Mar 2024 10:25:45 +0530 Subject: [PATCH 08/38] fix --- src/pandroid/app/src/main/res/layout/dialog_game_about.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml index a34268ec7..c3f7482ec 100644 --- a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml +++ b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml @@ -92,11 +92,12 @@ android:layout_marginTop="20dp" /> From 650332a310a8e17f545b3db432384e54bcdfd558 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sun, 17 Mar 2024 11:27:18 +0530 Subject: [PATCH 09/38] bonk --- src/pandroid/app/src/main/res/layout/dialog_game_about.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml index c3f7482ec..221460438 100644 --- a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml +++ b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml @@ -93,7 +93,7 @@ Date: Tue, 19 Mar 2024 13:49:56 +0530 Subject: [PATCH 10/38] bonk --- src/pandroid/app/src/main/res/layout/dialog_game_about.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml index 221460438..e4120ba3a 100644 --- a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml +++ b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml @@ -91,13 +91,11 @@ android:textStyle="bold" android:layout_marginTop="20dp" /> - From 591a275f84d9b567c186a8d5d54ce72b3efeee64 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Tue, 19 Mar 2024 14:54:38 +0530 Subject: [PATCH 11/38] Bonk --- .../src/main/res/layout/dialog_game_about.xml | 61 +++++++++++-------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml index e4120ba3a..33b7a5a67 100644 --- a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml +++ b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml @@ -81,24 +81,6 @@ android:text="@string/app_name" android:alpha="0.76" android:textSize="15sp"/> - - - - + + + + + + + android:text="@string/manage_save" + app:icon="@drawable/ic_shortcut" + app:iconTint="?colorOnSurfaceVariant" + android:textColor="?colorOnSurfaceVariant" + android:backgroundTint="?colorSurfaceVariant" + style="@style/Widget.Material3.Button.TonalButton.Icon"/> From b362cf35ad9f83d46f50f1c40bbab164c135b9b3 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:38:27 +0530 Subject: [PATCH 12/38] done --- .../src/main/res/layout/dialog_game_about.xml | 84 +++++++++++-------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml index 33b7a5a67..6fb15a5fe 100644 --- a/src/pandroid/app/src/main/res/layout/dialog_game_about.xml +++ b/src/pandroid/app/src/main/res/layout/dialog_game_about.xml @@ -81,6 +81,47 @@ android:text="@string/app_name" android:alpha="0.76" android:textSize="15sp"/> + + + + + + + + + - - - - - - + android:text="@string/play" + android:textColor="?colorOnPrimary" + android:backgroundTint="?colorPrimary" + app:icon="@drawable/ic_play" + app:rippleColor="?colorOnPrimary" + app:iconTint="?colorOnPrimary"/> From bddb1ea31e0038040e65f6d1331de87d6036118e Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:50:06 +0530 Subject: [PATCH 13/38] (wip) add export save functions --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 7fd6ed366..1e78381cd 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -47,6 +47,10 @@ protected void onCreate(Bundle savedInstanceState) { dismiss(); makeShortcut(); }); + findViewById(R.id.export_save).setOnClickListener(v -> { + String appPath = FileUtils.getPrivatePath(); + + }); if (game.getRomPath().startsWith("folder:")) { findViewById(R.id.remove).setVisibility(View.GONE); From 3508e819eff4cdba3c62b2cb2631db35a9a1cea9 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Wed, 20 Mar 2024 21:17:59 +0530 Subject: [PATCH 14/38] (wip) add export save functions --- .../pandroid/app/base/GameAboutDialog.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 1e78381cd..24e6b74ce 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -48,7 +48,27 @@ protected void onCreate(Bundle savedInstanceState) { makeShortcut(); }); findViewById(R.id.export_save).setOnClickListener(v -> { - String appPath = FileUtils.getPrivatePath(); + String inputPath = FileUtils.getPrivatePath() + game.getTitle() + "/SaveData"; + String outputPath = "/storage/emulated/0/"; + String outputName = "export.zip"; + + // Create an instance of ZipBuilder + ZipBuilder zipBuilder = new ZipBuilder(outputPath, outputName); + + try { + // Begin the zip file creation process + zipBuilder.begin(); + + // Append files or folders to the zip file + zipBuilder.append(inputPath); + + // End the zip file creation process + zipBuilder.end(); + + System.out.println("Zip file created successfully."); + } catch (Exception e) { + System.err.println("Error creating zip file: " + e.getMessage()); + } }); From c7a37a50be50937f326a7007dd053f8775f0bd51 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Wed, 20 Mar 2024 21:22:32 +0530 Subject: [PATCH 15/38] fixes --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 24e6b74ce..361a39c5d 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -19,6 +19,7 @@ import com.panda3ds.pandroid.data.game.GameMetadata; import com.panda3ds.pandroid.utils.CompatUtils; import com.panda3ds.pandroid.utils.FileUtils; +import com.panda3ds.pandroid.utils.ZipBuilder; import com.panda3ds.pandroid.utils.GameUtils; import com.panda3ds.pandroid.view.gamesgrid.GameIconView; From 63ef1f648afa4f1ff3dcf9d90d23768d0a3e2e95 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Wed, 20 Mar 2024 21:49:28 +0530 Subject: [PATCH 16/38] fix permission issue --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 361a39c5d..ee86f4231 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -50,7 +50,7 @@ protected void onCreate(Bundle savedInstanceState) { }); findViewById(R.id.export_save).setOnClickListener(v -> { String inputPath = FileUtils.getPrivatePath() + game.getTitle() + "/SaveData"; - String outputPath = "/storage/emulated/0/"; + String outputPath = "/storage/emulated/0/Android/media/com.panda3ds.pandroid/"; String outputName = "export.zip"; // Create an instance of ZipBuilder From 4411780a09d4e445db2ea8af8f940d20806c45ee Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Wed, 20 Mar 2024 22:16:44 +0530 Subject: [PATCH 17/38] fixes incorrect path --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index ee86f4231..065c765cd 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -49,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) { makeShortcut(); }); findViewById(R.id.export_save).setOnClickListener(v -> { - String inputPath = FileUtils.getPrivatePath() + game.getTitle() + "/SaveData"; + String inputPath = FileUtils.getPrivatePath() + "/", + game.getTitle() + "/SaveData"; String outputPath = "/storage/emulated/0/Android/media/com.panda3ds.pandroid/"; String outputName = "export.zip"; From 2b3f8ac3c5c5f98804a26382cf62b752e8fa5c52 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Thu, 21 Mar 2024 00:48:15 +0530 Subject: [PATCH 18/38] Bonk --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 065c765cd..6258fc4f4 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -49,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) { makeShortcut(); }); findViewById(R.id.export_save).setOnClickListener(v -> { - String inputPath = FileUtils.getPrivatePath() + "/", + game.getTitle() + "/SaveData"; + String inputPath = FileUtils.getPrivatePath() + "/" + game.getTitle() + "/SaveData"; String outputPath = "/storage/emulated/0/Android/media/com.panda3ds.pandroid/"; String outputName = "export.zip"; From 97b30e4376aa23cea8c70297cdc7a2db5981d8f9 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Thu, 21 Mar 2024 10:39:13 +0530 Subject: [PATCH 19/38] fixes incorrect savedata path --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 6258fc4f4..e527837f5 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -49,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) { makeShortcut(); }); findViewById(R.id.export_save).setOnClickListener(v -> { - String inputPath = FileUtils.getPrivatePath() + "/" + game.getTitle() + "/SaveData"; + String inputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()) + "/SaveData/"; String outputPath = "/storage/emulated/0/Android/media/com.panda3ds.pandroid/"; String outputName = "export.zip"; From 6d38a568e923f02a9739f133d3be15ad3969a9e0 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Thu, 21 Mar 2024 14:34:38 +0530 Subject: [PATCH 20/38] fixes --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index e527837f5..7013f7079 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -49,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) { makeShortcut(); }); findViewById(R.id.export_save).setOnClickListener(v -> { - String inputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()) + "/SaveData/"; + String inputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()).replaceAll("\\..*", "") + "/SaveData/"; String outputPath = "/storage/emulated/0/Android/media/com.panda3ds.pandroid/"; String outputName = "export.zip"; From a90532ccb1ac8e0ffba2fa7c35c1536360eba553 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Thu, 21 Mar 2024 21:25:17 +0530 Subject: [PATCH 21/38] ZipBuilder: fixes --- .../src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java index 760e32f93..604569621 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java @@ -45,7 +45,7 @@ private void append(String path, String parent) throws Exception { byte[] buffer = new byte[1024 * 64]; int len; while ((len = input.read(buffer)) != -1) { - output.write(buffer, 0, len); + zip.write(buffer, 0, len); } input.close(); zip.flush(); @@ -58,4 +58,4 @@ public void end() throws Exception { zip.close(); output.close(); } -} \ No newline at end of file +} From fbed49f8963bba10597c40bd1a7fe7a79ac96215 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:55:21 +0530 Subject: [PATCH 22/38] fixes --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 7013f7079..9bdb05413 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -56,6 +56,8 @@ protected void onCreate(Bundle savedInstanceState) { // Create an instance of ZipBuilder ZipBuilder zipBuilder = new ZipBuilder(outputPath, outputName); + + new Task(()->{ try { // Begin the zip file creation process zipBuilder.begin(); @@ -72,6 +74,7 @@ protected void onCreate(Bundle savedInstanceState) { } }); + }).start(); if (game.getRomPath().startsWith("folder:")) { findViewById(R.id.remove).setVisibility(View.GONE); From 995c0a17a77665b2a1e5ebe9e1dedb2e31086c58 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:56:32 +0530 Subject: [PATCH 23/38] bonk --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 9bdb05413..e4cb31233 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -57,7 +57,7 @@ protected void onCreate(Bundle savedInstanceState) { ZipBuilder zipBuilder = new ZipBuilder(outputPath, outputName); - new Task(()->{ + new Task(()->{ try { // Begin the zip file creation process zipBuilder.begin(); @@ -72,9 +72,8 @@ protected void onCreate(Bundle savedInstanceState) { } catch (Exception e) { System.err.println("Error creating zip file: " + e.getMessage()); } - + }).start(); }); - }).start(); if (game.getRomPath().startsWith("folder:")) { findViewById(R.id.remove).setVisibility(View.GONE); From 7836b93206f14fbac62f019f014571ade75baca0 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Fri, 29 Mar 2024 00:19:38 +0530 Subject: [PATCH 24/38] fixes --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index e4cb31233..7187c81f9 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -22,6 +22,7 @@ import com.panda3ds.pandroid.utils.ZipBuilder; import com.panda3ds.pandroid.utils.GameUtils; import com.panda3ds.pandroid.view.gamesgrid.GameIconView; +import com.panda3ds.pandroid.lang.Task; public class GameAboutDialog extends BaseSheetDialog { private final GameMetadata game; From 0c250f29770a4a123633edd9505bcc838d0270d2 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sat, 6 Apr 2024 10:19:06 +0530 Subject: [PATCH 25/38] fix zip builder --- .../src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java index 604569621..81cde7098 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipBuilder.java @@ -34,7 +34,7 @@ private void append(String path, String parent) throws Exception { String name = FileUtils.getName(path); if (FileUtils.isDirectory(path)) { for (String child : FileUtils.listFiles(path)) { - append(path + "/" + child, parent + "/" + child); + append(path + "/" + child, parent + "/" + name); } } else { ZipEntry entry = new ZipEntry((parent + "/" + name).replaceAll("//", "/")); From 70c710d82a31d180c1164fea22e8805717ec90dc Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sun, 14 Apr 2024 13:34:04 +0530 Subject: [PATCH 26/38] bonk --- .../pandroid/app/base/GameAboutDialog.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 7187c81f9..5bcd5d7e8 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -12,6 +12,7 @@ import androidx.core.content.pm.ShortcutInfoCompat; import androidx.core.content.pm.ShortcutManagerCompat; import androidx.core.graphics.drawable.IconCompat; +import androidx.documentfile.provider.DocumentFile; import com.panda3ds.pandroid.R; import com.panda3ds.pandroid.app.PandroidApplication; @@ -26,6 +27,7 @@ public class GameAboutDialog extends BaseSheetDialog { private final GameMetadata game; + private static final String MIME_TYPE_ZIP = "application/zip"; public GameAboutDialog(@NonNull Context context, GameMetadata game) { super(context); this.game = game; @@ -52,7 +54,7 @@ protected void onCreate(Bundle savedInstanceState) { findViewById(R.id.export_save).setOnClickListener(v -> { String inputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()).replaceAll("\\..*", "") + "/SaveData/"; String outputPath = "/storage/emulated/0/Android/media/com.panda3ds.pandroid/"; - String outputName = "export.zip"; + String outputName = game.getTitle() + ".zip"; // Create an instance of ZipBuilder ZipBuilder zipBuilder = new ZipBuilder(outputPath, outputName); @@ -70,12 +72,22 @@ protected void onCreate(Bundle savedInstanceState) { zipBuilder.end(); System.out.println("Zip file created successfully."); + createDocument(MIME_TYPE_ZIP, outputName, outputPath); } catch (Exception e) { System.err.println("Error creating zip file: " + e.getMessage()); } }).start(); }); + private void createDocument(@NonNull String mimeType, String fileName, String outputDirPath) { + Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType(mimeType); + intent.putExtra(Intent.EXTRA_TITLE, fileName); + intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Uri.fromFile(new File(outputDirPath))); + startActivityForResult(intent, 1); + } + if (game.getRomPath().startsWith("folder:")) { findViewById(R.id.remove).setVisibility(View.GONE); } else { From 6bfd47271cc3ab8744785028ada55f88051fbb72 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sun, 14 Apr 2024 14:03:09 +0530 Subject: [PATCH 27/38] pain --- .../pandroid/app/base/GameAboutDialog.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 5bcd5d7e8..40a27f9e6 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -79,15 +79,6 @@ protected void onCreate(Bundle savedInstanceState) { }).start(); }); - private void createDocument(@NonNull String mimeType, String fileName, String outputDirPath) { - Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType(mimeType); - intent.putExtra(Intent.EXTRA_TITLE, fileName); - intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Uri.fromFile(new File(outputDirPath))); - startActivityForResult(intent, 1); - } - if (game.getRomPath().startsWith("folder:")) { findViewById(R.id.remove).setVisibility(View.GONE); } else { @@ -101,6 +92,15 @@ private void createDocument(@NonNull String mimeType, String fileName, String ou } } + private void createDocument(@NonNull String mimeType, String fileName, String outputDirPath) { + Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType(mimeType); + intent.putExtra(Intent.EXTRA_TITLE, fileName); + intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Uri.fromFile(new File(outputDirPath))); + startActivityForResult(intent, 1); + } + // Make a shortcut for a specific game private void makeShortcut() { Context context = CompatUtils.findActivity(getContext()); From 6ad1f9ca48cd0e8e05e76c1bf2e9316f8141fe0d Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sun, 14 Apr 2024 14:37:44 +0530 Subject: [PATCH 28/38] Fixes --- .../com/panda3ds/pandroid/app/base/GameAboutDialog.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 40a27f9e6..109aba5b7 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -12,7 +12,9 @@ import androidx.core.content.pm.ShortcutInfoCompat; import androidx.core.content.pm.ShortcutManagerCompat; import androidx.core.graphics.drawable.IconCompat; +import androidx.appcompat.app.AppCompatActivity; import androidx.documentfile.provider.DocumentFile; +import android.provider.DocumentsContract; import com.panda3ds.pandroid.R; import com.panda3ds.pandroid.app.PandroidApplication; @@ -24,6 +26,7 @@ import com.panda3ds.pandroid.utils.GameUtils; import com.panda3ds.pandroid.view.gamesgrid.GameIconView; import com.panda3ds.pandroid.lang.Task; +import java.io.File; public class GameAboutDialog extends BaseSheetDialog { private final GameMetadata game; @@ -98,7 +101,11 @@ private void createDocument(@NonNull String mimeType, String fileName, String ou intent.setType(mimeType); intent.putExtra(Intent.EXTRA_TITLE, fileName); intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Uri.fromFile(new File(outputDirPath))); - startActivityForResult(intent, 1); + if (context instanceof AppCompatActivity) { + ((AppCompatActivity) context).startActivityForResult(intent, 1); + } else { + // Do Nothing + } } // Make a shortcut for a specific game From 78fcd1fdd117d86407067a11be74976c54e3d00f Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sun, 14 Apr 2024 14:51:46 +0530 Subject: [PATCH 29/38] bonk --- .../com/panda3ds/pandroid/app/base/GameAboutDialog.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 109aba5b7..27c292b83 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -101,11 +101,7 @@ private void createDocument(@NonNull String mimeType, String fileName, String ou intent.setType(mimeType); intent.putExtra(Intent.EXTRA_TITLE, fileName); intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Uri.fromFile(new File(outputDirPath))); - if (context instanceof AppCompatActivity) { - ((AppCompatActivity) context).startActivityForResult(intent, 1); - } else { - // Do Nothing - } + startActivityForResult(intent, 1); } // Make a shortcut for a specific game From aa4ebccc8cb68d5d5d316ca06112b6dc5575932c Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sun, 14 Apr 2024 15:48:15 +0530 Subject: [PATCH 30/38] hopefully work --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 27c292b83..c60ee2677 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -101,7 +101,7 @@ private void createDocument(@NonNull String mimeType, String fileName, String ou intent.setType(mimeType); intent.putExtra(Intent.EXTRA_TITLE, fileName); intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Uri.fromFile(new File(outputDirPath))); - startActivityForResult(intent, 1); + context.startActivity(intent); } // Make a shortcut for a specific game From d6c892af0be0a81b2c2b13676bb74258fcf6d037 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sun, 14 Apr 2024 16:48:07 +0530 Subject: [PATCH 31/38] I hate ``context`` --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index c60ee2677..53e70f034 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -75,7 +75,7 @@ protected void onCreate(Bundle savedInstanceState) { zipBuilder.end(); System.out.println("Zip file created successfully."); - createDocument(MIME_TYPE_ZIP, outputName, outputPath); + createDocument(getContext(), MIME_TYPE_ZIP, outputName, outputPath); } catch (Exception e) { System.err.println("Error creating zip file: " + e.getMessage()); } @@ -95,7 +95,7 @@ protected void onCreate(Bundle savedInstanceState) { } } - private void createDocument(@NonNull String mimeType, String fileName, String outputDirPath) { + private void createDocument(Context context, @NonNull String mimeType, String fileName, String outputDirPath) { Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(mimeType); From 30f0bf7662829b5bf934d4dee5ba06c59e164e31 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sun, 14 Apr 2024 17:14:07 +0530 Subject: [PATCH 32/38] fix wrong zip path --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 53e70f034..f3a4a6e92 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -58,6 +58,7 @@ protected void onCreate(Bundle savedInstanceState) { String inputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()).replaceAll("\\..*", "") + "/SaveData/"; String outputPath = "/storage/emulated/0/Android/media/com.panda3ds.pandroid/"; String outputName = game.getTitle() + ".zip"; + String zipPath = outputPath + outputName; // Create an instance of ZipBuilder ZipBuilder zipBuilder = new ZipBuilder(outputPath, outputName); @@ -75,7 +76,7 @@ protected void onCreate(Bundle savedInstanceState) { zipBuilder.end(); System.out.println("Zip file created successfully."); - createDocument(getContext(), MIME_TYPE_ZIP, outputName, outputPath); + createDocument(getContext(), MIME_TYPE_ZIP, outputName, zipPath); } catch (Exception e) { System.err.println("Error creating zip file: " + e.getMessage()); } From 8b11a4957dc9bc88c1011110337730514428259c Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sun, 14 Apr 2024 23:26:21 +0530 Subject: [PATCH 33/38] bonk --- .../pandroid/app/base/GameAboutDialog.java | 75 +++++++++---------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index f3a4a6e92..876a3a972 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -13,8 +13,9 @@ import androidx.core.content.pm.ShortcutManagerCompat; import androidx.core.graphics.drawable.IconCompat; import androidx.appcompat.app.AppCompatActivity; -import androidx.documentfile.provider.DocumentFile; -import android.provider.DocumentsContract; +import androidx.activity.result.ActivityResultCallback; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; import com.panda3ds.pandroid.R; import com.panda3ds.pandroid.app.PandroidApplication; @@ -30,7 +31,8 @@ public class GameAboutDialog extends BaseSheetDialog { private final GameMetadata game; - private static final String MIME_TYPE_ZIP = "application/zip"; + private final ActivityResultContracts.OpenDocumentTree openFolderContract = new ActivityResultContracts.OpenDocumentTree(); + private ActivityResultLauncher pickFolderRequest; public GameAboutDialog(@NonNull Context context, GameMetadata game) { super(context); this.game = game; @@ -40,6 +42,7 @@ public GameAboutDialog(@NonNull Context context, GameMetadata game) { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog_game_about); + pickFolderRequest = registerForActivityResult(openFolderContract, this); ((GameIconView) findViewById(R.id.game_icon)).setImageBitmap(game.getIcon()); ((TextView) findViewById(R.id.game_title)).setText(game.getTitle()); @@ -55,32 +58,7 @@ protected void onCreate(Bundle savedInstanceState) { makeShortcut(); }); findViewById(R.id.export_save).setOnClickListener(v -> { - String inputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()).replaceAll("\\..*", "") + "/SaveData/"; - String outputPath = "/storage/emulated/0/Android/media/com.panda3ds.pandroid/"; - String outputName = game.getTitle() + ".zip"; - String zipPath = outputPath + outputName; - - // Create an instance of ZipBuilder - ZipBuilder zipBuilder = new ZipBuilder(outputPath, outputName); - - - new Task(()->{ - try { - // Begin the zip file creation process - zipBuilder.begin(); - - // Append files or folders to the zip file - zipBuilder.append(inputPath); - - // End the zip file creation process - zipBuilder.end(); - - System.out.println("Zip file created successfully."); - createDocument(getContext(), MIME_TYPE_ZIP, outputName, zipPath); - } catch (Exception e) { - System.err.println("Error creating zip file: " + e.getMessage()); - } - }).start(); + pickFolderRequest.launch(null); }); if (game.getRomPath().startsWith("folder:")) { @@ -96,15 +74,6 @@ protected void onCreate(Bundle savedInstanceState) { } } - private void createDocument(Context context, @NonNull String mimeType, String fileName, String outputDirPath) { - Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType(mimeType); - intent.putExtra(Intent.EXTRA_TITLE, fileName); - intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Uri.fromFile(new File(outputDirPath))); - context.startActivity(intent); - } - // Make a shortcut for a specific game private void makeShortcut() { Context context = CompatUtils.findActivity(getContext()); @@ -124,4 +93,34 @@ private void makeShortcut() { shortcut.setIntent(intent); ShortcutManagerCompat.requestPinShortcut(context, shortcut.build(), null); } + + @Override + public void onActivityResult(Uri result) { + if (result != null) { + String inputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()).replaceAll("\\..*", "") + "/SaveData/"; + String outputPath = result.toString(); + String outputName = game.getTitle() + ".zip"; + + // Create an instance of ZipBuilder + ZipBuilder zipBuilder = new ZipBuilder(outputPath, outputName); + + + new Task(()->{ + try { + // Begin the zip file creation process + zipBuilder.begin(); + + // Append files or folders to the zip file + zipBuilder.append(inputPath); + + // End the zip file creation process + zipBuilder.end(); + + System.out.println("Zip file created successfully."); + } catch (Exception e) { + System.err.println("Error creating zip file: " + e.getMessage()); + } + }).start(); + } + } } From 38dd6e03d4c755c525ec33b1eacf0f3442c9360b Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Tue, 16 Apr 2024 19:25:28 +0530 Subject: [PATCH 34/38] Revert bonk --- .../pandroid/app/base/GameAboutDialog.java | 75 ++++++++++--------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 876a3a972..f3a4a6e92 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -13,9 +13,8 @@ import androidx.core.content.pm.ShortcutManagerCompat; import androidx.core.graphics.drawable.IconCompat; import androidx.appcompat.app.AppCompatActivity; -import androidx.activity.result.ActivityResultCallback; -import androidx.activity.result.ActivityResultLauncher; -import androidx.activity.result.contract.ActivityResultContracts; +import androidx.documentfile.provider.DocumentFile; +import android.provider.DocumentsContract; import com.panda3ds.pandroid.R; import com.panda3ds.pandroid.app.PandroidApplication; @@ -31,8 +30,7 @@ public class GameAboutDialog extends BaseSheetDialog { private final GameMetadata game; - private final ActivityResultContracts.OpenDocumentTree openFolderContract = new ActivityResultContracts.OpenDocumentTree(); - private ActivityResultLauncher pickFolderRequest; + private static final String MIME_TYPE_ZIP = "application/zip"; public GameAboutDialog(@NonNull Context context, GameMetadata game) { super(context); this.game = game; @@ -42,7 +40,6 @@ public GameAboutDialog(@NonNull Context context, GameMetadata game) { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog_game_about); - pickFolderRequest = registerForActivityResult(openFolderContract, this); ((GameIconView) findViewById(R.id.game_icon)).setImageBitmap(game.getIcon()); ((TextView) findViewById(R.id.game_title)).setText(game.getTitle()); @@ -58,7 +55,32 @@ protected void onCreate(Bundle savedInstanceState) { makeShortcut(); }); findViewById(R.id.export_save).setOnClickListener(v -> { - pickFolderRequest.launch(null); + String inputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()).replaceAll("\\..*", "") + "/SaveData/"; + String outputPath = "/storage/emulated/0/Android/media/com.panda3ds.pandroid/"; + String outputName = game.getTitle() + ".zip"; + String zipPath = outputPath + outputName; + + // Create an instance of ZipBuilder + ZipBuilder zipBuilder = new ZipBuilder(outputPath, outputName); + + + new Task(()->{ + try { + // Begin the zip file creation process + zipBuilder.begin(); + + // Append files or folders to the zip file + zipBuilder.append(inputPath); + + // End the zip file creation process + zipBuilder.end(); + + System.out.println("Zip file created successfully."); + createDocument(getContext(), MIME_TYPE_ZIP, outputName, zipPath); + } catch (Exception e) { + System.err.println("Error creating zip file: " + e.getMessage()); + } + }).start(); }); if (game.getRomPath().startsWith("folder:")) { @@ -74,6 +96,15 @@ protected void onCreate(Bundle savedInstanceState) { } } + private void createDocument(Context context, @NonNull String mimeType, String fileName, String outputDirPath) { + Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType(mimeType); + intent.putExtra(Intent.EXTRA_TITLE, fileName); + intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Uri.fromFile(new File(outputDirPath))); + context.startActivity(intent); + } + // Make a shortcut for a specific game private void makeShortcut() { Context context = CompatUtils.findActivity(getContext()); @@ -93,34 +124,4 @@ private void makeShortcut() { shortcut.setIntent(intent); ShortcutManagerCompat.requestPinShortcut(context, shortcut.build(), null); } - - @Override - public void onActivityResult(Uri result) { - if (result != null) { - String inputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()).replaceAll("\\..*", "") + "/SaveData/"; - String outputPath = result.toString(); - String outputName = game.getTitle() + ".zip"; - - // Create an instance of ZipBuilder - ZipBuilder zipBuilder = new ZipBuilder(outputPath, outputName); - - - new Task(()->{ - try { - // Begin the zip file creation process - zipBuilder.begin(); - - // Append files or folders to the zip file - zipBuilder.append(inputPath); - - // End the zip file creation process - zipBuilder.end(); - - System.out.println("Zip file created successfully."); - } catch (Exception e) { - System.err.println("Error creating zip file: " + e.getMessage()); - } - }).start(); - } - } } From aa8abf3ae02be4ed2f29ad808972a88a98370d45 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sun, 21 Apr 2024 14:24:20 +0530 Subject: [PATCH 35/38] fix --- .../pandroid/app/base/GameAboutDialog.java | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index f3a4a6e92..7187c81f9 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -12,9 +12,6 @@ import androidx.core.content.pm.ShortcutInfoCompat; import androidx.core.content.pm.ShortcutManagerCompat; import androidx.core.graphics.drawable.IconCompat; -import androidx.appcompat.app.AppCompatActivity; -import androidx.documentfile.provider.DocumentFile; -import android.provider.DocumentsContract; import com.panda3ds.pandroid.R; import com.panda3ds.pandroid.app.PandroidApplication; @@ -26,11 +23,9 @@ import com.panda3ds.pandroid.utils.GameUtils; import com.panda3ds.pandroid.view.gamesgrid.GameIconView; import com.panda3ds.pandroid.lang.Task; -import java.io.File; public class GameAboutDialog extends BaseSheetDialog { private final GameMetadata game; - private static final String MIME_TYPE_ZIP = "application/zip"; public GameAboutDialog(@NonNull Context context, GameMetadata game) { super(context); this.game = game; @@ -57,8 +52,7 @@ protected void onCreate(Bundle savedInstanceState) { findViewById(R.id.export_save).setOnClickListener(v -> { String inputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()).replaceAll("\\..*", "") + "/SaveData/"; String outputPath = "/storage/emulated/0/Android/media/com.panda3ds.pandroid/"; - String outputName = game.getTitle() + ".zip"; - String zipPath = outputPath + outputName; + String outputName = "export.zip"; // Create an instance of ZipBuilder ZipBuilder zipBuilder = new ZipBuilder(outputPath, outputName); @@ -76,7 +70,6 @@ protected void onCreate(Bundle savedInstanceState) { zipBuilder.end(); System.out.println("Zip file created successfully."); - createDocument(getContext(), MIME_TYPE_ZIP, outputName, zipPath); } catch (Exception e) { System.err.println("Error creating zip file: " + e.getMessage()); } @@ -96,15 +89,6 @@ protected void onCreate(Bundle savedInstanceState) { } } - private void createDocument(Context context, @NonNull String mimeType, String fileName, String outputDirPath) { - Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType(mimeType); - intent.putExtra(Intent.EXTRA_TITLE, fileName); - intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, Uri.fromFile(new File(outputDirPath))); - context.startActivity(intent); - } - // Make a shortcut for a specific game private void makeShortcut() { Context context = CompatUtils.findActivity(getContext()); From 7753c95b4b6c3f6f805b3730ff3788e026c99147 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Sun, 21 Apr 2024 14:27:04 +0530 Subject: [PATCH 36/38] add ``ZipExtractor`` class Co-authored-by: gabriel --- .../panda3ds/pandroid/utils/ZipExtractor.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipExtractor.java diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipExtractor.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipExtractor.java new file mode 100644 index 000000000..806ca6e50 --- /dev/null +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/ZipExtractor.java @@ -0,0 +1,63 @@ +package com.panda3ds.pandroid.utils; + +import android.net.Uri; + +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public class ZipExtractor { + + + public static void extract(String zipFile, String outputFolder, String outputName) throws Exception { + String path = outputFolder; + if (FileUtils.exists(path+"/"+outputName)) { + throw new IllegalArgumentException("File already exists in output location"); + } + + byte[] buffer = new byte[1024*256]; + int bufferLen = 0; + + ZipInputStream in = new ZipInputStream(FileUtils.getInputStream(zipFile)); + ZipEntry entry = in.getNextEntry(); + while (entry != null) { + if (!entry.isDirectory()) { + String[] dir = entry.getName().split("/"); + String parent; + { + StringBuilder builder = new StringBuilder(); + for (int i = dir[0].length() == 0 ? 1 : 0; i < dir.length - 1; i++) { + builder.append(dir[i]).append("/"); + } + parent = builder.toString(); + } + if (parent.length() > 0) { + mkdirs(path, parent); + } + if (parent.length() > 0) { + parent = "/" + parent; + } + String name = dir[dir.length-1]; + FileUtils.createFile(path+parent, name); + OutputStream out = FileUtils.getOutputStream(path+parent+"/"+name); + while ((bufferLen = in.read(buffer)) != -1) { + out.write(buffer, 0, bufferLen); + } + out.flush(); + out.close(); + } + entry = in.getNextEntry(); + } + in.close(); + } + + private static void mkdirs(String path, String subs) { + for (String segment: subs.split("/")) { + if (!FileUtils.exists(path+"/"+segment)) { + FileUtils.createDir(path, segment); + } + path = path + "/"+segment; + } + } +} From 2e441401328252bd0bd28cebd576510af354f2f7 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Tue, 28 May 2024 12:24:22 +0530 Subject: [PATCH 37/38] Implement SaveData import logic --- .../pandroid/app/base/GameAboutDialog.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 7187c81f9..21f09b680 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -23,6 +23,9 @@ import com.panda3ds.pandroid.utils.GameUtils; import com.panda3ds.pandroid.view.gamesgrid.GameIconView; import com.panda3ds.pandroid.lang.Task; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import java.io.File; public class GameAboutDialog extends BaseSheetDialog { private final GameMetadata game; @@ -76,6 +79,44 @@ protected void onCreate(Bundle savedInstanceState) { }).start(); }); + findViewById(R.id.import_save).setOnClickListener(v -> { + String outputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()).replaceAll("\\..*", "") + "/"; + + ZipExtractor zipExtractor = new ZipExtractor; + + JFrame frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(300, 200); + frame.setVisible(true); + + JFileChooser fileChooser = new JFileChooser(); + + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + + int returnValue = fileChooser.showOpenDialog(frame); + + if (returnValue == JFileChooser.APPROVE_OPTION) { + File selectedFile = fileChooser.getSelectedFile(); + String selectedFilePath = selectedFile.getAbsolutePath(); + new Task(()->{ + try { + ZipExtractor.extract(selectedFilePath, outputPath, "SaveData") + + System.out.println("Zip file extracted successfully."); + } catch (Exception e) { + System.err.println("Error extracting zip file: " + e.getMessage()); + } + }).start(); + System.out.println("Selected file path: " + selectedFilePath); + } else { + System.out.println("No file selected"); + } + + // Dispose of the JFrame + frame.dispose(); + }); + + if (game.getRomPath().startsWith("folder:")) { findViewById(R.id.remove).setVisibility(View.GONE); } else { From c5c8a0679c36caf56325746bda461bcad5915f18 Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Wed, 29 May 2024 13:46:06 +0530 Subject: [PATCH 38/38] fix syntax --- .../java/com/panda3ds/pandroid/app/base/GameAboutDialog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java index 21f09b680..a48ba2507 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/base/GameAboutDialog.java @@ -82,7 +82,7 @@ protected void onCreate(Bundle savedInstanceState) { findViewById(R.id.import_save).setOnClickListener(v -> { String outputPath = FileUtils.getPrivatePath() + "/" + FileUtils.getName(game.getRealPath()).replaceAll("\\..*", "") + "/"; - ZipExtractor zipExtractor = new ZipExtractor; + ZipExtractor zipExtractor = new ZipExtractor(); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -100,7 +100,7 @@ protected void onCreate(Bundle savedInstanceState) { String selectedFilePath = selectedFile.getAbsolutePath(); new Task(()->{ try { - ZipExtractor.extract(selectedFilePath, outputPath, "SaveData") + ZipExtractor.extract(selectedFilePath, outputPath, "SaveData"); System.out.println("Zip file extracted successfully."); } catch (Exception e) {