main: Initial add

This commit is contained in:
Nathan Woodburn 2023-06-06 16:26:14 +10:00
parent 0919e4cac0
commit ea95ad2fc6
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
9 changed files with 1190 additions and 76 deletions

190
FireWallet/CreateForm.Designer.cs generated Normal file
View File

@ -0,0 +1,190 @@
namespace FireWallet
{
partial class CreateForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
labelWelcome = new Label();
groupBoxNode = new GroupBox();
labelNodeStatus = new Label();
comboBoxNodeNetwork = new ComboBox();
buttonSave = new Button();
buttonNodeTest = new Button();
textBoxNodeKey = new TextBox();
textBoxNodeIP = new TextBox();
labelNodeKey = new Label();
labelNodeNetowrk = new Label();
labelNodeIP = new Label();
groupBoxNode.SuspendLayout();
SuspendLayout();
//
// labelWelcome
//
labelWelcome.AutoSize = true;
labelWelcome.Font = new Font("Segoe UI", 18F, FontStyle.Bold, GraphicsUnit.Point);
labelWelcome.Location = new Point(12, 9);
labelWelcome.Name = "labelWelcome";
labelWelcome.Size = new Size(358, 64);
labelWelcome.TabIndex = 0;
labelWelcome.Text = "Welcome to Fire Wallet\r\nPlease add your node settings";
labelWelcome.TextAlign = ContentAlignment.TopCenter;
//
// groupBoxNode
//
groupBoxNode.Controls.Add(labelNodeStatus);
groupBoxNode.Controls.Add(comboBoxNodeNetwork);
groupBoxNode.Controls.Add(buttonSave);
groupBoxNode.Controls.Add(buttonNodeTest);
groupBoxNode.Controls.Add(textBoxNodeKey);
groupBoxNode.Controls.Add(textBoxNodeIP);
groupBoxNode.Controls.Add(labelNodeKey);
groupBoxNode.Controls.Add(labelNodeNetowrk);
groupBoxNode.Controls.Add(labelNodeIP);
groupBoxNode.Location = new Point(12, 92);
groupBoxNode.Name = "groupBoxNode";
groupBoxNode.Size = new Size(402, 163);
groupBoxNode.TabIndex = 1;
groupBoxNode.TabStop = false;
groupBoxNode.Text = "Node";
//
// labelNodeStatus
//
labelNodeStatus.AutoSize = true;
labelNodeStatus.Location = new Point(87, 138);
labelNodeStatus.Name = "labelNodeStatus";
labelNodeStatus.Size = new Size(88, 15);
labelNodeStatus.TabIndex = 9;
labelNodeStatus.Text = "Not Connected";
//
// comboBoxNodeNetwork
//
comboBoxNodeNetwork.FlatStyle = FlatStyle.Popup;
comboBoxNodeNetwork.FormattingEnabled = true;
comboBoxNodeNetwork.Items.AddRange(new object[] { "Mainnet", "Regtest" });
comboBoxNodeNetwork.Location = new Point(62, 45);
comboBoxNodeNetwork.Name = "comboBoxNodeNetwork";
comboBoxNodeNetwork.Size = new Size(121, 23);
comboBoxNodeNetwork.TabIndex = 8;
comboBoxNodeNetwork.Text = "Mainnet";
//
// buttonSave
//
buttonSave.FlatStyle = FlatStyle.Flat;
buttonSave.Location = new Point(314, 134);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(75, 23);
buttonSave.TabIndex = 7;
buttonSave.Text = "Finish";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += SaveSettings;
//
// buttonNodeTest
//
buttonNodeTest.FlatStyle = FlatStyle.Flat;
buttonNodeTest.Location = new Point(6, 134);
buttonNodeTest.Name = "buttonNodeTest";
buttonNodeTest.Size = new Size(75, 23);
buttonNodeTest.TabIndex = 6;
buttonNodeTest.Text = "Test";
buttonNodeTest.UseVisualStyleBackColor = true;
buttonNodeTest.Click += TestAPI;
//
// textBoxNodeKey
//
textBoxNodeKey.Location = new Point(62, 71);
textBoxNodeKey.Name = "textBoxNodeKey";
textBoxNodeKey.Size = new Size(327, 23);
textBoxNodeKey.TabIndex = 5;
//
// textBoxNodeIP
//
textBoxNodeIP.Location = new Point(62, 16);
textBoxNodeIP.Name = "textBoxNodeIP";
textBoxNodeIP.Size = new Size(327, 23);
textBoxNodeIP.TabIndex = 3;
textBoxNodeIP.Text = "127.0.0.1";
//
// labelNodeKey
//
labelNodeKey.AutoSize = true;
labelNodeKey.Location = new Point(6, 74);
labelNodeKey.Name = "labelNodeKey";
labelNodeKey.Size = new Size(50, 15);
labelNodeKey.TabIndex = 2;
labelNodeKey.Text = "API Key:";
//
// labelNodeNetowrk
//
labelNodeNetowrk.AutoSize = true;
labelNodeNetowrk.Location = new Point(6, 48);
labelNodeNetowrk.Name = "labelNodeNetowrk";
labelNodeNetowrk.Size = new Size(32, 15);
labelNodeNetowrk.TabIndex = 1;
labelNodeNetowrk.Text = "Port:";
//
// labelNodeIP
//
labelNodeIP.AutoSize = true;
labelNodeIP.Location = new Point(6, 19);
labelNodeIP.Name = "labelNodeIP";
labelNodeIP.Size = new Size(20, 15);
labelNodeIP.TabIndex = 0;
labelNodeIP.Text = "IP:";
//
// CreateForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(438, 281);
Controls.Add(groupBoxNode);
Controls.Add(labelWelcome);
FormBorderStyle = FormBorderStyle.Fixed3D;
Name = "CreateForm";
Text = "Setup";
Load += CreateForm_Load;
Resize += CreateForm_Resize;
groupBoxNode.ResumeLayout(false);
groupBoxNode.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelWelcome;
private GroupBox groupBoxNode;
private TextBox textBoxNodeKey;
private TextBox textBoxNodeIP;
private Label labelNodeKey;
private Label labelNodeNetowrk;
private Label labelNodeIP;
private Button buttonNodeTest;
private Button buttonSave;
private ComboBox comboBoxNodeNetwork;
private Label labelNodeStatus;
}
}

