-
Notifications
You must be signed in to change notification settings - Fork 46
/
Main.vb
executable file
·2142 lines (1928 loc) · 95 KB
/
Main.vb
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports System.IO
Imports System.IO.Compression
Imports System.Environment
Imports System.Net
Imports System.Net.Sockets
Imports Open.Nat
Imports System.Text
Imports System.Web.Script.Serialization
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports System.Globalization
Imports VertcoinOneClickMiner.Core
Public Class Main
Dim JSONConverter As JavaScriptSerializer = New JavaScriptSerializer()
Private _logger As ILogger
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
'Styling
Invoke(New MethodInvoker(AddressOf Style))
If Environment.Is64BitOperatingSystem = True Then
platform = True '64-bit
Else
platform = False '32-bit
End If
settingsfolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Vertcoin One-Click Miner"
settingsfile = settingsfolder & "\Settings.json"
syslog = settingsfolder & "\SysLog.txt"
p2poolfolder = settingsfolder & "\p2pool"
scannerfolder = settingsfolder & "\scanner"
amdfolder = settingsfolder & "\amd"
nvidiafolder = settingsfolder & "\nvidia"
cpufolder = settingsfolder & "\cpu"
_logger = New FileLogger(syslog)
If System.IO.Directory.Exists(settingsfolder) = False Then
System.IO.Directory.CreateDirectory(settingsfolder)
End If
If System.IO.File.Exists(settingsfolder & "\Settings.ini") = True Then
Invoke(New MethodInvoker(AddressOf Update_Settings))
Else
If System.IO.File.Exists(settingsfile) = False Then
Invoke(New MethodInvoker(AddressOf SaveSettingsJSON))
End If
End If
If System.IO.File.Exists(syslog) = False Then
File.Create(syslog).Dispose()
End If
'Load Settings
Invoke(New MethodInvoker(AddressOf LoadSettingsJSON))
'Check for default miner selected. This is kept separate from autostart to allow user to see checkbox.
If default_miner = "amd" Then
ComboBox1.SelectedItem = "AMD"
ElseIf default_miner = "nvidia" Then
ComboBox1.SelectedItem = "NVIDIA"
ElseIf default_miner = "cpu" Then
ComboBox1.SelectedItem = "CPU"
End If
'Window state on start
If start_minimized = True Then
Me.WindowState = FormWindowState.Minimized
Else
Me.WindowState = FormWindowState.Normal
End If
'Check if p2pool or miner are already running
Invoke(New MethodInvoker(AddressOf Process_Check))
If p2pool_detected = True Then
'P2Pool is already running
CheckBox1.Checked = True
End If
'Autostart variables
If autostart_mining = True Then
If default_miner = "amd" Then
If System.IO.File.Exists(amdfolder & "\ocm_sgminer.exe") = True Then
amdminer = True
End If
mining_initialized = True
BeginInvoke(New MethodInvoker(AddressOf Start_Miner))
ElseIf default_miner = "nvidia" Then
If System.IO.File.Exists(nvidiafolder & "\ocm_vertminer.exe") = True Then
nvidiaminer = True
End If
mining_initialized = True
BeginInvoke(New MethodInvoker(AddressOf Start_Miner))
ElseIf default_miner = "cpu" Then
If System.IO.File.Exists(cpufolder & "\ocm_cpuminer.exe") = True Then
cpuminer = True
End If
mining_initialized = True
BeginInvoke(New MethodInvoker(AddressOf Start_Miner))
End If
End If
If autostart_p2pool = True Then
If System.IO.File.Exists(p2poolfolder & "\ocm_p2pool.exe") = True Then
BeginInvoke(New MethodInvoker(AddressOf Start_P2Pool))
End If
End If
DataGridView1.DataSource = Nothing
Invoke(New MethodInvoker(AddressOf Uptime_Checker_Status_Text))
Invoke(New MethodInvoker(AddressOf Update_Miner_Text))
BeginInvoke(New MethodInvoker(AddressOf Detected))
UpdateStatsInterval.Start()
Uptime_Timer.Start()
Catch ex As Exception
MsgBox(ex.Message)
_logger.LogError(ex)
Finally
_logger.Trace("Loaded: OK, V:" & Application.ProductVersion)
End Try
End Sub
Private Sub Main_Size_Change(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
NotifyIcon1.ContextMenu = New ContextMenu
If Me.WindowState = FormWindowState.Minimized Then
If start_minimized = True Then
Me.ShowInTaskbar = False
NotifyIcon1.Visible = True
NotifyIcon1.ShowBalloonTip(5, "System", "Vertcoin One-Click Miner is minimized.", ToolTipIcon.Info)
NotifyIcon1.ContextMenu.MenuItems.Add("Open", AddressOf Menu_Open)
NotifyIcon1.ContextMenu.MenuItems.Add("Close", AddressOf Menu_Close)
Else
NotifyIcon1.Visible = False
Me.Show()
End If
ElseIf Me.WindowState = FormWindowState.Normal Then
NotifyIcon1.Visible = False
Me.Show()
End If
End Sub
Private Sub Menu_Close()
Me.Close()
End Sub
Private Sub Menu_Open()
Me.WindowState = FormWindowState.Normal
End Sub
Private Sub Main_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
_logger.Trace(Environment.NewLine)
_logger.Trace("Closing: OK")
NotifyIcon1.Dispose()
If ComboBox1.SelectedItem = "AMD" Then
default_miner = "amd"
ElseIf ComboBox1.SelectedItem = "NVIDIA" Then
default_miner = "nvidia"
ElseIf ComboBox1.SelectedItem = "CPU" Then
default_miner = "cpu"
End If
Invoke(New MethodInvoker(AddressOf SaveSettingsJSON))
Invoke(New MethodInvoker(AddressOf Kill_Miner))
Invoke(New MethodInvoker(AddressOf Kill_P2Pool))
_logger.Trace("================================================================================")
Application.Exit()
End Sub
Public Sub Process_Check()
For Each p As Process In System.Diagnostics.Process.GetProcesses
If p.ProcessName.Contains("ocm_p2pool") Then
p2pool_detected = True
Exit For
Else
p2pool_detected = False
End If
Next
For Each p As Process In System.Diagnostics.Process.GetProcesses
If p.ProcessName.Contains("ocm_sgminer") Then
amd_detected = True
Exit For
Else
amd_detected = False
End If
Next
For Each p As Process In System.Diagnostics.Process.GetProcesses
If p.ProcessName.Contains("ocm_vertminer") Then
nvidia_detected = True
Exit For
Else
nvidia_detected = False
End If
Next
For Each p As Process In System.Diagnostics.Process.GetProcesses
If p.ProcessName.Contains("ocm_cpuminer") Then
cpu_detected = True
Exit For
Else
cpu_detected = False
End If
Next
For Each p As Process In System.Diagnostics.Process.GetProcesses
If (p.ProcessName.Contains("run_p2pool") Or p.ProcessName.Contains("p2pool")) And Not p.ProcessName.Contains("ocm") Then
otherp2pool = True
Exit For
Else
otherp2pool = False
End If
Next
For Each p As Process In System.Diagnostics.Process.GetProcesses
If p.ProcessName = ("vertminer") Or p.ProcessName = ("sgminer") Or p.ProcessName = ("cpuminer") And Not p.ProcessName.Contains("ocm") Then
otherminer = True
Exit For
Else
otherminer = False
End If
Next
End Sub
Public Sub Detected()
Me.Text = "Vertcoin OCM - BETA V:" & miner_version
If otherp2pool = True Then
MsgBox("One-Click Miner has detected other p2pool software running. Be aware of potential port conflicts.")
End If
If otherminer = True Then
MsgBox("One-Click Miner has detected other miner software running." & Environment.NewLine & "It is not recommended to run multiple miners on the same machine simultaneously.")
End If
End Sub
Public Sub UPnP()
Try
'using native upnp
'Dim ipAddress As String = GetIPv4Address()
'Dim upnpnat As New NATUPNPLib.UPnPNAT()
'Dim mappings As NATUPNPLib.IStaticPortMappingCollection = upnpnat.StaticPortMappingCollection
'mappings.Add(mining_port, "TCP", mining_port, ipAddress, True, "P2Pool Mining Server")
'mappings.Add(p2pool_port, "TCP", p2pool_port, ipAddress, True, "P2Pool P2P")
'using native upnp
'Dim upnpnat As New NATUPNPLib.UPnPNAT()
'Dim lMapper As NATUPNPLib.IStaticPortMappingCollection = upnpnat.StaticPortMappingCollection
'Dim lMappedPort As NATUPNPLib.IStaticPortMapping
'lMappedPort = DirectCast(lMapper.Add(mining_port, "TCP", mining_port, ipAddress, True, "P2Pool Mining Server"), NATUPNPLib.IStaticPortMapping)
'lMappedPort = DirectCast(lMapper.Add(p2pool_port, "TCP", p2pool_port, ipAddress, True, "P2Pool P2P"), NATUPNPLib.IStaticPortMapping)
'Using open.nat
Dim discoverer As New NatDiscoverer()
' using SSDP protocol, it discovers NAT device.
Dim device = discoverer.DiscoverDeviceAsync()
' create a New mapping in the router [external_ip1702 -> host_machine:1602]
device.Equals(New Mapping(Protocol.Tcp, mining_port, mining_port, "P2Pool Mining Server"))
device.Equals(New Mapping(Protocol.Tcp, p2pool_port, p2pool_port, "P2Pool P2P"))
' configure a TCP socket listening on port 1602
Dim EndPoint As New IPEndPoint(IPAddress.Any, mining_port)
Dim socket As New Socket(EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
socket.SetIPProtectionLevel(IPProtectionLevel.Unrestricted)
socket.Bind(EndPoint)
socket.Listen(4)
Dim EndPoint2 As New IPEndPoint(IPAddress.Any, p2pool_port)
Dim socket2 As New Socket(EndPoint2.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
socket2.SetIPProtectionLevel(IPProtectionLevel.Unrestricted)
socket2.Bind(EndPoint2)
socket2.Listen(4)
'Using Open.Nat
'Dim discoverer As New Open.Nat.NatDiscoverer()
'Dim cts As New System.Threading.CancellationTokenSource(10000)
'Dim device = discoverer.DiscoverDeviceAsync(Open.Nat.PortMapper.Upnp, cts)
'device.CreatePortMapAsync(New Open.Nat.Mapping(Open.Nat.Protocol.Tcp, 1600, 1700, "The mapping name"))
_logger.Trace("SET OK. Ports set: " & mining_port & "," & p2pool_port)
Catch ex As Exception
MsgBox(ex.Message)
_logger.LogError(ex)
Invoke(New MethodInvoker(AddressOf SaveSettingsJSON))
End Try
End Sub
Public Sub Download_Miner()
Try
progress.progress_text.Text = "Downloading Miner"
progress.Show()
downloadclient = New WebClient
AddHandler downloadclient.DownloadProgressChanged, AddressOf Client_ProgressChanged
AddHandler downloadclient.DownloadFileCompleted, AddressOf Client_MinerDownloadCompleted
'Compares the current version of the AMD miner with the latest available.
If amdminer = True Then
If (newestversion > System.Version.Parse(amd_version)) Or mining_installed = False Then
If System.IO.Directory.Exists(amdfolder) = False Then
'If AMD miner doesn't already exist, create folder and download
System.IO.Directory.CreateDirectory(amdfolder)
Else
System.IO.Directory.Delete(amdfolder, True)
System.Threading.Thread.Sleep(100)
System.IO.Directory.CreateDirectory(amdfolder)
End If
downloadclient.DownloadFileAsync(New Uri(updatelink), settingsfolder & "\amd\sgminer.zip", True)
Else
progress.Close()
End If
End If
'Compares the current version of the Nvidia miner with the latest available.
If nvidiaminer = True Then
If newestversion > System.Version.Parse(nvidia_version) Or mining_installed = False Then
If System.IO.Directory.Exists(nvidiafolder) = False Then
'If Nvidia miner doesn't already exist, create folder and download
System.IO.Directory.CreateDirectory(nvidiafolder)
Else
System.IO.Directory.Delete(nvidiafolder, True)
System.Threading.Thread.Sleep(100)
System.IO.Directory.CreateDirectory(nvidiafolder)
End If
downloadclient.DownloadFileAsync(New Uri(updatelink), settingsfolder & "\nvidia\vertminer.zip", True)
Else
progress.Close()
End If
End If
'Compares the current version of the CPU miner with the latest available.
If cpuminer = True Then
If newestversion > System.Version.Parse(cpu_version) Or mining_installed = False Then
If System.IO.Directory.Exists(cpufolder) = False Then
'If CPU miner doesn't already exist, create folder and download
System.IO.Directory.CreateDirectory(cpufolder)
Else
System.IO.Directory.Delete(cpufolder, True)
System.Threading.Thread.Sleep(100)
System.IO.Directory.CreateDirectory(cpufolder)
End If
downloadclient.DownloadFileAsync(New Uri(updatelink), settingsfolder & "\cpu\cpuminer.zip", True)
Else
progress.Close()
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
_logger.LogError(ex)
Invoke(New MethodInvoker(AddressOf SaveSettingsJSON))
Finally
_logger.Trace("Downloaded OK.")
End Try
End Sub
Public Sub Download_P2Pool()
Try
progress.progress_text.Text = "Downloading P2Pool"
progress.Show()
downloadclient = New WebClient
AddHandler downloadclient.DownloadProgressChanged, AddressOf Client_ProgressChanged
AddHandler downloadclient.DownloadFileCompleted, AddressOf Client_P2PoolDownloadCompleted
If (newestversion > System.Version.Parse(p2pool_version)) Or p2pool_installed = False Then
'Create p2pool directory and download/extract p2pool components into directory
If System.IO.Directory.Exists(p2poolfolder) = False Then
System.IO.Directory.CreateDirectory(p2poolfolder)
End If
MsgBox("Please note, you must also run a Vertcoin Wallet to use P2Pool locally.")
downloadclient.DownloadFileAsync(New Uri(updatelink), p2poolfolder & "\p2pool.zip", True)
End If
Catch ex As Exception
MsgBox("An issue occurred during the download. Please try again.")
_logger.LogError(ex)
Invoke(New MethodInvoker(AddressOf SaveSettingsJSON))
Finally
_logger.Trace("Downloaded OK.")
End Try
End Sub
Public Sub Download_P2PoolInterface()
Try
'Better P2Pool Site UI
Dim link As String = "http://github.com/justino/p2pool-ui-punchy/archive/master.zip"
progress.progress_text.Text = "Downloading P2Pool UI"
progress.Show()
downloadclient = New WebClient
AddHandler downloadclient.DownloadProgressChanged, AddressOf Client_ProgressChanged
AddHandler downloadclient.DownloadFileCompleted, AddressOf Client_P2PoolInterfaceDownloadCompleted
downloadclient.DownloadFileAsync(New Uri(link), p2poolfolder & "\interface.zip")
Catch ex As Exception
MsgBox("An issue occurred during the download. Please try again.")
_logger.LogError(ex)
Invoke(New MethodInvoker(AddressOf SaveSettingsJSON))
Finally
_logger.Trace("Downloaded OK.")
End Try
End Sub
Private Sub Client_ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
Dim percentage As Double = bytesIn / totalBytes * 100
If Int32.Parse(Math.Truncate(percentage).ToString()) >= 0 Then
progress.ProgressBar1.Value = Int32.Parse(Math.Truncate(percentage).ToString())
End If
End Sub
Private Sub Client_MinerDownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
Try
If canceldownloadasync = False Then
'Download proper miner and extract into respective directories
If amdminer = True Then
zipPath = settingsfolder & "\amd\sgminer.zip"
exe = settingsfolder & "\amd\ocm_sgminer.exe"
miner_config_file = settingsfolder & "\amd\config.bat"
ElseIf nvidiaminer = True Then
zipPath = settingsfolder & "\nvidia\vertminer.zip"
exe = settingsfolder & "\nvidia\ocm_vertminer.exe"
dll = settingsfolder & "\nvidia\msvcr120.dll"
miner_config_file = settingsfolder & "\nvidia\config.bat"
ElseIf cpuminer = True Then
zipPath = settingsfolder & "\cpu\cpuminer.zip"
exe = settingsfolder & "\cpu\ocm_cpuminer.exe"
miner_config_file = settingsfolder & "\cpu\config.bat"
End If
Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
'If platform = True Then '64-bit
For Each entry As ZipArchiveEntry In archive.Entries
If nvidiaminer = True Then 'Nvidia
If (entry.FullName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) Or entry.FullName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) Then
If entry.FullName.EndsWith(".exe") Then
extractpath = exe
ElseIf entry.FullName.EndsWith(".dll") Then
extractpath = dll
End If
entry.ExtractToFile(extractpath, True)
End If
ElseIf amdminer = True Then 'AMD
If (entry.FullName.Contains("kernel") And entry.FullName.EndsWith(".cl", StringComparison.OrdinalIgnoreCase)) Then
If System.IO.Directory.Exists(amdfolder & "\kernel\") = False Then
System.IO.Directory.CreateDirectory(amdfolder & "\kernel\")
End If
entry.ExtractToFile(amdfolder & "\kernel\" & entry.Name, True)
Else
If entry.FullName.EndsWith(".exe") Then
entry.ExtractToFile(exe, True)
ElseIf entry.FullName.EndsWith(".dll") Then
entry.ExtractToFile(amdfolder & "\" & entry.Name, True)
End If
End If
ElseIf cpuminer = True Then 'CPU
If (entry.FullName.EndsWith("corei7.exe", StringComparison.OrdinalIgnoreCase)) Then
If entry.FullName.EndsWith(".exe") Then
extractpath = exe
ElseIf entry.FullName.EndsWith(".dll") Then
extractpath = dll
End If
entry.ExtractToFile(extractpath, True)
End If
End If
Next
'Else '32-bit
' For Each entry As ZipArchiveEntry In archive.Entries
' If NvidiaMiner = True Then 'Nvidia
' If (entry.FullName.Contains("32") And entry.FullName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) Or (entry.FullName.Contains("32") And entry.FullName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) Then
' If entry.FullName.EndsWith(".exe") Then
' extractpath = exe
' ElseIf entry.FullName.EndsWith(".dll") Then
' extractpath = dll
' End If
' entry.ExtractToFile(extractpath, True)
' End If
' Else 'AMD
' If (entry.FullName.Contains("kernel") And entry.FullName.EndsWith(".cl", StringComparison.OrdinalIgnoreCase)) Then
' If System.IO.Directory.Exists(AmdFolder & "\kernel\") = False Then
' System.IO.Directory.CreateDirectory(AmdFolder & "\kernel\")
' End If
' entry.ExtractToFile(AmdFolder & "\kernel\" & entry.Name, True)
' Else
' If Not entry.Name = "" Then
' entry.ExtractToFile(AmdFolder & "\" & entry.Name, True)
' End If
' End If
' End If
' Next
'End If
End Using
'Create default miner config
If System.IO.File.Exists(miner_config_file) = False Then
Dim objWriter As New System.IO.StreamWriter(miner_config_file)
objWriter.WriteLine(miner_config)
objWriter.Close()
End If
Dim result1 As DialogResult = MsgBox("Miner is ready to run", MessageBoxButtons.OK)
If result1 = DialogResult.OK Then
progress.Close()
update_complete = True
End If
If amdminer = True Then
amd_version = System.Convert.ToString(newestversion)
ElseIf nvidiaminer = True Then
nvidia_version = System.Convert.ToString(newestversion)
ElseIf cpuminer = True Then
cpu_version = System.Convert.ToString(newestversion)
End If
amdminer = False
nvidiaminer = False
cpuminer = False
update_needed = False
End If
Catch ex As Exception
MsgBox("An issue occurred during the download. Please try again.")
_logger.LogError(ex)
Invoke(New MethodInvoker(AddressOf SaveSettingsJSON))
Finally
_logger.Trace("MinerDownloadCompleted: OK.")
End Try
End Sub
Private Sub Client_P2PoolDownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
Try
If canceldownloadasync = False Then
'Download proper miner and extract into respective directories
zipPath = p2poolfolder & "\p2pool.zip"
exe = p2poolfolder & "\ocm_p2pool.exe"
p2pool_config_file = p2poolfolder & "\start_p2pool.bat"
p2pool_config = "ocm_p2pool.exe" & Environment.NewLine & "exit /B"
ZipFile.ExtractToDirectory(zipPath, p2poolfolder)
Dim folders() As String = IO.Directory.GetDirectories(p2poolfolder)
For Each folder As String In folders
Dim files() As String = IO.Directory.GetFiles(folder)
For Each file As String In files
If file.Contains("run_p2pool") Then
My.Computer.FileSystem.MoveFile(file, p2poolfolder & "\" & "ocm_p2pool.exe", True)
Else
My.Computer.FileSystem.MoveFile(file, p2poolfolder & "\" & System.IO.Path.GetFileName(file), True)
End If
Next
Dim subfolders() As String = IO.Directory.GetDirectories(folder)
For Each subfolder As String In subfolders
Dim split As String() = subfolder.Split("\")
Dim newfolder As String = split(split.Length - 1)
My.Computer.FileSystem.MoveDirectory(subfolder, p2poolfolder & "\" & newfolder, True)
Next
System.IO.Directory.Delete(folder)
Next
If System.IO.File.Exists(p2poolfolder & "\Start P2Pool Network 1.bat") = True Then
System.IO.File.Delete(p2poolfolder & "\Start P2Pool Network 1.bat")
End If
If System.IO.File.Exists(p2poolfolder & "\Start P2Pool Network 2.bat") = True Then
System.IO.File.Delete(p2poolfolder & "\Start P2Pool Network 2.bat")
End If
'Create default p2pool config
If System.IO.File.Exists(p2pool_config_file) = False Then
Dim objWriter As New System.IO.StreamWriter(p2pool_config_file)
objWriter.WriteLine(p2pool_config)
objWriter.Close()
End If
Invoke(New MethodInvoker(AddressOf Download_P2PoolInterface))
End If
Catch ex As Exception
MsgBox("An issue occurred during the download. Please try again.")
_logger.LogError(ex)
Invoke(New MethodInvoker(AddressOf SaveSettingsJSON))
Finally
_logger.Trace("P2PoolDownloadCompleted: OK.")
End Try
End Sub
Private Sub Client_P2PoolInterfaceDownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
Try
'Download proper miner and extract into respective directories
zipPath = p2poolfolder & "\interface.zip"
ZipFile.ExtractToDirectory(zipPath, p2poolfolder)
Dim folders() As String = IO.Directory.GetDirectories(p2poolfolder)
If System.IO.Directory.Exists(p2poolfolder & "\web-static") = True Then
System.IO.Directory.Delete(p2poolfolder & "\web-static", True)
End If
My.Computer.FileSystem.RenameDirectory(p2poolfolder & "\p2pool-ui-punchy-master", "web-static")
Dim result1 As DialogResult = MsgBox("P2Pool has been installed.", MessageBoxButtons.OK)
If result1 = DialogResult.OK Then
progress.Close()
Invoke(New MethodInvoker(AddressOf Check_RPC_Settings))
update_complete = True
BeginInvoke(New MethodInvoker(AddressOf Start_P2Pool))
End If
p2pool_version = System.Convert.ToString(newestversion)
Catch ex As Exception
MsgBox("An issue occurred during the download. Please try again.")
_logger.LogError(ex)
Invoke(New MethodInvoker(AddressOf SaveSettingsJSON))
Finally
_logger.Trace("P2PoolInterfaceDownloadCompleted: OK.")
End Try
End Sub
Public Sub StartWithWindows()
Dim regKey As Microsoft.Win32.RegistryKey
Dim KeyName As String = "VertcoinOneClick"
Dim KeyValue As String = System.Windows.Forms.Application.StartupPath & "\Vertcoin One-Click Miner.exe"
regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
If start_with_windows = True Then
'create key if it doesn't already exist
If regKey.GetValue(KeyName) = Nothing Then
regKey.SetValue(KeyName, KeyValue, Microsoft.Win32.RegistryValueKind.String)
End If
Else
'Delete key if it exists
If Not regKey.GetValue(KeyName) = Nothing Then
regKey.DeleteValue(KeyName, False)
End If
End If
End Sub
Public Sub Uptime_Checker_Status_Text()
'Miner Info
If amd_detected = True Or nvidia_detected = True Or cpu_detected = True Then
If miner_hashrate > 0 Then
TextBox2.Text = "Running"
Else
TextBox2.Text = "Waiting for share"
End If
Button3.Text = "Stop"
Else
TextBox2.Text = "Offline"
Button3.Text = "Start"
TextBox3.Text = "0 kh/s"
End If
'P2Pool Info
If p2pool_detected = True Then
If p2pool_loaded = True Then
TextBox1.Text = "Running: Network " & p2pool_network
Else
TextBox1.Text = "Loading"
End If
CheckBox1.Checked = True
Else
TextBox1.Text = "Offline"
CheckBox1.Checked = False
End If
End Sub
Public Sub Update_Miner_Text()
'Miner Hashrate
If api_connected = True Then
If miner_hashrate < 1000 Then
miner_hashrate = Math.Round(miner_hashrate, 2)
TextBox3.Text = miner_hashrate.ToString & " kh/s"
ElseIf miner_hashrate >= 1000 And miner_hashrate < 1000000 Then
miner_hashrate = Math.Round((miner_hashrate / 1000), 2)
TextBox3.Text = miner_hashrate.ToString & " Mh/s"
ElseIf miner_hashrate >= 1000000 And miner_hashrate < 1000000000 Then
miner_hashrate = Math.Round((miner_hashrate / 1000000), 2)
TextBox3.Text = miner_hashrate.ToString & " Gh/s"
ElseIf miner_hashrate >= 1000000000 And miner_hashrate < 1000000000000 Then
miner_hashrate = Math.Round((miner_hashrate / 1000000000), 2)
TextBox3.Text = miner_hashrate.ToString & " Th/s"
End If
Else
TextBox3.Text = "0 kh/s"
End If
End Sub
Public Sub Update_Pool_Info()
'Miner Info
DataGridView1.DataSource = Nothing
DataGridView1.Rows.Clear()
DataGridView1.Columns.Clear()
Dim poolcount = pools.Count()
Dim workercount = workers.Count()
Dim passwordcount = passwords.Count()
Dim count As Decimal = Decimal.MaxValue
count = Math.Min(count, poolcount)
count = Math.Min(count, workercount)
count = Math.Min(count, passwordcount)
Dim poolbuff As New ArrayList
For Each line As String In pools
If Not line.Contains("http://") And Not line.Contains("stratum+tcp://") Then
line = "stratum+tcp://" & line
Else
line = line.Replace("http://", "stratum+tcp://")
End If
poolbuff.Add(line)
Next
pools.Clear()
pools = poolbuff
Dim chk As New DataGridViewCheckBoxColumn()
DataGridView1.Columns.Add(chk)
chk.HeaderText = "Select"
chk.Name = "Select"
DataGridView1.ColumnCount = 4
With DataGridView1.Columns(1)
.Name = "Pool"
.AutoSizeMode = DataGridViewAutoSizeColumnsMode.AllCells
End With
With DataGridView1.Columns(2)
.Name = "Worker"
End With
With DataGridView1.Columns(3)
.Name = "Password"
End With
If selected.Count < count And count > 0 Then
For x As Integer = selected.Count To count - 1
selected.Add(False)
Next
End If
If count > 0 Then
For x As Integer = 0 To count - 1
Dim row As String() = New String() {selected(x), pools(x), workers(x), passwords(x)}
DataGridView1.Rows.Add(row)
Next
End If
End Sub
Public Sub Update_Settings()
Try
System.IO.File.Delete(settingsfolder & "\settings.ini")
Catch ex As IOException
_logger.LogError(ex)
Invoke(New MethodInvoker(AddressOf SaveSettingsJSON))
Finally
_logger.Trace("UpdateSettings: OK.")
End Try
End Sub
Public Sub LoadSettingsJSON()
Try
Dim settingsJSON As Settings_JSON = New Settings_JSON()
Dim settings_string As String = File.ReadAllText(settingsfile)
If Not String.IsNullOrEmpty(settings_string) Then
settingsJSON = JSONConverter.Deserialize(Of Settings_JSON)(settings_string)
End If
appdata = settingsJSON.appdata
start_minimized = settingsJSON.start_minimized
start_with_windows = settingsJSON.start_with_windows
autostart_p2pool = settingsJSON.autostart_p2pool
autostart_mining = settingsJSON.autostart_mining
keep_miner_alive = settingsJSON.keep_miner_alive
keep_p2pool_alive = settingsJSON.keep_p2pool_alive
use_upnp = settingsJSON.use_upnp
show_cli = settingsJSON.show_cli
p2pool_network = settingsJSON.p2pool_network
p2pool_node_fee = settingsJSON.p2pool_node_fee
p2pool_donation = settingsJSON.p2pool_donation
max_connections = settingsJSON.max_connections
p2pool_port = settingsJSON.p2pool_port
mining_port = settingsJSON.mining_port
mining_intensity = settingsJSON.mining_intensity
p2pool_fee_address = settingsJSON.p2pool_fee_address
p2pool_version = settingsJSON.p2pool_version
amd_version = settingsJSON.amd_version
nvidia_version = settingsJSON.nvidia_version
cpu_version = settingsJSON.cpu_version
default_miner = settingsJSON.default_miner
devices = settingsJSON.devices
pools.Clear()
workers.Clear()
passwords.Clear()
selected.Clear()
Dim count = settingsJSON.pools.Count
If Not count = 0 Then
For x = 0 To count - 1
If Not settingsJSON.pools(x).url = "" And Not settingsJSON.pools(x).user = "" And Not settingsJSON.pools(x).pass = "" Then
Dim jsonstring = JSONConverter.Serialize(settingsJSON.pools(x))
Dim poolJSON = JSONConverter.Deserialize(Of Pools_JSON)(jsonstring)
pools.Add(poolJSON.url)
workers.Add(poolJSON.user)
passwords.Add(poolJSON.pass)
selected.Add(poolJSON.checked)
End If
Next
End If
Invoke(New MethodInvoker(AddressOf Update_Pool_Info))
Catch ex As IOException
_logger.LogError(ex)
Finally
_logger.Trace("LoadSettings: OK.")
End Try
End Sub
Public Sub SaveSettingsJSON()
Try
pools.Clear()
workers.Clear()
passwords.Clear()
selected.Clear()
For Each row As DataGridViewRow In DataGridView1.Rows
Dim chk As DataGridViewCheckBoxCell = row.Cells(DataGridView1.Columns(0).Name)
If chk.Value IsNot Nothing Then
pools.Add(DataGridView1.Rows(chk.RowIndex).Cells(1).Value)
workers.Add(DataGridView1.Rows(chk.RowIndex).Cells(2).Value)
passwords.Add(DataGridView1.Rows(chk.RowIndex).Cells(3).Value)
If chk.Value = False Then
selected.Add(False)
Else
selected.Add(True)
End If
End If
Next
Dim newjson As Settings_JSON = New Settings_JSON()
newjson.appdata = appdata
newjson.start_minimized = start_minimized
newjson.start_with_windows = start_with_windows
newjson.autostart_p2pool = autostart_p2pool
newjson.autostart_mining = autostart_mining
newjson.keep_miner_alive = keep_miner_alive
newjson.keep_p2pool_alive = keep_p2pool_alive
newjson.use_upnp = use_upnp
newjson.show_cli = show_cli
newjson.p2pool_network = p2pool_network
newjson.p2pool_node_fee = p2pool_node_fee
newjson.p2pool_donation = p2pool_donation
newjson.max_connections = max_connections
newjson.p2pool_port = p2pool_port
newjson.mining_port = mining_port
newjson.mining_intensity = mining_intensity
newjson.p2pool_fee_address = p2pool_fee_address
newjson.p2pool_version = p2pool_version
newjson.amd_version = amd_version
newjson.nvidia_version = nvidia_version
newjson.cpu_version = cpu_version
newjson.default_miner = default_miner
newjson.devices = devices
newjson.pools.Clear()
Dim poolcount = pools.Count()
Dim workercount = workers.Count()
Dim passwordcount = passwords.Count()
Dim count As Decimal = Decimal.MaxValue
count = Math.Min(count, poolcount)
count = Math.Min(count, workercount)
count = Math.Min(count, passwordcount)
If Not count = 0 Then
For x = 0 To count - 1
If Not pools(x) = "" And Not workers(x) = "" And Not passwords(x) = "" Then
Dim pooljson As Pools_JSON = New Pools_JSON()
pooljson.url = pools(x)
pooljson.user = workers(x)
pooljson.pass = passwords(x)
pooljson.checked = selected(x)
newjson.pools.Add(pooljson)
End If
Next
End If
Dim jsonstring = JSONConverter.Serialize(newjson)
If Not String.IsNullOrEmpty(jsonstring) Then
Dim jsonFormatted As String = JValue.Parse(jsonstring).ToString(Formatting.Indented)
File.WriteAllText(settingsfile, jsonFormatted)
End If
Catch ex As IOException
_logger.LogError(ex)
Finally
_logger.Trace("SaveSettings: OK.")
End Try
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If p2pool_network = "1" Then
If mining_port = "9181" Or mining_port = "" Then
mining_port = "9171"
End If
ElseIf p2pool_network = "2" Then
If mining_port = "9171" Or mining_port = "" Then
mining_port = "9181"
End If
End If
Dim pool_list = String.Join(",", pools.ToArray())
If CheckBox1.Checked = True Then
If Not pool_list.Contains("stratum+tcp://localhost:" & mining_port) Then
Dim dialog = New AddPool(_logger)
dialog.Show()
dialog.Pool_Address.Text = "stratum+tcp://localhost:" & mining_port
End If
End If
'See if P2Pool has already been downloaded/installed
If System.IO.Directory.Exists(p2poolfolder) = True Then
For Each file As String In Directory.GetFiles(p2poolfolder)
If file.Contains("ocm_p2pool.exe") And Not (System.Version.Parse(p2pool_version) = System.Version.Parse("0.0.0.0")) Then
p2pool_installed = True
Exit For
Else
p2pool_installed = False
End If
Next
End If
'Starts p2pool if p2pool software is already detected. If not, downloads p2pool software.
If CheckBox1.Checked = True Then
If p2pool_installed = True Then
Invoke(New MethodInvoker(AddressOf Check_RPC_Settings))
If p2pool_initialized = True Then
BeginInvoke(New MethodInvoker(AddressOf Start_P2Pool))
End If
Else
If Not Updater.IsBusy Then
p2pool_update = True
canceldownloadasync = False
Updater.RunWorkerAsync()
End If
End If
Else
p2pool_initialized = False
BeginInvoke(New MethodInvoker(AddressOf Kill_P2Pool))
End If
p2pool_installed = False
End Sub
Private Sub EditToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EditToolStripMenuItem.Click
Dim dialog = New settings(_logger)
dialog.Show()
End Sub
Public Sub Update_P2Pool_Config()
Try
exe = settingsfolder & "\p2pool\ocm_p2pool.exe"
p2pool_config_file = settingsfolder & "\p2pool\start_p2pool.bat"
Dim network As String = ""
If p2pool_network = "0" Or p2pool_network = "1" Then
network = " --net vertcoin"
'Allows any custom port other than default ports.
If p2pool_port = "9347" Then
p2pool_port = "9346"
End If
If mining_port = "9181" Then
mining_port = "9171"
End If
ElseIf p2pool_network = "2" Then
network = " --net vertcoin2"
'Allows any custom port other than default ports.
If p2pool_port = "9346" Then
p2pool_port = "9347"
End If
If mining_port = "9171" Then
mining_port = "9181"
End If
End If
If Not appdata.Contains("AppData") Then
p2pool_config = "ocm_p2pool.exe" & network & " --give-author " & p2pool_donation & " --fee " & p2pool_node_fee & " --address " & p2pool_fee_address & " --max-conns " & max_connections & " --worker-port " & mining_port & " --p2pool-port " & p2pool_port & " --bitcoind-config-path """ & appdata & "\vertcoin.conf""" & Environment.NewLine & "exit /B"
Else
p2pool_config = "ocm_p2pool.exe" & network & " --give-author " & p2pool_donation & " --fee " & p2pool_node_fee & " --address " & p2pool_fee_address & " --max-conns " & max_connections & " --worker-port " & mining_port & " --p2pool-port " & p2pool_port & Environment.NewLine & "exit /B"
End If
If System.IO.File.Exists(p2pool_config_file) = True Then
command = File.ReadAllText(p2pool_config_file)
End If
If Not p2pool_config = command Then
command = p2pool_config
File.WriteAllText(p2pool_config_file, command)
End If
Catch ex As Exception
MsgBox(ex.Message)
_logger.LogError(ex)
Invoke(New MethodInvoker(AddressOf SaveSettingsJSON))
Finally
_logger.Trace("Update_P2Pool_Config: OK.")
End Try
End Sub
Public Sub Update_Miner_Config()
Try
'JSON Configuration
pools.Clear()
workers.Clear()
passwords.Clear()
Dim newjson
Dim jsonstring As String = ""
For Each row As DataGridViewRow In DataGridView1.Rows
Dim chk As DataGridViewCheckBoxCell = row.Cells(DataGridView1.Columns(0).Name)
If chk.Value IsNot Nothing AndAlso chk.Value = True Then 'add AndAlso chk.Value = True to only add pools that are checked