Exemplo n.º 1
0
 public void SetDirectory(string path)
 {
     this.listbox.Items.Clear();
     try
     {
         if (path == SupportEDS.spec_folder)
         {
             List <string> f = Directory.EnumerateFiles(path).ToList();
             for (int i = 0; i < f.Count; i++)
             {
                 f[i] = f[i].Remove(f[i].Length - 5, 5);
                 string[] mas = f[i].Split('\\');
                 f[i] = mas[mas.Length - 1];
             }
             f = SupportEDS.Distinct(f);
             foreach (string str in f)
             {
                 AddKeysNode(str);
             }
         }
         else
         {
             foreach (string sub in Directory.EnumerateDirectories(path))
             {
                 DirectoryInfo dir = new DirectoryInfo(sub);
                 AddExplorerNode(sub, dir.Name, dir.LastWriteTime, explType.Folder, 0);
             }
             List <string> files = new List <string>(), eds = new List <string>(), all = Directory.EnumerateFiles(path).ToList();
             for (int i = 0; i < all.Count; i++)
             {
                 if (all[i].Substring(all[i].Length - 5, 5) == ".edsc")
                 {
                     eds.Add(all[i]);
                 }
                 else
                 {
                     files.Add(all[i]);
                 }
             }
             foreach (string sub in files)
             {
                 FileInfo file = new FileInfo(sub);
                 if (eds.Contains(sub + ".edsc"))
                 {
                     AddExplorerNode(sub, file.Name, file.LastWriteTime, explType.File, file.Length, true);
                 }
                 else
                 {
                     AddExplorerNode(sub, file.Name, file.LastWriteTime, explType.File, file.Length);
                 }
             }
         }
         this.CurrentDirectory = path;
         int indx = -1;
         for (int i = 0; i < this.path_combobox.Items.Count; i++)
         {
             if ((string)(this.path_combobox.Items[i]) == path)
             {
                 indx = i;
             }
         }
         if (indx != -1)
         {
             this.path_combobox.SelectedIndex = indx;
         }
         else
         {
             this.path_combobox.Items.Add(path);
             this.path_combobox.SelectedItem = this.path_combobox.Items[this.path_combobox.Items.Count - 1];
             if (this.path_combobox.Items.Count > 5)
             {
                 this.path_combobox.Items.RemoveAt(0);
             }
         }
     }
     catch (UnauthorizedAccessException)
     {
         MessageBox.Show(String.Format("Нет доступа к {0}", path), "Расположение недоступно", MessageBoxButton.OK, MessageBoxImage.Stop);
         BackButton_Click(this, null);
     }
     catch (Exception exp)
     {
         MessageBox.Show(exp.Message, "Ошибка");
         BackButton_Click(this, null);
     }
 }