added import/export options to KeyManager

This commit is contained in:
WeeXnes 2023-06-08 00:28:34 +02:00
parent 3ef67556dd
commit 884e12f980
5 changed files with 71 additions and 5 deletions

View file

@ -8,7 +8,7 @@ namespace WeeXnes.Core
{ {
public class Information public class Information
{ {
public const string Version = "4.2.8"; public const string Version = "4.3.0";
public const string EncryptionHash = "8zf5#RdyQ]$4x4_"; public const string EncryptionHash = "8zf5#RdyQ]$4x4_";
public const string ApiUrl = "https://api.github.com/repos/weexnes/weexnessuite/releases/latest"; public const string ApiUrl = "https://api.github.com/repos/weexnes/weexnessuite/releases/latest";
} }

View file

@ -1,4 +1,11 @@
using System; using System;
using System.Windows.Shapes;
using WeeXnes.Core;
using System.IO;
using System.Net;
using Wpf.Ui.Controls;
using Microsoft.Win32;
using Path = System.Windows.Shapes.Path;
namespace WeeXnes.Views.KeyManager namespace WeeXnes.Views.KeyManager
{ {
@ -18,5 +25,47 @@ namespace WeeXnes.Views.KeyManager
{ {
return this.Name; return this.Name;
} }
public void Export()
{
string filePath = Global.AppDataPathKEY.Value + "\\" + this.Filename;
Console.WriteLine(filePath);
SaveFileDialog dialog = new SaveFileDialog()
{
Filter = "WXFiles (*.wx)|*.wx",
Title = "Export KeyFile"
};
if (dialog.ShowDialog() == true)
{
File.Copy(filePath, dialog.FileName, true);
Console.WriteLine("Exported to: " + dialog.FileName);
}
}
public static void Import()
{
OpenFileDialog dialog = new OpenFileDialog()
{
Filter = "WXFiles (*.wx)|*.wx"
};
if (dialog.ShowDialog() == true)
{
WXFile wxFile = new WXFile(dialog.FileName);
KeyItem newItem = new KeyItem(
wxFile.GetName(),
EncryptionLib.EncryptorLibary.decrypt(
Information.EncryptionHash,
wxFile.GetValue()
)
);
newItem.Filename = System.IO.Path.GetFileName(dialog.FileName);
WXFile newWxFile = new WXFile(Global.AppDataPathKEY.Value + "\\" + newItem.Filename);
WXFile.Methods.WriteFile(newItem, newWxFile);
KeyManagerView.Data.KeyItemsList.Add(newItem);
Console.WriteLine("Imported: " + dialog.FileName);
}
}
} }
} }

View file

@ -21,7 +21,13 @@
<ContextMenu> <ContextMenu>
<MenuItem Header="Remove" <MenuItem Header="Remove"
Name="btn_context_remove" Name="btn_context_remove"
Click="MenuItem_OnClick"/> Click="ContextMenu_Remove"/>
<MenuItem Header="Export"
Name="btn_context_export"
Click="ContextMenu_Export"/>
<MenuItem Header="Import"
Name="btn_context_import"
Click="ContextMenu_Import"/>
</ContextMenu> </ContextMenu>
</ListView.ContextMenu> </ListView.ContextMenu>

View file

@ -34,6 +34,7 @@ namespace WeeXnes.Views.KeyManager
if(String.IsNullOrEmpty(tb_keyvalue.Text)) if(String.IsNullOrEmpty(tb_keyvalue.Text))
return; return;
try try
{ {
KeyItem newKey = new KeyItem( KeyItem newKey = new KeyItem(
@ -43,12 +44,13 @@ namespace WeeXnes.Views.KeyManager
WXFile wxFile = new WXFile( WXFile wxFile = new WXFile(
Global.AppDataPathKEY.Value + "\\" + newKey.Filename); Global.AppDataPathKEY.Value + "\\" + newKey.Filename);
WXFile.Methods.WriteFile(newKey, wxFile); WXFile.Methods.WriteFile(newKey, wxFile);
Data.KeyItemsList.Add(newKey); KeyManagerView.Data.KeyItemsList.Add(newKey);
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex.Message); Console.WriteLine(ex.Message);
} }
ClearInputs(); ClearInputs();
} }
@ -74,10 +76,19 @@ namespace WeeXnes.Views.KeyManager
} }
} }
private void MenuItem_OnClick(object sender, RoutedEventArgs e) private void ContextMenu_Remove(object sender, RoutedEventArgs e)
{ {
DeleteItem((KeyItem)ListviewKeys.SelectedItem); DeleteItem((KeyItem)ListviewKeys.SelectedItem);
} }
private void ContextMenu_Import(object sender, RoutedEventArgs e)
{
KeyItem.Import();
}
private void ContextMenu_Export(object sender, RoutedEventArgs e)
{
var item = (KeyItem)ListviewKeys.SelectedItem;
item.Export();
}
private void KeyValue_OnLoaded(object sender, RoutedEventArgs e) private void KeyValue_OnLoaded(object sender, RoutedEventArgs e)
{ {

View file

@ -4,7 +4,7 @@
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<Version>4.2.8</Version> <Version>4.3.0</Version>
<ProjectGuid>{4B33CEE7-C74D-43B9-B99A-8B273D5195BC}</ProjectGuid> <ProjectGuid>{4B33CEE7-C74D-43B9-B99A-8B273D5195BC}</ProjectGuid>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<RootNamespace>WeeXnes</RootNamespace> <RootNamespace>WeeXnes</RootNamespace>