added import/export to discord rpc + fixes

This commit is contained in:
WeeXnes 2023-06-08 16:45:48 +02:00
parent 884e12f980
commit 79dcc39826
8 changed files with 220 additions and 17 deletions

View file

@ -44,7 +44,7 @@ namespace WeeXnes
}
catch (Exception ex)
{
Console.WriteLine(ex);
WeeXnes.Core.CustomConsole.Error(ex.ToString());
}
}
}
@ -101,11 +101,11 @@ namespace WeeXnes
{
Game newGame = Game.Methods.GameFromIni(new INIFile(file.FullName));
DiscordRPCView.Data.Games.Add(newGame);
Console.WriteLine(file.Name + " loaded");
WeeXnes.Core.CustomConsole.WriteLine(file.Name + " loaded");
}
catch (Exception ex)
{
Console.WriteLine(file.Name + ": " + ex.Message);
WeeXnes.Core.CustomConsole.Error(file.Name + ": " + ex.Message);
MessageBox.Show(file.Name + ": " + ex.Message);
}
}
@ -127,12 +127,12 @@ namespace WeeXnes
);
newItem.Filename = file.Name;
KeyManagerView.Data.KeyItemsList.Add(newItem);
Console.WriteLine(file.Name + " loaded");
WeeXnes.Core.CustomConsole.WriteLine(file.Name + " loaded");
}
catch (Exception ex)
{
Console.WriteLine(file.Name + ": " + ex.Message);
WeeXnes.Core.CustomConsole.Error(file.Name + ": " + ex.Message);
}
}
}

View file

@ -0,0 +1,130 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using VanillaConsole = System.Console;
namespace WeeXnes.Core
{
public class CustomConsole
{
public static class Data
{
public static class Colors
{
public static bool colored_output = true;
public static ConsoleColor int_color = ConsoleColor.Blue;
public static ConsoleColor double_color = ConsoleColor.Cyan;
public static ConsoleColor float_color = ConsoleColor.DarkCyan;
}
public static class Formatting
{
public static string success_char = "✓";
public static string warning_char = "⌬";
public static string info_char = "◈";
public static string error_char = "☓";
public static string writeline_char = "•";
}
}
private static void ConfiguredWriteline(
string text,
ConsoleColor color,
ConsoleColor foregroundColor = ConsoleColor.White)
{
VanillaConsole.OutputEncoding = Encoding.UTF8;
ConsoleColor prevColor = VanillaConsole.BackgroundColor;
ConsoleColor prevForeColor = VanillaConsole.ForegroundColor;
if (Data.Colors.colored_output)
{
VanillaConsole.BackgroundColor = color;
VanillaConsole.ForegroundColor = foregroundColor;
}
VanillaConsole.WriteLine(text + " ");
if (Data.Colors.colored_output)
{
VanillaConsole.BackgroundColor = prevColor;
VanillaConsole.ForegroundColor = prevForeColor;
}
}
public static void WriteLine(string text,
[CallerLineNumber] int lineNumber = 0,
[CallerMemberName] string caller = null)
{
ConfiguredWriteline(" " + Data.Formatting.writeline_char + " (" + lineNumber + "|" + caller + ") " + text,VanillaConsole.BackgroundColor, ConsoleColor.White);
}
public static void WriteLine(float text,
[CallerLineNumber] int lineNumber = 0,
[CallerMemberName] string caller = null)
{
ConfiguredWriteline(" " + Data.Formatting.writeline_char + " (" + lineNumber + "|" + caller + ") " + text,Data.Colors.float_color, ConsoleColor.White);
}
public static void WriteLine(double text,
[CallerLineNumber] int lineNumber = 0,
[CallerMemberName] string caller = null)
{
ConfiguredWriteline(" " + Data.Formatting.writeline_char + " (" + lineNumber + "|" + caller + ") " + text,Data.Colors.double_color, ConsoleColor.White);
}
public static void WriteLine(int text,
[CallerLineNumber] int lineNumber = 0,
[CallerMemberName] string caller = null)
{
ConfiguredWriteline(" " + Data.Formatting.writeline_char + " (" + lineNumber + "|" + caller + ") " + text,Data.Colors.int_color, ConsoleColor.White);
}
public static void Success(string text,
[CallerLineNumber] int lineNumber = 0,
[CallerMemberName] string caller = null)
{
ConfiguredWriteline(" " + Data.Formatting.success_char + " (" + lineNumber + "|" + caller + ") " + text, ConsoleColor.Green,
ConsoleColor.Black);
}
public static void Info(string text,
[CallerLineNumber] int lineNumber = 0,
[CallerMemberName] string caller = null)
{
ConfiguredWriteline(" " + Data.Formatting.info_char + " (" + lineNumber + "|" + caller + ") " + text, ConsoleColor.Blue,
ConsoleColor.Black);
}
public static void Error(string text,
[CallerLineNumber] int lineNumber = 0,
[CallerMemberName] string caller = null)
{
ConfiguredWriteline(" " + Data.Formatting.error_char + " (" + lineNumber + "|" + caller + ") " + text, ConsoleColor.DarkRed,
ConsoleColor.Black);
}
public static void Warning(string text,
[CallerLineNumber] int lineNumber = 0,
[CallerMemberName] string caller = null)
{
ConfiguredWriteline(" " + Data.Formatting.warning_char + " (" + lineNumber + "|" + caller + ") " + text, ConsoleColor.DarkYellow,
ConsoleColor.Black);
}
public static void WriteLine<T>(List<T> List, bool verbose = true)
{
ConfiguredWriteline("List contains " + typeof(T) + "(" + List.Count + ")", ConsoleColor.DarkMagenta,
ConsoleColor.Black);
if (!verbose)
return;
for (int i = 0; i < List.Count; i++)
{
if (i % 2 == 0)
{
ConfiguredWriteline("(" + i + "): " + List[i], ConsoleColor.DarkGray);
}
else
{
ConfiguredWriteline("(" + i + "): " + List[i], ConsoleColor.Black);
}
}
}
}
}

View file

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

View file

@ -24,11 +24,17 @@
<ContextMenu>
<MenuItem Header="Edit"
Name="ButtonContextEdit"
Click="ContextEdit_OnClick"/>
Click="ContextMenu_Edit"/>
<MenuItem Header="Export"
Name="ButtonContextExport"
Click="ContextMenu_Export"/>
<MenuItem Header="Import"
Name="ButtonContextImport"
Click="ContextMenu_Import"/>
<Separator />
<MenuItem Header="Remove"
Name="ButtonContextRemove"
Click="ContextRemove_OnClick"/>
Click="ContextMenu_Remove"/>
</ContextMenu>
</ListBox.ContextMenu>
</ListBox>

View file

@ -4,7 +4,10 @@ using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Win32;
using Nocksoft.IO.ConfigFiles;
using WeeXnes.Core;
using CConsole = WeeXnes.Core.CustomConsole;
namespace WeeXnes.Views.DiscordRPC
{
@ -42,14 +45,66 @@ namespace WeeXnes.Views.DiscordRPC
Data.SelectedItem = (Game)listBox.SelectedItem;
}
private void ContextEdit_OnClick(object sender, RoutedEventArgs e)
private void ContextMenu_Edit(object sender, RoutedEventArgs e)
{
if(Data.SelectedItem == null)
return;
NavigationService.Navigate(new Uri("/Views/DiscordRPC/EditRPCView.xaml",UriKind.Relative));
}
private void ContextMenu_Export(object sender, RoutedEventArgs e)
{
Game selectedCache = Data.SelectedItem;
if(selectedCache == null)
return;
string filepath = Global.AppDataPathRPC.Value + "\\" + selectedCache.UUID + ".rpc";
private void ContextRemove_OnClick(object sender, RoutedEventArgs e)
SaveFileDialog dialog = new SaveFileDialog()
{
FileName = selectedCache.UUID,
Filter = "RPC File (*.rpc)|*.rpc",
Title = "Export RPC File"
};
if (dialog.ShowDialog() == true)
{
File.Copy(filepath, dialog.FileName, true);
CustomConsole.WriteLine("Exported to: " + dialog.FileName);
}
}
private void ContextMenu_Import(object sender, RoutedEventArgs e)
{
Game selectedCache = Data.SelectedItem;
if(selectedCache == null)
return;
OpenFileDialog dialog = new OpenFileDialog()
{
Filter = "RPC File (*.rpc)|*.rpc",
Title = "Import RPC File"
};
if (dialog.ShowDialog() == true)
{
Game newGame = Game.Methods.GameFromIni(new INIFile(dialog.FileName));
if (!File.Exists(Global.AppDataPathRPC.Value + "\\" + newGame.UUID + ".rpc"))
{
File.Copy(dialog.FileName, Global.AppDataPathRPC.Value + "\\" + newGame.UUID + ".rpc", true);
DiscordRPCView.Data.Games.Add(newGame);
CustomConsole.WriteLine("Imported: " + dialog.FileName);
}
else
{
CustomConsole.Error("not imported: " + dialog.FileName);
}
}
}
private void ContextMenu_Remove(object sender, RoutedEventArgs e)
{
Game selectedCache = Data.SelectedItem;
if(selectedCache == null)

View file

@ -6,6 +6,7 @@ using System.Net;
using Wpf.Ui.Controls;
using Microsoft.Win32;
using Path = System.Windows.Shapes.Path;
using Console = WeeXnes.Core.CustomConsole;
namespace WeeXnes.Views.KeyManager
{
@ -34,6 +35,7 @@ namespace WeeXnes.Views.KeyManager
SaveFileDialog dialog = new SaveFileDialog()
{
FileName = this.Filename,
Filter = "WXFiles (*.wx)|*.wx",
Title = "Export KeyFile"
};
@ -48,10 +50,12 @@ namespace WeeXnes.Views.KeyManager
{
OpenFileDialog dialog = new OpenFileDialog()
{
Filter = "WXFiles (*.wx)|*.wx"
Filter = "WXFiles (*.wx)|*.wx",
Title = "Import KeyFile"
};
if (dialog.ShowDialog() == true)
{
string filename = System.IO.Path.GetFileName(dialog.FileName);
WXFile wxFile = new WXFile(dialog.FileName);
KeyItem newItem = new KeyItem(
wxFile.GetName(),
@ -60,12 +64,18 @@ namespace WeeXnes.Views.KeyManager
wxFile.GetValue()
)
);
newItem.Filename = System.IO.Path.GetFileName(dialog.FileName);
WXFile newWxFile = new WXFile(Global.AppDataPathKEY.Value + "\\" + newItem.Filename);
WXFile.Methods.WriteFile(newItem, newWxFile);
newItem.Filename = filename;
if (!File.Exists(Global.AppDataPathKEY.Value + "\\" + filename))
{
File.Copy(dialog.FileName, Global.AppDataPathKEY.Value + "\\" + filename, true);
KeyManagerView.Data.KeyItemsList.Add(newItem);
Console.WriteLine("Imported: " + dialog.FileName);
}
else
{
Console.Error("Not Imported, already exists: " + dialog.FileName);
}
}
}
}
}

View file

@ -22,6 +22,7 @@
<MenuItem Header="Remove"
Name="btn_context_remove"
Click="ContextMenu_Remove"/>
<Separator />
<MenuItem Header="Export"
Name="btn_context_export"
Click="ContextMenu_Export"/>

View file

@ -4,7 +4,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<Version>4.3.0</Version>
<Version>4.3.1</Version>
<ProjectGuid>{4B33CEE7-C74D-43B9-B99A-8B273D5195BC}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>WeeXnes</RootNamespace>
@ -68,6 +68,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Core\CustomConsole.cs" />
<Compile Include="Core\EncryptorLibrary.cs" />
<Compile Include="Core\HandleLaunchArguments.cs" />
<Compile Include="Core\RpcLogEvents.cs" />