mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-01-20 09:52:33 +00:00
(Android) We now use the built-in assets extraction inside RA to
extract the 'assets' dir from the APK, no more Java JNI library for this
This commit is contained in:
parent
6062467d1b
commit
317049cd25
@ -211,7 +211,6 @@ void menu_free(menu_handle_t *menu)
|
||||
free(menu);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void bundle_decompressed(void *task_data, void *user_data, const char *err)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
@ -232,7 +231,6 @@ static void bundle_decompressed(void *task_data, void *user_data, const char *er
|
||||
|
||||
settings->bundle_assets_extract_last_version = settings->bundle_assets_extract_version_current;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* menu_init:
|
||||
@ -275,7 +273,6 @@ void *menu_init(const void *data)
|
||||
menu->help_screen_type = MENU_HELP_WELCOME;
|
||||
settings->menu_show_start_screen = false;
|
||||
|
||||
#if 0
|
||||
if (settings->bundle_assets_extract_enable &&
|
||||
settings->bundle_assets_src_path[0] != '\0' && settings->bundle_assets_dst_path[0] != '\0' &&
|
||||
settings->bundle_assets_extract_version_current != settings->bundle_assets_extract_last_version
|
||||
@ -284,7 +281,6 @@ void *menu_init(const void *data)
|
||||
rarch_task_push_decompress(settings->bundle_assets_src_path, settings->bundle_assets_dst_path,
|
||||
settings->bundle_assets_dst_path_subdir, NULL, bundle_decompressed, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
menu_shader_manager_init(menu);
|
||||
|
||||
|
@ -12,7 +12,6 @@ import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@ -63,119 +62,8 @@ public final class MainMenuFragment extends PreferenceListFragment implements On
|
||||
// Set the listeners for the menu items
|
||||
findPreference("resumeContentPref").setOnPreferenceClickListener(this);
|
||||
findPreference("quitRetroArch").setOnPreferenceClickListener(this);
|
||||
|
||||
// Extract assets.
|
||||
extractAssets();
|
||||
}
|
||||
|
||||
private void extractAssets()
|
||||
{
|
||||
if (areAssetsExtracted())
|
||||
return;
|
||||
|
||||
final Dialog dialog = new Dialog(ctx);
|
||||
final Handler handler = new Handler();
|
||||
dialog.setContentView(R.layout.assets);
|
||||
dialog.setCancelable(false);
|
||||
dialog.setTitle(R.string.asset_extraction);
|
||||
|
||||
// Java is fun :)
|
||||
Thread assetsThread = new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
extractAssetsThread();
|
||||
handler.post(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
assetsThread.start();
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
// Extract assets from native code. Doing it from Java side is apparently unbearably slow ...
|
||||
private void extractAssetsThread()
|
||||
{
|
||||
try
|
||||
{
|
||||
final String dataDir = ctx.getApplicationInfo().dataDir;
|
||||
final String apk = ctx.getApplicationInfo().sourceDir;
|
||||
|
||||
Log.i(TAG, "Extracting RetroArch assets from: " + apk + " ...");
|
||||
boolean success = NativeInterface.extractArchiveTo(apk, "assets", dataDir);
|
||||
if (!success) {
|
||||
throw new IOException("Failed to extract assets ...");
|
||||
}
|
||||
Log.i(TAG, "Extracted assets ...");
|
||||
|
||||
File cacheVersion = new File(dataDir, ".cacheversion");
|
||||
DataOutputStream outputCacheVersion = new DataOutputStream(new FileOutputStream(cacheVersion, false));
|
||||
outputCacheVersion.writeInt(getVersionCode());
|
||||
outputCacheVersion.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Log.e(TAG, "Failed to extract assets to cache.");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean areAssetsExtracted()
|
||||
{
|
||||
int version = getVersionCode();
|
||||
|
||||
try
|
||||
{
|
||||
String dataDir = ctx.getApplicationInfo().dataDir;
|
||||
File cacheVersion = new File(dataDir, ".cacheversion");
|
||||
if (cacheVersion.isFile() && cacheVersion.canRead() && cacheVersion.canWrite())
|
||||
{
|
||||
DataInputStream cacheStream = new DataInputStream(new FileInputStream(cacheVersion));
|
||||
int currentCacheVersion = 0;
|
||||
try
|
||||
{
|
||||
currentCacheVersion = cacheStream.readInt();
|
||||
cacheStream.close();
|
||||
}
|
||||
catch (IOException ignored)
|
||||
{
|
||||
}
|
||||
|
||||
if (currentCacheVersion == version)
|
||||
{
|
||||
Log.i("ASSETS", "Assets already extracted, skipping...");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Log.e(TAG, "Failed to extract assets to cache.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getVersionCode()
|
||||
{
|
||||
int version = 0;
|
||||
try
|
||||
{
|
||||
version = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionCode;
|
||||
}
|
||||
catch (NameNotFoundException ignored)
|
||||
{
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference)
|
||||
{
|
||||
|
@ -146,11 +146,17 @@ public final class UserPreferences
|
||||
|
||||
try
|
||||
{
|
||||
int version = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionCode;
|
||||
final String dst_path = dataDir + "/assets/";
|
||||
int version = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionCode;
|
||||
final String dst_path = dataDir;
|
||||
final String dst_path_subdir = "assets";
|
||||
|
||||
Log.i(TAG, "dst dir is: " + dst_path);
|
||||
Log.i(TAG, "dst subdir is: " + dst_path_subdir);
|
||||
|
||||
config.setBoolean("log_verbosity", true);
|
||||
config.setString("bundle_assets_src_path", ctx.getApplicationInfo().sourceDir);
|
||||
config.setString("bundle_assets_dst_path", dst_path);
|
||||
config.setString("bundle_assets_dst_path_subdir", dst_path_subdir);
|
||||
config.setInt("bundle_assets_extract_version_current", version);
|
||||
}
|
||||
catch (NameNotFoundException ignored)
|
||||
|
Loading…
x
Reference in New Issue
Block a user