Example #1
0
        private void USB_Device_Off(bool justTurnGpioOff = false)
        {
            Notify("Disconnecting USB Disk");
            _usbDeviceConnected = false;

            if (!justTurnGpioOff)
            {
                System.Threading.Thread.Sleep(2000);
                // Eject the usb device first
                if (!RemoveDriveTools.RemoveDrive(USBDiskLetter))
                {
                    MessageBox.Show(this, string.Format("Cannot eject drive {0}", USBDiskLetter), "Eject Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            _nusbio[gpio].High();
            Notify("USB Disk Off");
        }
Example #2
0
        private async void upgrade_process()
        {
            if (lstDevice.Items.Count == 1)
            {
                lstDevice.SelectAll();
            }

            if (lstDevice.SelectedItem != null)
            {
                upgrade_status = UPGRADE_STATUS.start;
                update_ui();

                bool bFormat = false;

                USBDeviceInfo item = (USBDeviceInfo)lstDevice.SelectedItems[0];
                if (cbxUpgradeFormat.IsChecked == true)
                {
                    await Task.Run(() => {
                        bFormat = format_device(item.DiskName);
                    });
                }
                else
                {
                    bFormat = true;
                }

                if (bFormat == true)
                {
                    if (cbbModels.SelectedItem != null && cbbLanguage.SelectedItem != null)
                    {
                        ModelInfo    model = (ModelInfo)cbbModels.SelectedItem;
                        LanguageInfo lan   = (LanguageInfo)cbbLanguage.SelectedItem;

                        try
                        {
                            await Task.Run(() => {
                                upgrade_device(item.DiskName, model, lan);
                            });

                            MessageBoxResult messageBoxResult = MessageBox.Show("업그레이드가 완료되었습니다, 안전하게 장치를 꺼내시겠습니까?", "Remove device confirmation", System.Windows.MessageBoxButton.YesNo);
                            if (messageBoxResult == MessageBoxResult.Yes)
                            {
                                bool remove_safe = RemoveDriveTools.RemoveDrive(item.DiskName);
                                if (remove_safe)
                                {
                                    MessageBox.Show("연결된 장치를 분리하셔도 됩니다.");
                                    // dispatch_usbList();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Select Model and Langauge");
                    }
                }

                upgrade_status = UPGRADE_STATUS.end;
                update_ui();
            }
            else
            {
                MessageBox.Show("Select device!");
            }
        }
Example #3
0
 private void copyBtn_Click(object sender, EventArgs e)
 {
     toolStatus.Text = "Working";
     this.Cursor     = Cursors.WaitCursor;
     foreach (DriveInfo usb in usbs)
     {
         if (usb.IsReady && usb.DriveType == DriveType.Removable)
         {
             bool error = false;
             if (changeName.Checked)
             {
                 usb.VolumeLabel = volumeNameTxt.Text;
             }
             if (format.Checked)
             {
                 bool formatted = false;
                 int  i         = 0;
                 while (!formatted)
                 {
                     i++;
                     if (i > tries.Value)
                     {
                         error = true;
                         break;
                     }
                     Enum.TryParse(formatFS.SelectedValue.ToString(), out FileSystem fs);
                     formatted = FormatDriveTools.FormatDrive(usb, fs, volumeNameTxt.Text);
                 }
                 if (error)
                 {
                     log.AppendText("Failed to format " + usb.Name + "\n");
                 }
                 else
                 {
                     log.AppendText(usb.Name + "has been formatted as " + formatFS.SelectedValue + "\n");
                 }
             }
             if (!error)
             {
                 foreach (ListViewItem file in files.Items)
                 {
                     FileInfo fileInfo = new FileInfo(file.Text);
                     if (fileInfo.Exists)
                     {
                         bool same = false;
                         int  i    = 0;
                         while (!same)
                         {
                             i++;
                             if (i > tries.Value)
                             {
                                 error = true;
                                 break;
                             }
                             File.Copy(fileInfo.FullName, usb.RootDirectory + fileInfo.Name, true);
                             Console.WriteLine("COPIED");
                             same = CheckFiles(fileInfo.FullName, usb.RootDirectory + fileInfo.Name);
                         }
                         if (error)
                         {
                             log.AppendText("Failed to copy " + fileInfo.Name + " to  drive " + usb.Name + "\n");
                         }
                         else
                         {
                             log.AppendText(fileInfo.Name + " has been copied to drive " + usb.Name + "\n");
                         }
                     }
                 }
             }
             if (eject.Checked && !error)
             {
                 RemoveDriveTools.RemoveDrive(usb.Name.Replace("\\", ""));
             }
         }
     }
     toolStatus.Text = "Ready";
     this.Cursor     = Cursors.Arrow;
 }