private void saveFunc() { isChanged = false; saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Текстовый документ (*.notepad)|*.notepad"; if (saveFileDialog.ShowDialog() == true) { txt = new TextRange(mainRichTextBox.Document.ContentStart, mainRichTextBox.Document.ContentEnd).Text; if (password != "") { doc = new TextDoc(txt, kegel, font, true, password); using (FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.OpenOrCreate)) { formatter.Serialize(fs, doc); } } else { doc = new TextDoc(txt, kegel, font, false); using (FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.OpenOrCreate)) { formatter.Serialize(fs, doc); } } } }
private void openButton_Click(object sender, RoutedEventArgs e) // откыть { openFileDialog = new OpenFileDialog(); // // dialog.Filter = "Text documents (*.txt)|*.txt|All files (*.*)|*.*"; // шаблон записи нескольких расширений openFileDialog.Filter = "Текстовый документ (*.notepad)|*.notepad"; // расширения файла openFileDialog.FilterIndex = 0; // индекс выбранного варианта расширения по умолчанию resultOpenDialog = openFileDialog.ShowDialog(); if (resultOpenDialog == true) { // Open document filename = openFileDialog.FileName; // установка переменной значения пути // mainTextBox.Text = filename; // проверка верности пути using (FileStream fs = new FileStream(openFileDialog.FileName, FileMode.OpenOrCreate)) { doc = (TextDoc)formatter.Deserialize(fs); if (doc.isEncrypted) { while (true) { try { passwordWindow = new Window1(); passwordWindow.ShowDialog(); password = passwordWindow.Password; isEncrypted = true; } catch { // password = ""; isEncrypted = false; } if (isEncrypted) { if (password == doc.password) { //mainTextBox.Text = doc.text; mainRichTextBox.Document.Blocks.Clear(); mainRichTextBox.Document.Blocks.Add(new Paragraph(new Run(doc.text))); mainRichTextBox.FontSize = doc.kegel; switch (doc.font) { case 1: mainRichTextBox.FontFamily = new FontFamily("Segoe UI"); firstFont.IsChecked = true; break; case 2: mainRichTextBox.FontFamily = new FontFamily("Ink Free"); secondFont.IsChecked = true; break; case 3: mainRichTextBox.FontFamily = new FontFamily("Source Code Pro Light"); thirdFont.IsChecked = true; break; } isEncryptedLabel.Content = "зашифрован"; encryptButton.Content = "дешивровать"; break; } else { if (passwordWindow.IsCanceled) { break; } else { MessageBox.Show("Введен неверный пароль!"); } } } } } else { isEncryptedLabel.Content = "не зашифрован"; encryptButton.Content = "шивровать"; mainRichTextBox.Document.Blocks.Clear(); mainRichTextBox.Document.Blocks.Add(new Paragraph(new Run(doc.text))); mainRichTextBox.FontSize = doc.kegel; switch (doc.font) { case 1: mainRichTextBox.FontFamily = new FontFamily("Segoe UI"); break; case 2: mainRichTextBox.FontFamily = new FontFamily("Ink Free"); break; case 3: mainRichTextBox.FontFamily = new FontFamily("Source Code Pro Light"); break; } } } } isChanged = false; }