StereoKit / StereoKit-PaintTutorial

Source for a Mixed Reality inking tutorial using StereoKit and C#!
https://stereokit.net
MIT License
32 stars 16 forks source link

UWP: Add full permission support for Documents, use native FilePicker #1

Closed doublerebel closed 3 years ago

doublerebel commented 4 years ago

Due to UWP's intent to sandbox the app and let the user choose file location, user files have no 'path' and only are accessible through StorageFolder/StorageFile interface. Related, the Documents folder is off-limits without manually adding the capability.

Path concept is hardcoded into the StereoKit FilePicker, but navigating UWP user folders without using the native FilePicker takes a lot of wrangling. Additionally, the native FilePicker must be run on the UI thread which is only always accessible through CoreWindow.

Result

Load/Save working on HoloLens 2 device 😃

Known issues

Extra path drawing is triggered when entering/exiting the native FilePicker.

maluoi commented 4 years ago

I have a number of thoughts here, but first off, -thank you- so much for this code! I had tried getting some of this stuff working, and totally failed at it. UWP code is not something I'm great at, and I had totally missed that HoloLens actually has a native file picker already!

The tricky bit is that I don't think this code necessarily belongs here in the tutorial, it would be better in StereoKit itself! My objective for the file picker in StereoKit is that it's a cross-platform solution that should work anywhere. Ideally, it would be awesome for it to wrap the native file pickers on each platform that provides a real MR file picker, and a fallback for those that don't.

But then I believe there's some further tricky bits, since StereoKit C# is actually .Net Standard and doesn't have access to UWP, nor do I really want it to. So this might need to be done at the C level where I do have access to UWP.

The objective for this repository is for it to be the simplest, most easily understood example of an application, so I'm a little reluctant to put in conditional compilation code and all that jazz, even as a placeholder, I hope you don't mind if I pass on this PR for now?

doublerebel commented 4 years ago

Glad to submit the PR! UWP and particularly HoloLens UWP can be tricky, it's been an adventure porting code from other platforms. I totally agree, I can see the FilePicker fix belonging in the framework and not in the tutorial. It did not feel good adding the conditionals.

The painting app is pretty fun though! First thing I tried when I painted something worth sharing, was to save the painting, and I knew somebody else might want the UWP solution too. There is not much to play with on HoloLens 2 yet. Maybe the PR could stay open or go in a separate branch for now?

SimonDarksideJ commented 3 years ago

Probably the best option @maluoi is to make the StereoKit's Save function overridable and just provide an example in the base to override the save function (with FilePicker) in the UWP platform. Probably the best option to keep the Core NetStandard.

maluoi commented 3 years ago

I actually have a new file picker coming in StereoKit v0.3.2! It's implemented on the native side of StereoKit, and uses the OS's native file pickers whenever possible. This does properly account for and solve the file permissions issue on UWP for files the user has picked. It's currently available in the v0.3.2-preview.1 NuGet package as Platform.FilePicker, and this sample will be updated to reflect that change once I fully release v0.3.2 :)

SimonDarksideJ commented 3 years ago

Woot, great work as always @maluoi :D

maluoi commented 3 years ago

StereoKit v0.3.2 is out and done, relevant commit for this repository is at adfa240dc34381fb0a7f89454c3e2b380f889728!