295
FireWallet/CreateForm.cs Normal file
View File

@ -0,0 +1,295 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
namespace FireWallet
{
public partial class CreateForm : Form
{
string dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\FireWallet\\";
public CreateForm()
{
InitializeComponent();
}
private void CreateForm_Load(object sender, EventArgs e)
{
AddLog("Starting Setup");
UpdateTheme();
SizeForm();
}
#region API
async void TestAPI(object sender, EventArgs e)
{
// This will curl the below URL and return the result
//curl http://x:api-key@127.0.0.1:12039/wallet/$id/account
string key = textBoxNodeKey.Text;
string ip = textBoxNodeIP.Text;
int network = comboBoxNodeNetwork.SelectedIndex;
string port = "1203";
if (network == 1)
{
port = "1303";
}
// Create HTTP client
HttpClient httpClient = new HttpClient();
AddLog("Testing: http://x:" + key + "@" + ip + " Network:" + comboBoxNodeNetwork.Text);
try
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://" + ip + ":" + port + "7");
// Add API key to header
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("x:" + key)));
// Send request and log response
HttpResponseMessage response = await httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
AddLog("Node Connected");
labelNodeStatus.Text = "Node Connected";
}
// Log errors to log textbox
catch (Exception ex)
{
AddLog("Node Failed: " + ex.Message);
labelNodeStatus.Text = "Node Connection failed";
}
}
#endregion
#region Logging
private void AddLog(string message)
{
StreamWriter sw = new StreamWriter(dir + "log.txt", true);
sw.WriteLine(DateTime.Now.ToString() + ": " + message);
sw.Dispose();
}
#endregion
#region Theming
private void UpdateTheme()
{
// Check if file exists
if (!Directory.Exists(dir))
{
CreateConfig(dir);
}
if (!File.Exists(dir + "theme.txt"))
{
CreateConfig(dir);
}
AddLog("Reading theme file");
// Read file
StreamReader sr = new StreamReader(dir + "theme.txt");
Dictionary<string, string> theme = new Dictionary<string, string>();
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
string[] split = line.Split(':');
theme.Add(split[0].Trim(), split[1].Trim());
}
sr.Dispose();
if (!theme.ContainsKey("background") || !theme.ContainsKey("background-alt") || !theme.ContainsKey("foreground") || !theme.ContainsKey("foreground-alt"))
{
AddLog("Theme file is missing key");
return;
}
// Apply theme
this.BackColor = ColorTranslator.FromHtml(theme["background"]);
// Foreground
this.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
// Need to specify this for each groupbox to override the black text
foreach (Control c in Controls)
{
if (c.GetType() == typeof(GroupBox))
{
c.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
foreach (Control sub in c.Controls)
{
if (sub.GetType() == typeof(TextBox) || sub.GetType() == typeof(Button)
|| sub.GetType() == typeof(ComboBox))
{
sub.ForeColor = ColorTranslator.FromHtml(theme["foreground-alt"]);
sub.BackColor = ColorTranslator.FromHtml(theme["background-alt"]);
}
}
}
if (c.GetType() == typeof(TextBox) || c.GetType() == typeof(Button)
|| c.GetType() == typeof(ComboBox))
{
c.ForeColor = ColorTranslator.FromHtml(theme["foreground-alt"]);
c.BackColor = ColorTranslator.FromHtml(theme["background-alt"]);
}
}
// Transparancy
AddLog("Finished applying theme");
AddLog("Applying transparency");
applyTransparency(theme);
}
private void applyTransparency(Dictionary<string, string> theme)
{
if (theme.ContainsKey("transparent-mode"))
{
switch (theme["transparent-mode"])
{
case "mica":
var accent = new AccentPolicy { AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND };
var accentStructSize = Marshal.SizeOf(accent);
var accentPtr = Marshal.AllocHGlobal(accentStructSize);
Marshal.StructureToPtr(accent, accentPtr, false);
var data = new WindowCompositionAttributeData
{
Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY,
SizeOfData = accentStructSize,
Data = accentPtr
};
User32.SetWindowCompositionAttribute(Handle, ref data);
Marshal.FreeHGlobal(accentPtr);
break;
case "key":
if (theme.ContainsKey("transparency-key"))
{
switch (theme["transparency-key"])
{
case "alt":
this.TransparencyKey = ColorTranslator.FromHtml(theme["background-alt"]);
break;
case "main":
this.TransparencyKey = ColorTranslator.FromHtml(theme["background"]);
break;
default:
this.TransparencyKey = ColorTranslator.FromHtml(theme["transparency-key"]);
break;
}
}
else
{
AddLog("No transparency-key found in theme file");
}
break;
case "percent":
if (theme.ContainsKey("transparency-percent"))
{
Opacity = Convert.ToDouble(theme["transparency-percent"]) / 100;
}
else
{
AddLog("No transparency-percent found in theme file");
}
break;
}
}
}
private void CreateConfig(string dir)
{
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
StreamWriter sw = new StreamWriter(dir + "theme.txt");
sw.WriteLine("background: #000000");
sw.WriteLine("foreground: #8e05c2");
sw.WriteLine("background-alt: #3e065f");
sw.WriteLine("foreground-alt: #ffffff");
sw.WriteLine("transparent-mode: off");
sw.WriteLine("transparency-key: main");
sw.WriteLine("transparency-percent: 90");
sw.Dispose();
AddLog("Created theme file");
}
// Required for mica effect
internal enum AccentState
{
ACCENT_DISABLED = 0,
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3,
ACCENT_INVALID_STATE = 4
}
internal enum WindowCompositionAttribute
{
WCA_ACCENT_POLICY = 19
}
[StructLayout(LayoutKind.Sequential)]
internal struct AccentPolicy
{
public AccentState AccentState;
public int AccentFlags;
public int GradientColor;
public int AnimationId;
}
[StructLayout(LayoutKind.Sequential)]
internal struct WindowCompositionAttributeData
{
public WindowCompositionAttribute Attribute;
public IntPtr Data;
public int SizeOfData;
}
internal static class User32
{
[DllImport("user32.dll")]
internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
}
#endregion
#region Sizing
private void CreateForm_Resize(object sender, EventArgs e)
{
SizeForm();
}
private void SizeForm()
{
labelWelcome.Left = (this.ClientSize.Width - labelWelcome.Size.Width) / 2;
}
#endregion
private void SaveSettings(object sender, EventArgs e)
{
buttonNodeTest.PerformClick();
if (labelNodeStatus.Text != "Node Connected")
{
return;
}
StreamWriter sw = new StreamWriter(dir + "node.txt");
sw.WriteLine("IP: " + textBoxNodeIP.Text);
sw.WriteLine("Network: " + comboBoxNodeNetwork.SelectedIndex);
sw.WriteLine("Key: " + textBoxNodeKey.Text);
sw.Dispose();
this.Close();
}
}
}

