UnitySimpleFileBrowser
UnitySimpleFileBrowser copied to clipboard
FileBrowserHelpers.GetEntriesInDirectory() only works when called once, returns null every time after
Description of the bug FileBrowserHelpers.GetEntriesInDirectory() only works when called once unless using the same folder path used the first time, returns null every time after when using a different folder path
Reproduction steps
In code write SimpleFileBrowser.FileSystemEntry[] _filePaths = FileBrowserHelpers.GetEntriesInDirectory([PUT A VALID FOLDER PATH HERE], false);, create 2 buttons and attach the method, make sure you have set a valid folder path for each method, after this method Debug.Log(_filePaths);, build and run as a UWP (Universal Windows Pacakge) then press the button which calls the method then press the other, it will only work the first time and throw errors every time after except for the method with the path which was called first otherwise it returns null.
Platform specs
- Unity version: Tested on 2022.3.47f1 & 6000.0.16f1
- Platform: Windows 11
- How did you download the plugin: updated version from GitHub (Here)
I've narrowed it down to 'System.IO.Directory.Getfiles' which is saying access denied in the UWP debug console. Directory.GetFiles is called inside of SimpleFileBrowser.FileBrowserHelpers.GetEntriesInDirectory, but is inside of a try/catch, so when the access is denied the code carries until the end and with no results it returns null.
Ultimately I believe System.IO.Directory.Getfiles is the cultpate but I can't understand why it's only working for the first path, and the first path can be anything and it will work so it's not that the other path is invalid or is unaccessible because if I use the second path first it's the same, only the first used path will work with Directory.GetFiles and every time it's used with another after/other than the first path it fails.
UWP isn't actually supported (mentioned in the asset description) because it doesn't grant access to filesystem (or am I remembering it wrong)? You may have access to persistentDataPath but I wouldn't expect access to Documents, Desktop, C:\ or other volumes. The issue shouldn't be related to this plugin since it uses System.IO APIs on UWP as you've observed. If I'm correct, replacing FileBrowserHelpers.GetEntriesInDirectory with Directory.GetFiles should result in the same behaviour. It may also give an exception describing the issue.