예제 #1
0
        /// <summary>
        /// 增加设备,用于在设备插入后将其添加到列表和处理队列中
        /// </summary>
        private void AddUSBDevices()
        {
            var    drives    = DriveInfo.GetDrives();
            string deviceNum = "";

            foreach (var drive in drives)
            {
                if (drive.IsReady && drive.DriveType == DriveType.Removable &&
                    !DriveList.Exists(x => x.Name == drive.Name) && Directory.Exists(drive.Name + MainWindow.devicePath))
                {
                    try
                    {
                        deviceNum = drive.Name;
                        if (File.Exists(drive.Name + "Config.ini"))
                        {
                            string[] deviceInfo = File.ReadAllLines(drive.Name + "Config.ini", Encoding.Default);
                            if (deviceInfo.Length > 1 && deviceInfo[0] == "调车")
                            {
                                deviceNum = deviceInfo[1] + "号";
                            }
                        }
                        string[] files = Directory.GetFiles(drive.Name + MainWindow.devicePath, "YC?????_*.MP4", SearchOption.TopDirectoryOnly);
                        if (files.Length != 0)
                        {
                            deviceNum = System.IO.Path.GetFileName(files[files.GetUpperBound(0)]).Substring(6, 1) + "号";
                        }
                    }
                    catch
                    {
                        MessageBox.Show("部分U盘设备未连接好,请重新连接");
                    }

                    AddControl(deviceNum, out ComState comState, out Button button);
                    USBDevice usbDevice = new USBDevice(drive.Name, comState, button, drive.DriveType);
                    DriveList.Add(usbDevice);
                    CopyQueue.Enqueue(usbDevice);
                }
            }
            if (DriveList.Count == 0)
            {
                NoDriveState.Visibility = Visibility.Visible;
            }
        }