mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-23 14:25:37 +00:00
Android: Add manual disc change from file
This commit is contained in:
parent
59810bf8db
commit
b107cdee53
|
@ -1503,4 +1503,22 @@ DEFINE_JNI_ARGS_METHOD(jboolean, AndroidHostInterface_setMediaPlaylistIndex, job
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFINE_JNI_ARGS_METHOD(jboolean, AndroidHostInterface_setMediaFilename, jstring obj, jstring filename)
|
||||||
|
{
|
||||||
|
if (!System::IsValid() || !filename)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::string filename_str(AndroidHelpers::JStringToString(env, filename));
|
||||||
|
AndroidHostInterface* hi = AndroidHelpers::GetNativeClass(env, obj);
|
||||||
|
hi->RunOnEmulationThread([filename_str, hi]() {
|
||||||
|
if (System::IsValid())
|
||||||
|
{
|
||||||
|
if (!System::InsertMedia(filename_str.c_str()))
|
||||||
|
hi->AddOSDMessage("Disc switch failed. Please make sure the file exists and is a supported disc image.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -124,6 +124,8 @@ public class AndroidHostInterface {
|
||||||
|
|
||||||
public native boolean setMediaPlaylistIndex(int index);
|
public native boolean setMediaPlaylistIndex(int index);
|
||||||
|
|
||||||
|
public native boolean setMediaFilename(String filename);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("duckstation-native");
|
System.loadLibrary("duckstation-native");
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,8 +300,19 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||||
applySettings();
|
applySettings();
|
||||||
}
|
}
|
||||||
} else if (requestCode == REQUEST_IMPORT_PATCH_CODES) {
|
} else if (requestCode == REQUEST_IMPORT_PATCH_CODES) {
|
||||||
if (data != null)
|
if (data == null)
|
||||||
importPatchesFromFile(data.getData());
|
return;
|
||||||
|
|
||||||
|
importPatchesFromFile(data.getData());
|
||||||
|
} else if (requestCode == REQUEST_CHANGE_DISC_FILE) {
|
||||||
|
if (data == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String path = GameDirectoriesActivity.getPathFromUri(this, data.getData());
|
||||||
|
if (path == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AndroidHostInterface.getInstance().setMediaFilename(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,6 +389,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||||
|
|
||||||
private static final int REQUEST_CODE_SETTINGS = 0;
|
private static final int REQUEST_CODE_SETTINGS = 0;
|
||||||
private static final int REQUEST_IMPORT_PATCH_CODES = 1;
|
private static final int REQUEST_IMPORT_PATCH_CODES = 1;
|
||||||
|
private static final int REQUEST_CHANGE_DISC_FILE = 2;
|
||||||
|
|
||||||
private void onMenuClosed() {
|
private void onMenuClosed() {
|
||||||
enableFullscreenImmersive();
|
enableFullscreenImmersive();
|
||||||
|
@ -560,21 +572,27 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||||
private void showDiscChangeMenu() {
|
private void showDiscChangeMenu() {
|
||||||
final String[] paths = AndroidHostInterface.getInstance().getMediaPlaylistPaths();
|
final String[] paths = AndroidHostInterface.getInstance().getMediaPlaylistPaths();
|
||||||
final int currentPath = AndroidHostInterface.getInstance().getMediaPlaylistIndex();
|
final int currentPath = AndroidHostInterface.getInstance().getMediaPlaylistIndex();
|
||||||
if (paths == null) {
|
final int numPaths = (paths != null) ? paths.length : 0;
|
||||||
onMenuClosed();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
|
||||||
CharSequence[] items = new CharSequence[paths.length];
|
CharSequence[] items = new CharSequence[numPaths + 1];
|
||||||
for (int i = 0; i < paths.length; i++)
|
for (int i = 0; i < numPaths; i++)
|
||||||
items[i] = GameListEntry.getFileNameForPath(paths[i]);
|
items[i] = GameListEntry.getFileNameForPath(paths[i]);
|
||||||
|
items[numPaths] = "Select New File...";
|
||||||
|
|
||||||
builder.setSingleChoiceItems(items, currentPath, (dialogInterface, i) -> {
|
builder.setSingleChoiceItems(items, (currentPath < numPaths) ? currentPath : -1, (dialogInterface, i) -> {
|
||||||
AndroidHostInterface.getInstance().setMediaPlaylistIndex(i);
|
|
||||||
dialogInterface.dismiss();
|
dialogInterface.dismiss();
|
||||||
onMenuClosed();
|
onMenuClosed();
|
||||||
|
|
||||||
|
if (i < numPaths) {
|
||||||
|
AndroidHostInterface.getInstance().setMediaPlaylistIndex(i);
|
||||||
|
} else {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
|
intent.setType("*/*");
|
||||||
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
|
startActivityForResult(Intent.createChooser(intent, getString(R.string.main_activity_choose_disc_image)), REQUEST_CHANGE_DISC_FILE);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
builder.setOnCancelListener(dialogInterface -> onMenuClosed());
|
builder.setOnCancelListener(dialogInterface -> onMenuClosed());
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
|
|
|
@ -235,6 +235,22 @@ public class GameDirectoriesActivity extends AppCompatActivity {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getPathFromUri(Context context, Uri uri) {
|
||||||
|
String path = FileUtil.getFullPathFromUri(uri, context);
|
||||||
|
if (path.length() < 5) {
|
||||||
|
new AlertDialog.Builder(context)
|
||||||
|
.setTitle(R.string.main_activity_error)
|
||||||
|
.setMessage(R.string.main_activity_get_path_from_file_error)
|
||||||
|
.setPositiveButton(R.string.main_activity_ok, (dialog, button) -> {
|
||||||
|
})
|
||||||
|
.create()
|
||||||
|
.show();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
public static void addSearchDirectory(Context context, String path, boolean recursive) {
|
public static void addSearchDirectory(Context context, String path, boolean recursive) {
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
final String key = recursive ? "GameList/RecursivePaths" : "GameList/Paths";
|
final String key = recursive ? "GameList/RecursivePaths" : "GameList/Paths";
|
||||||
|
|
|
@ -242,22 +242,6 @@ public class MainActivity extends AppCompatActivity {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPathFromUri(Uri uri) {
|
|
||||||
String path = FileUtil.getFullPathFromUri(uri, this);
|
|
||||||
if (path.length() < 5) {
|
|
||||||
new AlertDialog.Builder(this)
|
|
||||||
.setTitle(R.string.main_activity_error)
|
|
||||||
.setMessage(R.string.main_activity_get_path_from_file_error)
|
|
||||||
.setPositiveButton(R.string.main_activity_ok, (dialog, button) -> {
|
|
||||||
})
|
|
||||||
.create()
|
|
||||||
.show();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
@ -288,7 +272,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
if (resultCode != RESULT_OK)
|
if (resultCode != RESULT_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String path = getPathFromUri(data.getData());
|
String path = GameDirectoriesActivity.getPathFromUri(this, data.getData());
|
||||||
if (path == null)
|
if (path == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue