-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathForm1.cs
126 lines (107 loc) · 3.76 KB
/
Form1.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
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace LatinmineWin
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ProcessStartInfo cmdStartInfo = new ProcessStartInfo("cmd.exe");
cmdStartInfo.CreateNoWindow = true;
cmdStartInfo.RedirectStandardInput = true;
cmdStartInfo.RedirectStandardOutput = true;
cmdStartInfo.RedirectStandardError = true;
cmdStartInfo.UseShellExecute = false;
cmdStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
_cmd = new Process();
_cmd.StartInfo = cmdStartInfo;
if (_cmd.Start() == true)
{
_cmd.OutputDataReceived += new DataReceivedEventHandler(_cmd_OutputDataReceived);
_cmd.ErrorDataReceived += new DataReceivedEventHandler(_cmd_ErrorDataReceived);
_cmd.Exited += new EventHandler(_cmd_Exited);
_cmd.BeginOutputReadLine();
_cmd.BeginErrorReadLine();
}
else
{
_cmd = null;
}
}
private void button_start_Click(object sender, EventArgs e)
{
Form1.ActiveForm.FormClosing += Form1_FormClosing;
ExecuteCommand("phoenix\\PhoenixMiner.exe -pool stratum+tcp://us.latinmine.com:4444 -wal "+textbox_wallet.Text);
}
private void button_to_worker_Click(object sender, EventArgs e)
{
ProcessStartInfo psInfo = new ProcessStartInfo
{
FileName = "http://latinmine.com/#/account/" + textbox_wallet.Text,
UseShellExecute = true
};
Process.Start(psInfo);
}
Process _cmd;
private void ExecuteCommand(string _Command)
{
_cmd.StandardInput.WriteLine(_Command);
}
private void Window_Closed(object sender, EventArgs e)
{
if ((_cmd != null) &&
(_cmd.HasExited != true))
{
_cmd.CancelErrorRead();
_cmd.CancelOutputRead();
_cmd.Close();
_cmd.WaitForExit();
}
}
void _cmd_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
UpdateConsole(e.Data);
}
void _cmd_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
UpdateConsole(e.Data);
}
void _cmd_Exited(object sender, EventArgs e)
{
_cmd.OutputDataReceived -= new DataReceivedEventHandler(_cmd_OutputDataReceived);
_cmd.Exited -= new EventHandler(_cmd_Exited);
}
private void UpdateConsole(string text)
{
if (InvokeRequired)
{
this.Invoke(new Action<string>(UpdateConsole), new object[] { text });
return;
}
textboxLog.AppendText(Environment.NewLine);
text = textboxLog.Text + "\n" + text;
this.textboxLog.Text = text;
textboxLog.SelectionStart = textboxLog.TextLength;
textboxLog.ScrollToCaret();
}
private void closePhoenix()
{
foreach (var process in Process.GetProcessesByName("PhoenixMiner"))
{
process.Kill();
}
}
private void Form1_FormClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
closePhoenix();
e.Cancel = true;
}
private void stop_button_Click(object sender, EventArgs e)
{
closePhoenix();
UpdateConsole("Mining Stopped...");
}
}
}