Esempio n. 1
0
        static void Main(string[] args)
        {
            Icon ikona = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);

            SetConsoleIcon(ikona.Handle);

            char letter = char.MinValue;

            if (args != null)
            {
                if (args.Length == 1)
                {
                    letter = args[0][0];
                }
            }

            Console.WriteLine("Drive to open: " + letter);

            letter = CorrectCDDrive(letter);
            if (letter != char.MinValue)
            {
                EjectMedia.Run(letter);
            }
            else
            {
                Console.WriteLine("Wrong parametr or ejectable drive not found.");
            }
        }
Esempio n. 2
0
        public void Can_Eject_CD()
        {
            bool          settingsFound      = false;
            DirectoryInfo driveRootDirectory = null;
            string        settingsJsonStr    = null;

            for (int i = 0; i < 5 && false == settingsFound; ++i)
            {
                DriveInfo[] drives = DriveInfo.GetDrives().Where(d => d.DriveType == DriveType.CDRom && d.IsReady).ToArray();
                if (null != drives)
                {
                    foreach (var drive in drives)
                    {
                        driveRootDirectory = drive.RootDirectory;
                        string envPath = Path.Combine(driveRootDirectory.FullName, "env");
                        if (File.Exists(envPath))
                        {
                            settingsJsonStr = File.ReadAllText(envPath);
                            settingsFound   = true;
                            break;
                        }
                    }
                }
            }
            if (null != driveRootDirectory)
            {
                EjectMedia.Eject(driveRootDirectory.FullName);
            }
        }