Ejemplo n.º 1
0
        /// <summary>
        ///     A multi-section check to ensure nothing prevents the download from beginning
        /// </summary>
        /// <param name="selectedDrive">USB Drive</param>
        /// <returns>true/false as Boolean depending on if Download is cancelled or not</returns>
        public static async Task <bool> CancelDownloadCheck(USBHelper.Drive selectedDrive)
        {
            // Set local variables to the values of application level variables
            string driveLetter  = AppMan.App.DriveLetter;
            string downloadPath = AppMan.App.DownloadPath;

            // Ensure drive letter is not used as download path
            if (!string.IsNullOrEmpty(driveLetter))
            {
                if (downloadPath.Contains(driveLetter))
                {
                    await Application.Current.Dispatcher.BeginInvoke(() => UIHelper.ShowErrorDialog(LM.GetValue("MessageBox.CancelDownloadIsDrive")));

                    return(true);
                }
            }

            // Optional Format
            if (string.IsNullOrWhiteSpace(selectedDrive?.Path) && driveLetter != null)
            {
                try
                {
                    if (Directory.EnumerateFileSystemEntries(driveLetter, "*", SearchOption.AllDirectories).Any())
                    {
                        if (await Application.Current.Dispatcher.Invoke(() => UIHelper.ShowDialog(string.Format(LM.GetValue("MessageBox.OptionalFormat"), driveLetter), LM.GetValue("String.Notice"), LM.GetValue("String.No"),
                                                                                                  LM.GetValue("String.Yes"))) == ContentDialogResult.Primary)
                        {
                            AppMan.App.SkipFormat = false;
                        }
                        else
                        {
                            AppMan.Logger.Info("Selected folder will not be cleared before being used");
                            AppMan.App.SkipFormat = true;
                        }
                    }
                    else
                    {
                        AppMan.App.SkipFormat = true;
                    }
                }
                catch (DirectoryNotFoundException e)
                {
                    await Application.Current.Dispatcher.BeginInvoke(() => UIHelper.ShowErrorDialog(e.GetFullMessage()));

                    return(true);
                }
                catch (IOException e)
                {
                    await Application.Current.Dispatcher.BeginInvoke(() => UIHelper.ShowErrorDialog(e.GetFullMessage()));

                    return(true);
                }
            }
            else
            {
                if (selectedDrive?.FileSystem == "exFAT" && selectedDrive?.PartitionType == "MBR" && selectedDrive?.VolumeName == "CYANLABS")
                {
                    if (await Application.Current.Dispatcher.Invoke(() => UIHelper.ShowDialog(string.Format(LM.GetValue("MessageBox.OptionalFormatUSB"), selectedDrive.Name, driveLetter), LM.GetValue("String.Notice"),
                                                                                              LM.GetValue("String.No"), LM.GetValue("String.Yes"))) == ContentDialogResult.Primary)
                    {
                        AppMan.App.SkipFormat = false;
                    }
                    else
                    {
                        AppMan.Logger.Info("USB Drive not formatted, using existing filesystem and files");
                        AppMan.App.SkipFormat = true;
                    }
                }
            }

            // Format USB Drive
            if (selectedDrive != null && !string.IsNullOrWhiteSpace(selectedDrive.Path) && !AppMan.App.SkipFormat)
            {
                if (await Application.Current.Dispatcher.Invoke(() => UIHelper.ShowWarningDialog(string.Format(LM.GetValue("MessageBox.CancelFormatUSB"), selectedDrive.Name, driveLetter), LM.GetValue("String.Warning") + "!",
                                                                                                 LM.GetValue("String.No"), LM.GetValue("String.Yes"))) != ContentDialogResult.Primary)
                {
                    return(true);
                }
            }

            if (selectedDrive != null && selectedDrive?.Name == LM.GetValue("Home.NoUSBDir"))
            {
                AppMan.Logger.Info("Using 'Select a Directory' instead of a USB Drive");
                AppMan.App.DownloadToFolder = true;
                if (string.IsNullOrEmpty(driveLetter))
                {
                    return(true);
                }

                if (Directory.EnumerateFiles(driveLetter).Any() && !AppMan.App.SkipFormat)
                {
                    if (await Application.Current.Dispatcher.Invoke(() => UIHelper.ShowWarningDialog(string.Format(LM.GetValue("MessageBox.CancelDeleteFiles"), driveLetter), LM.GetValue("String.Warning") + "!",
                                                                                                     LM.GetValue("String.No"), LM.GetValue("String.Yes"))) != ContentDialogResult.Primary)
                    {
                        return(true);
                    }
                }
            }
            else
            {
                AppMan.App.DownloadToFolder = false;
            }

            // If nothing above has returned true then download has not been cancelled and method will return false;
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     A multi-section check to ensure nothing prevents the download from beginning
        /// </summary>
        /// <param name="selectedDrive">USB Drive</param>
        /// <param name="allowDownloadonly">True if download only is allowed, false if USB must be used</param>
        /// <returns>true/false as Boolean depending on if Download is cancelled or not</returns>
        public static bool CancelDownloadCheck(USBHelper.Drive selectedDrive, bool allowDownloadonly = true)
        {
            // Set local variables to the values of application level variables
            string driveLetter  = ApplicationManager.Instance.DriveLetter;
            string downloadPath = ApplicationManager.Instance.DownloadPath;

            // No USB drive selected, download only?
            if (string.IsNullOrWhiteSpace(selectedDrive.Path) || selectedDrive.Name == LanguageManager.GetValue("Home.NoUSB"))
            {
                if (allowDownloadonly)
                {
                    if (ModernWpf.MessageBox.Show(LanguageManager.GetValue("MessageBox.CancelNoUSB"), "Syn3 Updater", MessageBoxButton.YesNo, MessageBoxImage.Warning) ==
                        MessageBoxResult.Yes)
                    {
                        ApplicationManager.Logger.Info("No usb has been selected, download only mode activated");
                        ApplicationManager.Instance.DownloadOnly = true;
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    ModernWpf.MessageBox.Show(LanguageManager.GetValue("MessageBox.CancelNoUSBForced"), "Syn3 Updater", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return(true);
                }
            }

            // Ensure drive letter is not used as download path
            if (!string.IsNullOrEmpty(driveLetter))
            {
                if (downloadPath.Contains(driveLetter))
                {
                    ModernWpf.MessageBox.Show(LanguageManager.GetValue("MessageBox.CancelDownloadIsDrive"), "Syn3 Updater", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return(true);
                }
            }


            // Optional Format
            if (!string.IsNullOrWhiteSpace(selectedDrive.Path) && selectedDrive.Name != LanguageManager.GetValue("Home.NoUSB") && ApplicationManager.Instance.DownloadOnly == false)
            {
                if (ModernWpf.MessageBox.Show(string.Format(LanguageManager.GetValue("MessageBox.OptionalFormatUSB"), selectedDrive.Name, driveLetter),
                                              "Syn3 Updater", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    ApplicationManager.Instance.SkipFormat = false;
                }
                else
                {
                    ApplicationManager.Logger.Info("USB Drive not formatted, using existing filesystem and files");
                    ApplicationManager.Instance.SkipFormat = true;
                }
            }

            // Format USB Drive
            if (!string.IsNullOrWhiteSpace(selectedDrive.Path) && ApplicationManager.Instance.DownloadOnly == false && ApplicationManager.Instance.SkipFormat == false)
            {
                if (ModernWpf.MessageBox.Show(string.Format(LanguageManager.GetValue("MessageBox.CancelFormatUSB"), selectedDrive.Name, driveLetter), "Syn3 Updater",
                                              MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes)
                {
                    ApplicationManager.Logger.Info("USB Drive will be formatted, using fresh filesystem");
                    return(true);
                }
            }

            // If nothing above has returned true then download has not been cancelled and method will return false;
            return(false);
        }