Skip to content

Commit

Permalink
Map fs drives to the emulator folder
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita36078 committed Aug 14, 2023
1 parent 9d3dc49 commit 2b56c04
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
10 changes: 9 additions & 1 deletion app/src/main/java/javax/microedition/shell/MicroLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -131,6 +135,7 @@ private static String getRoot(String path) {
static Enumeration<String> listRoots() {
Vector<String> list = new Vector<>();
list.add(FC_ROOTS[0]);
list.add(FC_ROOTS[1]);
return list.elements();
}

Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/ru/playsoftware/j2meloader/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 2b56c04

Please sign in to comment.