Пример #1
0
        private bool DoEject(string driveLetter)
        {
            var loggerFactory = new LoggerFactoryAdapter(LoggerFactory);

            using (var volumeDeviceClass = new UsbEject.VolumeDeviceClass(loggerFactory))
            {
                var volume = volumeDeviceClass.SingleOrDefault(v => driveLetter.Equals(v.LogicalDrive));
                if (volume == null)
                {
                    Logger.LogError("Volume not found");
                    return(false);
                }

                var allowUI = true;
                var result  = volume.Eject(allowUI);
                if (result != null)
                {
                    Logger.LogError("Eject result: {0}", result);
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        private void CopyAllFiles(string remotepath)
        {
            notifyIcon.ShowBalloonTip(1000, "EC", "升级中···", ToolTipIcon.Info);
            try
            {
                List <string> u_Drive = new List <string>();
                DriveInfo[]   info    = DriveInfo.GetDrives();
                foreach (DriveInfo d in info)
                {
                    if (d.DriveType == DriveType.Removable)
                    {
                        u_Drive.Add(d.Name);
                    }
                }
                for (int i = 0; i < u_Drive.Count; i++)
                {
                    u_Drive[i] = u_Drive[i] + UDrive_UpdatePath;
                    if (!Directory.Exists(u_Drive[i]))
                    {
                        u_Drive.RemoveAt(i);
                    }
                }
                string sourcepath = string.Empty;;
                if (Directory.Exists(u_Drive[0]))
                {
                    sourcepath = u_Drive[0];
                    ShowStr    = "u盘复制文件路径:" + sourcepath;
                    ShowStr    = "更新文件路径:" + Update_filepath;
                }
                else
                {
                    ShowStr = "U盘路径丢失";
                    return;
                }
                copy(sourcepath, Update_filepath);
                ShowStr = "文件复制完毕\r\n等待U盘退出";
                for (int i = 5; i > 0; i--)
                {
                    ShowStr = string.Format("倒计时:{0}秒", i);
                    Thread.Sleep(1000);
                }
                //MessageBox.Show("点击退出U盘");
                #region U盘退出
                UsbEject.VolumeDeviceClass volumeDeviceClass = new UsbEject.VolumeDeviceClass();
                foreach (UsbEject.Volume device in volumeDeviceClass.Devices)
                {
                    // is this volume on USB disks?
                    if (!device.IsUsb)
                    {
                        continue;
                    }

                    // is this volume a logical disk?
                    if ((device.LogicalDrive == null) || (device.LogicalDrive.Length == 0))
                    {
                        continue;
                    }

                    device.Eject(true); // allow Windows to display any relevant UI
                }
                ShowStr = "U盘退出";
                notifyIcon.ShowBalloonTip(1000, "EC", "升级完毕\r\n可以拔出U盘", ToolTipIcon.Info);
                #endregion
            }
            catch (Exception ex)
            {
                ShowStr = ex.Message;
            }
            finally
            {
            }
        }