private static bool canWatch() { DriveInfo[] drives = DirectoryHelper.GetDrives(); if (drives.Length > watchList.Count) { clear(); FileSystemWatcher watcher; for (int i = 0; i < drives.Length; i++) { watcher = new FileSystemWatcher(drives[i].Name, Source); watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite; watcher.Created += new FileSystemEventHandler(draged); watcher.Changed += new FileSystemEventHandler(draged); watcher.IncludeSubdirectories = true; watchList.Add(watcher); } } return(watchList.Count != 0); }
internal static async Task <bool> SetItemsAsync(string path) { if (path.NullEmpty()) { return(false); } if ((path != LocalHelper.ThisPC) && !DirectoryHelper.Exists(path)) { return(false); } fsw.EnableRaisingEvents = false; List <SmartItem> items = new List <SmartItem>(); bool listed = false; await Task.Run(() => { if (path == Home) { SmartItem item = new SmartItem(); item.FullName = item.ItemName = LocalHelper.ThisPC; item.ItemIcon = IconHelper.Get((int)ImageList.SpecialFolderCSIDL.DRIVES); items.Add(item); //items.Add(documentsPath); listed = true; } if (path == LocalHelper.ThisPC) { DriveInfo[] localDrives = DirectoryHelper.GetDrives(); try { for (int i = 0; i < localDrives.Length; i++) { SmartItem Ditem = new SmartItem(new DirectoryInfo(localDrives[i].Name)); Ditem.ItemName = (localDrives[i].IsReady ? localDrives[i].VolumeLabel : string.Empty) + " (" + localDrives[i].Name.TrimEnd('\\') + ')' + (localDrives[i].IsReady ? " " + AppLanguage.Get("LangFreeSpaceX").FormatC(SizeUnit.Parse(localDrives[i].AvailableFreeSpace)) : string.Empty); items.Add(Ditem); } listed = true; } catch (Exception exp) { ExceptionHelper.Log(exp); } localDrives = null; } else { DirectoryInfo Localdir = null; try { Localdir = new DirectoryInfo(path); } catch (Exception exp) { ExceptionHelper.Log(exp); } if (Localdir != null) { listed = true; DirectoryInfo[] dirs = null; try { dirs = Localdir.GetDirectories(); for (int i = 0; i < dirs.Length; i++) { if ((dirs[i].Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { items.Add(new SmartItem(dirs[i])); } } } catch (Exception exp) { ExceptionHelper.Log(exp); } dirs = null; FileInfo[] files = null; try { files = Localdir.GetFiles(); for (int i = 0; i < files.Length; i++) { if ((files[i].Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { items.Add(new SmartItem(files[i])); } } } catch (Exception exp) { ExceptionHelper.Log(exp); } files = null; } Localdir = null; } }); if (listed) { if (DirectoryHelper.Exists(path)) { if (fsw.Path != path) { fsw.Path = path; } fsw.EnableRaisingEvents = true; } LastPath = CurrentPath; CurrentPath = path; if (path == LocalHelper.ThisPC) { ParentPath = Home; } else { ParentPath = DirectoryHelper.GetParentPath(path); } Items = new ObservableCollection <SmartItem>(items); return(true); } else { return(false); } }