From 79c0dc8b96c3b77dcba83a9883d557bbaab02010 Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Sun, 9 Jan 2022 17:44:45 +0200 Subject: [PATCH] SDL: data downloader from SDL2, it will not print anything to screen so please don't put big files there --- changeAppSettings.sh | 1 + project/java/DataDownloader.java | 51 ------------------- project/javaSDL2/MainActivity.java | 46 ++++++++++++++--- project/jni/application/supertux/project.diff | 12 +++++ 4 files changed, 51 insertions(+), 59 deletions(-) create mode 100644 project/jni/application/supertux/project.diff diff --git a/changeAppSettings.sh b/changeAppSettings.sh index dc37f6ad5..413284ad9 100755 --- a/changeAppSettings.sh +++ b/changeAppSettings.sh @@ -1144,6 +1144,7 @@ if [ -z "`ls project/assetpack/src/main/assets/ 2>/dev/null`" ] ; then $SEDI "/==ASSETPACK==/ d" project/app/build.gradle fi +if [ -e project/jni/application/src/project.diff ]; then patch -p1 --dry-run -f -R < project/jni/application/src/project.diff > /dev/null 2>&1 || patch -p1 --no-backup-if-mismatch < project/jni/application/src/project.diff || exit 1 ; fi if [ -e project/jni/application/src/project.patch ]; then patch -p1 --dry-run -f -R < project/jni/application/src/project.patch > /dev/null 2>&1 || patch -p1 --no-backup-if-mismatch < project/jni/application/src/project.patch || exit 1 ; fi rm -f project/lib diff --git a/project/java/DataDownloader.java b/project/java/DataDownloader.java index d777bd681..f4e9e4c7c 100644 --- a/project/java/DataDownloader.java +++ b/project/java/DataDownloader.java @@ -192,9 +192,6 @@ class DataDownloader extends Thread @Override public void run() { - if (Parent.getVideoLayout() != null) - Parent.getVideoLayout().setOnKeyListener(new BackKeyListener(Parent)); - String [] downloadFiles = Globals.DataDownloadUrl; int total = 0; int count = 0; @@ -235,8 +232,6 @@ class DataDownloader extends Thread } } DownloadComplete = true; - if (Parent.getVideoLayout() != null) - Parent.getVideoLayout().setOnKeyListener(null); initParent(); } @@ -879,52 +874,6 @@ class DataDownloader extends Thread Parent.getPackageName() + "/" + url.substring("obb:".length()) + "." + Parent.getPackageName() + ".obb"; } - public class BackKeyListener implements View.OnKeyListener - { - MainActivity p; - public BackKeyListener(MainActivity _p) - { - p = _p; - } - - @Override - public boolean onKey(View v, int keyCode, KeyEvent event) - { - if( DownloadFailed ) - System.exit(1); - - AlertDialog.Builder builder = new AlertDialog.Builder(p); - builder.setTitle(p.getResources().getString(R.string.cancel_download)); - builder.setMessage(p.getResources().getString(R.string.cancel_download) + (DownloadCanBeResumed ? " " + p.getResources().getString(R.string.cancel_download_resume) : "")); - - builder.setPositiveButton(p.getResources().getString(R.string.yes), new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int item) - { - System.exit(1); - dialog.dismiss(); - } - }); - builder.setNegativeButton(p.getResources().getString(R.string.no), new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int item) - { - dialog.dismiss(); - } - }); - builder.setOnCancelListener(new DialogInterface.OnCancelListener() - { - public void onCancel(DialogInterface dialog) - { - } - }); - AlertDialog alert = builder.create(); - alert.setOwnerActivity(p); - alert.show(); - return true; - } - } - public StatusWriter Status; public boolean DownloadComplete = false; public boolean DownloadFailed = false; diff --git a/project/javaSDL2/MainActivity.java b/project/javaSDL2/MainActivity.java index 2fb1f4a15..4acbca7f6 100644 --- a/project/javaSDL2/MainActivity.java +++ b/project/javaSDL2/MainActivity.java @@ -35,13 +35,34 @@ import java.util.ArrayList; import java.util.Arrays; public class MainActivity extends org.libsdl.app.SDLActivity { + public static MainActivity instance = null; + public String ObbMountPath = null; // Deprecated, always empty + public String assetPackPath = null; // Not saved to the config file + public boolean readExternalStoragePermissionDialogAnswered = false; // Deprecated, always false + public boolean nativeThreadResumeCaptured = false; + public DataDownloader dataDownloader = null; + @Override protected void onCreate(Bundle savedInstanceState) { this.instance = this; super.onCreate(savedInstanceState); Globals.DataDir = this.getFilesDir().getAbsolutePath(); - Settings.LoadConfig(this); // Load Globals.DataDir from SDL 1.2 installation, we never save config file + Settings.settingsLoaded = Settings.LoadConfig(this); // Load Globals.DataDir from SDL 1.2 installation + + if (Settings.settingsLoaded) { + Log.i("SDL", "libSDL: Settings.ProcessConfig(): loaded settings successfully"); + Log.i("SDL", "libSDL: old app version " + settingsAppVersion + ", new app version " + this.getApplicationVersion()); + if (Settings.settingsAppVersion != this.getApplicationVersion()) { + Settings.DeleteFilesOnUpgrade(this); + if (Globals.ResetSdlConfigForThisVersion) { + Log.i("SDL", "libSDL: old app version " + Settings.settingsAppVersion + ", new app version " + this.getApplicationVersion() + " and we need to clean up config file"); + // Delete settings file, and restart the application + Settings.DeleteSdlConfigOnUpgradeAndRestart(this); + } + Settings.Save(p); + } + } try { @@ -70,22 +91,35 @@ public class MainActivity extends org.libsdl.app.SDLActivity { Settings.setEnvVars(this); Log.v("SDL", "chdir() to: " + Globals.DataDir); Settings.nativeChdir(Globals.DataDir); + Log.i("SDL", "Starting data download"); + this.dataDownloader = new DataDownloader(this, null); } public void downloadFinishedInitSDL() { - // TODO: implement this + Log.i("SDL", "Data download finished, starting native thread"); + this.dataDownloader = null; + if (this.nativeThreadResumeCaptured) + this.resumeNativeThread(); + else + this.pauseNativeThread(); } @Override protected void pauseNativeThread() { Log.i("SDL", "Intercepted pauseNativeThread() from MainActivity"); - super.pauseNativeThread(); + this.nativeThreadResumeCaptured = false; + if (this.dataDownloader == null) { + super.pauseNativeThread(); + } } @Override protected void resumeNativeThread() { Log.i("SDL", "Intercepted resumeNativeThread() from MainActivity"); - super.resumeNativeThread(); + this.nativeThreadResumeCaptured = true; + if (this.dataDownloader == null) { + super.resumeNativeThread(); + } } @Override @@ -152,8 +186,4 @@ public class MainActivity extends org.libsdl.app.SDLActivity { return null; } - public static MainActivity instance = null; - public String ObbMountPath = null; // Deprecated, always empty - public String assetPackPath = null; // Not saved to the config file - public boolean readExternalStoragePermissionDialogAnswered = false; // Deprecated, always false } diff --git a/project/jni/application/supertux/project.diff b/project/jni/application/supertux/project.diff new file mode 100644 index 000000000..e05af430d --- /dev/null +++ b/project/jni/application/supertux/project.diff @@ -0,0 +1,12 @@ +--- a/project/AndroidManifest.xml 2022-01-08 21:01:39.060265726 +0200 ++++ b/project/AndroidManifest.xml 2022-01-08 21:03:51.333398840 +0200 +@@ -49,6 +49,9 @@ + + + ++ ++ ++ + + +