public static void Mount(MountableFileSystem fs) { if (CanMount()) { char drive = GetAvailableDriveLetter(); Thread thread = new Thread(new ThreadStart(() => { DokanOptions options = DokanOptions.RemovableDrive; if (fs.Mode != OpenMode.ReadWrite) { options |= DokanOptions.WriteProtection; } Dokan.Mount(fs, $"{drive}:", options); } )); if (Mounted.ContainsKey(fs)) { Unmount(fs); } thread.Start(); Mounted[fs] = new Tuple <Thread, char>(thread, drive); } else { MessageBox.Show("Dokan driver seems to be missing. Install the driver and try again."); } }
public static void Unmount(MountableFileSystem fs) { Dokan.Unmount(Mounted[fs].Item2); string mountPoint = $"{Mounted[fs].Item2}:"; Mounted[fs].Item1.Join(); // wait for thread to actually stop Dokan.RemoveMountPoint(mountPoint); }
public static void Mount(MountableFileSystem fs) { if (CanMount()) { char drive = GetAvailableDriveLetter(); Thread thread = new Thread(new ThreadStart(() => { Dokan.Mount(fs, $"{drive}:", DokanOptions.RemovableDrive | DokanOptions.WriteProtection); Mounted.Remove(fs); } )); if (Mounted.ContainsKey(fs)) { Unmount(fs); } thread.Start(); Mounted[fs] = new Tuple <Thread, char>(thread, drive); } }