/// <summary> /// Is executed when a new drive has been found. /// </summary> /// <param name="sender">The sender of this event.</param> /// <param name="e">The event arguments containing the changed drive.</param> private void NewDriveFound(object sender, RemovableDriveWatcherEventArgs e) { try { foundDrives = e.ChangedDrive; try { sPlay.Stream = Properties.Resources.指纹识别成功; sPlay.Load(); sPlay.Play(); //Thread.Sleep(1000); sPlay.Stream = Properties.Resources.杨先生您好欢迎使用; sPlay.Load(); sPlay.Play(); } catch (Exception) { } var ih = new IniFiles(foundDrives.RootDirectory + "\\" + "Sec.ini"); NameValueCollection Values = new NameValueCollection(); ih.ReadSectionValues("HiddenFolders", Values); foreach (string key in Values) { try { var path = Values[key]; if (path != "") { listBox1.Items.Add(path); //path += ".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}"; DirectoryInfo d = new DirectoryInfo(path); //if (path.LastIndexOf(".{", StringComparison.Ordinal) != -1) { // d.MoveTo(path.Substring(0, path.LastIndexOf(".", StringComparison.Ordinal))); //} d.Attributes = FileAttributes.Archive; } } catch (Exception) { } } try { NameValueCollection blog = new NameValueCollection(); ih.ReadSectionValues("Blog", blog); if (!string.IsNullOrEmpty(blog["User"])) { listBox2.Items.Add(blog["User"] + "\\********"); } } catch (Exception) { } } catch (Exception) { } //Console.WriteLine(string.Format("Found a new drive, the name is: {0}", e.ChangedDrive.Name)); }
/// <summary> /// Is executed when a drive has been removed. /// </summary> /// <param name="sender">The sender of this event.</param> /// <param name="e">The event arguments containing the changed drive.</param> private void DriveRemoved(object sender, RemovableDriveWatcherEventArgs e) { try { foundDrives = e.ChangedDrive; try { sPlay.Stream = Properties.Resources.指纹识别成功; sPlay.Load(); sPlay.Play(); //Thread.Sleep(1000); sPlay.Stream = Properties.Resources.感谢使用再见; sPlay.Load(); sPlay.Play(); } catch (Exception) { } try { foreach (string path in listBox1.Items) { try { DirectoryInfo dx = new DirectoryInfo(path); //if (path.LastIndexOf(".{") == -1) { // if (!dx.Root.Equals(dx.Parent.FullName)) { // var fullPath = dx.Parent.FullName + "\\" + dx.Name + ".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}"; // dx.MoveTo(fullPath); // } // else { // var fullPath = dx.Parent.FullName + dx.Name + ".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}"; // dx.MoveTo(fullPath); // } //} dx.Attributes = FileAttributes.Hidden; } catch (Exception ex) { } } } catch (Exception ex) { MessageBox.Show(ex.Message); } listBox1.Items.Clear(); listBox2.Items.Clear(); } catch (Exception) { } //Console.WriteLine(string.Format("The drive with the name {0} has been removed.", e.ChangedDrive.Name)); }