wa2c / cifs-documents-provider

CIFS Documents Provider
MIT License
295 stars 26 forks source link

Selecting directory fails for certain apps #17

Closed RebelliousX closed 2 years ago

RebelliousX commented 2 years ago

Hello,

When it comes to selecting a directory from the "Open From" files app, some apps won't even show CIFS Document Provider as an option, such as Duckstation, AetherSX2, fMSX emulators for PSX, PS2 and MSX.

Please take a look at the implementation of DuckStation of opening and getting URI from a tree: DuckStation's FileUtil.java

I am not asking to correct the code of such emulators, but to see what is missing in CIFS Document Provider that prevents such apps from showing the option to select a folder!

Some other apps work fine like the Dolphin, MSX.emu emulators for the WII, GameCube, and MSX. They show that CIFS Document Provider as an option to select a folder, they show "Access to Shared Folder" from "Open From" window, and I can indeed select a folder for all of my games in my NAS drive.

I really appreciate your work, it is really helpful when it comes to access my games' library from my NAS drive on all my android devices, including Android TV. Especially with newer and forced SAF of Android 11 and 12.

wa2c commented 2 years ago

@RebelliousX I saw some DuckStation code. I found the app uses local file selecting.

https://github.com/Blackbird88/duckstation-1/blob/master/android/app/src/main/java/com/github/stenzek/duckstation/MainActivity.java

    private void startAddGameDirectory() {
        if (!checkForExternalStoragePermissions())
            return;

        Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
        i.addCategory(Intent.CATEGORY_DEFAULT);
        i.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
        startActivityForResult(Intent.createChooser(i, getString(R.string.main_activity_choose_directory)),
                REQUEST_ADD_DIRECTORY_TO_GAME_LIST);
    }

This code is used to add the game directory. "EXTRA_LOCAL_ONLY" means that only local files are selected.

If I want to show CIFS Documents Provder on SAF Picker, I must add a flag "DocumentsContract.Root.FLAG_LOCAL_ONLY" on following code.

https://github.com/wa2c/cifs-documents-provider/blob/391b97a783b7dac0fa75af39ecba5d39dd939e97/app/src/main/java/com/wa2c/android/cifsdocumentsprovider/presentation/provider/CifsDocumentsProvider.kt

                add(DocumentsContract.Root.COLUMN_FLAGS,
                    DocumentsContract.Root.FLAG_SUPPORTS_IS_CHILD or
                            DocumentsContract.Root.FLAG_SUPPORTS_CREATE
                )

But I don't want to add this flag to the code by default. Because CIFS Documents Provider provides the remote storage access. If there are many requests, I may add an option to add this flag.

RebelliousX commented 2 years ago

Hopefully you will, because it is really painful to only select 1 game at a time but not browse the whole directory. Other emulators like PPSSPP does have the same problem. And with Android 11/12, you can't store the games locally easily as before.

wa2c commented 2 years ago

I will consider adding the option.

RebelliousX commented 2 years ago

Thank you for Everything, even if you don't add it, thank you. :)

RebelliousX commented 2 years ago

Thank you @wa2c for showing me what to do to fix this issue.

I just installed Android Studio, modified the code as you suggested. and built a release APK for my specific use. I know nothing about Kotlin, lol. But now everything works fine in all my apps, whether they expect local or network document provider. I didn't see any drawbacks for having this column flag FLAG_LOCAL_ONLY enabled.

Thanks again.

RebelliousX commented 2 years ago

Thank you @wa2c for implementing this feature in v1.5.0, I really appreciate it.