file editor update

This commit is contained in:
WeeXnes 2024-06-13 12:46:11 +02:00
parent 0d26606d5b
commit 5cb3c52ba7
2 changed files with 35 additions and 6 deletions

View file

@ -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_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_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> </Grid>
<RichTextBox Grid.Row="1"> <RichTextBox Name="rtb_FileEditor" Grid.Row="1">
<RichTextBox.Resources> <RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}"> <Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0"/> <Setter Property="Margin" Value="0"/>

View file

@ -1,13 +1,18 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Forms; using System.Windows.Forms;
using EncryptionLib;
using WeeXnes.Core;
namespace WeeXnes.Views.EncryptedTextEditor; namespace WeeXnes.Views.EncryptedTextEditor;
public partial class TextEditorView : Page public partial class TextEditorView : Page
{ {
public string currentFilePath { get; set; } = null;
public TextEditorView() public TextEditorView()
{ {
InitializeComponent(); InitializeComponent();
@ -26,18 +31,42 @@ public partial class TextEditorView : Page
if (openFileDialog.ShowDialog() == DialogResult.OK) 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) 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);
}
}
} }
} }