View File

@ -18,7 +18,7 @@
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>

View File

@ -1,39 +0,0 @@
namespace FireWallet
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace FireWallet
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

212
FireWallet/MainForm.Designer.cs generated Normal file
View File

@ -0,0 +1,212 @@
namespace FireWallet
{
partial class MainForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
statusStripmain = new StatusStrip();
toolStripStatusLabelNetwork = new ToolStripStatusLabel();
toolStripStatusLabelstatus = new ToolStripStatusLabel();
timerNodeStatus = new System.Windows.Forms.Timer(components);
panelaccount = new Panel();
groupBoxaccount = new GroupBox();
label1 = new Label();
comboBoxusername = new ComboBox();
textBox1 = new TextBox();
button2 = new Button();
labelaccountpassword = new Label();
labelaccountusername = new Label();
button1 = new Button();
statusStripmain.SuspendLayout();
panelaccount.SuspendLayout();
groupBoxaccount.SuspendLayout();
SuspendLayout();
//
// statusStripmain
//
statusStripmain.Dock = DockStyle.Top;
statusStripmain.Items.AddRange(new ToolStripItem[] { toolStripStatusLabelNetwork, toolStripStatusLabelstatus });
statusStripmain.Location = new Point(0, 0);
statusStripmain.Name = "statusStripmain";
statusStripmain.Size = new Size(1074, 22);
statusStripmain.SizingGrip = false;
statusStripmain.TabIndex = 0;
statusStripmain.Text = "statusStrip1";
//
// toolStripStatusLabelNetwork
//
toolStripStatusLabelNetwork.Margin = new Padding(0, 3, 50, 2);
toolStripStatusLabelNetwork.Name = "toolStripStatusLabelNetwork";
toolStripStatusLabelNetwork.Size = new Size(58, 17);
toolStripStatusLabelNetwork.Text = "Network: ";
//
// toolStripStatusLabelstatus
//
toolStripStatusLabelstatus.Margin = new Padding(0, 3, 50, 2);
toolStripStatusLabelstatus.Name = "toolStripStatusLabelstatus";
toolStripStatusLabelstatus.Size = new Size(126, 17);
toolStripStatusLabelstatus.Text = "Status: Not Connected";
//
// timerNodeStatus
//
timerNodeStatus.Enabled = true;
timerNodeStatus.Interval = 10000;
timerNodeStatus.Tick += timerNodeStatus_Tick;
//
// panelaccount
//
panelaccount.BackColor = Color.Transparent;
panelaccount.Controls.Add(groupBoxaccount);
panelaccount.Dock = DockStyle.Fill;
panelaccount.Location = new Point(0, 22);
panelaccount.Name = "panelaccount";
panelaccount.Size = new Size(1074, 642);
panelaccount.TabIndex = 1;
//
// groupBoxaccount
//
groupBoxaccount.Controls.Add(label1);
groupBoxaccount.Controls.Add(comboBoxusername);
groupBoxaccount.Controls.Add(textBox1);
groupBoxaccount.Controls.Add(button2);
groupBoxaccount.Controls.Add(labelaccountpassword);
groupBoxaccount.Controls.Add(labelaccountusername);
groupBoxaccount.Controls.Add(button1);
groupBoxaccount.FlatStyle = FlatStyle.Popup;
groupBoxaccount.Location = new Point(458, 155);
groupBoxaccount.Name = "groupBoxaccount";
groupBoxaccount.Size = new Size(308, 241);
groupBoxaccount.TabIndex = 5;
groupBoxaccount.TabStop = false;
groupBoxaccount.Text = "Login";
//
// label1
//
label1.AutoSize = true;
label1.Font = new Font("Segoe UI", 15.75F, FontStyle.Regular, GraphicsUnit.Point);
label1.Location = new Point(6, 19);
label1.Name = "label1";
label1.Size = new Size(281, 30);
label1.TabIndex = 7;
label1.Text = "Please Login to your account";
//
// comboBoxusername
//
comboBoxusername.FlatStyle = FlatStyle.Popup;
comboBoxusername.FormattingEnabled = true;
comboBoxusername.Location = new Point(97, 67);
comboBoxusername.Name = "comboBoxusername";
comboBoxusername.Size = new Size(190, 23);
comboBoxusername.TabIndex = 6;
//
// textBox1
//
textBox1.Location = new Point(97, 101);
textBox1.Name = "textBox1";
textBox1.Size = new Size(190, 23);
textBox1.TabIndex = 5;
textBox1.UseSystemPasswordChar = true;
//
// button2
//
button2.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
button2.Location = new Point(188, 164);
button2.Name = "button2";
button2.Size = new Size(99, 41);
button2.TabIndex = 3;
button2.Text = "button2";
button2.UseVisualStyleBackColor = true;
//
// labelaccountpassword
//
labelaccountpassword.AutoSize = true;
labelaccountpassword.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelaccountpassword.Location = new Point(12, 103);
labelaccountpassword.Name = "labelaccountpassword";
labelaccountpassword.Size = new Size(79, 21);
labelaccountpassword.TabIndex = 4;
labelaccountpassword.Text = "Password:";
//
// labelaccountusername
//
labelaccountusername.AutoSize = true;
labelaccountusername.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
labelaccountusername.Location = new Point(12, 67);
labelaccountusername.Name = "labelaccountusername";
labelaccountusername.Size = new Size(69, 21);
labelaccountusername.TabIndex = 1;
labelaccountusername.Text = "Account:";
//
// button1
//
button1.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
button1.Location = new Point(6, 164);
button1.Name = "button1";
button1.Size = new Size(99, 41);
button1.TabIndex = 2;
button1.Text = "button1";
button1.UseVisualStyleBackColor = true;
//
// MainForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1074, 664);
Controls.Add(panelaccount);
Controls.Add(statusStripmain);
Name = "MainForm";
Text = "FireWallet";
FormClosing += MainForm_Closing;
Load += MainForm_Load;
Resize += Form1_Resize;
statusStripmain.ResumeLayout(false);
statusStripmain.PerformLayout();
panelaccount.ResumeLayout(false);
groupBoxaccount.ResumeLayout(false);
groupBoxaccount.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private StatusStrip statusStripmain;
private ToolStripStatusLabel toolStripStatusLabelNetwork;
private ToolStripStatusLabel toolStripStatusLabelstatus;
private System.Windows.Forms.Timer timerNodeStatus;
private Panel panelaccount;
private Button button2;
private Button button1;
private Label labelaccountusername;
private Label labelaccountpassword;
private GroupBox groupBoxaccount;
private Label label1;
private ComboBox comboBoxusername;
private TextBox textBox1;
}
}

