Search Unity

Simple File Browser [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, Nov 19, 2016.

  1. unity_FOBkcrfCSVB5uw

    unity_FOBkcrfCSVB5uw

    Joined:
    Mar 5, 2020
    Posts:
    4
    Hello there,
    Is it normal that in my built app, chosen image isnt stored ? In edition mode with Unity everything works fine, but not with the built app.

    Which method should we call to store image ?
     
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Could you show the relevant section of your code to clarify things?
     
  3. unity_FOBkcrfCSVB5uw

    unity_FOBkcrfCSVB5uw

    Joined:
    Mar 5, 2020
    Posts:
    4
    Code (CSharp):
    1.     IEnumerator ShowLoadDialogCoroutine()
    2.     {
    3.         // Show a load file dialog and wait for a response from user
    4.         // Load file/folder: file, Allow multiple selection: true
    5.         // Initial path: default (Documents), Title: "Load File", submit button text: "Load"
    6.         yield return FileBrowser.WaitForLoadDialog( false, false, null, "Load File", "Load" );
    7.  
    8.         // Dialog is closed
    9.         // Print whether the user has selected some files/folders or cancelled the operation (FileBrowser.Success)
    10.         Debug.Log( FileBrowser.Success );
    11.  
    12.         if( FileBrowser.Success )
    13.         {
    14.  
    15.  
    16.             Debug.Log(FileBrowser.Result[0][FileBrowser.Result[0].Length-4]);
    17.             Name = FileBrowserHelpers.GetFilename( FileBrowser.Result[0] );
    18.             NameWithoutExtension=Name.Remove(Name.IndexOf("."),Name.Length-Name.IndexOf("."));
    19.  
    20.  
    21.             if(FileBrowserHelpers.FileExists( Application.dataPath + "/Resources/Images/background/"+Name ))
    22.             {
    23.             Name = Name.Insert(Name.Length-4,"_"+I);
    24.             I = I+1;
    25.  
    26.             }
    27.             path = FileBrowser.Result[0];
    28.  
    29.             FileBrowserHelpers.CreateFileInDirectory(Application.dataPath + "/Resources/Images/background/",Name);
    30.  
    31.          
    32.         }
    33.     }
    Here's my code. Even in edition mode it doesnt work, I need to close and launch again to see the image. But in built mode, it never works...
     
    Last edited: Jul 23, 2020
  4. yiduoke

    yiduoke

    Joined:
    Jun 22, 2020
    Posts:
    2
    Thank you so much!
     
  5. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    @unity_FOBkcrfCSVB5uw You can't access Application.dataPath in a built game. On built games, you have access to Application.persistentDataPath and Application.temporaryCachePath.
     
  6. MCorgi

    MCorgi

    Joined:
    Oct 27, 2019
    Posts:
    1
    Thank you so very much for this! I really like what you have done, easy to read, follow, and adjust if required. Thank you!
     
    yasirkula likes this.
  7. Shmexysmguy

    Shmexysmguy

    Joined:
    Nov 7, 2017
    Posts:
    1
    Hello,
    I'm trying to use this in a mod for a game, but when I call ShowLoadDialog() I get the error "ArgumentException: The Object you want to instantiate is null." I had some issues getting unity too recognize the plugin, and solved it by manually adding an assembly definition in the .asmdef file. Would that be the issue? I saw someone else had issues and needed to add a line to their proguard file, but as far as I can tell there is no proguard file for me.

    I'm on windows 10, using Unity 2019.3.15f1 and .NET framework 4.7.1. Any help would be great, this seems like an awesome asset!
     
  8. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    SimpleFileBrowser actually has its own Assembly Definition File. To access the SimpleFileBrowser scripts from your own scripts, you just need to add SimpleFileBrowser.Runtime Assembly Definition File to your own Assembly Definition File's Assembly References list. So I'd recommend you to reimport the plugin from scratch.

    Then, if you still get this error, please check which line throws it.
     
  9. Arkolis

    Arkolis

    Joined:
    Feb 6, 2015
    Posts:
    34
    Thanks for this plugin/extension, Ive already got it running and functioning in 2020.1.3f1
    I was wondering if there were any way to or planned way to theme or style this window? I would like to adjust its styling, font sizes and such.
    Thank you
     
  10. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    There isn't a built-in tool for this, unfortunately. You can modify the SimpleFileBrowserCanvas prefab but the huge downside is that, your changes will be overwritten when you update the plugin :/ I rarely update that prefab though. So you can decide not to update the prefab while updating the plugin.
     
  11. Arkolis

    Arkolis

    Joined:
    Feb 6, 2015
    Posts:
    34
    Thanks
     
  12. ZYMA123

    ZYMA123

    Joined:
    Jun 27, 2019
    Posts:
    8
    Hello, excuse me if this is a stupid question, the generation of quick links in Unity does not work for me, I have not changed the code, what could be the problem? upload_2020-8-31_15-46-42.png
     
  13. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Hmm, do they get populated after calling FileBrowser.ShowLoadDialog or ShowSaveDialog? If so, you need to call one of these functions to display the file browser :D
     
  14. ZYMA123

    ZYMA123

    Joined:
    Jun 27, 2019
    Posts:
    8
  15. Ganadote

    Ganadote

    Joined:
    May 25, 2014
    Posts:
    3
    Hello. This seems like an amazing add-on! However, I'm having trouble using it. I imported it into my game wit the asset manager and added your example code, but I get over 1000 of the following types of errors: "Assertion failed on expression...." and some "Failed to convert string ' to CFString."

    Could you help me with this? I'm not sure what the error is.
     
  16. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I'd ignore the assertion warnings since many different things in Unity can throw these and they are usually harmless. But I don't think the latter error is caused by my plugin because I don't have any native iOS code whereas CFString is a native iOS struct.

    Can you reproduce these errors on a new Unity project? If so, when do they occur? And can I see your code?

    If you can't reproduce the issue, please check out the other plugins you are using because one of them might be the culprit.
     
  17. Ganadote

    Ganadote

    Joined:
    May 25, 2014
    Posts:
    3
    It's strange; I reopened it twice and most of the errors disappeared. I wonder if plugins had to be reloaded or something.

    EDIT: ignore this. It started to work! (I was mixing up a different unrelated routine).
     
    Last edited: Sep 18, 2020
    yasirkula likes this.
  18. unity_PLKjP8lodos8NQ

    unity_PLKjP8lodos8NQ

    Joined:
    Jul 16, 2020
    Posts:
    1
    Hello !
    first, thank you a lot for this browser ! I used it for an app with android 9.0 and it worked perfectly.

    But now, I upgraded my tab to Android 10 Level 29 and the file browser does not work anymore. The box to see the path disappeared. It's like I don't have permission to acces to the files even if it's activated in the parameters of the app.

    Do you have a solution for this problem ?
     
  19. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    It's normal for the path to disappear on Android 10 because Storage Access Framework (SAF) is used on Android 10 and SAF paths aren't filepaths (e.g.
    content://com.android.externalstorage.documents/tree/primary%3A/document/primary%3APictures
    ), so it would only be confusing to show that SAF path. After opening the file picker, users must first click the "Select Folder" button to the left and then select a folder to browse. Then, they can select a file from inside that folder. The returned path will also be a SAF path. To work with that path, you must use the FileBrowserHelpers functions.
     
  20. NotoriousBob

    NotoriousBob

    Joined:
    May 18, 2020
    Posts:
    3
    Kinda disappointed - Doesn't want to work properly under 2019.3. When the FileItems are instantiated, the "Text" field doesn't get populated. Seems to be an issue with FileInfo even with the example. Tried everything, but no text. The left panel where drives are listed gets text OK, just not the main file window. :(
     
  21. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I can't reproduce this issue on 2019.3.6f1 in either the Unity Editor or a Windows standalone build:

    ss.png
     
  22. NotoriousBob

    NotoriousBob

    Joined:
    May 18, 2020
    Posts:
    3
  23. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Could you update to the latest version via this unitypackage, Collapse the logs in the Console and send me each error log's full stacktrace?
     
  24. NotoriousBob

    NotoriousBob

    Joined:
    May 18, 2020
    Posts:
    3
    sfb 3.png

    Installed the package you supplied and it's working! Awesome! :D
     
    yasirkula likes this.
  25. haim96

    haim96

    Joined:
    May 24, 2013
    Posts:
    107
    Hi,

    every time i open my project with your asset i get error:

    ArgumentException: The Object you want to instantiate is null.
    UnityEngine.Object.Instantiate[T] (T original) (at <e8645a79b0794e0e9a2b5bbff081b88a>:0)
    SimpleFileBrowser.FileBrowser.get_Instance () (at Assets/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs:139)
    SimpleFileBrowser.FileBrowser.ShowLoadDialog (SimpleFileBrowser.FileBrowser+OnSuccess onSuccess, SimpleFileBrowser.FileBrowser+OnCancel onCancel, System.Boolean folderMode, System.Boolean allowMultiSelection, System.String initialPath, System.String title, System.String loadButtonText) (at Assets/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs:1509)
    SimpleFileBrowser.FileBrowser+<WaitForLoadDialog>d__167.MoveNext () (at Assets/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs:1547)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <e8645a79b0794e0e9a2b5bbff081b88a>:0)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    DataManager:LoadFile() (at Assets/Scripts/DataManager.cs:136)
    UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity2019/2020.1.4f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:376)

    the error comes from this line:
    m_instance = Instantiate( Resources.Load<GameObject>( "SimpleFileBrowserCanvas" ) ).GetComponent<FileBrowser>();

    the file "SimpleFileBrowserCanvas" exist in resource folder.

    the funny thing is that if i move around the resource folder it start to work again, until i open the project once again.
    any idea why it happen?

    thanks,

    Haim.
     
  26. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    If you've moved SimpleFileBrowserCanvas into a subfolder of Resources, you should update the code like this:
    Resources.Load<GameObject>( "SubFolderName/SimpleFileBrowserCanvas" )
    . Also, the plugin mustn't be located inside StreamingAssets folder. If you've moved the plugin from Plugins folder, try putting it back there. If nothing works, I don't think this issue is caused by the plugin but rather by Unity's Resources API (somehow).

    P.S. You can also try deleting the plugin completely and reimporting it: https://github.com/yasirkula/UnityS...ownload/v1.3.1/SimpleFileBrowser.unitypackage
     
  27. haim96

    haim96

    Joined:
    May 24, 2013
    Posts:
    107
    hi,

    i didn't moved any thing beside the resource folder to the root asset folder (which should work fine)
    the odd thing that if duplicate the folder, do some rename stuff it works again!
    no code changes...

    does the github version is different from the unity store version?
     
  28. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    It is a few commits ahead bu no major changes. I'm not sure why moving the Resources folder breaks the plugin but if it works the way it is, then I'd recommend you to keep it inside SimpleFileBrowser folder :D
     
  29. haim96

    haim96

    Joined:
    May 24, 2013
    Posts:
    107

    the problem start when it already was there... :(
     
  30. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I'd recommend you to update Unity to a LTS version (e.g. 2019.4). It is very likely a Unity bug. My plugin doesn't have any editor scripts that might cause this behaviour.
     
  31. said123sawn

    said123sawn

    Joined:
    Oct 31, 2019
    Posts:
    26
    yasirkula türkçe biliyorsan sana türkçe olarak bir soru sorabilirmiyim?
     
  32. said123sawn

    said123sawn

    Joined:
    Oct 31, 2019
    Posts:
    26
    hello yasirkula there are 16 items in the file browser, but I want to add more by reducing their size, I looked at the codes in detail, but I could not find how to solve this problem.

    Can you help me?
     
  33. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You can simply change SimpleFileBrowserItem prefab's Height property. FYI, I've also sent you a PM.
     
  34. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    Hi,

    All is working fine, thanks for sharing :)
     
    yasirkula likes this.
  35. luthershaw

    luthershaw

    Joined:
    Feb 9, 2019
    Posts:
    2
    PLZ, I'm trying to use this plugin in the WebGL platform, but all the local drives has been disappeared. And I even don't know where the root folder is. Only a "Document" folder can be checked, but nothings in it. So how to change the
    drives or the DEFAULT_PATH to show my local folders?
     

    Attached Files:

  36. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  37. luthershaw

    luthershaw

    Joined:
    Feb 9, 2019
    Posts:
    2
    Thank you, but I have to check out other ways to make this solution.
     
  38. richkopelow

    richkopelow

    Joined:
    Jul 28, 2017
    Posts:
    2
    Hello,
    When I build and run for Android on a phone I receive the message java.lang.ClassNotFoundException com.jasirkula.unity.FileBrowser. When I run in editor everything works. I installed this via asset store. I see the plugin in my assets. I did set android permissions. I don't see a reference to FileBrowser in manifest.xml. (Unity 2019.4.12f1)
    Thanks, Rich.
     
  39. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    If your project uses ProGuard, try adding the following line to ProGuard filters:
    -keep class com.yasirkula.unity.* { *; }
     
  40. richkopelow

    richkopelow

    Joined:
    Jul 28, 2017
    Posts:
    2
    Thanks for both the plugin and the quick reply. I was using minify: Gradle (Experimental) (related to using Firebase and docs I read on that.) I switched to minify: none and everything worked fine. Then I switched to minify: Proguard and checked Custom Proguard File. Then I added the -keep line above to the file listed under the Custom Proguard File checkbox and again every worked fine. Firebase doesn't seem to have an issue with this setting either, so all is good.
    Thanks again,
    Rich.
     
    yasirkula likes this.
  41. blevok

    blevok

    Joined:
    Feb 16, 2017
    Posts:
    75
    Hello again. This has been working great, but some of my users have pointed out an issue with sorting that i hadn't noticed on my own.
    On windows, sorting seems to be normal in alphabetical order, but on android it seems to be random order, or something not related to the file name.
    Any idea about a way to sort it alphabetically?
    Here's some images that show the issue.

    Android
    sfb-android.jpg
    Windows
    sfb-windows.jpg
     
  42. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    blevok likes this.
  43. blevok

    blevok

    Joined:
    Feb 16, 2017
    Posts:
    75
    Awesome, thank you.
    To keep the folders at the top, i had to break it into separate arrays for files and folders, then sort them, and then combine them again.

    In case anyone else needs to do the same thing, here's what i added:
    Code (CSharp):
    1.  
    2. if (allFileEntries != null)
    3. {
    4.     List<FileSystemEntry> files = new List<FileSystemEntry>();
    5.     FileSystemEntry[] filesarray;
    6.     List<FileSystemEntry> directories = new List<FileSystemEntry>();
    7.     FileSystemEntry[] directoriesarray;
    8.     FileSystemEntry[] finalsortedarray;
    9.  
    10.     for (int i = 0; i < allFileEntries.Length; i++)
    11.     {
    12.         FileSystemEntry item = allFileEntries[i];
    13.  
    14.         if (!item.IsDirectory)
    15.         {
    16.             files.Add(item);
    17.         }
    18.         else
    19.         {
    20.             directories.Add(item);
    21.         }
    22.     }
    23.  
    24.     filesarray = files.ToArray();
    25.     Array.Sort(filesarray, (x, y) => String.Compare(x.Name, y.Name));
    26.     directoriesarray = directories.ToArray();
    27.     Array.Sort(directoriesarray, (x, y) => String.Compare(x.Name, y.Name));
    28.     finalsortedarray = directoriesarray.Concat(filesarray).ToArray();
    29.     allFileEntries = finalsortedarray;
    30. }
    31.  
    Note that the concatenation at the end requires Linq, but there are other ways if you don't want to use Linq.
     
  44. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    blevok likes this.
  45. blevok

    blevok

    Joined:
    Feb 16, 2017
    Posts:
    75
    Oh that's interesting, thanks.
     
  46. appminded

    appminded

    Joined:
    Nov 27, 2014
    Posts:
    7
    Hi,
    great asset
    I cannot understand why, but after I click save, my function return only about 50% of the time
    yield return FileBrowser.WaitForSaveDialog(false, false, null, "Save", "Save");
    Debug.Log(FileBrowser.Success + " " + FileBrowser.Result);


    the Debug is printing about 50% of the time and it looks totally random to me
    I am also using your dynamic panels, are they compatible?

    in another script I am using this function to load a file and it works 100% of the time
    yield return FileBrowser.WaitForLoadDialog(false, false, null, "Load Image", "Load");

    thanks
     
  47. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    SimpleFileBrowser and DynamicPanels don't have any conflicts. One possibility is that the object calling WaitForSaveDialog becomes inactive before the file browser is closed and thus, Unity stops executing the coroutine.

    If you check out the source code of WaitForSaveDialog and WaitForLoadDialog, you'll see that they are identical. It is impossible to have a bug that only affects WaitForSaveDialog. In the worst case, you can use ShowSaveDialog as shown in the example code: https://github.com/yasirkula/UnitySimpleFileBrowser#example-code
     
  48. appminded

    appminded

    Joined:
    Nov 27, 2014
    Posts:
    7
    thanks, you comments helped me find the problem.

    Your code is correct, the bug was in my implementation: I am refreshing periodically some elements of the GUI and the script was attached to one of that, so if I was slow in writing the filename before pressing save the refreshing was replacing the gameobject with the script and so the return was not resulting in the action

    thanks again for the quick reply!
     
    yasirkula likes this.
  49. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    Hey there. Any idea why this might be happening?
    exists.png
    Code:
    exists_code.png
    I'm on Android 10. Unity is 2019.4.14f1, JDK and such through the Hub. See permissions settings below.
    exists_settings.png

    When I try to create folders with regular System.IO I get an UnauthorizedAccessException, and when I try the SimpleFileBrowser I get "java.lang.NullPointerException: authority"
    exists_sfb_error.png
     
    Last edited: Nov 16, 2020
  50. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    On Android 10 and later, Storage Access Framework is used. FileBrowserHelpers will only work with paths returned via FileBrowser.ShowSaveDialog/ShowLoadDialog functions because these functions return Storage Access Framework paths that are compatible with FileBrowserHelpers. For reference, here's an example Storage Access Framework path:
    content://com.android.externalstorage.documents/tree/primary%3A/document/primary%3APictures


    In conclusion, you can't pass manually typed paths to FileBrowserHelpers, it won't work on Android 10+. User must select the directory via ShowSaveDialog/ShowLoadDialog.