示例#1
0
        private void Initialize()
        {
            download_status = DOWNLOAD_STATUS.ini;
            device_detected = false;
            upgrade_status  = UPGRADE_STATUS.ini;

            // DOWNLOAD_PATH = $@"{Directory.GetCurrentDirectory()}\_download";
            DOWNLOAD_PATH = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\mycaddy\_download";
            if (!Directory.Exists(DOWNLOAD_PATH))
            {
                Directory.CreateDirectory(DOWNLOAD_PATH);
            }
            // Load default manual
            download_manual();

            // USB Devices init
            usbDetector = new USBDetector();
            usbDetector.StartWatching();
            usbDetector.VolumeChanged += UsbDetector_VolumeChanged;
            usbList = new ObservableCollection <USBDeviceInfo>();
            dispatch_usbList();

            // Model List
            modelList = new ObservableCollection <ModelInfo>();
            dispatch_modelList();

            // Language List
            languageList = new ObservableCollection <LanguageInfo>();

            update_ui();
        }
示例#2
0
        private void Initialize()
        {
            AssemblyName assembly = Assembly.GetExecutingAssembly().GetName();

            txtToolBar.Text = "MYCADDY DWONLOADER version:" + assembly.Version.ToString();

            download_status = DOWNLOAD_STATUS.ini;
            device_detected = false;
            upgrade_status  = UPGRADE_STATUS.ini;

            // DOWNLOAD_PATH = $@"{Directory.GetCurrentDirectory()}\_download";
            DOWNLOAD_PATH = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\mycaddy\_download";
            if (!Directory.Exists(DOWNLOAD_PATH))
            {
                Directory.CreateDirectory(DOWNLOAD_PATH);
            }
            // Load default model and manual
            download_config();

            // USB Devices init
            usbDetector = new USBDetector();
            usbDetector.StartWatching();
            usbDetector.VolumeChanged += UsbDetector_VolumeChanged;
            usbList = new ObservableCollection <USBDeviceInfo>();
            dispatch_usbList();

            // Model List
            modelList = new ObservableCollection <ModelInfo>();
            dispatch_modelList();

            // Language List
            languageList = new ObservableCollection <LanguageInfo>();

            update_ui();
        }
示例#3
0
        private void CbbModels_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            download_status = DOWNLOAD_STATUS.ini;
            update_ui();

            ModelInfo item = (ModelInfo)(sender as ComboBox).SelectedItem;

            dispatch_languageList(item);

            load_manual($"{item.id}.ko.html");
        }
示例#4
0
        private void CbbModels_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            download_status = DOWNLOAD_STATUS.ini;
            update_ui();

            ModelInfo item = (ModelInfo)(sender as ComboBox).SelectedItem;

            if (item != null)
            {
                dispatch_languageList(item);

                cbxUpgradeFormat.IsChecked = item.formatDefault;

                load_manual($"{item.id}.{LanguageResources.Instance.CultureName.Substring(0, 2)}.html");
            }
        }
示例#5
0
        private void download_sftp(string remote_path, string local_path)
        {
            // https://stackoverflow.com/questions/43555982/displaying-progress-of-file-upload-in-a-progressbar-with-ssh-net
            // https://stackoverflow.com/questions/44442714/displaying-progress-of-file-download-in-a-progressbar-with-ssh-net

            download_status = DOWNLOAD_STATUS.start;
            update_ui();

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();


            SftpClient sftp = new SftpClient(Constants.SFTP_ADDR, Constants.SFTP_ID, Constants.SFTP_PWD);

            try
            {
                using (var stream = new FileStream(local_path, FileMode.Create))
                    using (sftp)
                    {
                        if (!sftp.IsConnected)
                        {
                            sftp.Connect();
                        }
                        SftpFileAttributes attributes = sftp.GetAttributes(remote_path);

                        // Set progress bar maximum on foreground thread
                        Application.Current.Dispatcher.Invoke(() => {
                            var file_size = ByteSize.FromBytes((double)attributes.Size);

                            prgbDownload.Value    = 0;
                            prgbDownload.Maximum  = (int)file_size.Bytes;
                            prgbDownloadText.Text = string.Format("{0} / {1:F1} MB", 0, file_size.MegaBytes);
                        });
                        sftp.DownloadFile(remote_path, stream, download_sftp_progress);
                        extract_zipfile(local_path);

                        download_status = DOWNLOAD_STATUS.end;
                        update_ui();
                    }
            }
            catch (Exception e)
            {
                download_status = DOWNLOAD_STATUS.ini;
                update_ui();
                MessageBox.Show(e.Message);
            }

            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);

            if (download_status == DOWNLOAD_STATUS.end)
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    prgbDownloadText.Text += "(" + elapsedTime + ")";
                });
            }

            sftp.Dispose();
        }
示例#6
0
 private void CbbLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     download_status = DOWNLOAD_STATUS.ini;
     update_ui();
 }