|
@@ -21,19 +21,16 @@ public class UserPreferences {
|
|
|
private static final String TAG = "UserPreferences";
|
|
|
|
|
|
// Disallow explicit instantiation.
|
|
|
- private UserPreferences()
|
|
|
- {
|
|
|
+ private UserPreferences() {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Retrieves the path to the default location of the libretro config.
|
|
|
*
|
|
|
* @param ctx the current {@link Context}
|
|
|
- *
|
|
|
* @return the path to the default location of the libretro config.
|
|
|
*/
|
|
|
- public static String getDefaultConfigPath(Context ctx)
|
|
|
- {
|
|
|
+ public static String getDefaultConfigPath(Context ctx) {
|
|
|
// Internal/External storage dirs.
|
|
|
final String internal = ctx.getFilesDir().getAbsolutePath();
|
|
|
String external = null;
|
|
@@ -58,30 +55,23 @@ public class UserPreferences {
|
|
|
|
|
|
String append_path;
|
|
|
// If we aren't using the global config.
|
|
|
- if (!globalConfigEnabled && !libretro_path.equals(coreDir))
|
|
|
- {
|
|
|
+ if (!globalConfigEnabled && !libretro_path.equals(coreDir)) {
|
|
|
String sanitized_name = sanitizeLibretroPath(libretro_path);
|
|
|
append_path = File.separator + sanitized_name + ".cfg";
|
|
|
- }
|
|
|
- else // Using global config.
|
|
|
+ } else // Using global config.
|
|
|
{
|
|
|
append_path = File.separator + "retroarch.cfg";
|
|
|
}
|
|
|
|
|
|
- if (external != null)
|
|
|
- {
|
|
|
+ if (external != null) {
|
|
|
String confPath = external + append_path;
|
|
|
if (new File(confPath).exists())
|
|
|
return confPath;
|
|
|
- }
|
|
|
- else if (internal != null)
|
|
|
- {
|
|
|
+ } else if (internal != null) {
|
|
|
String confPath = internal + append_path;
|
|
|
if (new File(confPath).exists())
|
|
|
return confPath;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
String confPath = "/mnt/extsd" + append_path;
|
|
|
if (new File(confPath).exists())
|
|
|
return confPath;
|
|
@@ -101,9 +91,7 @@ public class UserPreferences {
|
|
|
|
|
|
try {
|
|
|
new File(new_path).createNewFile();
|
|
|
- }
|
|
|
- catch (IOException e)
|
|
|
- {
|
|
|
+ } catch (IOException e) {
|
|
|
Log.e(TAG, "Failed to create config file to: " + new_path);
|
|
|
}
|
|
|
return new_path;
|
|
@@ -115,8 +103,7 @@ public class UserPreferences {
|
|
|
*
|
|
|
* @param ctx the current {@link Context}.
|
|
|
*/
|
|
|
- public static void updateConfigFile(Context ctx)
|
|
|
- {
|
|
|
+ public static void updateConfigFile(Context ctx, String systemDir) {
|
|
|
String path = getDefaultConfigPath(ctx);
|
|
|
ConfigFile config = new ConfigFile(path);
|
|
|
|
|
@@ -133,6 +120,8 @@ public class UserPreferences {
|
|
|
config.setString("input_overlay_enable", "false");
|
|
|
config.setBoolean("log_verbosity", true);
|
|
|
config.setBoolean("fps_show", true);
|
|
|
+ config.setString("system_directory", systemDir);//20230829添加system路径设置
|
|
|
+ DebugUtil.i(TAG,"write system dir:"+systemDir);
|
|
|
config.setInt("input_player1_analog_dpad_mode", 1);
|
|
|
|
|
|
config.setInt("frontend_log_level", 1);
|
|
@@ -143,66 +132,56 @@ public class UserPreferences {
|
|
|
config.setInt("audio_out_rate", samplingRate);
|
|
|
}
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- int version = ctx.getPackageManager().
|
|
|
+ try {
|
|
|
+ int version = ctx.getPackageManager().
|
|
|
getPackageInfo(ctx.getPackageName(), 0).versionCode;
|
|
|
- final String dst_path = dataDir;
|
|
|
- final String dst_path_subdir = "assets";
|
|
|
+ final String dst_path = dataDir;
|
|
|
+ final String dst_path_subdir = "assets";
|
|
|
|
|
|
Log.i(TAG, "dst dir is: " + dst_path);
|
|
|
Log.i(TAG, "dst subdir is: " + dst_path_subdir);
|
|
|
|
|
|
config.setString("bundle_assets_src_path", ctx.getApplicationInfo().sourceDir);
|
|
|
- DebugUtil.i(TAG,"source="+ctx.getApplicationInfo().sourceDir);
|
|
|
- DebugUtil.i(TAG,"versionCode="+version);
|
|
|
+ DebugUtil.i(TAG, "source=" + ctx.getApplicationInfo().sourceDir);
|
|
|
+ DebugUtil.i(TAG, "versionCode=" + version);
|
|
|
config.setString("bundle_assets_dst_path", dst_path);
|
|
|
config.setString("bundle_assets_dst_path_subdir", dst_path_subdir);
|
|
|
config.setInt("bundle_assets_extract_version_current", version);
|
|
|
- }
|
|
|
- catch (PackageManager.NameNotFoundException ignored)
|
|
|
- {
|
|
|
+ } catch (PackageManager.NameNotFoundException ignored) {
|
|
|
}
|
|
|
|
|
|
// Refactor this entire mess and make this usable for per-core config
|
|
|
- if (Build.VERSION.SDK_INT >= 17 && prefs.getBoolean("audio_latency_auto", true))
|
|
|
- {
|
|
|
+ if (Build.VERSION.SDK_INT >= 17 && prefs.getBoolean("audio_latency_auto", true)) {
|
|
|
int bufferSize = getLowLatencyBufferSize(ctx);
|
|
|
if (bufferSize != -1) {
|
|
|
config.setInt("audio_block_frames", bufferSize);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
+ try {
|
|
|
config.write(path);
|
|
|
- }
|
|
|
- catch (IOException e)
|
|
|
- {
|
|
|
+ } catch (IOException e) {
|
|
|
Log.e(TAG, "Failed to save config file to: " + path);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static void readbackString(ConfigFile cfg, SharedPreferences.Editor edit, String key)
|
|
|
- {
|
|
|
+ private static void readbackString(ConfigFile cfg, SharedPreferences.Editor edit, String key) {
|
|
|
if (cfg.keyExists(key))
|
|
|
edit.putString(key, cfg.getString(key));
|
|
|
else
|
|
|
edit.remove(key);
|
|
|
}
|
|
|
|
|
|
- private static void readbackBool(ConfigFile cfg, SharedPreferences.Editor edit, String key)
|
|
|
- {
|
|
|
+ private static void readbackBool(ConfigFile cfg, SharedPreferences.Editor edit, String key) {
|
|
|
if (cfg.keyExists(key))
|
|
|
edit.putBoolean(key, cfg.getBoolean(key));
|
|
|
else
|
|
|
edit.remove(key);
|
|
|
}
|
|
|
|
|
|
- private static void readbackDouble(ConfigFile cfg, SharedPreferences.Editor edit, String key)
|
|
|
- {
|
|
|
+ private static void readbackDouble(ConfigFile cfg, SharedPreferences.Editor edit, String key) {
|
|
|
if (cfg.keyExists(key))
|
|
|
- edit.putFloat(key, (float)cfg.getDouble(key));
|
|
|
+ edit.putFloat(key, (float) cfg.getDouble(key));
|
|
|
else
|
|
|
edit.remove(key);
|
|
|
}
|
|
@@ -231,11 +210,9 @@ public class UserPreferences {
|
|
|
* Sanitizes a libretro core path.
|
|
|
*
|
|
|
* @param path The path to the libretro core.
|
|
|
- *
|
|
|
* @return the sanitized libretro path.
|
|
|
*/
|
|
|
- private static String sanitizeLibretroPath(String path)
|
|
|
- {
|
|
|
+ private static String sanitizeLibretroPath(String path) {
|
|
|
String sanitized_name = path.substring(
|
|
|
path.lastIndexOf('/') + 1,
|
|
|
path.lastIndexOf('.'));
|
|
@@ -249,11 +226,9 @@ public class UserPreferences {
|
|
|
* Gets a {@link SharedPreferences} instance containing current settings.
|
|
|
*
|
|
|
* @param ctx the current {@link Context}.
|
|
|
- *
|
|
|
* @return A SharedPreference instance containing current settings.
|
|
|
*/
|
|
|
- public static SharedPreferences getPreferences(Context ctx)
|
|
|
- {
|
|
|
+ public static SharedPreferences getPreferences(Context ctx) {
|
|
|
return PreferenceManager.getDefaultSharedPreferences(ctx);
|
|
|
}
|
|
|
|
|
@@ -261,16 +236,14 @@ public class UserPreferences {
|
|
|
* Gets the optimal sampling rate for low-latency audio playback.
|
|
|
*
|
|
|
* @param ctx the current {@link Context}.
|
|
|
- *
|
|
|
* @return the optimal sampling rate for low-latency audio playback in Hz.
|
|
|
*/
|
|
|
@TargetApi(17)
|
|
|
- private static int getLowLatencyOptimalSamplingRate(Context ctx)
|
|
|
- {
|
|
|
+ private static int getLowLatencyOptimalSamplingRate(Context ctx) {
|
|
|
AudioManager manager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
|
|
|
String value = manager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
|
|
|
|
|
|
- if(value == null || value.isEmpty()) {
|
|
|
+ if (value == null || value.isEmpty()) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -281,16 +254,14 @@ public class UserPreferences {
|
|
|
* Gets the optimal buffer size for low-latency audio playback.
|
|
|
*
|
|
|
* @param ctx the current {@link Context}.
|
|
|
- *
|
|
|
* @return the optimal output buffer size in decimal PCM frames.
|
|
|
*/
|
|
|
@TargetApi(17)
|
|
|
- private static int getLowLatencyBufferSize(Context ctx)
|
|
|
- {
|
|
|
+ private static int getLowLatencyBufferSize(Context ctx) {
|
|
|
AudioManager manager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
|
|
|
String value = manager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
|
|
|
|
|
|
- if(value == null || value.isEmpty()) {
|
|
|
+ if (value == null || value.isEmpty()) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -309,11 +280,9 @@ public class UserPreferences {
|
|
|
* as returned by the hardware.
|
|
|
*
|
|
|
* @param ctx The current {@link Context}.
|
|
|
- *
|
|
|
* @return the optimal audio sampling rate in Hz.
|
|
|
*/
|
|
|
- private static int getOptimalSamplingRate(Context ctx)
|
|
|
- {
|
|
|
+ private static int getOptimalSamplingRate(Context ctx) {
|
|
|
int ret;
|
|
|
if (Build.VERSION.SDK_INT >= 17)
|
|
|
ret = getLowLatencyOptimalSamplingRate(ctx);
|