コード例 #1
0
        public static async Task <List <ListedItem> > ListEntries(
            StorageFolder rootFolder,
            StorageFolderWithPath currentStorageFolder,
            string returnformat,
            Type sourcePageType,
            CancellationToken cancellationToken,
            int countLimit,
            Func <List <ListedItem>, Task> intermediateAction
            )
        {
            var  sampler    = new IntervalSampler(500);
            var  tempList   = new List <ListedItem>();
            uint count      = 0;
            var  firstRound = true;

            while (true)
            {
                IReadOnlyList <IStorageItem> items;
                uint maxItemsToRetrieve = 300;

                if (intermediateAction == null)
                {
                    // without intermediate action increase batches significantly
                    maxItemsToRetrieve = 1000;
                }
                else if (firstRound)
                {
                    maxItemsToRetrieve = 32;
                    firstRound         = false;
                }
                try
                {
                    items = await rootFolder.GetItemsAsync(count, maxItemsToRetrieve);

                    if (items == null || items.Count == 0)
                    {
                        break;
                    }
                }
                catch (NotImplementedException)
                {
                    break;
                }
                catch (Exception ex) when(
                    ex is UnauthorizedAccessException ||
                    ex is FileNotFoundException ||
                    (uint)ex.HResult == 0x80070490)    // ERROR_NOT_FOUND
                {
                    // If some unexpected exception is thrown - enumerate this folder file by file - just to be sure
                    items = await EnumerateFileByFile(rootFolder, count, maxItemsToRetrieve);
                }
                foreach (var item in items)
                {
                    if (item.IsOfType(StorageItemTypes.Folder))
                    {
                        var folder = await AddFolderAsync(item as StorageFolder, currentStorageFolder, returnformat, cancellationToken);

                        if (folder != null)
                        {
                            tempList.Add(folder);
                        }
                    }
                    else
                    {
                        var file      = item as StorageFile;
                        var fileEntry = await AddFileAsync(file, currentStorageFolder, returnformat, true, sourcePageType, cancellationToken);

                        if (fileEntry != null)
                        {
                            tempList.Add(fileEntry);
                        }
                    }
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }
                }
                count += maxItemsToRetrieve;

                if (countLimit > -1 && count >= countLimit)
                {
                    break;
                }

                if (intermediateAction != null && (items.Count == maxItemsToRetrieve || sampler.CheckNow()))
                {
                    await intermediateAction(tempList);

                    // clear the temporary list every time we do an intermediate action
                    tempList.Clear();
                }
            }
            return(tempList);
        }
コード例 #2
0
        public static async Task <List <ListedItem> > ListEntries(
            string path,
            string returnformat,
            IntPtr hFile,
            WIN32_FIND_DATA findData,
            AppServiceConnection connection,
            CancellationToken cancellationToken,
            List <string> skipItems,
            int countLimit,
            Func <List <ListedItem>, Task> intermediateAction
            )
        {
            var sampler     = new IntervalSampler(500);
            var tempList    = new List <ListedItem>();
            var hasNextFile = false;
            var count       = 0;

            do
            {
                if (((FileAttributes)findData.dwFileAttributes & FileAttributes.System) != FileAttributes.System || !App.AppSettings.AreSystemItemsHidden)
                {
                    if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Hidden) != FileAttributes.Hidden || App.AppSettings.AreHiddenItemsVisible)
                    {
                        if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory)
                        {
                            var file = await GetFile(findData, path, returnformat, connection, cancellationToken);

                            if (file != null)
                            {
                                if (skipItems?.Contains(file.ItemPath) ?? false)
                                {
                                    skipItems.Remove(file.ItemPath);
                                }
                                else
                                {
                                    tempList.Add(file);
                                }
                                ++count;
                            }
                        }
                        else if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
                        {
                            if (findData.cFileName != "." && findData.cFileName != "..")
                            {
                                var folder = await GetFolder(findData, path, returnformat, cancellationToken);

                                if (folder != null)
                                {
                                    if (skipItems?.Contains(folder.ItemPath) ?? false)
                                    {
                                        skipItems.Remove(folder.ItemPath);
                                    }
                                    else
                                    {
                                        tempList.Add(folder);
                                    }
                                    ++count;
                                }
                            }
                        }
                    }
                }
                if (cancellationToken.IsCancellationRequested || count == countLimit)
                {
                    break;
                }

                hasNextFile = FindNextFile(hFile, out findData);
                if (intermediateAction != null && (count == 32 || sampler.CheckNow()))
                {
                    await intermediateAction(tempList);

                    // clear the temporary list every time we do an intermediate action
                    tempList.Clear();
                }
            } while (hasNextFile);

            FindClose(hFile);
            return(tempList);
        }
コード例 #3
0
        public static async Task <List <ListedItem> > ListEntries(
            BaseStorageFolder rootFolder,
            StorageFolderWithPath currentStorageFolder,
            CancellationToken cancellationToken,
            int countLimit,
            Func <List <ListedItem>, Task> intermediateAction,
            Dictionary <string, BitmapImage> defaultIconPairs = null
            )
        {
            var  sampler    = new IntervalSampler(500);
            var  tempList   = new List <ListedItem>();
            uint count      = 0;
            var  firstRound = true;

            IUserSettingsService userSettingsService = Ioc.Default.GetService <IUserSettingsService>();

            while (true)
            {
                IReadOnlyList <IStorageItem> items;
                uint maxItemsToRetrieve = 300;

                if (intermediateAction == null)
                {
                    // without intermediate action increase batches significantly
                    maxItemsToRetrieve = 1000;
                }
                else if (firstRound)
                {
                    maxItemsToRetrieve = 32;
                    firstRound         = false;
                }
                try
                {
                    items = await rootFolder.GetItemsAsync(count, maxItemsToRetrieve);

                    if (items == null || items.Count == 0)
                    {
                        break;
                    }
                }
                catch (NotImplementedException)
                {
                    break;
                }
                catch (Exception ex) when(
                    ex is UnauthorizedAccessException ||
                    ex is FileNotFoundException ||
                    (uint)ex.HResult == 0x80070490)    // ERROR_NOT_FOUND
                {
                    // If some unexpected exception is thrown - enumerate this folder file by file - just to be sure
                    items = await EnumerateFileByFile(rootFolder, count, maxItemsToRetrieve);
                }
                foreach (var item in items)
                {
                    var startWithDot = item.Name.StartsWith(".");
                    if (!startWithDot || userSettingsService.PreferencesSettingsService.ShowDotFiles)
                    {
                        if (item.IsOfType(StorageItemTypes.Folder))
                        {
                            var folder = await AddFolderAsync(item.AsBaseStorageFolder(), currentStorageFolder, cancellationToken);

                            if (folder != null)
                            {
                                if (defaultIconPairs?.ContainsKey(string.Empty) ?? false)
                                {
                                    folder.SetDefaultIcon(defaultIconPairs[string.Empty]);
                                }
                                tempList.Add(folder);
                            }
                        }
                        else
                        {
                            var fileEntry = await AddFileAsync(item.AsBaseStorageFile(), currentStorageFolder, cancellationToken);

                            if (fileEntry != null)
                            {
                                if (defaultIconPairs != null)
                                {
                                    if (!string.IsNullOrEmpty(fileEntry.FileExtension))
                                    {
                                        var lowercaseExtension = fileEntry.FileExtension.ToLowerInvariant();
                                        if (defaultIconPairs.ContainsKey(lowercaseExtension))
                                        {
                                            fileEntry.SetDefaultIcon(defaultIconPairs[lowercaseExtension]);
                                        }
                                    }
                                }
                                tempList.Add(fileEntry);
                            }
                        }
                    }
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }
                }
                count += maxItemsToRetrieve;

                if (countLimit > -1 && count >= countLimit)
                {
                    break;
                }

                if (intermediateAction != null && (items.Count == maxItemsToRetrieve || sampler.CheckNow()))
                {
                    await intermediateAction(tempList);

                    // clear the temporary list every time we do an intermediate action
                    tempList.Clear();
                }
            }
            return(tempList);
        }
コード例 #4
0
        public static async Task <List <ListedItem> > ListEntries(
            string path,
            string returnformat,
            IntPtr hFile,
            WIN32_FIND_DATA findData,
            NamedPipeAsAppServiceConnection connection,
            CancellationToken cancellationToken,
            int countLimit,
            Func <List <ListedItem>, Task> intermediateAction,
            Dictionary <string, BitmapImage> defaultIconPairs = null
            )
        {
            var sampler     = new IntervalSampler(500);
            var tempList    = new List <ListedItem>();
            var hasNextFile = false;
            var count       = 0;

            IUserSettingsService userSettingsService = Ioc.Default.GetService <IUserSettingsService>();
            bool showFolderSize = userSettingsService.PreferencesSettingsService.ShowFolderSize;

            do
            {
                var isSystem     = ((FileAttributes)findData.dwFileAttributes & FileAttributes.System) == FileAttributes.System;
                var isHidden     = ((FileAttributes)findData.dwFileAttributes & FileAttributes.Hidden) == FileAttributes.Hidden;
                var startWithDot = findData.cFileName.StartsWith(".");
                if ((!isHidden ||
                     (userSettingsService.PreferencesSettingsService.AreHiddenItemsVisible &&
                      (!isSystem || !userSettingsService.PreferencesSettingsService.AreSystemItemsHidden))) &&
                    (!startWithDot || userSettingsService.PreferencesSettingsService.ShowDotFiles))
                {
                    if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory)
                    {
                        var file = await GetFile(findData, path, returnformat, connection, cancellationToken);

                        if (file != null)
                        {
                            if (defaultIconPairs != null)
                            {
                                if (!string.IsNullOrEmpty(file.FileExtension))
                                {
                                    var lowercaseExtension = file.FileExtension.ToLowerInvariant();
                                    if (defaultIconPairs.ContainsKey(lowercaseExtension))
                                    {
                                        file.SetDefaultIcon(defaultIconPairs[lowercaseExtension]);
                                    }
                                }
                            }
                            tempList.Add(file);
                            ++count;
                        }
                    }
                    else if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        if (findData.cFileName != "." && findData.cFileName != "..")
                        {
                            var folder = await GetFolder(findData, path, returnformat, cancellationToken);

                            if (folder != null)
                            {
                                if (defaultIconPairs?.ContainsKey(string.Empty) ?? false)
                                {
                                    // Set folder icon (found by empty extension string)
                                    folder.SetDefaultIcon(defaultIconPairs[string.Empty]);
                                }
                                tempList.Add(folder);
                                ++count;

                                if (showFolderSize)
                                {
                                    folderSizeProvider.UpdateFolder(folder, cancellationToken);
                                }
                            }
                        }
                    }
                }
                if (cancellationToken.IsCancellationRequested || count == countLimit)
                {
                    break;
                }

                hasNextFile = FindNextFile(hFile, out findData);
                if (intermediateAction != null && (count == 32 || sampler.CheckNow()))
                {
                    await intermediateAction(tempList);

                    // clear the temporary list every time we do an intermediate action
                    tempList.Clear();
                }
            } while (hasNextFile);

            FindClose(hFile);
            return(tempList);
        }
コード例 #5
0
        public static async Task <List <ListedItem> > ListEntries(
            string path,
            string returnformat,
            IntPtr hFile,
            WIN32_FIND_DATA findData,
            NamedPipeAsAppServiceConnection connection,
            CancellationToken cancellationToken,
            int countLimit,
            Func <List <ListedItem>, Task> intermediateAction
            )
        {
            var sampler     = new IntervalSampler(500);
            var tempList    = new List <ListedItem>();
            var hasNextFile = false;
            var count       = 0;

            IUserSettingsService userSettingsService = Ioc.Default.GetService <IUserSettingsService>();

            do
            {
                var isSystem = ((FileAttributes)findData.dwFileAttributes & FileAttributes.System) == FileAttributes.System;
                var isHidden = ((FileAttributes)findData.dwFileAttributes & FileAttributes.Hidden) == FileAttributes.Hidden;
                if (!isHidden || (userSettingsService.FilesAndFoldersSettingsService.AreHiddenItemsVisible && (!isSystem || !userSettingsService.FilesAndFoldersSettingsService.AreSystemItemsHidden)))
                {
                    if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory)
                    {
                        var file = await GetFile(findData, path, returnformat, connection, cancellationToken);

                        if (file != null)
                        {
                            tempList.Add(file);
                            ++count;
                        }
                    }
                    else if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        if (findData.cFileName != "." && findData.cFileName != "..")
                        {
                            var folder = await GetFolder(findData, path, returnformat, cancellationToken);

                            if (folder != null)
                            {
                                tempList.Add(folder);
                                ++count;
                            }
                        }
                    }
                }
                if (cancellationToken.IsCancellationRequested || count == countLimit)
                {
                    break;
                }

                hasNextFile = FindNextFile(hFile, out findData);
                if (intermediateAction != null && (count == 32 || sampler.CheckNow()))
                {
                    await intermediateAction(tempList);

                    // clear the temporary list every time we do an intermediate action
                    tempList.Clear();
                }
            } while (hasNextFile);

            FindClose(hFile);
            return(tempList);
        }