|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.IO; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using Windows.Storage; |
| 6 | +using static Files.Helpers.NativeFindStorageItemHelper; |
| 7 | +using FileAttributes = System.IO.FileAttributes; |
| 8 | + |
| 9 | +namespace Files.Filesystem |
| 10 | +{ |
| 11 | + public static class FolderHelpers |
| 12 | + { |
| 13 | + public static bool CheckFolderAccessWithWin32(string path) |
| 14 | + { |
| 15 | + FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS.FindExInfoBasic; |
| 16 | + int additionalFlags = FIND_FIRST_EX_LARGE_FETCH; |
| 17 | + IntPtr hFileTsk = FindFirstFileExFromApp(path + "\\*.*", findInfoLevel, out WIN32_FIND_DATA findDataTsk, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, |
| 18 | + additionalFlags); |
| 19 | + if (hFileTsk.ToInt64() != -1) |
| 20 | + { |
| 21 | + FindClose(hFileTsk); |
| 22 | + return true; |
| 23 | + } |
| 24 | + return false; |
| 25 | + } |
| 26 | + |
| 27 | + public static bool CheckFolderForHiddenAttribute(string path) |
| 28 | + { |
| 29 | + if (string.IsNullOrEmpty(path)) |
| 30 | + { |
| 31 | + return false; |
| 32 | + } |
| 33 | + FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS.FindExInfoBasic; |
| 34 | + int additionalFlags = FIND_FIRST_EX_LARGE_FETCH; |
| 35 | + IntPtr hFileTsk = FindFirstFileExFromApp(path + "\\*.*", findInfoLevel, out WIN32_FIND_DATA findDataTsk, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, |
| 36 | + additionalFlags); |
| 37 | + if (hFileTsk.ToInt64() == -1) |
| 38 | + { |
| 39 | + return false; |
| 40 | + } |
| 41 | + var isHidden = ((FileAttributes)findDataTsk.dwFileAttributes & FileAttributes.Hidden) == FileAttributes.Hidden; |
| 42 | + FindClose(hFileTsk); |
| 43 | + return isHidden; |
| 44 | + } |
| 45 | + |
| 46 | + public static async Task<bool> CheckBitlockerStatusAsync(StorageFolder rootFolder, string path) |
| 47 | + { |
| 48 | + if (rootFolder == null || rootFolder.Properties == null) |
| 49 | + { |
| 50 | + return false; |
| 51 | + } |
| 52 | + if (Path.IsPathRooted(path) && Path.GetPathRoot(path) == path) |
| 53 | + { |
| 54 | + IDictionary<string, object> extraProperties = await rootFolder.Properties.RetrievePropertiesAsync(new string[] { "System.Volume.BitLockerProtection" }); |
| 55 | + return (int?)extraProperties["System.Volume.BitLockerProtection"] == 6; // Drive is bitlocker protected and locked |
| 56 | + } |
| 57 | + return false; |
| 58 | + } |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// This function is used to determine whether or not a folder has any contents. |
| 62 | + /// </summary> |
| 63 | + /// <param name="targetPath">The path to the target folder</param> |
| 64 | + /// |
| 65 | + public static bool CheckForFilesFolders(string targetPath) |
| 66 | + { |
| 67 | + FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS.FindExInfoBasic; |
| 68 | + int additionalFlags = FIND_FIRST_EX_LARGE_FETCH; |
| 69 | + |
| 70 | + IntPtr hFile = FindFirstFileExFromApp(targetPath + "\\*.*", findInfoLevel, out WIN32_FIND_DATA _, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, additionalFlags); |
| 71 | + FindNextFile(hFile, out _); |
| 72 | + var result = FindNextFile(hFile, out _); |
| 73 | + FindClose(hFile); |
| 74 | + return result; |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments