mirror of
https://github.com/shagr4th/droid48
synced 2024-12-26 21:58:12 +01:00
Move the x48 support files in the proper Android external directory
(rather than the old .hp48 one). An uninstall will delete all files this way
This commit is contained in:
parent
adda6bc7a0
commit
a2828de9b4
6 changed files with 46 additions and 49 deletions
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.ab.x48" android:installLocation="auto" android:versionCode="43" android:versionName="1.43">
|
||||
package="org.ab.x48" android:installLocation="auto" android:versionCode="50" android:versionName="1.50">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
<activity android:name=".X48"
|
||||
android:label="@string/app_name"
|
||||
|
@ -16,7 +16,7 @@
|
|||
</activity>
|
||||
<activity android:name=".Settings" android:label="@string/choose_contrast_value"></activity>
|
||||
</application>
|
||||
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/>
|
||||
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/>
|
||||
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true"></supports-screens>
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
|
||||
|
|
|
@ -242,6 +242,7 @@ typedef struct saturn_t {
|
|||
|
||||
#define NIBBLES_PER_ROW 0x22
|
||||
|
||||
extern char files_path [256];
|
||||
extern char rom_filename [256];
|
||||
extern char ram_filename [256];
|
||||
extern char conf_filename [256];
|
||||
|
|
25
jni/init.c
25
jni/init.c
|
@ -1156,13 +1156,7 @@ read_files()
|
|||
FILE *fp;
|
||||
|
||||
|
||||
FILE *sd;
|
||||
if (NULL == (sd = fopen("/sdcard/.hp48/", "rw"))) {
|
||||
strcpy(path, "/data/data/org.ab.x48/");
|
||||
|
||||
}
|
||||
else
|
||||
strcpy(path, "/sdcard/.hp48/");
|
||||
strcpy(path, files_path);
|
||||
|
||||
//get_home_directory(path);
|
||||
LOGI("path: %s", path);
|
||||
|
@ -1617,14 +1611,7 @@ write_files()
|
|||
FILE *fp;
|
||||
|
||||
make_dir = 0;
|
||||
//get_home_directory(path);
|
||||
FILE *sd;
|
||||
if (NULL == (sd = fopen("/sdcard/.hp48/", "rw"))) {
|
||||
strcpy(path, "/data/data/org.ab.x48/");
|
||||
//fclose(sd);
|
||||
}
|
||||
else
|
||||
strcpy(path, "/sdcard/.hp48/");
|
||||
strcpy(path, files_path);
|
||||
|
||||
if (stat(path, &st) == -1)
|
||||
{
|
||||
|
@ -1814,13 +1801,7 @@ init_emulator()
|
|||
|
||||
char path[1024];
|
||||
|
||||
FILE *sd;
|
||||
if (NULL == (sd = fopen("/sdcard/.hp48/", "rw"))) {
|
||||
strcpy(path, "/data/data/org.ab.x48/");
|
||||
|
||||
}
|
||||
else
|
||||
strcpy(path, "/sdcard/.hp48/");
|
||||
strcpy(path, files_path);
|
||||
|
||||
|
||||
strcat(path, rom_filename);
|
||||
|
|
|
@ -245,6 +245,7 @@ printf("%s\n", nl_langinfo(CODESET));*/
|
|||
return 0;
|
||||
}
|
||||
|
||||
char files_path [256];
|
||||
char rom_filename [256];
|
||||
char ram_filename [256];
|
||||
char conf_filename [256];
|
||||
|
@ -252,14 +253,18 @@ char port1_filename [256];
|
|||
char port2_filename [256];
|
||||
|
||||
void
|
||||
Java_org_ab_x48_X48_registerClass( JNIEnv* env, jobject caller, jobject callback, jstring rom, jstring ram, jstring conf,
|
||||
Java_org_ab_x48_X48_registerClass( JNIEnv* env, jobject caller, jobject callback, jstring path, jstring rom, jstring ram, jstring conf,
|
||||
jstring port1, jstring port2 )
|
||||
{
|
||||
LOGI("--registerClass--");
|
||||
android_env = env;
|
||||
android_callback = (*android_env)->NewGlobalRef(env, callback);
|
||||
|
||||
const char * fp = (*android_env)->GetStringUTFChars(env, path, NULL);
|
||||
strcpy(files_path, fp);
|
||||
(*android_env)->ReleaseStringUTFChars(env, path, fp);
|
||||
|
||||
const char * fp = (*android_env)->GetStringUTFChars(env, rom, NULL);
|
||||
fp = (*android_env)->GetStringUTFChars(env, rom, NULL);
|
||||
strcpy(rom_filename, fp);
|
||||
(*android_env)->ReleaseStringUTFChars(env, rom, fp);
|
||||
|
||||
|
|
|
@ -5,30 +5,40 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
public class AssetUtil {
|
||||
|
||||
public static void copyAsset(AssetManager am, boolean force) {
|
||||
public static void copyAsset(Context context, AssetManager am, boolean force) {
|
||||
File newDir = context.getExternalFilesDir(null);
|
||||
File sd = Environment.getExternalStorageDirectory();
|
||||
if (sd.exists() && sd.isDirectory()) {
|
||||
if (sd.exists() && sd.isDirectory() && newDir.exists() && newDir.isDirectory()) {
|
||||
File hpDir = new File(sd, ".hp48");
|
||||
copyAsset(am, hpDir.exists() || hpDir.mkdir(), force);
|
||||
} else {
|
||||
copyAsset(am, false, force);
|
||||
if (hpDir.exists()) {
|
||||
File allFiles [] = hpDir.listFiles();
|
||||
if (allFiles != null && allFiles.length > 0) {
|
||||
Log.i("x48", "Moving x48 files from the old dir " + sd.getAbsolutePath() + " to the proper one :");
|
||||
for(File file:allFiles) {
|
||||
File newFile = new File(newDir, file.getName());
|
||||
Log.i("x48", "Moving " + file.getAbsolutePath() + " to " + newFile);
|
||||
file.renameTo(newFile);
|
||||
}
|
||||
}
|
||||
Log.i("x48", "Deleting old directory");
|
||||
hpDir.delete();
|
||||
}
|
||||
}
|
||||
copyAsset(am, newDir, force);
|
||||
}
|
||||
|
||||
public static File getSDDir() {
|
||||
File hpDir = new File(Environment.getExternalStorageDirectory(), ".hp48");
|
||||
if (hpDir.exists())
|
||||
return hpDir;
|
||||
return null;
|
||||
public static File getSDDir(Context context) {
|
||||
return context.getExternalFilesDir(null);
|
||||
}
|
||||
|
||||
public static void copyAsset(AssetManager am, boolean sd, boolean force) {
|
||||
private static void copyAsset(AssetManager am, File rep, boolean force) {
|
||||
try {
|
||||
String assets[] = am.list( "" );
|
||||
for( int i = 0 ; i < assets.length ; i++ ) {
|
||||
|
@ -49,7 +59,6 @@ public class AssetUtil {
|
|||
required = 262144;
|
||||
//boolean SKUNK = assets[i].equals("SKUNK");
|
||||
if (hp48 || rom || ram || hp48s || roms || rams) {
|
||||
File rep = sd?new File(Environment.getExternalStorageDirectory(), ".hp48"):new File(Environment.getDataDirectory(), "data/org.ab.x48");
|
||||
File fout = new File(rep, assets[i]);
|
||||
if (!fout.exists() || fout.length() == 0 || (required > 0 && fout.length() != required) || force) {
|
||||
Log.i("x48", "Overwriting " + assets[i]);
|
||||
|
@ -70,12 +79,10 @@ public class AssetUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean isFilesReady() {
|
||||
File hpDir = new File(Environment.getExternalStorageDirectory(), ".hp48");
|
||||
public static boolean isFilesReady(Context context) {
|
||||
File hpDir = context.getExternalFilesDir(null);
|
||||
if (!hpDir.exists() || !hpDir.isDirectory()) {
|
||||
hpDir = new File(Environment.getDataDirectory(), "data/org.ab.x48");
|
||||
if (!hpDir.exists() || !hpDir.isDirectory())
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
File hp = new File(hpDir, "hp48");
|
||||
File rom = new File(hpDir, "rom");
|
||||
|
|
|
@ -43,9 +43,9 @@ public class X48 extends Activity {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.i("x48", "starting activity");
|
||||
AssetUtil.copyAsset(getResources().getAssets(), false);
|
||||
AssetUtil.copyAsset(this, getResources().getAssets(), false);
|
||||
readyToGo() ;
|
||||
if (!AssetUtil.isFilesReady()) {
|
||||
if (!AssetUtil.isFilesReady(this)) {
|
||||
showDialog(DIALOG_ROM_KO);
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ public class X48 extends Activity {
|
|||
public native void stopHPEmulator();
|
||||
public native int buttonPressed(int code);
|
||||
public native int buttonReleased(int code);
|
||||
public native void registerClass(X48 instance, String rom_filename, String ram_filename, String conf_filename, String port1_filename, String port2_filename);
|
||||
public native void registerClass(X48 instance, String path, String rom_filename, String ram_filename, String conf_filename, String port1_filename, String port2_filename);
|
||||
public native int fillAudioData(short data []);
|
||||
public native int fillScreenData(short data [], boolean ann []);
|
||||
public native void flipScreen();
|
||||
|
@ -188,7 +188,7 @@ public class X48 extends Activity {
|
|||
changeKeybLite();
|
||||
return true;
|
||||
case RESET_ID:
|
||||
AssetUtil.copyAsset(getResources().getAssets(), true);
|
||||
AssetUtil.copyAsset(this, getResources().getAssets(), true);
|
||||
//stopHPEmulator();
|
||||
finish();
|
||||
need_to_quit = true;
|
||||
|
@ -345,7 +345,7 @@ public class X48 extends Activity {
|
|||
|
||||
private void managePort(int number, String value) {
|
||||
int size = Integer.parseInt(value);
|
||||
File f = AssetUtil.getSDDir();
|
||||
File f = AssetUtil.getSDDir(this);
|
||||
if (f != null) {
|
||||
boolean change = false;
|
||||
File port = new File(f, "port" + number);
|
||||
|
@ -423,7 +423,10 @@ private void managePort(int number, String value) {
|
|||
|
||||
|
||||
public void registerClass() {
|
||||
registerClass(this, hp48s?"roms":"rom", hp48s?"rams":"ram", hp48s?"hp48s":"hp48",
|
||||
String files_path = AssetUtil.getSDDir(this).getAbsolutePath();
|
||||
if (!files_path.endsWith("/"))
|
||||
files_path = files_path + "/";
|
||||
registerClass(this, files_path, hp48s?"roms":"rom", hp48s?"rams":"ram", hp48s?"hp48s":"hp48",
|
||||
hp48s?"port1s":"port1", hp48s?"port2s":"port2");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue