Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: File pickers on UIKit, Android, and UWP #9657

Open
Ravbug opened this issue Apr 30, 2024 · 3 comments
Open

Feature Request: File pickers on UIKit, Android, and UWP #9657

Ravbug opened this issue Apr 30, 2024 · 3 comments
Milestone

Comments

@Ravbug
Copy link
Contributor

Ravbug commented Apr 30, 2024

The new SDL FileDialog API is amazing. I would love to see file choosers on non-desktop platforms, because it would greatly assist users in importing and exporting save data from games, among other things.

UWP has the FileOpenPicker and FolderPicker documented here: https://learn.microsoft.com/en-us/windows/uwp/files/quickstart-using-file-and-folder-pickers. They give sample code in C# but the C++ equivalent is probably very similar. As far as I am aware, this is also supported on UWP for Xbox.

UIKit has the UIDocumentPickerViewController, documented here: https://developer.apple.com/documentation/uikit/uidocumentpickerviewcontroller. It's available on iOS and visionOS. You can choose folders by passing kUTTypeFolder into the documentTypes parameter of the UIDocumentPickerViewController constructor.

Android has ACTION_OPEN_DOCUMENT and ACTION_OPEN_DOCUMENT_TREE which prompt the system to display a DocumentsProvider and return the chosen items as content:/// URLs. It's documented here: https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT. It may require JNI interop to invoke.

@slouken
Copy link
Collaborator

slouken commented Apr 30, 2024

Sounds great, feel free to post a PR implementing one or more of those. :)

@Semphriss
Copy link
Contributor

Posting the original idea I had here:

I planned to add a function similar to the existing file dialogs, but instead of treating with path strings, it would treat with SDL_IOStreams, which should be compatible with pretty much any conception of importing/exporting data. It would fallback on ordinary file dialogs on desktop platforms.

I wanted to investigate into the various platforms (at least iOS/Android, but also console and Emscripten) to understand how they work before developing the interface, but I haven't yet finished my research. If somebody else is working on it, please let me know so that I don't duplicate the work.

@MikuAuahDark
Copy link
Contributor

I have an idea for Android and may try to get my hands on it next week.

Since Android returns content:// URI as opposed to regular file path, I propose one of these function:

  • int SDL_AndroidContentURIToFileDescriptor(conost char *uri, const char *mode); function that converts the content:// URI to integer file descriptor (so you can pass it to fdopen); or
  • SDL_IOStream *SDL_AndroidOpenContentURI(const char *uri, const char *mode);.

With this method, the filelist can be kept as const char* without breaking current API. Note that the mode is either "r" (for reading/open file dialog) or "w" (for writing/save file dialog) or both. Feel free to discuss which one is better.

So how would be 3rd-party apps retrieve the filename? It's not possible to deduce the filename from content:// URI string alone but Android has an API that gives you the filename along with the content:// URI. The idea then is to put the filename in the query string to it. So, content://something/somefile?SDL_filename=filename.txt&SDL_mtime=1234567890. I'm not sure if Android will ignore the query string completely or we have to clear it before passing it to Android ContentResolver or if this method of putting the filename work at all.

If there are things that you want to know or want me to know, feel free to tell me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants