Ejemplo n.º 1
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!");
            }
        }
Ejemplo n.º 2
0
        private async void upgrade_task()
        {
            ModelInfo    model = (ModelInfo)cbbModels.SelectedItem;
            LanguageInfo lan   = (LanguageInfo)cbbLanguage.SelectedItem;

            load_manual($"{model.id}.{LanguageResources.Instance.CultureName.Substring(0, 2)}.html");

            try
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                upgrade_status = UPGRADE_STATUS.start;
                update_ui();

                USBDeviceInfo item    = (USBDeviceInfo)lstDevice.SelectedItems[0];
                bool          bFormat = false;
                if (cbxUpgradeFormat.IsChecked == true)
                {
                    await Task.Run(() => {
                        bFormat = format_device(item.DiskName, model.id, model.fileSystem, model.quickFormat, model.clusterSize);
                    });
                }

                // Check Drive size

                /*
                 * DriveInfo drive_info = new DriveInfo(item.DiskName);
                 * if (model.size != drive_info.TotalSize)
                 * {
                 *  Application.Current.Dispatcher.Invoke(() => {
                 *      prgbUpgrade.Value = 0;
                 *      prgbUpgradeText.Foreground = Brushes.Red;
                 *      prgbUpgradeText.Text = "Upgrade Fail: Invalid disk drive size! retry Format";
                 *  });
                 * }
                 */

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

                /*
                 * MessageBoxResult messageBoxResult = MessageBox.Show("Upgrade completed, do you want to safely eject your device?", "Remove device confirmation", System.Windows.MessageBoxButton.YesNo);
                 * if (messageBoxResult == MessageBoxResult.Yes)
                 * {
                 *  bool remove_safe = RemoveDriveTools.RemoveDrive(item.DiskName);
                 *  if (remove_safe)
                 *  {
                 *      MessageBox.Show("You can also disconnect the connected device.");
                 *      // dispatch_usbList();
                 *  }
                 * }
                 */
                if (stopWatch.IsRunning)
                {
                    stopWatch.Stop();
                }
                TimeSpan ts          = stopWatch.Elapsed;
                string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);

                Application.Current.Dispatcher.Invoke(() => {
                    prgbUpgrade.Value    = upgrade_count;
                    prgbUpgradeText.Text = $"Completed({elapsedTime})";
                    load_manual($"{model.id}.{LanguageResources.Instance.CultureName.Substring(0, 2)}.complete.html");
                });
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                Application.Current.Dispatcher.Invoke(() => {
                    prgbUpgrade.Value          = 0;
                    prgbUpgradeText.Foreground = Brushes.Red;
                    prgbUpgradeText.Text       = "Upgrade Fail:" + e.Message;
                });
            }
            finally
            {
                upgrade_status = UPGRADE_STATUS.end;
                update_ui();
            }
        }