Skip to content

Commit

Permalink
Implement configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
Lustyn committed Apr 20, 2016
1 parent be9a76b commit b791218
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
20 changes: 20 additions & 0 deletions DTK/Config.cs
Original file line number Diff line number Diff line change
@@ -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";
}
}
}
1 change: 1 addition & 0 deletions DTK/DTK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="Main.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
31 changes: 29 additions & 2 deletions DTK/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Nintendo3DSRelease> loadedTitles = new List<Nintendo3DSRelease>();

public Main()
Expand All @@ -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();
}
}


Expand Down Expand Up @@ -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<Nintendo3DSRelease> ParseTicketsFrom3dsDb(List<Nintendo3DSRelease> parsedTickets)
{
Console.WriteLine("Checking Title IDs against 3dsdb.com database");
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit b791218

Please sign in to comment.