diff --git a/app/src/main/java/javax/microedition/shell/MicroLoader.java b/app/src/main/java/javax/microedition/shell/MicroLoader.java index f62fb5acc..47077ab69 100644 --- a/app/src/main/java/javax/microedition/shell/MicroLoader.java +++ b/app/src/main/java/javax/microedition/shell/MicroLoader.java @@ -102,6 +102,14 @@ public boolean init() { if (cacheDir != null && cacheDir.exists()) { FileUtils.clearDirectory(cacheDir); } + File internalDriveDir = new File(Config.getFsInternalDir()); + if (!internalDriveDir.exists()) { + internalDriveDir.mkdirs(); + } + File externalDriveDir = new File(Config.getFsExternalDir()); + if (!externalDriveDir.exists()) { + externalDriveDir.mkdirs(); + } StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() .permitNetwork() .penaltyLog() @@ -201,7 +209,7 @@ private void setProperties() { System.setProperty("fileconn.dir.cache", dataUri + "/cache"); System.setProperty("fileconn.dir.private", dataUri + "/private"); System.setProperty("fileconn.dir.music", musicUri); - System.setProperty("user.home", primaryStoragePath); + System.setProperty("user.home", Config.getFsInternalDir()); } public int getOrientation() { diff --git a/app/src/main/java/org/microemu/cldc/file/FileSystemFileConnection.java b/app/src/main/java/org/microemu/cldc/file/FileSystemFileConnection.java index d56c5043e..90bce2bb4 100644 --- a/app/src/main/java/org/microemu/cldc/file/FileSystemFileConnection.java +++ b/app/src/main/java/org/microemu/cldc/file/FileSystemFileConnection.java @@ -53,6 +53,8 @@ import androidx.core.content.FileProvider; +import ru.playsoftware.j2meloader.config.Config; + public class FileSystemFileConnection implements FileConnection { private static final String TAG = FileSystemFileConnection.class.getSimpleName(); @@ -65,7 +67,6 @@ public class FileSystemFileConnection implements FileConnection { "1:/", "fs/MyStuff/", }; - private static final String[] FS_ROOTS = {System.getProperty("user.home")}; private final String host; private final String root; @@ -114,12 +115,15 @@ public class FileSystemFileConnection implements FileConnection { } private String getFsRoot() { - return FS_ROOTS[0] + DIR_SEP_STR; + if (root.equalsIgnoreCase(FC_ROOTS[1])) { + return Config.getFsExternalDir(); + } + return Config.getFsInternalDir(); } private static String getRoot(String path) { for (String root : FC_ROOTS) { - if (path.startsWith(root)) + if (path.toLowerCase().startsWith(root)) return root; } int separator = path.indexOf(DIR_SEP); @@ -131,6 +135,7 @@ private static String getRoot(String path) { static Enumeration listRoots() { Vector list = new Vector<>(); list.add(FC_ROOTS[0]); + list.add(FC_ROOTS[1]); return list.elements(); } diff --git a/app/src/main/java/ru/playsoftware/j2meloader/config/Config.java b/app/src/main/java/ru/playsoftware/j2meloader/config/Config.java index 2531ca282..1cf4c6e70 100644 --- a/app/src/main/java/ru/playsoftware/j2meloader/config/Config.java +++ b/app/src/main/java/ru/playsoftware/j2meloader/config/Config.java @@ -38,6 +38,7 @@ public class Config { public static final String DEX_OPT_CACHE_DIR = "dex_opt"; + public static final String FS_DIR = "/fs/"; public static final String MIDLET_CONFIG_FILE = "/config.json"; public static final String MIDLET_CONFIGS_DIR = "/configs/"; public static final String MIDLET_DATA_DIR = "/data/"; @@ -106,6 +107,18 @@ public static String getShadersDir() { return emulatorDir + SHADERS_DIR; } + public static String getFsInternalDir() { + return emulatorDir + FS_DIR + "c/"; + } + + public static String getFsExternalDir() { + if (FileUtils.isExternalStorageLegacy()) { + return Environment.getExternalStorageDirectory().getPath() + "/"; + } else { + return emulatorDir + FS_DIR + "e/"; + } + } + public static void startApp(Context context, String name, String path, boolean showSettings) { startApp(context, name, path, showSettings, null); }