Skip to content

UnauthorizedAccessException for system folders on Mac OS #66

Open

Description

@hippogamesunity

Description of the bug

Hi! I'm testing the plugin on Mac OS and there is an issue with UnauthorizedAccessException when writing to the Root drive.
The situation is:

  • the app can list system drives and open files
  • the app can't write to Root or Root/Users (UnauthorizedAccessException)
  • when I'm trying to move files to Root or Root/Users with Finder, it's asks for a user password (so I think it's considered as secured pathes)

Showing this exception to users blocks me from passing the App Store review, so I'm looking for a workarounds to hide drives or hide inaccessible locations maybe.
image

Reproduction steps

  • save any file to the Root drive on Mac OS

Platform specs

Any Unity, any Mac

Additional info

The app asks for permissions to Documents when starting the first time.

Activity

  1. hippogamesunity commented on May 26, 2022

    @hippogamesunity
    Author

    image

  2. yasirkula commented on May 26, 2022

    @yasirkula
    Owner

    First thing I could think of is, every time the path changes, we check for write access in that directory and if we don't have access, disable the Save button. I'll probably give it a shot sometime soon.

  3. hippogamesunity commented on May 26, 2022

    @hippogamesunity
    Author

    Thanks for your reply! Here is another screenshot from the app store reviewer team.
    image

  4. yasirkula commented on May 27, 2022

    @yasirkula
    Owner

    What seems to be the issue in this screenshot?

  5. hippogamesunity commented on May 27, 2022

    @hippogamesunity
    Author

    I mean the error may occur not only for the Root drive, but for others as well.

    Btw I've found code to comment to hide drives (as a workaround).

  6. hippogamesunity commented on May 28, 2022

    @hippogamesunity
    Author

    Another similar exception when listing files (not saving as before).
    image

  7. hippogamesunity commented on May 28, 2022

    @hippogamesunity
    Author

    All previous errors were from an old x64 Mac.
    On the latest Mac OS the plugin doesn't work at all due to sandbox, all pathes are incorrect (like Documents and Desktop).
    image

  8. yasirkula commented on May 29, 2022

    @yasirkula
    Owner

    Thanks again for the feedback! I didn't know about sandboxing, will google it while working on a bugfix for this issue.

  9. hippogamesunity commented on May 29, 2022

    @hippogamesunity
    Author

    As you see, these paths are similar to iOS, so I can suggest Mac sandboxing is similar to iOS. BTW you can't send an app to review without adding the Sandbox capability in Xcode. At the same time, even with this feature enabled, you can't test a sandboxed app by running from Xcode. It gets really sandboxed only after downloaded from the App Store. Also I'm noob in Mac OS)

  10. hippogamesunity commented on May 29, 2022

    @hippogamesunity
    Author

    Sorry to bothering you, but I'm trying to provide as much info as I have. Thanks!

  11. manituan commented on Jul 10, 2023

    @manituan

    Hi, we're facing this issue in our project and I'm wondering if you're still planning on fixing this issue. Thanks.

  12. yasirkula commented on Jul 10, 2023

    @yasirkula
    Owner

    My schedule unfortunately won't allow me to fix this issue soon. I'm planning to work on this at some point but not soon.

  13. yasirkula commented on Sep 1, 2024

    @yasirkula
    Owner

    @hippogamesunity @manituan If I were to add a "Browse..." button that allows the user to pick a directory using Mac's native file picker (upon completion, user will be able to browse that folder's contents using SimpleFileBrowser), do you think App Store Review team would object with the reason "if you're gonna show the native dialog anyways, then do everything with the native dialog; why show a uGUI dialog and native dialog together"?

    I'd personally prefer the native dialog over uGUI dialog but there are already several native file browser plugins and some users would prefer showing their customized uGUI dialog (e.g. to display a World Space file browser). In any case, the solution will be either a fully native dialog experience or a combination of native+uGUI dialogs as I've described in my first paragraph.

  14. Nuker9999999999 commented on Mar 3, 2025

    @Nuker9999999999

    i fixed it here is the code
    `using UnityEngine;
    using System.Collections;
    using System.IO;
    using SimpleFileBrowser;

    public class FileBrowserTest : MonoBehaviour
    {
    // Warning: paths returned by FileBrowser dialogs do not contain a trailing '' character
    // Warning: FileBrowser can only show 1 dialog at a time

    void Start()
    {
    	// Set filters (optional)
    	// It is sufficient to set the filters just once (instead of each time before showing the file browser dialog), 
    	// if all the dialogs will be using the same filters
    	FileBrowser.SetFilters( true, /*new FileBrowser.Filter( "text", ".json", ".txt" ),*/ new FileBrowser.Filter( "Text Files", ".txt", ".pdf" ) );
    
    	// Set default filter that is selected when the dialog is shown (optional)
    	// Returns true if the default filter is set successfully
    	// In this case, set Images filter as the default filter
    	FileBrowser.SetDefaultFilter( ".json" );
    	// Set excluded file extensions (optional) (by default, .lnk and .tmp extensions are excluded)
    	// Note that when you use this function, .lnk and .tmp extensions will no longer be
    	// excluded unless you explicitly add them as parameters to the function
    	FileBrowser.SetExcludedExtensions( ".lnk", ".tmp", ".zip", ".rar", ".exe" );
    
    	// Add a new quick link to the browser (optional) (returns true if quick link is added successfully)
    	// It is sufficient to add a quick link just once
    	// Name: Users
    	// Path: C:\Users
    	// Icon: default (folder icon)
    	FileBrowser.AddQuickLink( "Users", "C:\\Users", null );
    	
    	// !!! Uncomment any of the examples below to show the file browser !!!
    
    	// Example 1: Show a save file dialog using callback approach
    	// onSuccess event: not registered (which means this dialog is pretty useless)
    	// onCancel event: not registered
    	// Save file/folder: file, Allow multiple selection: false
    	// Initial path: "C:\", Initial filename: "Screenshot.png"
    	// Title: "Save As", Submit button text: "Save"
    	// FileBrowser.ShowSaveDialog( null, null, FileBrowser.PickMode.Files, false, "C:\\", "Screenshot.png", "Save As", "Save" );
    
    	// Example 2: Show a select folder dialog using callback approach
    	// onSuccess event: print the selected folder's path
    	// onCancel event: print "Canceled"
    	// Load file/folder: folder, Allow multiple selection: false
    	//Initial path: default (Application.PersistentDataPath), Initial filename: empty
    	// Title: "Select Folder", Submit button text: "Select"
    	// FileBrowser.ShowLoadDialog( ( paths ) => { Debug.Log( "Selected: " + paths[0] ); },
    	//						   () => { Debug.Log( "Canceled" ); },
    	//						   FileBrowser.PickMode.Folders, false, null, null, "Select Folder", "Select" );
    
    	// Example 3: Show a select file dialog using coroutine approach
    	 StartCoroutine( ShowLoadDialogCoroutine() );
    }
    
    IEnumerator ShowLoadDialogCoroutine()
    {
    	// Show a load file dialog and wait for a response from user
    	// Load file/folder: file, Allow multiple selection: true
    	// Initial path: default (Documents), Initial filename: empty
    	// Title: "Load File", Submit button text: "Load"
    	yield return FileBrowser.WaitForLoadDialog( FileBrowser.PickMode.Files, true, Application.persistentDataPath, null, "Select Files", "Load" );
    
    	// Dialog is closed
    	// Print whether the user has selected some files or cancelled the operation (FileBrowser.Success)
    	Debug.Log( FileBrowser.Success );
    
    	if( FileBrowser.Success )
    		OnFilesSelected( FileBrowser.Result ); // FileBrowser.Result is null, if FileBrowser.Success is false
    }
    
    void OnFilesSelected( string[] filePaths )
    {
    	// Print paths of the selected files
    	for( int i = 0; i < filePaths.Length; i++ )
    		Debug.Log( filePaths[i] );
    
    	// Get the file path of the first selected file
    	string filePath = filePaths[0];
    
    	// Read the bytes of the first file via FileBrowserHelpers
    	// Contrary to File.ReadAllBytes, this function works on Android 10+, as well
    	byte[] bytes = FileBrowserHelpers.ReadBytesFromFile( filePath );
    
    	// Or, copy the first file to persistentDataPath
    	string destinationPath = Path.Combine( Application.persistentDataPath, FileBrowserHelpers.GetFilename( filePath ) );
    	FileBrowserHelpers.CopyFile( filePath, destinationPath );
    }
    

    }`

  15. yasirkula commented on Mar 3, 2025

    @yasirkula
    Owner

    @Nuker9999999999 This issue occurs on Mac OS when App Sandbox is enabled. The operating system throws errors while attempting to read contents of directories, so file browser simply stops functioning. Your solution may be related to another issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions