public static async Task <FileModelCollection> SearchFolder(string path, string searchPattern) { List <FileModel> fileModelList = new List <FileModel>(); DirectoryInfo[] folders = await GetFolders(path, searchPattern); if (folders != null) { foreach (DirectoryInfo folder in folders) { FileModel childFileModel = FileModel.FromDirectoryInfo(folder); childFileModel.Parent = FileModel.FromDirectoryInfo(folder.Parent); fileModelList.Add(childFileModel); } } FileInfo[] files = await GetFiles(path, searchPattern); if (files != null) { foreach (FileInfo file in files) { FileModel childFileModel = FileModel.FromFileInfo(file); childFileModel.Parent = FileModel.FromDirectoryInfo(file.Directory); fileModelList.Add(childFileModel); } } return(new FileModelCollection(fileModelList)); }
public static FileModelCollection GetQuickAccess(FileModel fileModel) { List <FileModel> fileModelList = new List <FileModel>(); foreach (string folder in UserFolders) { FileModel childFileModel = FileModel.FromDirectoryInfo(new DirectoryInfo(folder)); childFileModel.Parent = fileModel; fileModelList.Add(childFileModel); } if (!String.IsNullOrEmpty(Settings.Default.QuickAccessFolders)) { foreach (string folder in Settings.Default.QuickAccessFolders.Split(';')) { FileModel childFileModel = FileModel.FromDirectoryInfo(new DirectoryInfo(folder)); childFileModel.Parent = fileModel; fileModelList.Add(childFileModel); } } return(new FileModelCollection(fileModelList)); }
public static async Task <FileModelCollection> GetFolders(FileModel fileModel) { if (fileModel == Computer) { return(GetDrives(fileModel)); } if (fileModel == QuickAccess) { return(GetQuickAccess(fileModel)); } List <FileModel> fileModelList = new List <FileModel>(); DirectoryInfo[] folders = await GetFolders(fileModel.FullPath); if (folders != null) { foreach (DirectoryInfo folder in folders) { FileModel childFileModel = FileModel.FromDirectoryInfo(folder); childFileModel.Parent = fileModel; fileModelList.Add(childFileModel); } } return(new FileModelCollection(fileModelList)); }
public static async Task <FileModelCollection> GetNetworkShares(FileModel host) { List <DirectoryInfo> folders = new List <DirectoryInfo>(); await Task.Run(() => { try { foreach (ShareInfo shareInfo in Host.EnumerateShares(host.FullPath, ShareType.DiskTree, true)) { if (shareInfo.DirectoryInfo.Exists) { folders.Add(shareInfo.DirectoryInfo); } } } catch { } }).ConfigureAwait(false); List <FileModel> fileModelList = new List <FileModel>(); foreach (DirectoryInfo directoryInfo in folders) { FileModel fileModel = FileModel.FromDirectoryInfo(directoryInfo); fileModel.Parent = host; fileModelList.Add(fileModel); FileSystemWatcherHelper.RegisterDirectoryWatcher(fileModel.FullPath); } return(new FileModelCollection(fileModelList)); }