file editor update
This commit is contained in:
parent
0d26606d5b
commit
5cb3c52ba7
2 changed files with 35 additions and 6 deletions
|
@ -21,9 +21,9 @@
|
|||
|
||||
<Button Name="btn_openFile" Click="Btn_openFile_OnClick" Grid.Column="0" Content="Open File" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5"/>
|
||||
<Button Name="btn_saveFile" Click="Btn_saveFile_OnClick" Grid.Column="1" Content="Save" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5"/>
|
||||
<Button Name="btn_saveFileAs" Click="flkpw" Grid.Column="2" Content="Save As" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5"/>
|
||||
<Button Name="btn_saveFileAs" Click="Btn_saveFileAs_OnClick" Grid.Column="2" Content="Save As" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5"/>
|
||||
</Grid>
|
||||
<RichTextBox Grid.Row="1">
|
||||
<RichTextBox Name="rtb_FileEditor" Grid.Row="1">
|
||||
<RichTextBox.Resources>
|
||||
<Style TargetType="{x:Type Paragraph}">
|
||||
<Setter Property="Margin" Value="0"/>
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Forms;
|
||||
using EncryptionLib;
|
||||
using WeeXnes.Core;
|
||||
|
||||
namespace WeeXnes.Views.EncryptedTextEditor;
|
||||
|
||||
public partial class TextEditorView : Page
|
||||
{
|
||||
public string currentFilePath { get; set; } = null;
|
||||
public TextEditorView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
@ -26,18 +31,42 @@ public partial class TextEditorView : Page
|
|||
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
|
||||
this.currentFilePath = openFileDialog.FileName;
|
||||
string[] FileContent = File.ReadAllLines(openFileDialog.FileName);
|
||||
string[] decryptedContent = EncryptorLibary.decryptArray(Information.EncryptionHash, FileContent);
|
||||
rtb_FileEditor.Document.Blocks.Clear();
|
||||
foreach (string line in decryptedContent)
|
||||
{
|
||||
rtb_FileEditor.Document.Blocks.Add(new Paragraph(new Run(line)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Btn_saveFile_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
if(this.currentFilePath == null)
|
||||
return;
|
||||
}
|
||||
|
||||
private void flkpw(object sender, RoutedEventArgs e)
|
||||
private void Btn_saveFileAs_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
|
||||
{
|
||||
this.currentFilePath = saveFileDialog.FileName;
|
||||
saveFileDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
saveFileDialog.Filter = "WXN Text Files (*.wtf)|*.wtf";
|
||||
saveFileDialog.RestoreDirectory = true ;
|
||||
|
||||
if(saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
TextRange textRange = new TextRange(rtb_FileEditor.Document.ContentStart, rtb_FileEditor.Document.ContentEnd);
|
||||
string plainText = textRange.Text;
|
||||
string[] lines = plainText.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
|
||||
string[] encryptedContent =
|
||||
EncryptionLib.EncryptorLibary.encryptArray(Information.EncryptionHash, lines);
|
||||
File.WriteAllLines(saveFileDialog.FileName, encryptedContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue