hrydgard / ppsspp

A PSP emulator for Android, Windows, Mac and Linux, written in C++. Want to contribute? Join us on Discord at https://discord.gg/5NJB6dD or just send pull requests / issues. For discussion use the forums at forums.ppsspp.org.
https://www.ppsspp.org
Other
11.12k stars 2.16k forks source link

PPSSPP open file using SAF issue - can it handle selecting multiple files returned by SAF picker? #18874

Open tvdev7805 opened 7 months ago

tvdev7805 commented 7 months ago

Game or games this happens in

None

What area of the game / PPSSPP

PPSSPP "LOAD..." function When trying to open an ISO file using LOAD.. It opens ACTION_OPEN_DOCUMENT intent, the SAF FILE PICKER can return the result in 2 ways, one is to return a single file uri in data, the other way is to return multiple files uri array in clipdata.

What should happen

It's best if PPSSPP can allow users to select multiple files and add them to library using SAF file picker.

I am writing an SAF FILE PICKER ui for Android TV 11+ and Google TV (Android 12), it already worked with PPSSPP when selecting only one file from device's storage or usb, I hope it can support selecting multiple files.

Logs

No response

Platform

Android

Mobile device model or graphics card (GPU)

MIBOX S GEN 2

PPSSPP version affected

1.17.1

Last working version

No response

Graphics backend (3D API)

Vulkan

Checklist

anr2me commented 7 months ago

What library? you mean the recent games history?

hrydgard commented 7 months ago

This should be doable - but you're in the best position to make the change since you clearly have a good test setup :) PPSSPP is very easy to build.

Here are some code pointers:

Where we spawn the dialog:

https://github.com/hrydgard/ppsspp/blob/master/android/src/org/ppsspp/ppsspp/NativeActivity.java#L1419

Where we read the result:

https://github.com/hrydgard/ppsspp/blob/master/android/src/org/ppsspp/ppsspp/NativeActivity.java#L1207

PRs very much accepted :)

tvdev7805 commented 7 months ago

Thanks for replying, I hope you (or someone) can add this for me because I am not familiar with building the project. here is the concept codes in java

if (resultCode == Result.Ok) {
    if (data != null) {
        if (data.getClipData() != null) { // Handling multiple files
            List<String> uriList = new ArrayList<>();
            ActivityFlags permissionsFlags = data.getFlags() & (ActivityFlags.GrantReadUriPermission | ActivityFlags.GrantWriteUriPermission);

            for (int index = 0; index < data.getClipData().getItemCount(); index++) {
                Uri fileUri = data.getClipData().getItemAt(index).getUri();
                ContentResolver.takePersistableUriPermission(fileUri, permissionsFlags);
                uriList.add(fileUri.toString());
            }

        } else {  // Handling single file

        }
    }
}
tvdev7805 commented 7 months ago

What library? you mean the recent games history?

I mean, adding game files to the game library.. Yes that is recent game files. Since you can take persistable permission for these files, users can open any of them later after adding games to the library (recent game files)

anr2me commented 7 months ago

Thanks for replying, I hope you (or someone) can add this for me because I am not familiar with building the project. here is the concept codes in java

PPSSPP is a valid Android Studio project, you just need to open it (Open, Not Import! as some people made a mistake by importing it) with Android Studio (the latest version should works too as i remembered), but the recommended NDK is 21e

Quoted from https://github.com/hrydgard/ppsspp/wiki/Build-instructions#building-for-android-with-android-studio

Building for Android with Android Studio

Open the PPSSPP folder as a project in Android Studio. Change the build variant to "normalOptimized" and build and run. Everything should work, provided you have installed the NDK and CMake properly through the SDK manager.

tvdev7805 commented 7 months ago

Here is a video demostration of how it works. If anyone wants to test it for development purpose, please DM me

https://www.youtube.com/watch?v=Pm8WTnLG_P4

hrydgard commented 7 months ago

Why close?

tvdev7805 commented 7 months ago

What I had in mind is that since I'm not experienced with GitHub and I couldn't successfully build the project using Android Studio despite my attempts, if there's no interest in this, I'll simply close it. However, if anyone is interested in this "new feature," I would be more than happy to proceed.