SDL: data downloader from SDL2, it will not print anything to screen so please don't put big files there

This commit is contained in:
Sergii Pylypenko
2022-01-09 17:44:45 +02:00
parent 1f88f05321
commit 79c0dc8b96
4 changed files with 51 additions and 59 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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
}

View File

@@ -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 @@
<!-- Allow access to the vibrator -->
<uses-permission android:name="android.permission.VIBRATE" />
+ <!-- Internet access, it was dumb for SDL2 to not include this permission, it does not even need a permission dialog -->
+ <uses-permission android:name="android.permission.INTERNET" />
+
<!-- if you want to capture audio, uncomment this. -->
<!-- <uses-permission android:name="android.permission.RECORD_AUDIO" /> -->