mirror of https://git.sr.ht/~rabbits/uxn
android: copy all roms from assets to cache dir
This commit is contained in:
parent
c86854a562
commit
a00a17badd
|
@ -12,6 +12,7 @@ import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.AssetManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
@ -58,6 +59,9 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@ -294,10 +298,9 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||||
} catch(Exception ignored) {
|
} catch(Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copyAssets();
|
||||||
setContentView(mLayout);
|
setContentView(mLayout);
|
||||||
|
|
||||||
setWindowStyle(false);
|
setWindowStyle(false);
|
||||||
|
|
||||||
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
|
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
|
||||||
|
|
||||||
// Get filename from "Open with" of another application
|
// Get filename from "Open with" of another application
|
||||||
|
@ -326,6 +329,24 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||||
SDLActivity.handleNativeState();
|
SDLActivity.handleNativeState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void copyAssets() {
|
||||||
|
try {
|
||||||
|
AssetManager assets = getAssets();
|
||||||
|
for (String s : assets.list("")) {
|
||||||
|
if (!s.endsWith(".rom"))
|
||||||
|
continue;
|
||||||
|
Path path = Paths.get(getCacheDir().getPath() + "/" + s);
|
||||||
|
if (Files.notExists(path)) {
|
||||||
|
InputStream data = assets.open(s);
|
||||||
|
Files.copy(data, path);
|
||||||
|
data.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "asset copy failed: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent intent) {
|
protected void onNewIntent(Intent intent) {
|
||||||
Uri uri = intent.getData();
|
Uri uri = intent.getData();
|
||||||
|
@ -350,7 +371,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||||
filename = "external.rom";
|
filename = "external.rom";
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = this.getCacheDir().getPath() + "/" + filename;
|
filename = getCacheDir().getPath() + "/" + filename;
|
||||||
FileOutputStream out = new FileOutputStream(filename, false);
|
FileOutputStream out = new FileOutputStream(filename, false);
|
||||||
out.write(raw, 0, size);
|
out.write(raw, 0, size);
|
||||||
out.close();
|
out.close();
|
||||||
|
|
Loading…
Reference in New Issue