Esempio n. 1
0
        private static void Main(string[] args)
        {
            try
            {
                if (args.Length != 2)
                {
                    Console.WriteLine(@"usage: mountbck.exe S 'C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Backup\AdventureWorks2014.bak'");
                    Console.WriteLine("Press any key for exit.");
                    Console.ReadKey();
                    return;
                }

                var driveLetter    = args[0][0];
                var backupFileName = args[1];

                Dokan.Unmount(driveLetter);
                var backupVfs = new SqlBackupVfs(backupFileName, driveLetter);
                backupVfs.Mount($"{driveLetter}:\\", DokanOptions.NetworkDrive, 1);

                Console.WriteLine("Success");
            }
            catch (DokanException ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
Esempio n. 2
0
        private static void Monitor_DeviceDisconnected(object sender, DeviceDataEventArgs e)
        {
            Log.Information("Device disconnected", e.Device);
            List <VirtualDrive> drivesToRemove = new List <VirtualDrive>();

            foreach (VirtualDrive d in Devices)
            {
                if (e.Device.Serial.Equals(d.AndroidDevice.Serial))
                {
                    if (Dokan.Unmount(d.DriveLetter))
                    {
                        Log.Information("Successfully unmounted drive " + d.DriveLetter);
                    }
                    else
                    {
                        Log.Warning("Error while unmounting " + d.DriveLetter);
                    }
                    drivesToRemove.Add(d);
                }
            }
            foreach (VirtualDrive d in drivesToRemove)
            {
                Devices.Remove(d);
            }
        }
Esempio n. 3
0
 private void unmountBtn_Click(object sender, EventArgs e)
 {
     unmountBtn.Enabled = false;
     SetFUSEStatus("Unmounting...", Color.Orange);
     Dokan.Unmount(DriveLetter);
     SetFUSEStatus("Unmounted.", Color.Red);
 }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 public static void AssemblyCleanup()
 {
     mounterThread.Abort();
     mounterThread2.Abort();
     Dokan.Unmount(DokanOperationsFixture.NormalMountPoint[0]);
     Dokan.Unmount(DokanOperationsFixture.UnsafeMountPoint[0]);
     Dokan.RemoveMountPoint(DokanOperationsFixture.NormalMountPoint);
     Dokan.RemoveMountPoint(DokanOperationsFixture.UnsafeMountPoint);
 }
Esempio n. 6
0
        public bool UnMountVirtualDrive()
        {
            if (_mountPoint == null)
            {
                return(false);
            }

            return(Dokan.Unmount(_mountPoint[0]) && Dokan.RemoveMountPoint(_mountPoint));
        }
Esempio n. 7
0
        public void Unmount()
        {
            if (_th != null)
            {
                _th.Abort();
            }

            Dokan.Unmount(this.DriveLetter);
            Dokan.RemoveMountPoint(this.DriveLetter + ":");
        }
Esempio n. 8
0
        public static void startVDrive(char vDriveLetter)
        {
            Dokan.Unmount(vDriveLetter);
            di = new VDrive();
#if DEBUG
            Thread t2 = new Thread(() => { di.Mount(vDriveLetter + ":\\", DokanOptions.DebugMode, 1); });
#else
            Thread t2 = new Thread(() => { di.Mount(vDriveLetter + ":\\", DokanOptions.FixedDrive, 10); });
#endif
            t2.Start();
        }
Esempio n. 9
0
        private void startVDriveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Dokan.Unmount(vDriveLetter);
            di = new VDrive();
#if DEBUG
            Thread t2 = new Thread(() => { di.Mount(vDriveLetter + ":\\", DokanOptions.DebugMode, 1); });
#else
            Thread t2 = new Thread(() => { di.Mount(vDriveLetter + ":\\", DokanOptions.FixedDrive, 10); });
#endif
            t2.Start();
        }
        private void OnClosing(object sender, CancelEventArgs e)
        {
            if (unmountingPhase != UnmountingPhase.NotInitiated)
            {
                if (unmountingPhase == UnmountingPhase.Initiated)
                {
                    e.Cancel = true;
                }

                return;
            }

            try
            {
                fs.Save();

                if (Dokan.Unmount(DRIVE_LETTER))
                {
                    e.Cancel        = true;
                    unmountingPhase = UnmountingPhase.Initiated;

                    pathRow.Opacity      = 0;
                    messageRow.Text      = "Unmounting...";
                    saveButton.Opacity   = 0;
                    saveButton.IsEnabled = false;
                }

                else
                {
                    throw new IOException("Unmount error");
                }
            }

            catch (WrappedFileException ef)
            {
                if (MessageBox.Show("Some files were not successfully converted and retained unmodified. "
                                    + "If you close this application now, you will lose any changes made to these 'faulted' files.\n\n"
                                    + ef.MessageBoxText + "\n\nDo you want to close the app?", "Warning",
                                    MessageBoxButton.YesNoCancel, MessageBoxImage.Warning) != MessageBoxResult.Yes)
                {
                    e.Cancel = true;
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show("Due to some reason, unmounting wasn't successful.\n\n"
                                + ex.GetType().ToString() + ": " + ex.Message + "\n\n"
                                + "The application will be TERMINATED right after the OK button is pressed.\n\nBye.", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(-1);
            }
        }
Esempio n. 11
0
 public static void End()
 {
     try
     {
         Dokan.Unmount(Properties.Settings.Default.MountPoint[0]);
         Dokan.RemoveMountPoint(Properties.Settings.Default.MountPoint + ":\\");
     }
     catch (Exception)
     {
         // ignored
     }
 }
Esempio n. 12
0
 public static void UnmountAll()
 {
     foreach (Tuple <Thread, char> fs in Mounted.Values)
     {
         Dokan.Unmount(fs.Item2); // tell every drive to unmount
     }
     foreach (Tuple <Thread, char> fs in new List <Tuple <Thread, char> >(Mounted.Values))
     {
         fs.Item1.Join(); // wait for thread to stop (wait for drives to be unmounted)
     }
     Mounted.Clear();
 }
Esempio n. 13
0
 /// <summary>
 /// Unmount the main volume - not used in current implementation
 /// </summary>
 public void UnmountMainVolume()
 {
     if (_mainMounted)
     {
         char driveLetter = fsOp.Drive.ToCharArray()[0];
         Console.WriteLine("Unmounting main volume from '" + driveLetter + "'");
         Dokan.Unmount(driveLetter);
     }
     else
     {
         throw new VolumeMountManagerException("Main volume can only be unmounted if it was mounted before.");
     }
 }
Esempio n. 14
0
        private static void Unmount(this Settings settings)
        {
            try
            {
                Dokan.Unmount(mountpoint);

                Console.WriteLine($"Unmounted {mountpoint}:\\");
            }
            catch
            {
            }
            finally
            {
                if (regkey != null)
                {
                    try
                    {
                        regkey.Close();

                        Registry.LocalMachine.OpenSubKey(REG_BASE).DeleteSubKeyTree($"{mountpoint}", false);
                    }
                    catch
                    {
                    }
                    finally
                    {
                        regkey.Dispose();
                        regkey = null;
                    }
                }

                if (settings.DeleteCache && (filesys != null))
                {
                    try
                    {
                        if (filesys.TemporaryDirectory.Exists)
                        {
                            filesys.TemporaryDirectory.Delete(true);
                        }
                    }
                    catch
                    {
                    }
                }

                filesys = null;

                OnExit();
            }
        }
Esempio n. 15
0
        internal static void Main(string[] args)
        {
            var mountSection = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).Sections[MountSection.Name] as MountSection;

            if (mountSection == null)
            {
                throw new ConfigurationErrorsException("Mount configuration missing");
            }

            CompositionInitializer.Preload(typeof(IgorSoft.CloudFS.Interface.Composition.ICloudGateway));
            CompositionInitializer.Initialize(mountSection.LibPath, "IgorSoft.CloudFS.Gateways.*.dll");
            var factory = new CloudDriveFactory();

            CompositionInitializer.SatisfyImports(factory);

            try {
                var logger = new LogFactory().GetCurrentClassLogger();
                using (var tokenSource = new CancellationTokenSource()) {
                    var tasks = new List <Task>();
                    foreach (var drive in mountSection.Drives.Cast <DriveElement>())
                    {
                        var operations = new CloudOperations(factory.CreateCloudDrive(drive.Schema, drive.UserName, drive.Root, new CloudDriveParameters()
                        {
                            EncryptionKey = drive.EncryptionKey, Parameters = drive.GetParameters()
                        }), logger);

                        // HACK: handle non-unique parameter set of DokanOperations.Mount() by explicitely specifying AllocationUnitSize and SectorSize
                        tasks.Add(Task.Run(() => operations.Mount(drive.Root, DokanOptions.RemovableDrive | DokanOptions.MountManager | DokanOptions.CurrentSession, mountSection.Threads, 1100, TimeSpan.FromSeconds(drive.Timeout != 0 ? drive.Timeout : 20), null, 512, 512), tokenSource.Token));

                        var driveInfo = new DriveInfo(drive.Root);
                        while (!driveInfo.IsReady)
                        {
                            Thread.Sleep(10);
                        }
                    }

                    Console.ReadKey(true);

                    tokenSource.Cancel();
                }
            } finally {
                foreach (var drive in mountSection.Drives.Cast <DriveElement>())
                {
                    Dokan.Unmount(drive.Root[0]);
                }
            }
        }
Esempio n. 16
0
        public bool UnmapDrive(string driveLetter)
        {
            if (string.IsNullOrEmpty(driveLetter))
            {
                throw new ArgumentNullException(nameof(driveLetter));
            }

            try
            {
                Dokan.Unmount(driveLetter[0]);
                return(true);
            }
            catch (Exception ex)
            {
                ex.Log(ExceptionType.SecureVolume, @"Can not unmount virtual drive");
                return(false);
            }
        }
Esempio n. 17
0
        private static void Main()
        {
            try
            {
                var driveLetter    = 'S';
                var backupFileName = @"C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Backup\AdventureWorks2014.bak";

                Dokan.Unmount(driveLetter);
                var backupVfs = new SqlBackupVfs(backupFileName, driveLetter);
                backupVfs.Mount($"{driveLetter}:\\", DokanOptions.NetworkDrive, 1);

                Console.WriteLine("Success");
            }
            catch (DokanException ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
Esempio n. 18
0
        public static BuildFsFileSystem Mount(char letter, DokanOptions options)
        {
            Dokan.Unmount(letter);

            var fs = new BuildFsFileSystem();

            fs.Letter = letter;
            var t = Task.Run(() => Dokan.Mount(fs, letter + ":", options, 1));
            var e = Stopwatch.StartNew();

            while (e.ElapsedMilliseconds < 3000)
            {
                Thread.Sleep(200);
                if (t.Exception != null)
                {
                    throw t.Exception;
                }
                if (Directory.Exists(letter + ":\\"))
                {
                    return(fs);
                }
            }
            return(fs);
        }
Esempio n. 19
0
        static void Start(Options options)
        {
            var auths = GetAuthMechanisms(options);

            var fs = auths
                     .Select(auth => AttemptConnection(auth.Item1, auth.Item2, options.Path))
                     .FirstOrDefault(result => result != null);

            if (fs == null)
            {
                throw new InvalidOperationException(
                          "Could not connect to server with any known authentication mechanism");
            }

            fs.Disconnected  += (sender, e) => Environment.Exit(0);
            fs.ErrorOccurred += (sender, e) => Environment.Exit(0);

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
                e.Cancel = true;
                Console.WriteLine("Ctrl-C detected, start exiting . . .");
                Dokan.Unmount(options.DriveLetter);
            };

            ILogger logger = null; // Use default logger in DokanNet

            if (options.Logging)
            {
                logger = new ConsoleLogger(); // Verbose
            }
            else
            {
                logger = new NullLogger(); // Override the default logger in DokanNet
            }
            fs.Mount($"{options.DriveLetter}", logger);
            Console.WriteLine("Program exited gracefully.");
        }
Esempio n. 20
0
 public static void AssemblyCleanup()
 {
     mounterThread.Abort();
     Dokan.Unmount(DokanOperationsFixture.MOUNT_POINT[0]);
     Dokan.RemoveMountPoint(DokanOperationsFixture.MOUNT_POINT.ToString(CultureInfo.InvariantCulture));
 }
Esempio n. 21
0
 public static void Unmount(char letter)
 {
     Dokan.Unmount(letter);
 }
Esempio n. 22
0
 public static void AssemblyCleanup()
 {
     mounterThread.Abort();
     Dokan.Unmount(DokanOperationsFixture.MOUNT_POINT[0]);
     Dokan.RemoveMountPoint(DokanOperationsFixture.MOUNT_POINT);
 }
Esempio n. 23
0
 private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     Dokan.Unmount(vDriveLetter);
 }
Esempio n. 24
0
 private void closeVDriveToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Dokan.Unmount(vDriveLetter);
 }
Esempio n. 25
0
        private int Mount(string passPhrase, IList <string> userNames)
        {
            var mountSection = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).Sections[MountSection.Name] as MountSection;

            if (mountSection == null)
            {
                throw new ConfigurationErrorsException("Mount configuration missing");
            }

            settingsPassPhrase = passPhrase;

            try {
                using (var logFactory = new LogFactory()) {
                    logger = logFactory.GetCurrentClassLogger();
                    var factory = InitializeCloudDriveFactory(mountSection.LibPath);
                    using (var tokenSource = new CancellationTokenSource()) {
                        var tasks = new List <Task>();
                        foreach (var driveElement in mountSection.Drives.Where(d => !userNames.Any() || userNames.Contains(d.UserName)))
                        {
                            var drive = factory.CreateCloudDrive(driveElement.Schema, driveElement.UserName, driveElement.Root, new CloudDriveParameters()
                            {
                                ApiKey = driveElement.ApiKey, EncryptionKey = driveElement.EncryptionKey, Parameters = driveElement.GetParameters()
                            });
                            if (!drive.TryAuthenticate())
                            {
                                var displayRoot = drive.DisplayRoot;
                                drive.Dispose();
                                logger.Warn($"Authentication failed for drive '{displayRoot}'");
                                continue;
                            }

                            var operations = new CloudOperations(drive, logger);

                            // HACK: handle non-unique parameter set of DokanOperations.Mount() by explicitely specifying AllocationUnitSize and SectorSize
                            tasks.Add(Task.Run(() => operations.Mount(driveElement.Root, DokanOptions.RemovableDrive | DokanOptions.MountManager | DokanOptions.CurrentSession, mountSection.Threads, 1100, TimeSpan.FromSeconds(driveElement.Timeout != 0 ? driveElement.Timeout : 20), null, 512, 512), tokenSource.Token));

                            var driveInfo = new DriveInfo(driveElement.Root);
                            while (!driveInfo.IsReady)
                            {
                                Thread.Sleep(10);
                            }
                            logger.Info($"Drive '{drive.DisplayRoot}' mounted successfully.");
                        }

                        Console.WriteLine("Press CTRL-BACKSPACE to clear log, any other key to unmount drives");
                        while (true)
                        {
                            var keyInfo = Console.ReadKey(true);
                            if (keyInfo.Modifiers.HasFlag(ConsoleModifiers.Control) && keyInfo.Key == ConsoleKey.Backspace)
                            {
                                Console.Clear();
                            }
                            else
                            {
                                break;
                            }
                        }

                        tokenSource.Cancel();

                        return(0);
                    }
                }
            } catch (Exception ex) {
                Console.Error.WriteLine($"{ex.GetType().Name}: {ex.Message}");
                return(-1);
            } finally {
                foreach (var driveElement in mountSection.Drives.Cast <DriveElement>())
                {
                    Dokan.Unmount(driveElement.Root[0]);
                }
                UIThread.Shutdown();
            }
        }
Esempio n. 26
0
 public void Unmount()
 {
     _cancellation.Cancel();
     Dokan.Unmount(DriveLetter);
     Mounted = false;
 }
Esempio n. 27
0
 protected override void OnExit(ExitEventArgs e)
 {
     Dokan.Unmount(MOUNT_POINT);
     taskbarIcon?.Dispose(); //the icon would clean up automatically, but this is cleaner
     base.OnExit(e);
 }
Esempio n. 28
0
 public void Dispose()
 {
     //_mounterThread.Abort();
     Dokan.Unmount(MOUNT_POINT[0]);
     Dokan.RemoveMountPoint(MOUNT_POINT);
 }
Esempio n. 29
0
 public NtStatusCodes Unmount(DokanFileInfo info)
 {
     return(Dokan.Unmount(DriveLetter) ? NtStatusCodes.VolumeMounted : NtStatusCodes.WrongVolume);
 }
Esempio n. 30
0
 private void Unmount() => Dokan.Unmount(_settings.Drive);