From b79121856c5848d8e3843d6d8a66fc1092cfddd3 Mon Sep 17 00:00:00 2001 From: Justyn Date: Wed, 20 Apr 2016 17:54:59 -0500 Subject: [PATCH] Implement configuration files --- DTK/Config.cs | 20 ++++++++++++++++++++ DTK/DTK.csproj | 1 + DTK/Main.cs | 31 +++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 DTK/Config.cs diff --git a/DTK/Config.cs b/DTK/Config.cs new file mode 100644 index 0000000..873a33e --- /dev/null +++ b/DTK/Config.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTK +{ + public class Config + { + public string PythonPath { get; set; } + public string FunKeyCIAPath { get; set; } + + public Config() + { + PythonPath = "python"; + FunKeyCIAPath = "FunKeyCIA.py"; + } + } +} diff --git a/DTK/DTK.csproj b/DTK/DTK.csproj index 59b6083..54ec364 100644 --- a/DTK/DTK.csproj +++ b/DTK/DTK.csproj @@ -53,6 +53,7 @@ + Form diff --git a/DTK/Main.cs b/DTK/Main.cs index c45489b..6d02c68 100644 --- a/DTK/Main.cs +++ b/DTK/Main.cs @@ -17,8 +17,10 @@ public partial class Main : Form { private const string _3dsDbPath = "3dsreleases.xml"; private const string _keyDbPath = "db.ebin"; + private const string _configPath = "config.xml"; private static string aaa = "aHR0cDovLzNkcy5uZnNob3N0LmNvbS9kb3dubG9hZGVuYw=="; - private const string _FunKeyCIAPath = "FunKeyCIA.py"; + private static string _FunKeyCIAPath = "FunKeyCIA.py"; + private static string _pythonPath = "python"; private List loadedTitles = new List(); public Main() @@ -37,7 +39,22 @@ public Main() { MessageBox.Show("Could not find FunKeyCIA.py. Downloading from CDN will not work"); } + if (File.Exists(_configPath)) + { + Config loadedConfig = ParseConfig(); + _pythonPath = loadedConfig.PythonPath; + _FunKeyCIAPath = loadedConfig.FunKeyCIAPath; + } else + { + Config cfg = new Config(); + System.Xml.Serialization.XmlSerializer writer = + new System.Xml.Serialization.XmlSerializer(typeof(Config)); + System.IO.FileStream file = System.IO.File.Create(_configPath); + + writer.Serialize(file, cfg); + file.Close(); + } } @@ -130,6 +147,16 @@ public static string Base64Decode(string base64EncodedData) return System.Text.Encoding.UTF8.GetString(base64EncodedBytes); } + private static Config ParseConfig() + { + Console.WriteLine("Loading config..."); + System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(Config)); + System.IO.StreamReader file = new System.IO.StreamReader(_configPath); + Config cfg = (Config)reader.Deserialize(file); + file.Close(); + return cfg; + } + private static List ParseTicketsFrom3dsDb(List parsedTickets) { Console.WriteLine("Checking Title IDs against 3dsdb.com database"); @@ -245,7 +272,7 @@ private void titleView_ItemActivate(object sender, EventArgs e) { foreach (ListViewItem item in this.titleView.SelectedItems) { - var strCmdText = "/k python FunKeyCIA.py -title " + item.SubItems[1].Text + " -key " + item.SubItems[2].Text; + var strCmdText = "/k "+ _pythonPath + " " + _FunKeyCIAPath + " -title " + item.SubItems[1].Text + " -key " + item.SubItems[2].Text; System.Diagnostics.Process.Start("CMD.exe", strCmdText); } }