示例#1
0
    public void GetSubFolders(bool refresh) {
      if (!refresh) {
        if (Items.Count <= 0) return;
        if (Items[0].Title != @"...") return;
      }
      Items.Clear();

      foreach (string dir in Directory.GetDirectories(FullPath).OrderBy(x => x)) {
        if (!ACore.CanViewerSeeThisDirectory(dir)) continue;
        DirectoryInfo di = new DirectoryInfo(dir);
        Folder item = new Folder {
          Title = di.Name,
          FullPath = dir,
          IconName = "appbar_folder",
          Parent = this,
          IsAccessible = true
        };
        try {
          if (di.GetDirectories().Length > 0)
            item.Items.Add(new Folder {Title = "..."});
        } catch (UnauthorizedAccessException) {
          item.IconName = "appbar_folder_lock";
          item.IsAccessible = false;
        } finally {
          Items.Add(item);
        }
      }
    }
示例#2
0
 public bool GetVisibleTreeIndexFor(ObservableCollection<BaseTreeViewItem> folders, Folder folder, ref int index) {
   foreach (var item in folders) {
     index++;
     if (item.Equals(folder)) return true;
     if (!item.IsExpanded) continue;
     if (GetVisibleTreeIndexFor(item.Items, folder, ref index)) return true;
   }
   return false;
 }
示例#3
0
    public Folder New(string folderName) {
      IsExpanded = true;
      var newFullPath = $"{FullPath}\\{folderName}";
      Directory.CreateDirectory(newFullPath);
      ACore.Db.InsertDirecotryInToDb(newFullPath);

      var newFolder = new Folder {
        Title = folderName,
        FullPath = newFullPath,
        IconName = "appbar_folder",
        Parent = this,
        IsAccessible = true
      };

      Folder folder = Items.Cast<Folder>().FirstOrDefault(f => string.Compare(f.Title, folderName, StringComparison.OrdinalIgnoreCase) >= 0);
      Items.Insert(folder == null ? Items.Count : Items.IndexOf(folder), newFolder);

      return newFolder;
    }
示例#4
0
    public void AddDrives() {
      Items.Clear();
      string[] drives = Environment.GetLogicalDrives();

      foreach (string drive in drives) {
        DriveInfo di = new DriveInfo(drive);
        string driveImage;

        switch (di.DriveType) {
          case DriveType.CDRom:
            driveImage = "appbar_cd";
            break;
          case DriveType.Network:
            driveImage = "appbar_drive";
            break;
          case DriveType.NoRootDirectory:
          case DriveType.Unknown:
            driveImage = "appbar_drive_error";
            break;
          default:
            driveImage = "appbar_drive";
            break;
        }
        Folder item = new Folder {
          Title = $"{(di.IsReady ? di.VolumeLabel : di.DriveType.ToString())} ({di.Name})",
          FullPath = drive,
          IconName = driveImage,
          IsAccessible = di.IsReady
        };

        if (di.IsReady)
          item.Items.Add(new Folder {Title = "..."});

        Items.Add(item);
      }
    }
 private void LoadFolders() {
   var paths = Settings.Default.CatalogFolders.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
       .OrderBy(x => x).ToList();
   Folders.Items.Clear();
   foreach (var path in paths) {
     DirectoryInfo di = new DirectoryInfo(path);
     ViewModel.Folder item = new ViewModel.Folder {
       Title = di.Name,
       FullPath = path,
       IconName = "appbar_folder",
       IsAccessible = true
     };
     try {
       if (di.GetDirectories().Length > 0)
         item.Items.Add(new ViewModel.Folder {Title = "..."});
     }
     catch (UnauthorizedAccessException) {
       item.IconName = "appbar_folder_lock";
       item.IsAccessible = false;
     }
     catch (DirectoryNotFoundException) {
       item.IconName = "appbar_folder_lock";
       item.IsAccessible = false;
     } finally {
       Folders.Items.Add(item);
     }
   }
 }