mirror of
https://github.com/mauiaaron/apple2.git
synced 2024-12-25 09:29:48 +00:00
Expose save-state file in /sdcard/apple2ix
This commit is contained in:
parent
bea9e1ee31
commit
db04d330c7
@ -39,7 +39,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
|
|
||||||
public class Apple2MainMenu {
|
public class Apple2MainMenu {
|
||||||
|
|
||||||
private final static String SAVE_FILE = "emulator.state";
|
public final static String SAVE_FILE = "emulator.state";
|
||||||
private final static String TAG = "Apple2MainMenu";
|
private final static String TAG = "Apple2MainMenu";
|
||||||
|
|
||||||
private Apple2Activity mActivity = null;
|
private Apple2Activity mActivity = null;
|
||||||
@ -299,7 +299,14 @@ public class Apple2MainMenu {
|
|||||||
public void maybeSaveRestore() {
|
public void maybeSaveRestore() {
|
||||||
mActivity.pauseEmulation();
|
mActivity.pauseEmulation();
|
||||||
|
|
||||||
final String quickSavePath = Apple2Utils.getDataDir(mActivity) + File.separator + SAVE_FILE;
|
final String quickSavePath;
|
||||||
|
final File extStorage = Apple2Utils.getExternalStorageDirectory(mActivity);
|
||||||
|
|
||||||
|
if (extStorage != null) {
|
||||||
|
quickSavePath = extStorage + File.separator + SAVE_FILE;
|
||||||
|
} else {
|
||||||
|
quickSavePath = Apple2Utils.getDataDir(mActivity) + File.separator + SAVE_FILE;
|
||||||
|
}
|
||||||
|
|
||||||
final AtomicBoolean selectionAlreadyHandled = new AtomicBoolean(false);
|
final AtomicBoolean selectionAlreadyHandled = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
@ -174,8 +174,10 @@ public class Apple2Preferences {
|
|||||||
|
|
||||||
Log.v(TAG, "Triggering migration to Apple2ix version : " + BuildConfig.VERSION_NAME);
|
Log.v(TAG, "Triggering migration to Apple2ix version : " + BuildConfig.VERSION_NAME);
|
||||||
setJSONPref(PREF_DOMAIN_INTERFACE, PREF_EMULATOR_VERSION, BuildConfig.VERSION_CODE);
|
setJSONPref(PREF_DOMAIN_INTERFACE, PREF_EMULATOR_VERSION, BuildConfig.VERSION_CODE);
|
||||||
|
|
||||||
|
Apple2Utils.migrate(activity);
|
||||||
if (BuildConfig.VERSION_CODE >= 17) {
|
if (BuildConfig.VERSION_CODE >= 17) {
|
||||||
// FIXME TODO : remove this after shipping 1.1.7+
|
// FIXME TODO : remove this after most/all app users are on 18+
|
||||||
|
|
||||||
boolean keypadPreset = false;
|
boolean keypadPreset = false;
|
||||||
Apple2AbstractMenu.IMenuEnum menuEnum = null;
|
Apple2AbstractMenu.IMenuEnum menuEnum = null;
|
||||||
|
@ -19,11 +19,13 @@ import android.util.Log;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
|
||||||
|
import org.deadc0de.apple2ix.basic.BuildConfig;
|
||||||
import org.deadc0de.apple2ix.basic.R;
|
import org.deadc0de.apple2ix.basic.R;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
@ -100,6 +102,52 @@ public class Apple2Utils {
|
|||||||
return attempts < maxAttempts;
|
return attempts < maxAttempts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void migrate(Apple2Activity activity) {
|
||||||
|
do {
|
||||||
|
if (BuildConfig.VERSION_CODE >= 18) {
|
||||||
|
|
||||||
|
// Migrate emulator.state file from internal path to external storage to allow user manipulation
|
||||||
|
// TODO FIXME : Remove this migration code when all/most users are on version >= 18
|
||||||
|
|
||||||
|
final File extStorage = Apple2Utils.getExternalStorageDirectory(activity);
|
||||||
|
if (extStorage == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String srcPath = getDataDir(activity) + File.separator + Apple2MainMenu.SAVE_FILE;
|
||||||
|
final File srcFile = new File(srcPath);
|
||||||
|
if (!srcFile.exists()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String dstPath = extStorage + File.separator + Apple2MainMenu.SAVE_FILE;
|
||||||
|
|
||||||
|
final int maxAttempts = 5;
|
||||||
|
int attempts = 0;
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
FileInputStream is = new FileInputStream(srcFile);
|
||||||
|
FileOutputStream os = new FileOutputStream(dstPath);
|
||||||
|
copyFile(is, os);
|
||||||
|
break;
|
||||||
|
} catch (InterruptedIOException e) {
|
||||||
|
// EINTR, EAGAIN ...
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.d(TAG, "OOPS exception attempting to copy emulator.state file : " + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(100, 0);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
++attempts;
|
||||||
|
} while (attempts < maxAttempts);
|
||||||
|
|
||||||
|
srcFile.delete();
|
||||||
|
}
|
||||||
|
} while (false);
|
||||||
|
}
|
||||||
|
|
||||||
public static File getExternalStorageDirectory(Apple2Activity activity) {
|
public static File getExternalStorageDirectory(Apple2Activity activity) {
|
||||||
|
|
||||||
@ -140,7 +188,7 @@ public class Apple2Utils {
|
|||||||
return sRealExternalFilesDir;
|
return sRealExternalFilesDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACK NOTE 2015/02/22 : Apparently native code cannot easily access stuff in the APK ... so copy various resources
|
// HACK NOTE 2015/02/22 : Apparently native code cannot easily access stuff in the APK ... so copy various resources
|
||||||
// out of the APK and into the /data/data/... for ease of access. Because this is FOSS software we don't care about
|
// out of the APK and into the /data/data/... for ease of access. Because this is FOSS software we don't care about
|
||||||
// security or DRM for these assets =)
|
// security or DRM for these assets =)
|
||||||
public static String getDataDir(Apple2Activity activity) {
|
public static String getDataDir(Apple2Activity activity) {
|
||||||
|
Loading…
Reference in New Issue
Block a user