-
Notifications
You must be signed in to change notification settings - Fork 22
/
Splash.cs
129 lines (117 loc) · 4.89 KB
/
Splash.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TurtleWallet
{
public partial class Splash : Form
{
public string walletPath
{
get;
set;
}
public string walletPassword
{
get;
set;
}
protected override CreateParams CreateParams
{
get
{
const int CS_DROPSHADOW = 0x20000;
CreateParams cp = base.CreateParams;
cp.ClassStyle |= CS_DROPSHADOW;
return cp;
}
}
public Splash(string _wallet, string _password)
{
InitializeComponent();
walletPath = _wallet;
walletPassword = _password;
versionLabel.Text = "v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
}
private void Splash_Load(object sender, EventArgs e)
{
string curDir = Directory.GetCurrentDirectory();
webBrowser1.Navigate(new Uri(String.Format("file:///{0}/html/trtl.html", curDir)));
((Control)webBrowser1).Enabled = false;
StatusLabel.Text = "Connecting to daemon ...";
splashBackgroundWorker.RunWorkerAsync();
}
private void splashBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
int failcount = 0;
try
{
var connReturn = ConnectionManager.startDaemon(walletPath, walletPassword);
if(connReturn.Item1 == false)
{
this.StatusLabel.BeginInvoke((MethodInvoker)delegate () { this.StatusLabel.Text = "Daemon Connection Failed: " + connReturn.Item2; });
System.Threading.Thread.Sleep(5000);
Environment.Exit(3);
}
while (true)
{
System.Threading.Thread.Sleep(500);
try
{
if(Process.GetProcessesByName("walletd").Length < 1)
{
throw new Exception("Daemon exited!");
}
var resp = ConnectionManager.request("getStatus");
if (resp.Item1 == false)
throw new Exception("No RPC connection/Failed");
var block_count = (int)resp.Item3["blockCount"];
var known_block_count = (int)resp.Item3["knownBlockCount"];
if(known_block_count == 0)
{
this.StatusLabel.BeginInvoke((MethodInvoker)delegate () { this.StatusLabel.Text = "Waiting on known block count..." ; });
continue;
}
this.StatusLabel.BeginInvoke((MethodInvoker)delegate () { this.StatusLabel.Text = "Syncing... [" + block_count.ToString() + " / " + known_block_count.ToString() + "]"; });
if(known_block_count > 0 && (block_count >= known_block_count))
{
this.StatusLabel.BeginInvoke((MethodInvoker)delegate () { this.StatusLabel.Text = "Wallet is synced, opening..."; });
e.Result = connReturn.Item3;
break;
}
}
catch (Exception ex)
{
failcount += 1;
if(failcount >= 15)
throw new Exception("MAXTRYERROR: " + ex.Message);
this.StatusLabel.BeginInvoke((MethodInvoker)delegate () { this.StatusLabel.Text = "Daemon Connect Error, trying..(" + failcount.ToString() + "/15)"; });
}
}
}
catch (Exception ex)
{
this.StatusLabel.BeginInvoke((MethodInvoker)delegate () { this.StatusLabel.Text = "Daemon Connection Failed: " + ex.Message ; });
MessageBox.Show("Daemon Connection Failed: " + ex.Message, "TurtleCoin Wallet", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(3);
}
}
private void splashBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
private void splashBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.Hide();
var walletWindow = new wallet(walletPath, walletPassword, (Process)e.Result);
walletWindow.Closed += (s, args) => this.Close();
walletWindow.Show();
}
}
}