Fix getDefaultConfigPath not correctly looking up external and internal data directories
This commit is contained in:
parent
4a0d2367d6
commit
b7779f04e0
|
@ -39,8 +39,15 @@ public final class UserPreferences
|
||||||
public static String getDefaultConfigPath(Context ctx)
|
public static String getDefaultConfigPath(Context ctx)
|
||||||
{
|
{
|
||||||
// Internal/External storage dirs.
|
// Internal/External storage dirs.
|
||||||
final String internal = System.getenv("INTERNAL_STORAGE");
|
final String internal = ctx.getFilesDir().getAbsolutePath();
|
||||||
final String external = System.getenv("EXTERNAL_STORAGE");
|
String external = null;
|
||||||
|
|
||||||
|
// Get the App's external storage folder
|
||||||
|
final String state = android.os.Environment.getExternalStorageState();
|
||||||
|
if (android.os.Environment.MEDIA_MOUNTED.equals(state)) {
|
||||||
|
File extsd = ctx.getExternalFilesDir(null);
|
||||||
|
external = extsd.getAbsolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
// Native library directory and data directory for this front-end.
|
// Native library directory and data directory for this front-end.
|
||||||
final String dataDir = ctx.getApplicationInfo().dataDir;
|
final String dataDir = ctx.getApplicationInfo().dataDir;
|
||||||
|
@ -84,15 +91,26 @@ public final class UserPreferences
|
||||||
return confPath;
|
return confPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (internal != null && new File(internal + append_path).canWrite())
|
// Config file does not exist. Create empty one.
|
||||||
return internal + append_path;
|
|
||||||
else if (external != null && new File(internal + append_path).canWrite())
|
// emergency fallback
|
||||||
return external + append_path;
|
String new_path = "/mnt/sd" + append_path;
|
||||||
|
|
||||||
|
if (external != null)
|
||||||
|
new_path = external + append_path;
|
||||||
|
else if (internal != null)
|
||||||
|
new_path = internal + append_path;
|
||||||
else if (dataDir != null)
|
else if (dataDir != null)
|
||||||
return dataDir + append_path;
|
new_path = dataDir + append_path;
|
||||||
else
|
|
||||||
// emergency fallback, all else failed
|
try {
|
||||||
return "/mnt/sd" + append_path;
|
new File(new_path).createNewFile();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
Log.e(TAG, "Failed to create config file to: " + new_path);
|
||||||
|
}
|
||||||
|
return new_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -226,15 +244,15 @@ public final class UserPreferences
|
||||||
|
|
||||||
if (prefs.getBoolean("savefile_directory_enable", false))
|
if (prefs.getBoolean("savefile_directory_enable", false))
|
||||||
{
|
{
|
||||||
config.setString("savefile_directory", prefs.getString("savefile_directory", ""));
|
config.setString("savefile_directory", prefs.getString("savefile_directory", ""));
|
||||||
}
|
}
|
||||||
if (prefs.getBoolean("savestate_directory_enable", false))
|
if (prefs.getBoolean("savestate_directory_enable", false))
|
||||||
{
|
{
|
||||||
config.setString("savestate_directory", prefs.getString("savestate_directory", ""));
|
config.setString("savestate_directory", prefs.getString("savestate_directory", ""));
|
||||||
}
|
}
|
||||||
if (prefs.getBoolean("system_directory_enable", false))
|
if (prefs.getBoolean("system_directory_enable", false))
|
||||||
{
|
{
|
||||||
config.setString("system_directory", prefs.getString("system_directory", ""));
|
config.setString("system_directory", prefs.getString("system_directory", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
config.setBoolean("video_font_enable", prefs.getBoolean("video_font_enable", true));
|
config.setBoolean("video_font_enable", prefs.getBoolean("video_font_enable", true));
|
||||||
|
@ -244,11 +262,11 @@ public final class UserPreferences
|
||||||
for (int i = 1; i <= 4; i++)
|
for (int i = 1; i <= 4; i++)
|
||||||
{
|
{
|
||||||
final String[] btns =
|
final String[] btns =
|
||||||
{
|
{
|
||||||
"up", "down", "left", "right",
|
"up", "down", "left", "right",
|
||||||
"a", "b", "x", "y", "start", "select",
|
"a", "b", "x", "y", "start", "select",
|
||||||
"l", "r", "l2", "r2", "l3", "r3"
|
"l", "r", "l2", "r2", "l3", "r3"
|
||||||
};
|
};
|
||||||
|
|
||||||
for (String b : btns)
|
for (String b : btns)
|
||||||
{
|
{
|
||||||
|
@ -305,14 +323,14 @@ public final class UserPreferences
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
private static void readbackInt(ConfigFile cfg, SharedPreferences.Editor edit, String key)
|
private static void readbackInt(ConfigFile cfg, SharedPreferences.Editor edit, String key)
|
||||||
{
|
{
|
||||||
if (cfg.keyExists(key))
|
if (cfg.keyExists(key))
|
||||||
edit.putInt(key, cfg.getInt(key));
|
edit.putInt(key, cfg.getInt(key));
|
||||||
else
|
else
|
||||||
edit.remove(key);
|
edit.remove(key);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitizes a libretro core path.
|
* Sanitizes a libretro core path.
|
||||||
|
|
Loading…
Reference in New Issue