From a04d4d1a76a5b0301565bfca9ddef1f5bd642296 Mon Sep 17 00:00:00 2001 From: yasirkula Date: Sat, 8 Jan 2022 16:00:16 +0300 Subject: [PATCH 1/5] Rare bugfixes related to up button and scroll view --- .../SimpleFileBrowser/Scripts/FileBrowser.cs | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs b/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs index c6d7cdb..2e25afe 100644 --- a/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs +++ b/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs @@ -574,7 +574,16 @@ private string CurrentPath upButton.interactable = !string.IsNullOrEmpty( FileBrowserHelpers.GetDirectoryName( m_currentPath ) ); else #endif - upButton.interactable = Directory.GetParent( m_currentPath ) != null; + { + try // When "C:/" or "C:" is typed instead of "C:\", an exception is thrown + { + upButton.interactable = Directory.GetParent( m_currentPath ) != null; + } + catch + { + upButton.interactable = false; + } + } m_searchString = string.Empty; searchInputField.text = m_searchString; @@ -1244,9 +1253,15 @@ public void OnUpButtonPressed() else #endif { - DirectoryInfo parentPath = Directory.GetParent( m_currentPath ); - if( parentPath != null ) - CurrentPath = parentPath.FullName; + try // When "C:/" or "C:" is typed instead of "C:\", an exception is thrown + { + DirectoryInfo parentPath = Directory.GetParent( m_currentPath ); + if( parentPath != null ) + CurrentPath = parentPath.FullName; + } + catch + { + } } } @@ -1943,7 +1958,7 @@ public void RefreshFiles( bool pathChanged ) listView.UpdateList(); // Prevent the case where all the content stays offscreen after changing the search string - filesScrollRect.OnScroll( nullPointerEventData ); + EnsureScrollViewIsWithinBounds(); } // Quickly selects all files and folders in the current directory @@ -2200,6 +2215,16 @@ private bool AddQuickLink( Sprite icon, string name, string path ) return true; } + // Makes sure that scroll view's contents are within scroll view's bounds + private void EnsureScrollViewIsWithinBounds() + { + // When scrollbar is snapped to the very bottom of the scroll view, sometimes OnScroll alone doesn't work + if( filesScrollRect.verticalNormalizedPosition <= Mathf.Epsilon ) + filesScrollRect.verticalNormalizedPosition = 0.0001f; + + filesScrollRect.OnScroll( nullPointerEventData ); + } + internal void EnsureWindowIsWithinBounds() { Vector2 canvasSize = rectTransform.sizeDelta; @@ -2267,7 +2292,7 @@ internal void OnWindowDimensionsChanged( Vector2 size ) showHiddenFilesToggle.gameObject.SetActive( m_displayHiddenFilesToggle ); listView.OnViewportDimensionsChanged(); - filesScrollRect.OnScroll( nullPointerEventData ); + EnsureScrollViewIsWithinBounds(); } } else @@ -2285,7 +2310,7 @@ internal void OnWindowDimensionsChanged( Vector2 size ) showHiddenFilesToggle.gameObject.SetActive( false ); listView.OnViewportDimensionsChanged(); - filesScrollRect.OnScroll( nullPointerEventData ); + EnsureScrollViewIsWithinBounds(); } } } From 8edc266990dde5bb1c4020259f92f8787c54308c Mon Sep 17 00:00:00 2001 From: yasirkula Date: Sat, 8 Jan 2022 16:06:11 +0300 Subject: [PATCH 2/5] Added FileBrowser.DisplayedEntriesFilter event to programmatically filter the displayed entries --- .github/README.md | 12 +++++++ .../SimpleFileBrowser/Scripts/FileBrowser.cs | 36 +++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/.github/README.md b/.github/README.md index b95c70b..a9c2044 100644 --- a/.github/README.md +++ b/.github/README.md @@ -130,6 +130,18 @@ When **showAllFilesFilter** is set to true, a filter by the name "*All Files (.\ public static bool SetDefaultFilter( string defaultFilter ); ``` +You can programmatically filter the files/folders displayed in the file browser via the **DisplayedEntriesFilter** event: + +```csharp +FileBrowser.DisplayedEntriesFilter += ( entry ) => +{ + if( !entry.IsDirectory ) + return true; // Don't filter files + + return entry.Name.StartsWith( "Save" ); // Show only the directories whose name start with "Save" +}; +``` + You can set whether or not hidden files should be shown in the file browser via **FileBrowser.ShowHiddenFiles** (has no effect when Storage Access Framework is used on Android 10+). This value can also be changed from the "*Show hidden files*" toggle in the user interface. To change the visibility of that toggle, you can use **FileBrowser.DisplayHiddenFilesToggle**. Note that this toggle is always hidden on Android 10+ when Storage Access Framework is used or on mobile devices when device is held in portrait orientation. To open files or directories in the file browser with a single click (instead of double clicking), you can set **FileBrowser.SingleClickMode** to *true*. diff --git a/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs b/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs index 2e25afe..8ed1263 100644 --- a/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs +++ b/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs @@ -187,6 +187,32 @@ public static bool SingleClickMode set { m_singleClickMode = value; } } + private static FileSystemEntryFilter m_displayedEntriesFilter; + public static event FileSystemEntryFilter DisplayedEntriesFilter + { + add + { + m_displayedEntriesFilter -= value; + m_displayedEntriesFilter += value; + + if( m_instance ) + { + m_instance.PersistFileEntrySelection(); + m_instance.RefreshFiles( false ); + } + } + remove + { + m_displayedEntriesFilter -= value; + + if( m_instance ) + { + m_instance.PersistFileEntrySelection(); + m_instance.RefreshFiles( false ); + } + } + } + #if UNITY_EDITOR || ( !UNITY_ANDROID && !UNITY_IOS && !UNITY_WSA && !UNITY_WSA_10_0 ) private static float m_drivesRefreshInterval = 5f; #else @@ -727,6 +753,7 @@ private string LastBrowsedFolder #region Delegates public delegate void OnSuccess( string[] paths ); public delegate void OnCancel(); + public delegate bool FileSystemEntryFilter( FileSystemEntry entry ); #if UNITY_EDITOR || UNITY_ANDROID public delegate void AndroidSAFDirectoryPickCallback( string rawUri, string name ); #endif @@ -1918,8 +1945,13 @@ public void RefreshFiles( bool pathChanged ) continue; } - if( m_searchString.Length == 0 || textComparer.IndexOf( item.Name, m_searchString, textCompareOptions ) >= 0 ) - validFileEntries.Add( item ); + if( m_searchString.Length > 0 && textComparer.IndexOf( item.Name, m_searchString, textCompareOptions ) < 0 ) + continue; + + if( m_displayedEntriesFilter != null && !m_displayedEntriesFilter( item ) ) + continue; + + validFileEntries.Add( item ); } catch( Exception e ) { From e9c32eceed8d93e26d496000c9c1f550d24ccd39 Mon Sep 17 00:00:00 2001 From: yasirkula Date: Sat, 8 Jan 2022 16:09:22 +0300 Subject: [PATCH 3/5] Added FileBrowser.ClearQuickLinks function --- .github/README.md | 2 +- .../SimpleFileBrowser/Scripts/FileBrowser.cs | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.github/README.md b/.github/README.md index a9c2044..c614aea 100644 --- a/.github/README.md +++ b/.github/README.md @@ -101,7 +101,7 @@ public static void HideDialog( bool invokeCancelCallback = false ); If there is an open dialog and the **invokeCancelCallback** parameter is set to *true*, the *onCancel* callback of the dialog will be invoked. This function can also be used to initialize the file browser ahead of time, which in turn will reduce the lag when you first open a dialog. -To add a quick link to the browser, you can use the following function: +To add a quick link to the browser, you can use the following function (to clear all quick links, use `ClearQuickLinks()`): ```csharp public static bool AddQuickLink( string name, string path, Sprite icon = null ); diff --git a/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs b/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs index 8ed1263..0cd1171 100644 --- a/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs +++ b/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs @@ -2247,6 +2247,29 @@ private bool AddQuickLink( Sprite icon, string name, string path ) return true; } + private void ClearQuickLinksInternal() + { + Vector2 anchoredPos = Vector2.zero; + for( int i = 0; i < allQuickLinks.Count; i++ ) + { + if( allQuickLinks[i].TargetPath == SAF_PICK_FOLDER_QUICK_LINK_PATH ) + { + allQuickLinks[i].TransformComponent.anchoredPosition = anchoredPos; + anchoredPos.y -= m_skin.FileHeight; + } + else + { + Destroy( allQuickLinks[i].gameObject ); + allQuickLinks.RemoveAt( i-- ); + } + } + + quickLinksContainer.sizeDelta = new Vector2( 0f, -anchoredPos.y ); + + quickLinksInitialized = true; + generateQuickLinksForDrives = false; + } + // Makes sure that scroll view's contents are within scroll view's bounds private void EnsureScrollViewIsWithinBounds() { @@ -2684,6 +2707,11 @@ public static bool AddQuickLink( string name, string path, Sprite icon = null ) return Instance.AddQuickLink( icon, name, path ); } + public static void ClearQuickLinks() + { + Instance.ClearQuickLinksInternal(); + } + public static void SetExcludedExtensions( params string[] excludedExtensions ) { Instance.excludedExtensions = excludedExtensions ?? new string[0]; From e7a0a959307e46dd0d2fb68f371d02ca181cc3e6 Mon Sep 17 00:00:00 2001 From: yasirkula Date: Sat, 8 Jan 2022 16:15:10 +0300 Subject: [PATCH 4/5] On Android 10+, when Storage Access Framework is used, paths that can be accessed via System.IO (like persistentDataPath) can still be browsed using System.IO and added as quick links --- .../SimpleFileBrowser/Scripts/FileBrowser.cs | 28 ++++---- .../Scripts/FileBrowserHelpers.cs | 67 ++++++++++++------- package.json | 2 +- 3 files changed, 59 insertions(+), 38 deletions(-) diff --git a/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs b/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs index 0cd1171..c952002 100644 --- a/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs +++ b/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs @@ -557,11 +557,14 @@ private string CurrentPath get { return m_currentPath; } set { + if( value != null ) + { + value = value.Trim(); #if !UNITY_EDITOR && UNITY_ANDROID - if( !FileBrowserHelpers.ShouldUseSAF ) + if( !FileBrowserHelpers.ShouldUseSAFForPath( value ) ) #endif - if( value != null ) - value = GetPathWithoutTrailingDirectorySeparator( value.Trim() ); + value = GetPathWithoutTrailingDirectorySeparator( value ); + } if( string.IsNullOrEmpty( value ) ) { @@ -597,7 +600,10 @@ private string CurrentPath forwardButton.interactable = currentPathIndex < pathsFollowed.Count - 1; #if !UNITY_EDITOR && UNITY_ANDROID if( FileBrowserHelpers.ShouldUseSAF ) - upButton.interactable = !string.IsNullOrEmpty( FileBrowserHelpers.GetDirectoryName( m_currentPath ) ); + { + string parentPath = FileBrowserHelpers.GetDirectoryName( m_currentPath ); + upButton.interactable = !string.IsNullOrEmpty( parentPath ) && ( FileBrowserHelpers.ShouldUseSAFForPath( parentPath ) || FileBrowserHelpers.DirectoryExists( parentPath ) ); // DirectoryExists: Directory may not be accessible on Android 10+, this function checks that + } else #endif { @@ -627,7 +633,7 @@ private string CurrentPath // If a quick link points to this directory, highlight it #if !UNITY_EDITOR && UNITY_ANDROID // Path strings aren't deterministic on Storage Access Framework but the paths' absolute parts usually are - if( FileBrowserHelpers.ShouldUseSAF ) + if( FileBrowserHelpers.ShouldUseSAFForPath( m_currentPath ) ) { int SAFAbsolutePathSeparatorIndex = m_currentPath.LastIndexOf( '/' ); if( SAFAbsolutePathSeparatorIndex >= 0 ) @@ -1274,7 +1280,7 @@ public void OnUpButtonPressed() if( FileBrowserHelpers.ShouldUseSAF ) { string parentPath = FileBrowserHelpers.GetDirectoryName( m_currentPath ); - if( !string.IsNullOrEmpty( parentPath ) ) + if( !string.IsNullOrEmpty( parentPath ) && ( FileBrowserHelpers.ShouldUseSAFForPath( parentPath ) || FileBrowserHelpers.DirectoryExists( parentPath ) ) ) // DirectoryExists: Directory may not be accessible on Android 10+, this function checks that CurrentPath = parentPath; } else @@ -1462,7 +1468,7 @@ public void OnSubmitButtonClicked() } #if !UNITY_EDITOR && UNITY_ANDROID - if( FileBrowserHelpers.ShouldUseSAF ) + if( FileBrowserHelpers.ShouldUseSAFForPath( m_currentPath ) ) { if( m_pickerMode == PickMode.Folders ) result[fileCount++] = FileBrowserHelpers.CreateFolderInDirectory( m_currentPath, filename ); @@ -1688,7 +1694,7 @@ public void OnItemSelected( FileBrowserItem item, bool isDoubleClick ) { // Enter the directory #if !UNITY_EDITOR && UNITY_ANDROID - if( FileBrowserHelpers.ShouldUseSAF ) + if( FileBrowserHelpers.ShouldUseSAFForPath( m_currentPath ) ) { for( int i = 0; i < validFileEntries.Count; i++ ) { @@ -2211,7 +2217,7 @@ private bool AddQuickLink( Sprite icon, string name, string path ) return false; #if !UNITY_EDITOR && UNITY_ANDROID - if( !FileBrowserHelpers.ShouldUseSAF ) + if( !FileBrowserHelpers.ShouldUseSAFForPath( path ) ) #endif { if( !Directory.Exists( path ) ) @@ -2690,10 +2696,8 @@ public static IEnumerator WaitForLoadDialog( PickMode pickMode, bool allowMultiS public static bool AddQuickLink( string name, string path, Sprite icon = null ) { -#if !UNITY_EDITOR && UNITY_ANDROID - if( FileBrowserHelpers.ShouldUseSAF ) + if( string.IsNullOrEmpty( path ) || !FileBrowserHelpers.DirectoryExists( path ) ) return false; -#endif if( !quickLinksInitialized ) { diff --git a/Plugins/SimpleFileBrowser/Scripts/FileBrowserHelpers.cs b/Plugins/SimpleFileBrowser/Scripts/FileBrowserHelpers.cs index 169cdad..3db0100 100644 --- a/Plugins/SimpleFileBrowser/Scripts/FileBrowserHelpers.cs +++ b/Plugins/SimpleFileBrowser/Scripts/FileBrowserHelpers.cs @@ -88,12 +88,17 @@ public static bool ShouldUseSAF return m_shouldUseSAF.Value; } } + + public static bool ShouldUseSAFForPath( string path ) // true: path should be managed with AJC (native helper class for Storage Access Framework), false: path should be managed with System.IO + { + return ShouldUseSAF && ( string.IsNullOrEmpty( path ) || path[0] != '/' ); + } #endif public static bool FileExists( string path ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( path ) ) return AJC.CallStatic( "SAFEntryExists", Context, path, false ); #endif return File.Exists( path ); @@ -102,8 +107,20 @@ public static bool FileExists( string path ) public static bool DirectoryExists( string path ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( path ) ) return AJC.CallStatic( "SAFEntryExists", Context, path, true ); + else if( ShouldUseSAF ) // Directory.Exists returns true even for inaccessible directories on Android 10+, we need to check if the directory is accessible + { + try + { + Directory.GetFiles( path, "testtesttest" ); + return true; + } + catch + { + return false; + } + } #endif return Directory.Exists( path ); } @@ -111,7 +128,7 @@ public static bool DirectoryExists( string path ) public static bool IsDirectory( string path ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( path ) ) return AJC.CallStatic( "SAFEntryDirectory", Context, path ); #endif if( Directory.Exists( path ) ) @@ -126,7 +143,7 @@ public static bool IsDirectory( string path ) public static string GetDirectoryName( string path ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( path ) ) return AJC.CallStatic( "GetParentDirectory", Context, path ); #endif return Path.GetDirectoryName( path ); @@ -135,7 +152,7 @@ public static string GetDirectoryName( string path ) public static FileSystemEntry[] GetEntriesInDirectory( string path, bool extractOnlyLastSuffixFromExtensions ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( path ) ) { string resultRaw = AJC.CallStatic( "OpenSAFFolder", Context, path ); int separatorIndex = resultRaw.IndexOf( "<>" ); @@ -235,7 +252,7 @@ public static FileSystemEntry[] GetEntriesInDirectory( string path, bool extract public static string CreateFileInDirectory( string directoryPath, string filename ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( directoryPath ) ) return AJC.CallStatic( "CreateSAFEntry", Context, directoryPath, false, filename ); #endif @@ -247,7 +264,7 @@ public static string CreateFileInDirectory( string directoryPath, string filenam public static string CreateFolderInDirectory( string directoryPath, string folderName ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( directoryPath ) ) return AJC.CallStatic( "CreateSAFEntry", Context, directoryPath, true, folderName ); #endif @@ -259,7 +276,7 @@ public static string CreateFolderInDirectory( string directoryPath, string folde public static void WriteBytesToFile( string targetPath, byte[] bytes ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( targetPath ) ) { File.WriteAllBytes( TemporaryFilePath, bytes ); AJC.CallStatic( "WriteToSAFEntry", Context, targetPath, TemporaryFilePath, false ); @@ -274,7 +291,7 @@ public static void WriteBytesToFile( string targetPath, byte[] bytes ) public static void WriteTextToFile( string targetPath, string text ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( targetPath ) ) { File.WriteAllText( TemporaryFilePath, text ); AJC.CallStatic( "WriteToSAFEntry", Context, targetPath, TemporaryFilePath, false ); @@ -289,7 +306,7 @@ public static void WriteTextToFile( string targetPath, string text ) public static void AppendBytesToFile( string targetPath, byte[] bytes ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( targetPath ) ) { File.WriteAllBytes( TemporaryFilePath, bytes ); AJC.CallStatic( "WriteToSAFEntry", Context, targetPath, TemporaryFilePath, true ); @@ -307,7 +324,7 @@ public static void AppendBytesToFile( string targetPath, byte[] bytes ) public static void AppendTextToFile( string targetPath, string text ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( targetPath ) ) { File.WriteAllText( TemporaryFilePath, text ); AJC.CallStatic( "WriteToSAFEntry", Context, targetPath, TemporaryFilePath, true ); @@ -322,7 +339,7 @@ public static void AppendTextToFile( string targetPath, string text ) private static void AppendFileToFile( string targetPath, string sourceFileToAppend ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( targetPath ) ) { AJC.CallStatic( "WriteToSAFEntry", Context, targetPath, sourceFileToAppend, true ); return; @@ -341,7 +358,7 @@ private static void AppendFileToFile( string targetPath, string sourceFileToAppe public static byte[] ReadBytesFromFile( string sourcePath ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( sourcePath ) ) { AJC.CallStatic( "ReadFromSAFEntry", Context, sourcePath, TemporaryFilePath ); byte[] result = File.ReadAllBytes( TemporaryFilePath ); @@ -355,7 +372,7 @@ public static byte[] ReadBytesFromFile( string sourcePath ) public static string ReadTextFromFile( string sourcePath ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( sourcePath ) ) { AJC.CallStatic( "ReadFromSAFEntry", Context, sourcePath, TemporaryFilePath ); string result = File.ReadAllText( TemporaryFilePath ); @@ -369,7 +386,7 @@ public static string ReadTextFromFile( string sourcePath ) public static void CopyFile( string sourcePath, string destinationPath ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAF ) // No need to use ShouldUseSAFForPath because both SAF paths and raw file paths are handled on the native-side { AJC.CallStatic( "CopyFile", Context, sourcePath, destinationPath, false ); return; @@ -381,7 +398,7 @@ public static void CopyFile( string sourcePath, string destinationPath ) public static void CopyDirectory( string sourcePath, string destinationPath ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAF ) // No need to use ShouldUseSAFForPath because both SAF paths and raw directory paths are handled on the native-side { AJC.CallStatic( "CopyDirectory", Context, sourcePath, destinationPath, false ); return; @@ -406,7 +423,7 @@ private static void CopyDirectoryRecursively( DirectoryInfo sourceDirectory, str public static void MoveFile( string sourcePath, string destinationPath ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAF ) // No need to use ShouldUseSAFForPath because both SAF paths and raw file paths are handled on the native-side { AJC.CallStatic( "CopyFile", Context, sourcePath, destinationPath, true ); return; @@ -418,7 +435,7 @@ public static void MoveFile( string sourcePath, string destinationPath ) public static void MoveDirectory( string sourcePath, string destinationPath ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAF ) // No need to use ShouldUseSAFForPath because both SAF paths and raw directory paths are handled on the native-side { AJC.CallStatic( "CopyDirectory", Context, sourcePath, destinationPath, true ); return; @@ -430,7 +447,7 @@ public static void MoveDirectory( string sourcePath, string destinationPath ) public static string RenameFile( string path, string newName ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( path ) ) return AJC.CallStatic( "RenameSAFEntry", Context, path, newName ); #endif string newPath = Path.Combine( Path.GetDirectoryName( path ), newName ); @@ -442,7 +459,7 @@ public static string RenameFile( string path, string newName ) public static string RenameDirectory( string path, string newName ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( path ) ) return AJC.CallStatic( "RenameSAFEntry", Context, path, newName ); #endif string newPath = Path.Combine( new DirectoryInfo( path ).Parent.FullName, newName ); @@ -454,7 +471,7 @@ public static string RenameDirectory( string path, string newName ) public static void DeleteFile( string path ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( path ) ) { AJC.CallStatic( "DeleteSAFEntry", Context, path ); return; @@ -466,7 +483,7 @@ public static void DeleteFile( string path ) public static void DeleteDirectory( string path ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( path ) ) { AJC.CallStatic( "DeleteSAFEntry", Context, path ); return; @@ -478,7 +495,7 @@ public static void DeleteDirectory( string path ) public static string GetFilename( string path ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( path ) ) return AJC.CallStatic( "SAFEntryName", Context, path ); #endif return Path.GetFileName( path ); @@ -487,7 +504,7 @@ public static string GetFilename( string path ) public static long GetFilesize( string path ) { #if !UNITY_EDITOR && UNITY_ANDROID - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( path ) ) return AJC.CallStatic( "SAFEntrySize", Context, path ); #endif return new FileInfo( path ).Length; @@ -497,7 +514,7 @@ public static System.DateTime GetLastModifiedDate( string path ) { #if !UNITY_EDITOR && UNITY_ANDROID // Credit: https://stackoverflow.com/a/28504416/2373034 - if( ShouldUseSAF ) + if( ShouldUseSAFForPath( path ) ) return new System.DateTime( 1970, 1, 1, 0, 0, 0 ).AddMilliseconds( AJC.CallStatic( "SAFEntryLastModified", Context, path ) ); #endif return new FileInfo( path ).LastWriteTime; diff --git a/package.json b/package.json index 20ccd39..9df2df9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.yasirkula.simplefilebrowser", "displayName": "Simple File Browser", - "version": "1.5.1", + "version": "1.5.2", "documentationUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser", "changelogUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser/releases", "licensesUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser/blob/master/LICENSE.txt", From 9bc2196551ade286f3faf444069a9028cfe17276 Mon Sep 17 00:00:00 2001 From: yasirkula Date: Sat, 8 Jan 2022 16:26:16 +0300 Subject: [PATCH 5/5] Updated README.txt with latest changes --- Plugins/SimpleFileBrowser/README.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Plugins/SimpleFileBrowser/README.txt b/Plugins/SimpleFileBrowser/README.txt index b423d2c..c09586e 100644 --- a/Plugins/SimpleFileBrowser/README.txt +++ b/Plugins/SimpleFileBrowser/README.txt @@ -69,6 +69,8 @@ void HideDialog( bool invokeCancelCallback = false ); // Customizing the dialog bool AddQuickLink( string name, string path, Sprite icon = null ); +void ClearQuickLinks(); + void SetExcludedExtensions( params string[] excludedExtensions ); // Filters should include the period (e.g. ".jpg" instead of "jpg") @@ -79,6 +81,10 @@ void SetFilters( bool showAllFilesFilter, params FileBrowser.Filter[] filters ); bool SetDefaultFilter( string defaultFilter ); +// Filtering displayed files/folders programmatically +delegate bool FileSystemEntryFilter( FileSystemEntry entry ); +event FileSystemEntryFilter DisplayedEntriesFilter; + // Android runtime permissions FileBrowser.Permission CheckPermission(); FileBrowser.Permission RequestPermission();