340
FireWallet/MainForm.cs Normal file
View File

@ -0,0 +1,340 @@
using System.Runtime.InteropServices;
namespace FireWallet
{
public partial class MainForm : Form
{
#region Variables
string dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\FireWallet\\";
Dictionary<string, string> nodeSettings;
Dictionary<string, string> theme;
int Network;
#endregion
#region Application
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
AddLog("Loading");
UpdateTheme();
LoadNode();
AddLog("Finished loading");
ResizeForm();
}
private void MainForm_Closing(object sender, FormClosingEventArgs e)
{
AddLog("Closing");
}
#endregion
#region Settings
private void LoadNode()
{
AddLog("Loading Node");
if (!File.Exists(dir + "node.txt"))
{
AddLog("Node file not found");
AddLog("Starting Node Setup");
CreateForm cf = new CreateForm();
cf.ShowDialog();
// Initial run
}
if (!File.Exists(dir + "node.txt"))
{
AddLog("Node setup failed");
this.Close();
return;
}
StreamReader sr = new StreamReader(dir + "node.txt");
nodeSettings = new Dictionary<string, string>();
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
string[] split = line.Split(':');
nodeSettings.Add(split[0].Trim(), split[1].Trim());
}
sr.Dispose();
if (!nodeSettings.ContainsKey("Network") || !nodeSettings.ContainsKey("Key") || !nodeSettings.ContainsKey("IP"))
{
AddLog("Node Settings file is missing key");
this.Close();
return;
}
Network = Convert.ToInt32(nodeSettings["Network"]);
switch (Network)
{
case 0:
toolStripStatusLabelNetwork.Text = "Network: Mainnet";
break;
case 1:
toolStripStatusLabelNetwork.Text = "Network: Regtest";
break;
case 2:
toolStripStatusLabelNetwork.Text = "Network: Testnet";
break;
}
NodeStatus();
}
#endregion
#region Logging
private void AddLog(string message)
{
StreamWriter sw = new StreamWriter(dir + "log.txt", true);
sw.WriteLine(DateTime.Now.ToString() + ": " + message);
sw.Dispose();
}
#endregion
#region Theming
private void UpdateTheme()
{
// Check if file exists
if (!Directory.Exists(dir))
{
CreateConfig(dir);
}
if (!File.Exists(dir + "theme.txt"))
{
CreateConfig(dir);
}
AddLog("Reading theme file");
// Read file
StreamReader sr = new StreamReader(dir + "theme.txt");
theme = new Dictionary<string, string>();
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
string[] split = line.Split(':');
theme.Add(split[0].Trim(), split[1].Trim());
}
sr.Dispose();
if (!theme.ContainsKey("background") || !theme.ContainsKey("background-alt") || !theme.ContainsKey("foreground") || !theme.ContainsKey("foreground-alt"))
{
AddLog("Theme file is missing key");
return;
}
// Apply theme
this.BackColor = ColorTranslator.FromHtml(theme["background"]);
// Foreground
this.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
// Need to specify this for each groupbox to override the black text
foreach (Control c in Controls)
{
ThemeControl(c);
}
// Transparancy
AddLog("Finished applying theme");
AddLog("Applying transparency");
applyTransparency(theme);
}
private void ThemeControl(Control c)
{
if (c.GetType() == typeof(GroupBox) || c.GetType() == typeof(Panel))
{
c.ForeColor = ColorTranslator.FromHtml(theme["foreground"]);
foreach (Control sub in c.Controls)
{
ThemeControl(sub);
}
}
if (c.GetType() == typeof(TextBox) || c.GetType() == typeof(Button)
|| c.GetType() == typeof(ComboBox) || c.GetType() == typeof(StatusStrip))
{
c.ForeColor = ColorTranslator.FromHtml(theme["foreground-alt"]);
c.BackColor = ColorTranslator.FromHtml(theme["background-alt"]);
}
}
private void applyTransparency(Dictionary<string, string> theme)
{
if (theme.ContainsKey("transparent-mode"))
{
switch (theme["transparent-mode"])
{
case "mica":
var accent = new AccentPolicy { AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND };
var accentStructSize = Marshal.SizeOf(accent);
var accentPtr = Marshal.AllocHGlobal(accentStructSize);
Marshal.StructureToPtr(accent, accentPtr, false);
var data = new WindowCompositionAttributeData
{
Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY,
SizeOfData = accentStructSize,
Data = accentPtr
};
User32.SetWindowCompositionAttribute(Handle, ref data);
Marshal.FreeHGlobal(accentPtr);
break;
case "key":
if (theme.ContainsKey("transparency-key"))
{
switch (theme["transparency-key"])
{
case "alt":
this.TransparencyKey = ColorTranslator.FromHtml(theme["background-alt"]);
break;
case "main":
this.TransparencyKey = ColorTranslator.FromHtml(theme["background"]);
break;
default:
this.TransparencyKey = ColorTranslator.FromHtml(theme["transparency-key"]);
break;
}
}
else
{
AddLog("No transparency-key found in theme file");
}
break;
case "percent":
if (theme.ContainsKey("transparency-percent"))
{
Opacity = Convert.ToDouble(theme["transparency-percent"]) / 100;
}
else
{
AddLog("No transparency-percent found in theme file");
}
break;
}
}
}
private void CreateConfig(string dir)
{
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
StreamWriter sw = new StreamWriter(dir + "theme.txt");
sw.WriteLine("background: #000000");
sw.WriteLine("foreground: #8e05c2");
sw.WriteLine("background-alt: #3e065f");
sw.WriteLine("foreground-alt: #ffffff");
sw.WriteLine("transparent-mode: off");
sw.WriteLine("transparency-key: main");
sw.WriteLine("transparency-percent: 90");
sw.Dispose();
AddLog("Created theme file");
}
// Required for mica effect
internal enum AccentState
{
ACCENT_DISABLED = 0,
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3,
ACCENT_INVALID_STATE = 4
}
internal enum WindowCompositionAttribute
{
WCA_ACCENT_POLICY = 19
}
[StructLayout(LayoutKind.Sequential)]
internal struct AccentPolicy
{
public AccentState AccentState;
public int AccentFlags;
public int GradientColor;
public int AnimationId;
}
[StructLayout(LayoutKind.Sequential)]
internal struct WindowCompositionAttributeData
{
public WindowCompositionAttribute Attribute;
public IntPtr Data;
public int SizeOfData;
}
internal static class User32
{
[DllImport("user32.dll")]
internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
}
#endregion
private void timerNodeStatus_Tick(object sender, EventArgs e)
{
NodeStatus();
}
private async void NodeStatus()
{
// This will curl the below URL and return the result
//curl http://x:api-key@127.0.0.1:12039/wallet/$id/account
string key = nodeSettings["Key"];
string ip = nodeSettings["IP"];
string port = "1203";
if (Network == 1)
{
port = "1303";
}
// Create HTTP client
HttpClient httpClient = new HttpClient();
try
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://" + ip + ":" + port + "7");
// Add API key to header
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("x:" + key)));
// Send request and log response
HttpResponseMessage response = await httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
toolStripStatusLabelstatus.Text = "Status: Node Connected";
}
// Log errors to log textbox
catch (Exception ex)
{
AddLog("Connection Failed: " + ex.Message);
toolStripStatusLabelstatus.Text = "Status: Node Not Connected";
}
}
private void Form1_Resize(object sender, EventArgs e)
{
ResizeForm();
}
private void ResizeForm()
{
groupBoxaccount.Left = (this.ClientSize.Width - groupBoxaccount.Width) / 2;
groupBoxaccount.Top = (this.ClientSize.Height - groupBoxaccount.Height) / 2;
}
}
}

126
FireWallet/MainForm.resx Normal file
View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStripmain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="timerNodeStatus.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>133, 17</value>
</metadata>
</root>

View File

@ -11,7 +11,7 @@ namespace FireWallet
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
Application.Run(new MainForm());
}
}
}