PutioFS.Windows.WinMounter.GetAvailableDriveLetter C# (CSharp) Method

GetAvailableDriveLetter() public static method

public static GetAvailableDriveLetter ( char Preferred ) : Char
Preferred char
return Char
        public static Char GetAvailableDriveLetter(char Preferred)
        {
            Char[] drives = System.Environment.GetLogicalDrives().Select(x => x[0]).ToArray();
            if (!drives.Contains(Preferred))
                return Preferred;

            Preferred = 'A';
            while (drives.Contains(Preferred) && Preferred <= 'Z')
            {
                Preferred++;
            }
            if (Preferred <= 'Z')
                return Preferred;
            throw new Exception("Can not find available drive letter to mount.");
        }

Usage Example

Example #1
0
        public static void Main(string[] args)
        {
            if (Environment.Version.Major < 4)
            {
                MessageBox.Show("You need to install Microsoft .NET Framework Version 4 in order to use put.io mounter.");
                return;
            }

            WinMounter mounter = new WinMounter(WinMounter.GetAvailableDriveLetter('P'));

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(mounter.CrashLogger);
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            mounter.SettingsForm = new SettingsForm(mounter);
            mounter.MainWindow   = new MainWindow(mounter);
            mounter.MainWindow.InitializeTrayIcon();
            mounter.MainWindow.GoInvisible();
            mounter.Silent = args.Contains(@"/silent");

            try
            {
                mounter.TryMount(null, null);
                mounter.RefreshCacheSize();
                mounter.MainWindow.notify_icon.Visible = true;
                Application.Run();
                logger.Debug("Exiting.");
                mounter.MainWindow.notify_icon.Visible = false;
            }
            finally
            {
                PutioDokanOperations._DokanUnmount(mounter.DriveLetter);
            }
        }