Search Unity

Native File Browser - Use native File Browser on Mac and Windows!

Discussion in 'Assets and Asset Store' started by PygmyMonkey, Jul 26, 2016.

  1. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    That's at the top of the first crash log I posted above; it's Mac OS X 10.11.6 (15G1217).

    It does not; an example path is "/Users/jstrout/LuminaryApps/clients/ModularMining/notes/from\ Dave/CurveSpeedTest/Path\ Bengalla\ All.csv". But remember, this happens reliably when I cancel the dialog, in which case I haven't selected a path at all.

    Huh. As an API design issue, I think'd be better to return empty or null, but at this point I'd be happy just to not crash.

    Yes, I just bought it last Thursday.
     
  2. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    I'm also using OS X 10.11.6 :/
    What Unity version are you using?

    Do you also have the error when you're using the demo scene?
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I'm using Unity 5.5.0f3.

    And no, I'm not getting the crash in the demo scene. So I'm currently trying to figure out what the key difference is that triggers it. Will report back if I'm able to reproduce it there.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    OK, maybe I've found the trigger: throwing an exception in the callback delegate code.

    Obviously this isn't something you would intentionally do, but I was calling some file-loading code that goes way back (previously invoked from a Canvas-based file browser). And I was doing this, at first, even when the user had canceled, which means I was trying to use "cancel" as a file path. As that's not a valid path, the IO frameworks would have certainly thrown an exception at some point.

    I'm able to reproduce the problem in the demo scene by just adding
    Code (csharp):
    1. throw new IndexOutOfRangeException();
    to the demo code. It crashes Unity, with a crash log like this:

    This is probably because we are in a situation where managed (C#) code is being invoked by unmanaged (C/C++) code. That's a very dangerous situation, as described in the "Runtime Exception Propagation" section of this document.

    I guess we can work around it by wrapping the guts of our delegates in a try-block, or otherwise making sure that no exception ever propagates upward from there. But it'd be great if you could find some way to do this within your plugin (even if that means a C# wrapper for your native code).
     
  5. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Oh nice!
    Thanks for finding this. You're right, this is a problem and I should find a way to fix that :)

    One simple way I've found is just add a try/catch block inside the callback from C++ in my C# wrapper.
    I'll make some tests on Windows too to see if it's needed and show the fix here.
     
  6. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Well, seems like it's only needed for OS X.
    So in the FileBrowserMac.cs file, at the very end, in the ReceiveDeviceMessage method, you just need to add a try/catch. I'll submit a fix to the Asset Store :)

    Thanks again for finding this!
     
  7. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Version submitted to the Asset Store :)
    Plus, when you click cancel, I now return null instead of "cancel" for the filePath!
     
    JoeStrout likes this.
  8. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Sounds great! Thank you for the quick fix.
     
    PygmyMonkey likes this.
  9. Andrew_Cirtex

    Andrew_Cirtex

    Joined:
    Jun 6, 2016
    Posts:
    6
    Hey I am very interested in getting this asset.

    This might be a dumb question, but I was just wondering if this will work for allowing users to upload photos which will then be displayed within the game window? I am asking because I have developed an app which allows users to upload a photo and drag and then drop images on top of their photo to sort of design their space with products before they buy them. I am currently using another File Browser, but it is absolutely terrible and does not support Mac. This Asset seems perfect though.

    Thanks! :)
     
  10. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    It wouldn't be "uploading" since it's just opening a file on the local machine. But yes, this would work fine for that.
     
  11. Andrew_Cirtex

    Andrew_Cirtex

    Joined:
    Jun 6, 2016
    Posts:
    6
    Thanks for your answer. I have now purchased the asset. Although, I'm more of a visual programmer, and was unaware you had to make your own scripts to use this..

    How would I go about creating a button which opens the file explorer and only allows you to choose image files, then once they open it, it then displays on the screen?

    Any help would be appreciated :)

    Thanks
     
  12. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Er... that's a pretty tall order. And probably more suited to the Getting Started or Scripting forums.

    The asset comes with a demo scene that shows you how to open a file (in the sense of, get the path to the file the user chose). So you have that much, at least.
     
  13. Andrew_Cirtex

    Andrew_Cirtex

    Joined:
    Jun 6, 2016
    Posts:
    6
    Yeah I have figured that out, got the button working to choose a file and everything, but it just displays the photo path text, instead of actually displaying the photo, that's the only part i'm stuck with. Is it hard to make the image actually display?

    Thanks
     
  14. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    It's non-trivial, and off-topic for this thread. Check out the docs for Texture2D.LoadImage, and if you have more questions, I suggest you start a new thread in the Getting Started forum.
     
  15. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    NativeFileBrowser 1.0.7 is now available on the Asset Store!
    • NEW: Fixed issue when throwing an exception in the callback method on OS X,
    • NEW: The filePath returned when cancel is clicked is now null (previously it was "cancel")
     
    jGate99 and JoeStrout like this.
  16. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello,

    I've just added that to the demo scene, thanks to you :)
    It will be part of the next update.

    But here's what you have to do, first create in your scene a RawImage from the GameObject/UI menu. Place it wherever you want in the scene, and then use the script below. It will open the file browser to ask for a path, then load the image in memory and display it inside your rawImage.
    You'll see that I've added something to resize the image so it's not distorted. It will keep the ratio of the original image, but will only change the width or height of your Raw Image in your scene. You decide which one with the bool keepImageWidth = true; variable.

    Here's the script!



    You have to attach it to a Game Object, and you'll see in the inspector an empty field for the Raw Image, simply drag and drop the Raw Image you added to the scene to this field and it should be good ;)

    Have a great day!
     
    Andrew_Cirtex and JoeStrout like this.
  17. Andrew_Cirtex

    Andrew_Cirtex

    Joined:
    Jun 6, 2016
    Posts:
    6
    Hey PygmyMonkey!

    Wow! I really can't thank you enough for doing this, this is absolutely perfect!

    You're a life saver, thanks for your help :)
     
    PygmyMonkey likes this.
  18. Fab-London

    Fab-London

    Joined:
    Feb 6, 2013
    Posts:
    35
    Hi,

    I have bought the asset from the Asset Store but I am getting the following error message with Windows 10, it is working with no problem on MacOS.

    I am using the syntax provided in the example provided in the downloaded asset.

    Any idea on what the problem might be ?

    [FileBrowserWindows] Error:The system cannot find the path specified.
    UnityEngine.Debug:LogError(Object)
    <CommonPanel>c__AnonStorey6:<>m__0() (at Assets/ThirdParty/PygmyMonkey/FileBrowser/Scripts/FileBrowserWindows.cs:199)
    FileBrowserDispatcher:Update() (at Assets/ThirdParty/PygmyMonkey/FileBrowser/Scripts/FileBrowserDispatcher.cs:96)
     
  19. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello!

    Can you tell me what is the path of the file/folder you're trying to access? Maybe there's a special character in there or something.
    Also, have you tried to load this file from the demo scene to see if you have the issue?
     
  20. Legend_Bacon

    Legend_Bacon

    Joined:
    Jan 19, 2016
    Posts:
    3
    Hey there,

    So I've bought your package a while ago, and it's been awesome so far. Great work.

    I am running into a problem now though: for this particular project, my build needs to be installed in C:\Program Files (x86). But when I try to call OpenFilePanel from there, it doesn't work. No errors, just nothing happens.

    As a side note, it does work if I move that same build to the documents or Desktop folder, or if I start the build with "run as administrator". Sadly, I know my users won't have admin rights, and using the C:\Program Files (x86) folder is a requirement.

    I personally think the problem is the FileBrowser EXE, as running another EXE from StreamingAssets isn't allowed in C:\Program Files (x86). So I'm thinking about moving your PygmyMonkey folder to PersistentDataPath through code with the rest of my data, and call the EXE from there .

    Do you think that would work? Is there something in your code that absolutely requires the FileBrowser to be in the StreamingAssets folder? Did you encounter that kind of problem before?

    Cheers
     
  21. Fab-London

    Fab-London

    Joined:
    Feb 6, 2013
    Posts:
    35
    Hi,

    Yes I have tried to load the Demo Scene and I get the following error for all buttons
    clicking on the error it goes to FIleBorowserWindows.cs line 199
    Debug.LogError("[FileBrowserWindows] Error:" + error);

    Running Windows 10 pro coming with Microsoft Surface Book 4.


    Cheers
    Fabien
     

    Attached Files:

  22. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello,

    Yes I think moving this particular .exe inside persistentDataPath is the correct solution.
    I'm adding this right now to the to do list, and will do that when I can!

    Thanks for noticing that!
     
  23. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Okay, so can you give me:
    - the exact path of the file you're trying to open? Simple open the File Explorer in Windows, navigate to the file, right click Properties and give me its path + filename
    - Click on the error message in the console of Unity, and give me the entire error message (copy/paste it)

    Thanks!
     
  24. skullthug

    skullthug

    Joined:
    Oct 16, 2011
    Posts:
    202
    Does this support UWP / Windows Store applications? I ask because they utilize different libraries than Windows Standalone and it's a mess.
     
  25. Caronte3D

    Caronte3D

    Joined:
    Sep 16, 2014
    Posts:
    43
    it's possible to have separate file extensions in the DropDownBox to choose only one on the file browser?
     
  26. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello!

    I don't know, I never tried :/
    But Native File Browser is using an executable that I made to work, so as long as it's a Windows computer, I guess it will run just fine.
     
  27. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello,

    Currently it's only possible to display multiple extensions in a single option of the dropdown sorry.
     
  28. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,276
    This asset is useful but if you end up building to android or iOS from the same project, the Filebrowser streamingAsset exe gets copied in!
    Is there no way to exclude it from certain platforms?
     
  29. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello,

    I don't think there's an easy way to do that.
    You would have to write your own custom build solution, that will move the file away, trigger the build, and put the file back in.
    You could do that pretty easily with another one of my tool Advanced Builder: http://www.pygmymonkey.com/tools/advanced-builder/
     
  30. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,276
    your tool allows to exclude such a folder or would just allow me to run a pre-build script to move it away?
     
  31. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello,

    Only to easily run a pre-build script to move it away. Among tons of other things :)
     
  32. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    I was just reading the documentation, and it says:
    Unity now supports .Net 4.6. Does that mean you could include a DLL and we wouldn't need to use the .exe? You should include both since not everyone will be targeting .Net 4.6, but it would be nice for those that are.

    Edit: Feature request... please put your code in a namespace.
     
    Last edited: Nov 28, 2017
  33. EddieChristian

    EddieChristian

    Joined:
    Oct 9, 2012
    Posts:
    725
    I am looking for a file browser that will work with Oculus vr and Curved UI. Can I do it with this??
     
  34. Nifflas

    Nifflas

    Joined:
    Jun 13, 2013
    Posts:
    118
    Hi! Everything seems nice so far!

    I'm away from home and don't have access to a mac right now. The message argument in SaveFilePanel, the one that only shows up on macOS, where does it actually show up? Should I use it the same way as the title? Can I set this argument to null?
     
  35. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello!

    From what I remember, I already tried to do that (.Net 4.6) when it was in beta and it didn't work. Edit: So I tried again today and still no success. It seems the only compatible Windows form dll Unity uses is in .Net 2.0.
    Also yes for the namespace, noted thanks!
     
    Last edited: Dec 7, 2017
  36. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello,

    Sorry but no, this file browser opens the native file browser of Windows or Mac, so it's not VR compatible.
     
  37. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello,

    It appears on the very top of the window, see here (where it's written "Type here your message..."):


    And yes, you can definitely pass null to it :)
     
  38. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    @PygmyMonkey Have you considered adding Linux support? If not, how difficult do you think it’d be to add?
     
  39. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hey,

    Yes I did consider it, but I don't really know how to do that on Linux :/
    And I think you're the first to ask for it.

    I could search and implement it, but I don't really have time for that right now sorry.
     
  40. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    Ok. I meant how difficult of a task is it in general because I was thinking about attempting it. If I decide to try I may ask for help. I don’t need it right now but might later.
     
  41. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Well, in theory you could make a simple project that creates an executable for Linux and that trigger the OpenFile dialog and the SaveDialog. If you have that, I could *easily* integrate this in Native File Browser by making a wrapper and modifying the Linux binary you created.
     
  42. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    Ok thank you
     
  43. MatsuImg

    MatsuImg

    Joined:
    Jul 11, 2017
    Posts:
    9
    Hello,

    I am looking for file dialog assets that can be used with .NET 4.6 compatibility settings.
    Does this asset work on the Unity application (Windows standalone application) built with the following settings?

    Edit > Project Settings > Player > Other Settings > Scripting Runtime Version: "Experimental (.NET 4.6 Equivalent)"

    Thank you
     
  44. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello,

    On Windows, i'm using a small exe file that is in StreamingAssets to trigger the file browser, so even if you're using .NET 4.6 or something else, this should have absolutely no impact :)
     
  45. MatsuImg

    MatsuImg

    Joined:
    Jul 11, 2017
    Posts:
    9
    Hello,

    Thank you for your answer.
    Your asset is amazing!
    I plan to use it.

    Thank you
     
    PygmyMonkey likes this.
  46. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Thanks a lot :)
     
  47. visualjump3d

    visualjump3d

    Joined:
    Jun 6, 2014
    Posts:
    14
    FileBrowser.SaveFilePanel("Open file Title","", startpath, "", null, null, (bool canceled, string filePath) =>

    " startpath " foo is the directory that I would like to open

    but it opens in the last open, not the one indicated in the string "startpah"
     
    Last edited: Mar 19, 2018
  48. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello,

    Can you show me the exact path that is inside the startpath variable?
    If the path does not exist on the file system, it should use the last open location instead.
     
  49. puhanda

    puhanda

    Joined:
    Jul 4, 2018
    Posts:
    7
    hello, I use lastest version1.0.8, and use unity 2018.1.6f1 version to build a test demo. and select il2cpp as scritping backend. I find the program is crashed when I open a file browser. please help me look what happed. thanks. I will upload a file about the crash info. here is the demo download link: https://drive.google.com/file/d/13kKl0RwzYaOdaU182YCrLBa5dHTro97I/view
     

    Attached Files:

  50. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello!

    Can you try using Mono instead of il2cpp and tell me if it works?

    It's true that I completely forgot building with il2cpp...