예제 #1
0
        private void btnCheck_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckInput())
            {
                return;
            }

            LoadingWindow.TryShowLoadingWindow(Properties.Strings.ProgressMessageCheckingConnection, new Action(() =>
            {
                // try connect
                Exception ex;
                if (!this.networkDrive.CheckConnection(out ex))
                {
                    log.Error("Connection check of \"" + this.networkDrive.LocalDriveLetter + "\" to \"" + this.networkDrive.ExpandedRemoteAddress + "\" with user \"" + this.networkDrive.Username + "\" failed: " + ex.Message + " (" + ex.GetType().Name + ")", ex);
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        MessageBox.Show(LoadingWindow.GetStaticLoadingWindow(), string.Format(Properties.Strings.MessageCouldNotConnect, this.networkDrive.LocalDriveLetter, Helper.GetUserMessage(ex)), Properties.Strings.TitleCheckConnection, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }));
                }
                else
                {
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        MessageBox.Show(LoadingWindow.GetStaticLoadingWindow(), Properties.Strings.MessageConnectionSuccessfull, Properties.Strings.TitleCheckConnection, MessageBoxButton.OK, MessageBoxImage.Information);
                    }));
                }
            }), this);
        }
예제 #2
0
        private bool CheckNetworkDrive(NetworkDrive drive)
        {
            bool result = false;

            LoadingWindow.TryShowLoadingWindow(Properties.Strings.ProgressMessageCheckingConnection, new Action(() =>
            {
                Exception ex;
                result = drive.CheckConnection(out ex);
                if (!result)
                {
                    log.Error("Connection check of \"" + drive.LocalDriveLetter + "\" to \"" + drive.ExpandedRemoteAddress + "\" with user \"" + drive.Username + "\" failed: " + ex.Message + " (" + ex.GetType().Name + ")", ex);
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        MessageBox.Show(LoadingWindow.GetStaticLoadingWindow(), string.Format(Properties.Strings.MessageCouldNotConnect, drive.LocalDriveLetter, Helper.GetUserMessage(ex)), Properties.Strings.TitleCheckConnection, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }));
                }
            }));

            return(result);
        }
예제 #3
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (cbxUseEncryption.IsChecked == true)
            {
                if (tbxEncryptionPassword.Password != tbxEncryptionPasswordRepeat.Password)
                {
                    MessageBox.Show(Strings.MessagePasswordsDoNotMatch, this.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }

                if (string.IsNullOrEmpty(tbxEncryptionPassword.Password))
                {
                    MessageBox.Show(Strings.ExportWindowNoPasswordMessage, this.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
            }

            if (cbxStorePassword.IsChecked == true && cbxUseEncryption.IsChecked != true)
            {
                MessageBox.Show(Strings.ExportWindowPasswordWithoutEncryptionMessage, this.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            SaveFileDialog dialog = new SaveFileDialog();

            dialog.DefaultExt = ".drives";
            dialog.Title      = this.Title;
            dialog.Filter     = "*.drives|*.drives";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                bool   storeUsername = (cbxStoreUsername.IsChecked == true);
                bool   storePassword = (cbxStorePassword.IsChecked == true);
                bool   useEncryption = (cbxUseEncryption.IsChecked == true);
                string password      = tbxEncryptionPassword.Password;

                bool close = false;
                LoadingWindow.TryShowLoadingWindow(Strings.MainWindowExportProgressMessage, new Action(() =>
                {
                    try
                    {
                        JArray drivesList = new JArray();
                        foreach (NetworkDrive drive in this.exportDrives)
                        {
                            JObject obj = drive.ExportToJson();

                            if (!storeUsername)
                            {
                                // remove credentials
                                obj["Username"] = null;
                                obj["Password"] = null;
                            }
                            else if (storePassword)
                            {
                                // write unencrypted password to file
                                obj["Password"] = drive.GetPassword();
                            }
                            else
                            {
                                obj["Password"] = null;
                            }

                            if (useEncryption)
                            {
                                foreach (KeyValuePair <string, JToken> kvp in obj)
                                {
                                    if (kvp.Value.Type == JTokenType.String)
                                    {
                                        obj[kvp.Key] = Helper.EncryptValue(kvp.Value.Value <string>(), password);
                                    }
                                }
                            }

                            drivesList.Add(obj);
                        }

                        JObject exportObj = new JObject();
                        exportObj.Add("IsEncrypted", useEncryption);
                        if (useEncryption)
                        {
                            // save salted checksum of the password to check for the correct password
                            exportObj.Add("Check", Helper.GeneratePasswordStore(password));
                        }
                        exportObj.Add("Drives", drivesList);

                        log.Info("Export " + drivesList.Count + " drives to \"" + dialog.FileName + "\"");
                        File.WriteAllText(dialog.FileName, exportObj.ToString(), Encoding.UTF8);

                        close = true;
                    }
                    catch (Exception ex)
                    {
                        log.Error("Unable to export drives: " + ex.Message + " (" + ex.GetType().Name + ")", ex);
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            MessageBox.Show(LoadingWindow.GetStaticLoadingWindow(), string.Format(Strings.MainWindowExportErrorMessage, ex.GetType().Name, ex.Message, ex.StackTrace), Strings.TitleCheckConnection, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        }));
                    }
                }));

                if (close)
                {
                    this.DialogResult = true;
                    Close();
                }
            }
        }