From 7388710704356848cff9665ffc7b63aa9bc2d69b Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 9 Jun 2023 23:43:50 +1000 Subject: [PATCH] main: Added bug fixes for new installs --- FireWallet/MainForm.Designer.cs | 3 +- FireWallet/MainForm.cs | 125 ++++++++++++++++++++++---------- FireWallet/SplashScreen.cs | 5 +- 3 files changed, 89 insertions(+), 44 deletions(-) diff --git a/FireWallet/MainForm.Designer.cs b/FireWallet/MainForm.Designer.cs index 69a8c59..c4c76b1 100644 --- a/FireWallet/MainForm.Designer.cs +++ b/FireWallet/MainForm.Designer.cs @@ -964,16 +964,17 @@ namespace FireWallet AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1152, 575); + Controls.Add(panelaccount); Controls.Add(panelRecieve); Controls.Add(panelSettings); Controls.Add(panelDomains); Controls.Add(panelSend); Controls.Add(panelPortfolio); Controls.Add(panelNav); - Controls.Add(panelaccount); Controls.Add(statusStripmain); Icon = (Icon)resources.GetObject("$this.Icon"); Name = "MainForm"; + Opacity = 0D; Text = "FireWallet"; FormClosing += MainForm_Closing; Load += MainForm_Load; diff --git a/FireWallet/MainForm.cs b/FireWallet/MainForm.cs index e8251dd..5f93835 100644 --- a/FireWallet/MainForm.cs +++ b/FireWallet/MainForm.cs @@ -39,15 +39,16 @@ namespace FireWallet public MainForm() { InitializeComponent(); + panelaccount.Visible = true; } - private void MainForm_Load(object sender, EventArgs e) + private async void MainForm_Load(object sender, EventArgs e) { watchOnly = false; account = ""; timerNodeStatus.Stop(); LoadSettings(); UpdateTheme(); - LoadNode(); + if (await LoadNode() != true) this.Close(); if (userSettings.ContainsKey("hide-splash")) { @@ -59,6 +60,13 @@ namespace FireWallet ss.Dispose(); } } + else + { + // Show splash screen + SplashScreen ss = new SplashScreen(); + ss.ShowDialog(); + ss.Dispose(); + } @@ -79,16 +87,16 @@ namespace FireWallet GetAccounts(); AddLog("Loaded"); + Opacity = 1; batchMode = false; textBoxaccountpassword.Focus(); - timerNodeStatus.Start(); } private void MainForm_Closing(object sender, FormClosingEventArgs e) { AddLog("Closing"); if (hsdProcess != null) { - this.Hide(); + this.Opacity = 0; hsdProcess.Kill(); AddLog("HSD Closed"); Thread.Sleep(1000); @@ -109,7 +117,7 @@ namespace FireWallet #region Settings - private async void LoadNode() + private async Task LoadNode() { HSD = false; if (!File.Exists(dir + "node.txt")) @@ -123,7 +131,8 @@ namespace FireWallet { AddLog("Node setup failed"); this.Close(); - return; + await Task.Delay(1000); + AddLog("Close Failed"); } StreamReader sr = new StreamReader(dir + "node.txt"); @@ -141,7 +150,8 @@ namespace FireWallet { AddLog("Node Settings file is missing key"); this.Close(); - return; + await Task.Delay(1000); + AddLog("Close Failed"); } network = Convert.ToInt32(nodeSettings["Network"]); switch (network) @@ -181,33 +191,52 @@ namespace FireWallet } hsdProcess = new Process(); - hsdProcess.StartInfo.CreateNoWindow = true; - - hsdProcess.StartInfo.RedirectStandardInput = true; - hsdProcess.StartInfo.RedirectStandardOutput = false; - hsdProcess.StartInfo.UseShellExecute = false; - hsdProcess.StartInfo.RedirectStandardError = false; - hsdProcess.StartInfo.FileName = "node.exe"; - hsdProcess.StartInfo.Arguments = dir + "hsd/bin/hsd --index-tx --index-address --api-key" + nodeSettings["Key"]; - - string bobPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Bob\\hsd_data"; - if (Directory.Exists(bobPath)) + bool hideScreen = true; + if (nodeSettings.ContainsKey("HideScreen")) { - hsdProcess.StartInfo.Arguments = hsdProcess.StartInfo.Arguments + " --prefix " + bobPath; + if (nodeSettings["HideScreen"].ToLower() == "false") + { + hideScreen = false; + } } - hsdProcess.Start(); + try + { + hsdProcess.StartInfo.CreateNoWindow = hideScreen; + hsdProcess.StartInfo.RedirectStandardInput = true; + hsdProcess.StartInfo.RedirectStandardOutput = false; + hsdProcess.StartInfo.UseShellExecute = false; + hsdProcess.StartInfo.RedirectStandardError = false; + hsdProcess.StartInfo.FileName = "node.exe"; + hsdProcess.StartInfo.Arguments = dir + "hsd/bin/hsd --index-tx --index-address --api-key " + nodeSettings["Key"]; + string bobPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Bob\\hsd_data"; + if (Directory.Exists(bobPath)) + { + hsdProcess.StartInfo.Arguments = hsdProcess.StartInfo.Arguments + " --prefix " + bobPath; + } + hsdProcess.Start(); + // Wait for HSD to start + await Task.Delay(2000); + } catch (Exception ex) + { + AddLog("HSD Failed to start"); + AddLog(ex.Message); + this.Close(); + await Task.Delay(1000); + AddLog("Close Failed"); + } } } - + timerNodeStatus.Start(); NodeStatus(); - + return true; } private void LoadSettings() { + if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); if (!File.Exists(dir + "settings.txt")) { AddLog("Creating settings file"); @@ -455,19 +484,27 @@ namespace FireWallet } private async void GetAccounts() { - string APIresponse = await APIGet("wallet", true); - comboBoxaccount.Items.Clear(); - if (APIresponse != "Error") + try { - comboBoxaccount.Enabled = true; - JArray jArray = JArray.Parse(APIresponse); - foreach (string account in jArray) + string APIresponse = await APIGet("wallet", true); + comboBoxaccount.Items.Clear(); + if (APIresponse != "Error") { - comboBoxaccount.Items.Add(account); - } - if (comboBoxaccount.Items.Count > 0) - { - comboBoxaccount.SelectedIndex = 0; + comboBoxaccount.Enabled = true; + JArray jArray = JArray.Parse(APIresponse); + foreach (string account in jArray) + { + comboBoxaccount.Items.Add(account); + } + if (comboBoxaccount.Items.Count > 0) + { + comboBoxaccount.SelectedIndex = 0; + } + else + { + comboBoxaccount.Items.Add("No accounts found"); + comboBoxaccount.Enabled = false; + } } else { @@ -475,10 +512,9 @@ namespace FireWallet comboBoxaccount.Enabled = false; } } - else + catch { - comboBoxaccount.Items.Add("No accounts found"); - comboBoxaccount.Enabled = false; + AddLog("Error getting accounts"); } } private async Task Login() @@ -676,6 +712,8 @@ namespace FireWallet /// public async Task APIGet(string path, bool wallet) { + if (nodeSettings == null) return "Error"; + if (!nodeSettings.ContainsKey("Key") || !nodeSettings.ContainsKey("IP")) return "Error"; string key = nodeSettings["Key"]; string ip = nodeSettings["IP"]; @@ -1234,12 +1272,21 @@ namespace FireWallet { try { + bool hideScreen = true; + if (nodeSettings.ContainsKey("HideScreen")) + { + if (nodeSettings["HideScreen"].ToLower() == "false") + { + hideScreen = false; + } + } + ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "git"; startInfo.Arguments = $"clone {repositoryUrl} {destinationPath}"; startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; - startInfo.CreateNoWindow = true; + startInfo.CreateNoWindow = hideScreen; Process process = new Process(); process.StartInfo = startInfo; @@ -1257,7 +1304,7 @@ namespace FireWallet FileName = "cmd", RedirectStandardInput = true, WorkingDirectory = destinationPath, - CreateNoWindow = true + CreateNoWindow = hideScreen }; var pNpmRunDist = Process.Start(psiNpmRunDist); pNpmRunDist.StandardInput.WriteLine("npm install & exit"); @@ -1582,7 +1629,7 @@ namespace FireWallet - + } } \ No newline at end of file diff --git a/FireWallet/SplashScreen.cs b/FireWallet/SplashScreen.cs index c8439a0..c7246dd 100644 --- a/FireWallet/SplashScreen.cs +++ b/FireWallet/SplashScreen.cs @@ -27,10 +27,7 @@ namespace FireWallet private void SplashScreen_FormClosing(object sender, FormClosingEventArgs e) { - if (!close) - { - e.Cancel = true; - } + } private void label2_Click(object sender, EventArgs e)