-
Notifications
You must be signed in to change notification settings - Fork 3
/
NPlusMiner.ps1
2104 lines (1861 loc) · 115 KB
/
NPlusMiner.ps1
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
<#
This file is part of NPlusMiner
Copyright (c) 2018-2020 MrPlus
NPlusMiner is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
NPlusMiner is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
#>
<#
Product: NPlusMiner
File: NPlusMiner.ps1
version: 7.3.2
version date: 20200509
#>
param(
[Parameter(Mandatory=$false)]
[String]$Wallet = "134bw4oTorEJUUVFhokDQDfNqTs7rBMNYy",
[Parameter(Mandatory=$false)]
[String]$UserName = "MrPlus",
[Parameter(Mandatory=$false)]
[String]$WorkerName = "ID=NPlusMiner2.2",
[Parameter(Mandatory=$false)]
[Int]$API_ID = 0,
[Parameter(Mandatory=$false)]
[String]$API_Key = "",
[Parameter(Mandatory=$false)]
[Int]$Interval = 180, #seconds before between cycles after the first has passed
[Parameter(Mandatory=$false)]
[Int]$FirstInterval = 30, #seconds of the first cycle of activated or started first time miner
[Parameter(Mandatory=$false)]
[Int]$StatsInterval = 300, #seconds of current active to gather hashrate if not gathered yet
[Parameter(Mandatory=$false)]
[String]$Location = "US", #europe/us/asia
[Parameter(Mandatory=$false)]
[Switch]$SSL = $false,
[Parameter(Mandatory=$false)]
[Array]$Type = "nvidia", #AMD/NVIDIA/CPU
[Parameter(Mandatory=$false)]
[String]$SelGPUDSTM = "0 1",
[Parameter(Mandatory=$false)]
[String]$SelGPUCC = "0,1",
[Parameter(Mandatory=$false)]
[Array]$Algorithm = $null, #i.e. Ethash,Equihash,Cryptonight ect.
[Parameter(Mandatory=$false)]
[Array]$MinerName = $null,
[Parameter(Mandatory=$false)]
[Array]$PoolName = $null,
[Parameter(Mandatory=$false)]
[Array]$Currency = ("USD"), #i.e. GBP,USD,AUD,NZD ect.
[Parameter(Mandatory=$false)]
[Array]$Passwordcurrency = ("BTC"), #i.e. BTC,LTC,ZEC,ETH ect.
[Parameter(Mandatory=$false)]
[Int]$Donate = 5, #Minutes per Day
[Parameter(Mandatory=$false)]
[String]$Proxy = "", #i.e http://192.0.0.1:8080
[Parameter(Mandatory=$false)]
[Int]$Delay = 1, #seconds before opening each miner
[Parameter(Mandatory=$false)]
[Int]$GPUCount = 1, # Number of GPU on the system
[Parameter(Mandatory=$false)]
[Int]$ActiveMinerGainPct = 5, # percent of advantage that active miner has over candidates in term of profit
[Parameter(Mandatory=$false)]
[Float]$MarginOfError = 0, #0.4, # knowledge about the past wont help us to predict the future so don't pretend that Week_Fluctuation means something real
[Parameter(Mandatory=$false)]
[String]$UIStyle = "Light", # Light or Full. Defines level of info displayed
[Parameter(Mandatory=$false)]
[Bool]$TrackEarnings = $True, # Display earnings information
[Parameter(Mandatory=$false)]
[Bool]$Autoupdate = $True, # Autoupdate
[Parameter(Mandatory=$false)]
[String]$ConfigFile = ".\Config\config.json"
)
. .\Includes\include.ps1
. .\Includes\Core.ps1
@"
NPlusMiner
Copyright (c) 2018-2020 MrPlus
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
https://github.com/MrPlusGH/NPlusMiner/blob/master/LICENSE
NPlusMiner is licensed under the GNU General Public License v3.0
Permissions of this strong copyleft license are conditioned on making
available complete source code of licensed works and modifications,
which include larger works using a licensed work, under the same license.
"@
Write-Host -F Yellow " Copyright and license notices must be preserved."
@"
+
"@
$Global:Config = [hashtable]::Synchronized(@{})
$Global:Config | Add-Member -Force @{ConfigFile = $ConfigFile}
$Global:Variables = [hashtable]::Synchronized(@{})
$Global:Variables | Add-Member -Force -MemberType ScriptProperty -Name 'StatusText' -Value{ $this._StatusText;$This._StatusText = [System.Collections.ArrayList]::Synchronized(@()) } -SecondValue { If (!$this._StatusText){$this._StatusText=[System.Collections.ArrayList]::Synchronized(@())};$this._StatusText+=$args[0];$Variables.RefreshNeeded = $True }
# Set Console size
$ConsoleHeight = 50
$ConsoleWidth = 160
$pswindow = (get-host).ui.rawui
$newsize = $pswindow.buffersize
# $newsize.height = 3000
$newsize.width = $ConsoleWidth
$pswindow.buffersize = $newsize
$newsize = $pswindow.windowsize
# $newsize.height = $ConsoleHeight
$newsize.width = $ConsoleWidth
$pswindow.windowsize = $newsize
rv ConsoleHeight, ConsoleWidth, pswindow, newsize
# Load Branding
If (Test-Path ".\Config\Branding.json") {
$Branding = Get-Content ".\Config\Branding.json" | ConvertFrom-Json
} Else {
$Branding = [PSCustomObject]@{
LogoPath = "https://raw.githubusercontent.com/MrPlusGH/NPlusMiner/master/Includes/NPM.png"
BrandName = "NPlusMiner"
BrandWebSite = "https://github.com/MrPlusGH/NPlusMiner"
ProductLable = "NPlusMiner"
}
}
Function Global:TimerUITick
{
$TimerUI.Stop()
# If something (pause button, idle timer) has set the RestartCycle flag, stop and start mining to switch modes immediately
If ($Variables.RestartCycle) {
$Variables.RestartCycle = $False
Stop-Mining
Start-Mining
If ($Variables.Paused) {
$EarningsDGV.DataSource = [System.Collections.ArrayList]@()
$RunningMinersDGV.DataSource = [System.Collections.ArrayList]@()
$LabelBTCD.ForeColor = "Red"
$TimerUI.Stop()
}
}
If ($Variables.RefreshNeeded -and $Variables.Started -and -not $Variables.Paused) {
If (!$Variables.EndLoop) {Update-Status($Variables.StatusText)}
# $TimerUI.Interval = 1
$LabelBTCD.ForeColor = "Green"
Start-ChildJobs
$Variables.EarningsTrackerJobs | ? {$_.state -eq "Running"} | foreach {
$EarnTrack = $_ | Receive-Job
If ($EarnTrack) {
# $Variables.Earnings = @{}
$EarnTrack | ? {$_.Pool -ne ""} | sort date,pool | select -Last ($EarnTrack.Pool | Sort -Unique).Count | ForEach {
If ($true) { #$_.Pool -in ($config.PoolName -replace "24hr","" -replace "plus","")) {
$Variables.EarningsPool = $_.Pool
$Variables.Earnings.($_.Pool) = $_
$Variables.Earnings.($_.Pool).PaymentThreshold =
If ($Config.PoolsConfig.($_.Pool).PayoutThreshold.($Config.Passwordcurrency)) {
$Config.PoolsConfig.($_.Pool).PayoutThreshold.($Config.Passwordcurrency)
} Else {
$_.PaymentThreshold
}
}
}
rv EarnTrack
}
}
If ((compare -ReferenceObject $CheckedListBoxPools.Items -DifferenceObject ((Get-ChildItem ".\Pools").BaseName | sort -Unique) | ? {$_.SideIndicator -eq "=>"}).InputObject -gt 0) {
(compare -ReferenceObject $CheckedListBoxPools.Items -DifferenceObject ((Get-ChildItem ".\Pools").BaseName | sort -Unique) | ? {$_.SideIndicator -eq "=>"}).InputObject | % { if ($_ -ne $null){}$CheckedListBoxPools.Items.AddRange($_)}
$Config.PoolName | foreach {$CheckedListBoxPools.SetItemChecked($CheckedListBoxPools.Items.IndexOf($_),$True)}
}
$Variables.InCycle = $True
# $MainForm.Number+=1
$MainForm.Text = $Branding.ProductLable + " " + $Variables.CurrentVersion + " Runtime " + ("{0:dd\ \d\a\y\s\ hh\:mm}" -f ((get-date)-$Variables.ScriptStartDate)) + " Path: " + (Split-Path $script:MyInvocation.MyCommand.Path)
$host.UI.RawUI.WindowTitle = $Branding.ProductLable + " " + $Variables.CurrentVersion + " Runtime " + ("{0:dd\ \d\a\y\s\ hh\:mm}" -f ((get-date)-$Variables.ScriptStartDate)) + " Path: " + (Split-Path $script:MyInvocation.MyCommand.Path)
If ($Variables.EndLoop) {
$SwitchingDisplayTypes = @()
$SwitchingPageControls | foreach {if ($_.Checked){$SwitchingDisplayTypes += $_.Tag}}
# If (Test-Path ".\Logs\switching.log"){$SwitchingArray = [System.Collections.ArrayList]@(Import-Csv ".\Logs\switching.log" | ? {$_.Type -in $SwitchingDisplayTypes} | Select -Last 13)}
# If (Test-Path ".\Logs\switching.log"){$SwitchingArray = [System.Collections.ArrayList]@(Import-Csv ".\Logs\switching.log" | ? {$_.Type -in $SwitchingDisplayTypes} | Select -Last 13)}
If (Test-Path ".\Logs\switching.log"){$SwitchingArray = [System.Collections.ArrayList]@(@((get-content ".\Logs\switching.log" -First 1) , (get-content ".\logs\switching.log" -last 50)) | ConvertFrom-Csv | ? {$_.Type -in $SwitchingDisplayTypes} | Select -Last 13)}
$SwitchingDGV.DataSource = $SwitchingArray
# Fixed memory leak to to chart object not being properly disposed in 5.3.0
# https://stackoverflow.com/questions/8466343/why-controls-do-not-want-to-get-removed
If (Test-Path ".\logs\DailyEarnings.csv"){
$Chart1 = Invoke-Expression -Command ".\Includes\Charting.ps1 -Chart 'Front7DaysEarnings' -Width 505 -Height 85 -Currency $($Config.Passwordcurrency)"
$Chart1.top = 74
$Chart1.left = 0
$RunPage.Controls.Add($Chart1)
$Chart1.BringToFront()
$Chart2 = Invoke-Expression -Command ".\Includes\Charting.ps1 -Chart 'DayPoolSplit' -Width 200 -Height 85 -Currency $($Config.Passwordcurrency)"
$Chart2.top = 74
$Chart2.left = 500
$RunPage.Controls.Add($Chart2)
$Chart2.BringToFront()
$RunPage.Controls | ? {($_.gettype()).name -eq "Chart" -and $_ -ne $Chart1 -and $_ -ne $Chart2} | % {$RunPage.Controls[$RunPage.Controls.IndexOf($_)].Dispose();$RunPage.Controls.Remove($_)}
}
If ($Variables.Earnings -and $Config.TrackEarnings) {
$DisplayEarnings = [System.Collections.ArrayList]@($Variables.Earnings.Values | select @(
@{Name="Pool";Expression={$_.Pool}},
@{Name="Trust";Expression={"{0:P0}" -f $_.TrustLevel}},
@{Name="Balance";Expression={$_.Balance}},
# @{Name="Unpaid";Expression={$_.total_unpaid}},
# @{Name="BTC/D";Expression={"{0:N8}" -f ($_.BTCD)}},
@{Name="1h $((Get-DisplayCurrency $_.Growth1 24).UnitStringPerDay)";Expression={(Get-DisplayCurrency $_.Growth1 24).RoundedValue}},
@{Name="6h $((Get-DisplayCurrency $_.Growth6 4).UnitStringPerDay)";Expression={(Get-DisplayCurrency $_.Growth6 4).RoundedValue}},
@{Name="24h $((Get-DisplayCurrency $_.Growth24).UnitStringPerDay)";Expression={(Get-DisplayCurrency $_.Growth24).RoundedValue}},
@{Name = "Est. Pay Date"; Expression = {if ($_.EstimatedPayDate -is 'DateTime') {$_.EstimatedPayDate.ToShortDateString()} else {$_.EstimatedPayDate}}},
@{Name="PaymentThreshold";Expression={"$($_.PaymentThreshold) ($('{0:P0}' -f $($_.Balance / $_.PaymentThreshold)))"}}#,
# @{Name="Wallet";Expression={$_.Wallet}}
) | Sort "1h $((Get-DisplayCurrency $_.Growth1 24).UnitStringPerDay)","6h $((Get-DisplayCurrency $_.Growth6 4).UnitStringPerDay)","24h $((Get-DisplayCurrency $_.Growth24).UnitStringPerDay)" -Descending)
$EarningsDGV.DataSource = [System.Collections.ArrayList]@($DisplayEarnings)
$EarningsDGV.ClearSelection()
}
If ($Variables.Miners) {
$DisplayEstimations = [System.Collections.ArrayList]@($Variables.Miners | Select @(
@{Name = "Type";Expression={$_.Type}},
@{Name = "Miner";Expression={$_.Name}},
@{Name = "Algorithm";Expression={$_.HashRates.PSObject.Properties.Name}},
@{Name = "Coin"; Expression={$_.Pools.PSObject.Properties.Value | ForEach {"$($_.Info)"}}},
@{Name = "Pool"; Expression={$_.Pools.PSObject.Properties.Value | ForEach {"$($_.Name)"}}},
@{Name = "Speed"; Expression={$_.HashRates.PSObject.Properties.Value | ForEach {if($_ -ne $null){"$($_ | ConvertTo-Hash)/s"}else{"Benchmarking"}}}},
# @{Name = "mBTC/Day"; Expression={$_.Profits.PSObject.Properties.Value | ForEach {if($_ -ne $null){($_*1000).ToString("N3")}else{"Benchmarking"}}}},
@{Name = "mBTC/Day"; Expression={(($_.Profits.PSObject.Properties.Value | Measure -Sum).Sum *1000).ToString("N3")}},
# @{Name = "BTC/Day"; Expression={$_.Profits.PSObject.Properties.Value | ForEach {if($_ -ne $null){$_.ToString("N5")}else{"Benchmarking"}}}},
@{Name = "BTC/Day"; Expression={(($_.Profits.PSObject.Properties.Value | Measure -Sum).Sum).ToString("N3")}},
# @{Name = "BTC/GH/Day"; Expression={$_.Pools.PSObject.Properties.Value.Price | ForEach {($_*1000000000).ToString("N15")}}}
@{Name = "BTC/GH/Day"; Expression={(($_.Pools.PSObject.Properties.Value.Price | Measure -Sum).Sum *1000000000).ToString("N5")}}
) | sort "mBTC/Day" -Descending)
If ($Config.ShowOnlyTopCoins){
$EstimationsDGV.DataSource = [System.Collections.ArrayList]@($DisplayEstimations | sort "mBTC/Day" -Descending | Group "Type","Algorithm" | % { $_.Group | select -First 1} | sort "mBTC/Day" -Descending)
} else {
$EstimationsDGV.DataSource = [System.Collections.ArrayList]@($DisplayEstimations)
}
$EstimationsDGV.Columns["mBTC/Day"].DefaultCellStyle.BackColor = [System.Drawing.Color]::LightGray
}
$EstimationsDGV.ClearSelection()
$SwitchingDGV.ClearSelection()
If ($Variables.Workers -and $Config.ShowWorkerStatus) {
$DisplayWorkers = [System.Collections.ArrayList]@($Variables.Workers | select @(
@{Name = "Worker"; Expression = {$_.worker}},
@{Name = "Status"; Expression = {$_.status}},
@{Name = "Last Seen"; Expression = {$_.timesincelastreport}},
@{Name = "Version"; Expression = {$_.version}},
@{Name = "Est. BTC/Day"; Expression = {[decimal]$_.profit}},
@{Name = "Miner"; Expression = {$_.data.name -join ','}},
@{Name = "Pool"; Expression = {$_.data.pool -join ','}},
@{Name = "Algo"; Expression = {$_.data.algorithm -join ','}},
@{Name = "Speed"; Expression = {if ($_.data.currentspeed) {($_.data.currentspeed | ConvertTo-Hash) -join ','} else {""}}},
@{Name = "Benchmark Speed"; Expression = {if ($_.data.estimatedspeed) {($_.data.estimatedspeed | ConvertTo-Hash) -join ','} else {""}}}
) | Sort "Worker Name")
$WorkersDGV.DataSource = [System.Collections.ArrayList]@($DisplayWorkers)
# Set row color
$WorkersDGV.Rows | ForEach-Object {
if ($_.DataBoundItem.Status -eq "Offline") {
$_.DefaultCellStyle.Backcolor = [System.Drawing.Color]::FromArgb(255, 213, 142, 176)
}
elseif ($_.DataBoundItem.Status -eq "Paused") {
$_.DefaultCellStyle.Backcolor = [System.Drawing.Color]::FromArgb(255, 247, 252, 168)
}
elseif ($_.DataBoundItem.Status -eq "Running") {
$_.DefaultCellStyle.Backcolor = [System.Drawing.Color]::FromArgb(255, 127, 191, 144)
}
else {
$_.DefaultCellStyle.Backcolor = [System.Drawing.Color]::FromArgb(255, 255, 255, 255)
}
}
$WorkersDGV.ClearSelection()
$LabelMonitoringWorkers.text = "Worker Status - Updated $($Variables.WorkersLastUpdated.ToString())"
}
If ($Variables.ActiveMinerPrograms) {
# $RunningMinersDGV.DataSource = [System.Collections.ArrayList]@($Variables.ActiveMinerPrograms | ? {$_.Status -eq "Running"} | select Type,Algorithms,Coin,Name,@{Name="HashRate";Expression={"$($_.HashRate | ConvertTo-Hash)/s"}},@{Name="Active";Expression={"{0:hh}:{0:mm}:{0:ss}" -f $_.Active}},@{Name="Total Active";Expression={"{0:hh}:{0:mm}:{0:ss}" -f $_.TotalActive}},Host | sort Type)
$RunningMinersDGV.DataSource = [System.Collections.ArrayList]@($Variables.ActiveMinerPrograms.Clone() | ? {$_.Status -eq "Running"} | select @(
@{Name = "Type";Expression={$_.Type}},
@{Name = "Algorithm";Expression={$_.Algorithms}},
@{Name = "Coin"; Expression={$_.Coin}},
@{Name = "Miner";Expression={$_.Name}},
@{Name="HashRate";Expression={"$($_.HashRate | ConvertTo-Hash)/s"}},
@{Name ="Active";Expression={"{0:hh}:{0:mm}:{0:ss}" -f $_.Active}},
@{Name ="Total Active";Expression={"{0:hh}:{0:mm}:{0:ss}" -f $_.TotalActive}},
@{Name = "Pool"; Expression={$_.Pools.PSObject.Properties.Value | ForEach {"$($_.Name)"}}} ) | sort Type
)
$RunningMinersDGV.ClearSelection()
[Array] $processRunning = $Variables.ActiveMinerPrograms | Where { $_.Status -eq "Running" }
If ($ProcessRunning -eq $null){
# Update-Status("No miner running")
}
}
$LabelBTCPrice.text = If($Variables.Rates.$Currency -gt 0){"$($Config.Passwordcurrency)/$($Config.Currency) $($Variables.Rates.($Config.Currency))"}
$Variables.InCycle = $False
If ($Variables.Earnings.Values -ne $Null){
$LabelBTCD.Text = "Avg: " + ((Get-DisplayCurrency ($Variables.Earnings.Values | measure -Property Growth24 -Sum).sum)).DisplayStringPerDay
$LabelEarningsDetails.Lines = @()
# If ((($Variables.Earnings.Values | measure -Property Growth1 -Sum).sum*1000*24) -lt ((($Variables.Earnings.Values | measure -Property BTCD -Sum).sum*1000)*0.999)) {
# $LabelEarningsDetails.ForeColor = "Red" } else { $LabelEarningsDetails.ForeColor = "Green" }
$TrendSign = switch ([Math]::Round((($Variables.Earnings.Values | measure -Property Growth1 -Sum).sum*1000*24),3) - [Math]::Round((($Variables.Earnings.Values | measure -Property Growth6 -Sum).sum*1000*4),3)) {
{$_ -eq 0}
{"="}
{$_ -gt 0}
{">"}
{$_ -lt 0}
{"<"}
}
$LabelEarningsDetails.Lines += "Last 1h: " + ((Get-DisplayCurrency ($Variables.Earnings.Values | measure -Property Growth1 -Sum).sum 24)).DisplayStringPerDay + " " + $TrendSign
$TrendSign = switch ([Math]::Round((($Variables.Earnings.Values | measure -Property Growth6 -Sum).sum*1000*4),3) - [Math]::Round((($Variables.Earnings.Values | measure -Property Growth24 -Sum).sum*1000),3)) {
{$_ -eq 0}
{"="}
{$_ -gt 0}
{">"}
{$_ -lt 0}
{"<"}
}
$LabelEarningsDetails.Lines += "Last 6h: " + ((Get-DisplayCurrency ($Variables.Earnings.Values | measure -Property Growth6 -Sum).sum 4)).DisplayStringPerDay + " " + $TrendSign
$TrendSign = switch ([Math]::Round((($Variables.Earnings.Values | measure -Property Growth24 -Sum).sum*1000),3) - [Math]::Round((($Variables.Earnings.Values | measure -Property BTCD -Sum).sum*1000*0.96),3)) {
{$_ -eq 0}
{"="}
{$_ -gt 0}
{">"}
{$_ -lt 0}
{"<"}
}
$LabelEarningsDetails.Lines += "Last 24h: " + ((Get-DisplayCurrency ($Variables.Earnings.Values | measure -Property Growth24 -Sum).sum)).DisplayStringPerDay + " " + $TrendSign
rv TrendSign
} else {
$LabelBTCD.Text = "Waiting data from pools."
$LabelEarningsDetails.Lines = @()
}
if (!(IsLoaded(".\Includes\include.ps1"))) {. .\Includes\include.ps1;RegisterLoaded(".\Includes\include.ps1")}
if (!(IsLoaded(".\Includes\Core.ps1"))) {. .\Includes\Core.ps1;RegisterLoaded(".\Includes\Core.ps1")}
$Variables.CurrentProduct = (Get-Content .\Version.json | ConvertFrom-Json).Product
$Variables.CurrentVersion = [Version](Get-Content .\Version.json | ConvertFrom-Json).Version
$Variables.CurrentVersionAutoUpdated = (Get-Content .\Version.json | ConvertFrom-Json).AutoUpdated.Value
if ((Get-Content .\Version.json | ConvertFrom-Json).AutoUpdated -and $LabelNotifications.Lines[$LabelNotifications.Lines.Count-1] -ne "Auto Updated on $($Variables.CurrentVersionAutoUpdated)"){
$LabelNotifications.ForeColor = "Green"
Update-Notifications("Running $($Variables.CurrentProduct) Version $([Version]$Variables.CurrentVersion)")
Update-Notifications("Auto Updated on $($Variables.CurrentVersionAutoUpdated)")
}
#Display mining information
if($host.UI.RawUI.KeyAvailable){$KeyPressed = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,IncludeKeyUp");sleep -Milliseconds 300;$host.UI.RawUI.FlushInputBuffer()
If ($KeyPressed.KeyDown){
Switch ($KeyPressed.Character) {
"s" {if ($Config.UIStyle -eq "Light"){$Config.UIStyle="Full"}else{$Config.UIStyle="Light"}}
"e" {$Config.TrackEarnings=-not $Config.TrackEarnings}
}}}
Clear-Host
[Array] $processesIdle = $Variables.ActiveMinerPrograms | Where { $_.Status -eq "Idle" }
IF ($Config.UIStyle -eq "Full"){
if ($processesIdle.Count -gt 0) {
Write-Host "Idle: " $processesIdle.Count
$processesIdle | Sort {if($_.Process -eq $null){(Get-Date)}else{$_.Process.ExitTime}} | Format-Table -Wrap (
@{Label = "Speed"; Expression={$_.HashRate | ForEach {"$($_ | ConvertTo-Hash)/s"}}; Align='right'},
@{Label = "Exited"; Expression={"{0:dd}:{0:hh}:{0:mm}" -f $(if($_.Process -eq $null){(0)}else{(Get-Date) - $_.Process.ExitTime}) }},
@{Label = "Active"; Expression={"{0:dd}:{0:hh}:{0:mm}" -f $(if($_.Process -eq $null){$_.Active}else{if($_.Process.ExitTime -gt $_.Process.StartTime){($_.Active+($_.Process.ExitTime-$_.Process.StartTime))}else{($_.Active+((Get-Date)-$_.Process.StartTime))}})}},
@{Label = "Cnt"; Expression={Switch($_.Activated){0 {"Never"} 1 {"Once"} Default {"$_"}}}},
@{Label = "Command"; Expression={"$($_.Path.TrimStart((Convert-Path ".\"))) $($_.Arguments)"}}
) | Out-Host
}
}
Write-Host " 1BTC = $($Variables.Rates.($Config.Currency)) $($Config.Currency)"
# Get and display earnings stats
If ($Variables.Earnings -and $Config.TrackEarnings) {
# $Variables.Earnings.Values | select Pool,Wallet,Balance,AvgDailyGrowth,EstimatedPayDate,TrustLevel | ft *
$Variables.Earnings.Values | foreach {
Write-Host "+++++" $_.Wallet -B DarkBlue -F DarkGray -NoNewline; Write-Host " " $_.pool "Balance="$_.balance ("{0:P0}" -f ($_.balance/$_.PaymentThreshold))
Write-Host "Trust Level " ("{0:P0}" -f $_.TrustLevel) -NoNewline; Write-Host -F darkgray " Avg based on [" ("{0:dd\ \d\a\y\s\ hh\:mm}" -f ($_.Date - $_.StartTime))"]"
Write-Host "Average BTC/H BTC =" ("{0:N8}" -f $_.AvgHourlyGrowth) "| mBTC =" ("{0:N3}" -f ($_.AvgHourlyGrowth*1000))
Write-Host "Average BTC/D" -NoNewline; Write-Host " BTC =" ("{0:N8}" -f ($_.BTCD)) "| mBTC =" ("{0:N3}" -f ($_.BTCD*1000)) -F Yellow
Write-Host "Estimated Pay Date " $_.EstimatedPayDate ">" $_.PaymentThreshold "BTC"
# Write-Host "+++++" -F Blue
}
}
Write-Host "+++++" -F Blue
if ($Variables.Miners | ? {$_.HashRates.PSObject.Properties.Value -eq $null}) {$Config.UIStyle = "Full"}
IF ($Config.UIStyle -eq "Full"){
# $Variables.Miners | Sort -Descending Type,Profit | Format-Table -GroupBy Type (
# @{Label = "Miner"; Expression={$_.Name}},
# @{Label = "Algorithm"; Expression={$_.HashRates.PSObject.Properties.Name}},
# @{Label = "Speed"; Expression={$_.HashRates.PSObject.Properties.Value | ForEach {if($_ -ne $null){"$($_ | ConvertTo-Hash)/s"}else{"Benchmarking"}}}; Align='right'},
# @{Label = "mBTC/Day"; Expression={$_.Profits.PSObject.Properties.Value*1000 | ForEach {if($_ -ne $null){$_.ToString("N3")}else{"Benchmarking"}}}; Align='right'},
# @{Label = "BTC/Day"; Expression={$_.Profits.PSObject.Properties.Value | ForEach {if($_ -ne $null){$_.ToString("N5")}else{"Benchmarking"}}}; Align='right'},
# @{Label = "$($Config.Currency)/Day"; Expression={$_.Profits.PSObject.Properties.Value | ForEach {if($_ -ne $null){($_ * $Variables.Rates.($Config.Currency)).ToString("N3")}else{"Benchmarking"}}}; Align='right'},
# @{Label = "BTC/GH/Day"; Expression={$_.Pools.PSObject.Properties.Value.Price | ForEach {($_*1000000000).ToString("N5")}}; Align='right'},
# @{Label = "Pool"; Expression={$_.Pools.PSObject.Properties.Value | ForEach {"$($_.Name)-$($_.Info)"}}}
# ) | Out-Host
If ($Config.ShowOnlyTopCoins){
$DisplayEstimations | sort "mBTC/Day" -Descending | Group "Type","Algorithm" | % { $_.Group | select -First 1} | sort Type,"mBTC/Day" -Descending | Format-Table -GroupBy Type | Out-Host
} else {
$DisplayEstimations | sort Type,"mBTC/Day" -Descending | Format-Table -GroupBy Type | Out-Host
}
#Display active miners list
[Array] $processRunning = $Variables.ActiveMinerPrograms | Where { $_.Status -eq "Running" }
Write-Host "Running:"
$processRunning | Sort {if($_.Process -eq $null){[DateTime]0}else{$_.Process.StartTime}} | Format-Table -Wrap (
@{Label = "Speed"; Expression={$_.HashRate | ForEach {"$($_ | ConvertTo-Hash)/s"}}; Align='right'},
@{Label = "Started"; Expression={"{0:dd}:{0:hh}:{0:mm}" -f $(if($_.Process -eq $null){(0)}else{(Get-Date) - $_.Process.StartTime}) }},
@{Label = "Active"; Expression={"{0:dd}:{0:hh}:{0:mm}" -f $(if($_.Process -eq $null){$_.Active}else{if($_.Process.ExitTime -gt $_.Process.StartTime){($_.Active+($_.Process.ExitTime-$_.Process.StartTime))}else{($_.Active+((Get-Date)-$_.Process.StartTime))}})}},
@{Label = "Cnt"; Expression={Switch($_.Activated){0 {"Never"} 1 {"Once"} Default {"$_"}}}},
@{Label = "Command"; Expression={"$($_.Path.TrimStart((Convert-Path ".\"))) $($_.Arguments)"}}
) | Out-Host
[Array] $processesFailed = $Variables.ActiveMinerPrograms | Where { $_.Status -eq "Failed" }
if ($processesFailed.Count -gt 0) {
Write-Host -ForegroundColor Red "Failed: " $processesFailed.Count
$processesFailed | Sort {if($_.Process -eq $null){[DateTime]0}else{$_.Process.StartTime}} | Format-Table -Wrap (
@{Label = "Speed"; Expression={$_.HashRate | ForEach {"$($_ | ConvertTo-Hash)/s"}}; Align='right'},
@{Label = "Exited"; Expression={"{0:dd}:{0:hh}:{0:mm}" -f $(if($_.Process -eq $null){(0)}else{(Get-Date) - $_.Process.ExitTime}) }},
@{Label = "Active"; Expression={"{0:dd}:{0:hh}:{0:mm}" -f $(if($_.Process -eq $null){$_.Active}else{if($_.Process.ExitTime -gt $_.Process.StartTime){($_.Active+($_.Process.ExitTime-$_.Process.StartTime))}else{($_.Active+((Get-Date)-$_.Process.StartTime))}})}},
@{Label = "Cnt"; Expression={Switch($_.Activated){0 {"Never"} 1 {"Once"} Default {"$_"}}}},
@{Label = "Command"; Expression={"$($_.Path.TrimStart((Convert-Path ".\"))) $($_.Arguments)"}}
) | Out-Host
}
Write-Host "--------------------------------------------------------------------------------"
} else {
[Array] $processRunning = $Variables.ActiveMinerPrograms | Where { $_.Status -eq "Running" }
Write-Host "Running:"
$processRunning | Sort {if($_.Process -eq $null){[DateTime]0}else{$_.Process.StartTime}} | Format-Table -Wrap (
@{Label = "Speed"; Expression={$_.HashRate | ForEach {"$($_ | ConvertTo-Hash)/s"}}; Align='right'},
@{Label = "Started"; Expression={"{0:dd}:{0:hh}:{0:mm}" -f $(if($_.Process -eq $null){(0)}else{(Get-Date) - $_.Process.StartTime}) }},
@{Label = "Active"; Expression={"{0:dd}:{0:hh}:{0:mm}" -f $(if($_.Process -eq $null){$_.Active}else{if($_.Process.ExitTime -gt $_.Process.StartTime){($_.Active+($_.Process.ExitTime-$_.Process.StartTime))}else{($_.Active+((Get-Date)-$_.Process.StartTime))}})}},
@{Label = "Cnt"; Expression={Switch($_.Activated){0 {"Never"} 1 {"Once"} Default {"$_"}}}},
@{Label = "Command"; Expression={"$($_.Path.TrimStart((Convert-Path ".\"))) $($_.Arguments)"}}
) | Out-Host
Write-Host "--------------------------------------------------------------------------------"
}
Write-Host -ForegroundColor Yellow "Last refresh: $(Get-Date) | Next refresh: $((Get-Date).AddSeconds($Variables.TimeToSleep))"
Update-Status($Variables.StatusText)
}
if (Test-Path ".\EndUIRefresh.ps1"){Invoke-Expression (Get-Content ".\EndUIRefresh.ps1" -Raw)}
$Variables.RefreshNeeded = $False
}
$TimerUI.Start()
}
Function Form_Load
{
$DblBuff = ($MainForm.GetType()).GetProperty("DoubleBuffered", ('Instance','NonPublic'))
$DblBuff.SetValue($MainForm, $True, $null)
$MainForm.Text = "$($Branding.ProductLable) $($Variables.CurrentVersion)"
$LabelBTCD.Text = "$($Branding.ProductLable) $($Variables.CurrentVersion)"
$MainForm.Number = 0
$TimerUI.Add_Tick({
# Timer never disposes objects until it is disposed
$MainForm.Number = $MainForm.Number + 1
$TimerUI.Stop()
TimerUITick
If ($MainForm.Number -gt 6000) {
# Write-Host -B R "Releasing Timer"
$MainForm.Number = 0
# $TimerUI.Stop()
$TimerUI.Remove_Tick({TimerUITick})
$TimerUI.Dispose()
$TimerUI = New-Object System.Windows.Forms.Timer
$TimerUI.Add_Tick({TimerUITick})
# $TimerUI.Start()
}
$TimerUI.Start()
})
$TimerUI.Interval = 50
$TimerUI.Stop()
If ($CheckBoxConsole.Checked) {
$null = $ShowWindow::ShowWindowAsync($ConsoleHandle, 0)
Update-Status("Console window hidden")
}
else {
$null = $ShowWindow::ShowWindowAsync($ConsoleHandle, 8)
# Update-Status("Console window shown")
}
}
Function CheckedListBoxPools_Click ($Control) {
$Config | Add-Member -Force @{$Control.Tag = $Control.CheckedItems}
$EarningTrackerConfig = Get-Content ".\Config\EarningTrackerConfig.json" | ConvertFrom-JSON
$EarningTrackerConfig | Add-Member -Force @{"Pools" = ($Control.CheckedItems.Replace("24hr", "")).Replace("Plus", "") | sort -Unique}
$EarningTrackerConfig | ConvertTo-JSON | Out-File ".\Config\EarningTrackerConfig.json"
}
Function PrepareWriteConfig{
If ($Variables.DonationRunning) {Update-Status("Donation Running - Not saving config"); return}
If ($Config.ManualConfig) {Update-Status("Manual config mode - Not saving config"); return}
If ($Config -eq $null){$Config = [hashtable]::Synchronized(@{})}
$Config | Add-Member -Force @{$TBAddress.Tag = $TBAddress.Text}
$Config | Add-Member -Force @{$TBWorkerName.Tag = $TBWorkerName.Text}
$ConfigPageControls | ? {(($_.gettype()).Name -eq "CheckBox")} | foreach {$Config | Add-Member -Force @{$_.Tag = $_.Checked}}
$ConfigPageControls | ? {(($_.gettype()).Name -eq "TextBox")} | foreach {$Config | Add-Member -Force @{$_.Tag = $_.Text}}
$ConfigPageControls | ? {(($_.gettype()).Name -eq "TextBox") -and ($_.Tag -eq "GPUCount")} | foreach {
$Config | Add-Member -Force @{$_.Tag = [Int]$_.Text}
If ($CheckBoxDisableGPU0.checked -and [Int]$_.Text -gt 1){$FirstGPU = 1}else{$FirstGPU = 0}
$Config | Add-Member -Force @{SelGPUCC = (($FirstGPU..($_.Text-1)) -join ",")}
$Config | Add-Member -Force @{SelGPUDSTM = (($FirstGPU..($_.Text-1)) -join " ")}
}
$ConfigPageControls | ? {(($_.gettype()).Name -eq "TextBox") -and ($_.Tag -eq "Algorithm")} | foreach {
$Config | Add-Member -Force @{$_.Tag = @($_.Text -split ",")}
}
$ConfigPageControls | ? {(($_.gettype()).Name -eq "TextBox") -and ($_.Tag -in @("Donate","Interval","ActiveMinerGainPct"))} | foreach {
$Config | Add-Member -Force @{$_.Tag = [Int]$_.Text}
}
$Config | Add-Member -Force @{$CheckedListBoxPools.Tag = $CheckedListBoxPools.CheckedItems}
$ServermodePageControls | ? {(($_.gettype()).Name -eq "CheckBox")} | foreach {$Config | Add-Member -Force @{$_.Tag = $_.Checked}}
$ServermodePageControls | ? {(($_.gettype()).Name -eq "TextBox")} | foreach {$Config | Add-Member -Force @{$_.Tag = $_.Text}}
$MonitoringSettingsControls | ? {(($_.gettype()).Name -eq "CheckBox")} | foreach {$Config | Add-Member -Force @{$_.Tag = $_.Checked}}
$MonitoringSettingsControls | ? {(($_.gettype()).Name -eq "TextBox")} | foreach {$Config | Add-Member -Force @{$_.Tag = $_.Text}}
Write-Config -ConfigFile $ConfigFile -Config $Config
$Config = Load-Config -ConfigFile $ConfigFile
$ServerPasswd = ConvertTo-SecureString $Config.Server_Password -AsPlainText -Force
$ServerCreds = New-Object System.Management.Automation.PSCredential ($Config.Server_User, $ServerPasswd)
$Variables.ServerCreds = $ServerCreds
$ServerClientPasswd = ConvertTo-SecureString $Config.Server_ClientPassword -AsPlainText -Force
$ServerClientCreds = New-Object System.Management.Automation.PSCredential ($Config.Server_ClientUser, $ServerClientPasswd)
$Variables.ServerClientCreds = $ServerClientCreds
$MainForm.Refresh
# [windows.forms.messagebox]::show("Please restart NPlusMiner",'Config saved','ok','Information') | out-null
}
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
# If (Test-Path ".\Logs\switching.log"){$log=Import-Csv ".\Logs\switching.log" | Select -Last 14}
# $SwitchingArray = [System.Collections.ArrayList]@($Log)
If (Test-Path ".\Logs\switching.log"){$SwitchingArray = [System.Collections.ArrayList]@(Import-Csv ".\Logs\switching.log" | Select -Last 14)}
$MainForm = New-Object system.Windows.Forms.Form
$NPMIcon = New-Object system.drawing.icon (".\Includes\NPM.ICO")
$MainForm.Icon = $NPMIcon
$MainForm.ClientSize = '740,450' # best to keep under 800,600
$MainForm.text = "Form"
$MainForm.TopMost = $false
$MainForm.FormBorderStyle = 'Fixed3D'
$MainForm.MaximizeBox = $false
$MainForm.add_Shown({
# Check if new version is available
Update-Status("Checking version")
try {
$Version = Invoke-WebRequest "http://tiny.cc/m155qy" -TimeoutSec 15 -UseBasicParsing -Headers @{"Cache-Control"="no-cache"} | ConvertFrom-Json} catch {$Version = Get-content ".\Config\version.json" | Convertfrom-json}
If ($Version -ne $null){$Version | ConvertTo-json | Out-File ".\Config\version.json"}
If ($Version.Product -eq $Variables.CurrentProduct -and [Version]$version.Version -gt $Variables.CurrentVersion -and $Version.Update) {
Update-Status("Version $($version.Version) available. (You are running $($Variables.CurrentVersion))")
# If ([version](GetNVIDIADriverVersion) -ge [Version]$Version.MinNVIDIADriverVersion){
$LabelNotifications.ForeColor = "Green"
$LabelNotifications.Lines += "Version $([Version]$version.Version) available"
$LabelNotifications.Lines += $version.Message
If ($Config.Autoupdate -and ! $Config.ManualConfig) {Autoupdate}
# } else {
# Update-Status("Version $($version.Version) available. Please update NVIDIA driver. Will not AutoUpdate")
# $LabelNotifications.ForeColor = "Red"
# $LabelNotifications.Lines += "Driver update required. Version $([Version]$version.Version) available"
# }
}
# TimerCheckVersion
$TimerCheckVersion = New-Object System.Windows.Forms.Timer
$TimerCheckVersion.Enabled = $true
$TimerCheckVersion.Interval = 700*60*1000
$TimerCheckVersion.Add_Tick({
Update-Status("Checking version")
try {
$Version = Invoke-WebRequest "http://tiny.cc/rrxqry" -TimeoutSec 15 -UseBasicParsing -Headers @{"Cache-Control"="no-cache"} | ConvertFrom-Json} catch {$Version = Get-content ".\Config\version.json" | Convertfrom-json}
If ($Version -ne $null){$Version | ConvertTo-json | Out-File ".\Config\version.json"}
If ($Version.Product -eq $Variables.CurrentProduct -and [Version]$version.Version -gt $Variables.CurrentVersion -and $Version.Update) {
Update-Status("Version $($version.Version) available. (You are running $($Variables.CurrentVersion))")
# If ([version](GetNVIDIADriverVersion) -ge [Version]$Version.MinNVIDIADriverVersion){
$LabelNotifications.ForeColor = "Green"
$LabelNotifications.Lines += "Version $([Version]$version.Version) available"
$LabelNotifications.Lines += $version.Message
If ($Config.Autoupdate -and ! $Config.ManualConfig) {Autoupdate}
# } else {
# Update-Status("Version $($version.Version) available. Please update NVIDIA driver. Will not AutoUpdate")
# $LabelNotifications.ForeColor = "Red"
# $LabelNotifications.Lines += "Driver update required. Version $([Version]$version.Version) available"
# }
}
})
# Detects GPU count if 0 or Null in config
If ($Config.GPUCount -eq $null -or $Config.GPUCount -lt 1){
If ($Config -eq $null){$Config = [hashtable]::Synchronized(@{})}
$Config | Add-Member -Force @{GPUCount = DetectGPUCount}
$TBGPUCount.Text = $Config.GPUCount
PrepareWriteConfig
}
# Start on load if Autostart
If ($Config.Autostart){$ButtonStart.PerformClick()}
If ($Config.StartGUIMinimized){$MainForm.WindowState = [System.Windows.Forms.FormWindowState]::Minimized}
})
$MainForm.Add_FormClosing({
$TimerUI.Stop()
Update-Status("Stopping jobs and miner")
if ($Variables.EarningsTrackerJobs) {$Variables.EarningsTrackerJobs | %{$_ | Stop-Job | Remove-Job}}
if ($Variables.BrainJobs) {$Variables.BrainJobs | %{$_ | Stop-Job | Remove-Job}}
If ($Variables.ActiveMinerPrograms) {
$Variables.ActiveMinerPrograms | ForEach {
[Array]$filtered = ($BestMiners_Combo | Where Path -EQ $_.Path | Where Arguments -EQ $_.Arguments)
if($filtered.Count -eq 0)
{
if($_.Process -eq $null)
{
$_.Status = "Failed"
}
elseif($_.Process.HasExited -eq $false)
{
$_.Active += (Get-Date)-$_.Process.StartTime
$_.Process.CloseMainWindow() | Out-Null
Sleep 1
# simply "Kill with power"
Stop-Process $_.Process -Force | Out-Null
Write-Host -ForegroundColor Yellow "closing miner"
Sleep 1
$_.Status = "Idle"
}
}
}
}
# $Result = $powershell.EndInvoke($Variables.CycleRunspaceHandle)
if ($CycleRunspace) {$CycleRunspace.Close()}
if ($powershell) {$powershell.Dispose()}
if ($IdleRunspace) {$IdleRunspace.Close()}
if ($idlePowershell) {$idlePowershell.Dispose()}
})
$Config = Load-Config -ConfigFile $ConfigFile
$Config | Add-Member -Force -MemberType ScriptProperty -Name "PoolsConfig" -Value {
If (Test-Path ".\Config\PoolsConfig.json"){
get-content ".\Config\PoolsConfig.json" | ConvertFrom-json
}else{
[PSCustomObject]@{default=[PSCustomObject]@{
Wallet = "134bw4oTorEJUUVFhokDQDfNqTs7rBMNYy"
UserName = "mrplus"
WorkerName = "NPlusMinerNoCfg"
PricePenaltyFactor = 1
}}
}
}
$MainForm | Add-Member -Name "Config" -Value $Config -MemberType NoteProperty -Force
$SelGPUDSTM = $Config.SelGPUDSTM
$SelGPUCC = $Config.SelGPUCC
$MainForm | Add-Member -Name "Variables" -Value $Variables -MemberType NoteProperty -Force
$Variables.CurrentProduct = (Get-Content .\Version.json | ConvertFrom-Json).Product
$Variables.CurrentVersion = [Version](Get-Content .\Version.json | ConvertFrom-Json).Version
$Variables.CurrentVersionAutoUpdated = (Get-Content .\Version.json | ConvertFrom-Json).AutoUpdated.Value
$Variables.StatusText = "Idle"
$TabControl = New-object System.Windows.Forms.TabControl
Try{
$DblBuff = ($TabControl.GetType()).GetProperty("DoubleBuffered", ('Instance','NonPublic'))
$DblBuff.SetValue($MainForm, $True, $null)
} catch {}
$RunPage = New-Object System.Windows.Forms.TabPage
$RunPage.Text = "Run"
$SwitchingPage = New-Object System.Windows.Forms.TabPage
$SwitchingPage.Text = "Switching"
$ConfigPage = New-Object System.Windows.Forms.TabPage
$ConfigPage.Text = "Config"
$MonitoringPage = New-Object System.Windows.Forms.TabPage
$MonitoringPage.Text = "Monitoring"
$EstimationsPage = New-Object System.Windows.Forms.TabPage
$EstimationsPage.Text = "Benchmarks"
$ServerModePage = New-Object System.Windows.Forms.TabPage
$ServerModePage.Text = "Server Mode"
$tabControl.DataBindings.DefaultDataSourceUpdateMode = 0
$tabControl.Location = New-Object System.Drawing.Point(10,91)
$tabControl.Name = "tabControl"
$tabControl.width = 720
$tabControl.height = 359
$MainForm.Controls.Add($tabControl)
$TabControl.Controls.AddRange(@($RunPage, $SwitchingPage, $ConfigPage, $MonitoringPage, $EstimationsPage, $ServerModePage))
# Form Controls
$MainFormControls = @()
# $Logo = [System.Drawing.Image]::Fromfile('.\config\logo.png')
$pictureBoxLogo = new-object Windows.Forms.PictureBox
$pictureBoxLogo.Width = 47 #$img.Size.Width
$pictureBoxLogo.Height = 47 #$img.Size.Height
# $pictureBoxLogo.Image = $Logo
$pictureBoxLogo.SizeMode = 1
$pictureBoxLogo.ImageLocation = $Branding.LogoPath
$MainFormControls += $pictureBoxLogo
$LabelEarningsDetails = New-Object system.Windows.Forms.TextBox
$LabelEarningsDetails.Tag = ""
$LabelEarningsDetails.MultiLine = $true
$LabelEarningsDetails.text = ""
$LabelEarningsDetails.AutoSize = $false
$LabelEarningsDetails.width = 382 #200
$LabelEarningsDetails.height = 47 #62
$LabelEarningsDetails.location = New-Object System.Drawing.Point(57,2)
$LabelEarningsDetails.Font = 'lucida console,10'
$LabelEarningsDetails.BorderStyle = 'None'
$LabelEarningsDetails.BackColor = [System.Drawing.SystemColors]::Control
$LabelEarningsDetails.ForeColor = "Green"
$LabelEarningsDetails.Visible = $True
# $TBNotifications.TextAlign = "Right"
$MainFormControls += $LabelEarningsDetails
$LabelBTCD = New-Object system.Windows.Forms.Label
$LabelBTCD.text = "BTC/D"
$LabelBTCD.AutoSize = $False
$LabelBTCD.width = 473
$LabelBTCD.height = 35
$LabelBTCD.location = New-Object System.Drawing.Point(247,2)
$LabelBTCD.Font = 'Microsoft Sans Serif,14'
$LabelBTCD.TextAlign = "MiddleRight"
$LabelBTCD.ForeColor = "Green"
$LabelBTCD.Backcolor = "Transparent"
# $LabelBTCD.BorderStyle = 'FixedSingle'
$MainFormControls += $LabelBTCD
$LabelBTCPrice = New-Object system.Windows.Forms.Label
$LabelBTCPrice.text = If($Variables.Rates.$Currency -gt 0){"BTC/$($Config.Currency) $($Variables.Rates.$Currency)"}
$LabelBTCPrice.AutoSize = $false
$LabelBTCPrice.width = 400
$LabelBTCPrice.height = 20
$LabelBTCPrice.location = New-Object System.Drawing.Point(630,39)
$LabelBTCPrice.Font = 'Microsoft Sans Serif,8'
# $LabelBTCPrice.ForeColor = "Gray"
$MainFormControls += $LabelBTCPrice
$ButtonPause = New-Object system.Windows.Forms.Button
$ButtonPause.text = "Pause"
$ButtonPause.width = 60
$ButtonPause.height = 30
$ButtonPause.location = New-Object System.Drawing.Point(610,62)
$ButtonPause.Font = 'Microsoft Sans Serif,10'
$ButtonPause.Visible = $False
$MainFormControls += $ButtonPause
$ButtonStart = New-Object system.Windows.Forms.Button
$ButtonStart.text = "Start"
$ButtonStart.width = 60
$ButtonStart.height = 30
$ButtonStart.location = New-Object System.Drawing.Point(670,62)
$ButtonStart.Font = 'Microsoft Sans Serif,10'
$MainFormControls += $ButtonStart
$LabelNotifications = New-Object system.Windows.Forms.TextBox
$LabelNotifications.Tag = ""
$LabelNotifications.MultiLine = $true
# $TBNotifications.Scrollbars = "Vertical"
$LabelNotifications.text = ""
$LabelNotifications.AutoSize = $false
$LabelNotifications.width = 280
$LabelNotifications.height = 18
$LabelNotifications.location = New-Object System.Drawing.Point(10,49)
$LabelNotifications.Font = 'Microsoft Sans Serif,10'
$LabelNotifications.BorderStyle = 'None'
$LabelNotifications.BackColor = [System.Drawing.SystemColors]::Control
$LabelNotifications.Visible = $True
# $TBNotifications.TextAlign = "Right"
$MainFormControls += $LabelNotifications
$LabelAddress = New-Object system.Windows.Forms.Label
$LabelAddress.text = "Wallet Address"
$LabelAddress.AutoSize = $false
$LabelAddress.width = 100
$LabelAddress.height = 20
$LabelAddress.location = New-Object System.Drawing.Point(10,68)
$LabelAddress.Font = 'Microsoft Sans Serif,10'
$MainFormControls += $LabelAddress
$TBAddress = New-Object system.Windows.Forms.TextBox
$TBAddress.Tag = "Wallet"
$TBAddress.MultiLine = $False
# $TBAddress.Scrollbars = "Vertical"
$TBAddress.text = $Config.Wallet
$TBAddress.AutoSize = $false
$TBAddress.width = 280
$TBAddress.height = 20
$TBAddress.location = New-Object System.Drawing.Point(112,68)
$TBAddress.Font = 'Microsoft Sans Serif,10'
# $TBAddress.TextAlign = "Right"
$MainFormControls += $TBAddress
# Run Page Controls
$RunPageControls = @()
$LabelStatus = New-Object system.Windows.Forms.TextBox
$LabelStatus.MultiLine = $true
$LabelStatus.Scrollbars = "Vertical"
$LabelStatus.text = ""
$LabelStatus.AutoSize = $true
$LabelStatus.width = 712
$LabelStatus.height = 50
$LabelStatus.location = New-Object System.Drawing.Point(2,2)
$LabelStatus.Font = 'Microsoft Sans Serif,10'
$RunPageControls += $LabelStatus
$LabelEarnings = New-Object system.Windows.Forms.Label
$LabelEarnings.text = "Earnings Tracker (Past 7 days earnings / Per pool earnings today)"
$LabelEarnings.AutoSize = $false
$LabelEarnings.width = 600
$LabelEarnings.height = 20
$LabelEarnings.location = New-Object System.Drawing.Point(2,54)
$LabelEarnings.Font = 'Microsoft Sans Serif,10'
$RunPageControls += $LabelEarnings
If (Test-Path ".\logs\DailyEarnings.csv"){
$Chart1 = Invoke-Expression -Command ".\Includes\Charting.ps1 -Chart 'Front7DaysEarnings' -Width 505 -Height 85 -Currency $($Config.Passwordcurrency)"
$Chart1.top = 74
$Chart1.left = 2
$RunPageControls += $Chart1
}
If (Test-Path ".\logs\DailyEarnings.csv"){
$Chart2 = Invoke-Expression -Command ".\Includes\Charting.ps1 -Chart 'DayPoolSplit' -Width 200 -Height 85 -Currency $($Config.Passwordcurrency)"
$Chart2.top = 74
$Chart2.left = 500
$RunPageControls += $Chart2
}
$EarningsDGV = New-Object system.Windows.Forms.DataGridView
$EarningsDGV.width = 712
# $EarningsDGV.height = 305
# $EarningsDGV.height = 170
$EarningsDGV.height = 85
$EarningsDGV.location = New-Object System.Drawing.Point(2,159)
$EarningsDGV.DataBindings.DefaultDataSourceUpdateMode = 0
$EarningsDGV.AutoSizeColumnsMode = "Fill"
$EarningsDGV.RowHeadersVisible = $False
$RunPageControls += $EarningsDGV
$LabelGitHub = New-Object System.Windows.Forms.LinkLabel
# $LabelGitHub.Location = New-Object System.Drawing.Size(415,39)
# $LabelGitHub.Size = New-Object System.Drawing.Size(160,18)
$LabelGitHub.Location = New-Object System.Drawing.Size(600,246)
$LabelGitHub.Size = New-Object System.Drawing.Size(160,20)
$LabelGitHub.LinkColor = "BLUE"
$LabelGitHub.ActiveLinkColor = "BLUE"
$LabelGitHub.Text = "Help? Join on Discord"
$LabelGitHub.add_Click({[system.Diagnostics.Process]::start("https://discord.gg/2BCqPxe")})
$RunPageControls += $LabelGitHub
$LabelCopyright = New-Object System.Windows.Forms.LinkLabel
# $LabelCopyright.Location = New-Object System.Drawing.Size(415,61)
# $LabelCopyright.Size = New-Object System.Drawing.Size(200,20)
$LabelCopyright.Location = New-Object System.Drawing.Size(395,246)
$LabelCopyright.Size = New-Object System.Drawing.Size(200,20)
$LabelCopyright.LinkColor = "BLUE"
$LabelCopyright.ActiveLinkColor = "BLUE"
$LabelCopyright.Text = "Copyright (c) 2018-2020 MrPlus"
$LabelCopyright.add_Click({[system.Diagnostics.Process]::start("https://github.com/MrPlusGH/NPlusMiner/blob/master/LICENSE")})
$RunPageControls += $LabelCopyright
$LabelWebUI = New-Object System.Windows.Forms.LinkLabel
# $LabelWebUI.Location = New-Object System.Drawing.Size(415,61)
# $LabelWebUI.Size = New-Object System.Drawing.Size(200,20)
$LabelWebUI.Location = New-Object System.Drawing.Size(250,246)
$LabelWebUI.Size = New-Object System.Drawing.Size(200,20)
$LabelWebUI.LinkColor = "BLUE"
$LabelWebUI.ActiveLinkColor = "BLUE"
$LabelWebUI.Text = "Web interface"
$LabelWebUI.add_Click({[system.Diagnostics.Process]::start("http://$($Config.Server_ClientIP):$($Config.Server_ClientPort)/Status")})
$RunPageControls += $LabelWebUI
$LabelRunningMiners = New-Object system.Windows.Forms.Label
$LabelRunningMiners.text = "Running Miners"
$LabelRunningMiners.AutoSize = $false
$LabelRunningMiners.width = 200
$LabelRunningMiners.height = 20
$LabelRunningMiners.location = New-Object System.Drawing.Point(2,246)
$LabelRunningMiners.Font = 'Microsoft Sans Serif,10'
$RunPageControls += $LabelRunningMiners
$RunningMinersDGV = New-Object system.Windows.Forms.DataGridView
$RunningMinersDGV.width = 712
# $EarningsDGV.height = 305
$RunningMinersDGV.height = 95
$RunningMinersDGV.location = New-Object System.Drawing.Point(2,266)
$RunningMinersDGV.DataBindings.DefaultDataSourceUpdateMode = 0
$RunningMinersDGV.AutoSizeColumnsMode = "Fill"
$RunningMinersDGV.RowHeadersVisible = $False
$RunPageControls += $RunningMinersDGV
$RunPageControls | foreach {
# If ($_.GetType() -ne "System.Windows.Forms.DataGridView") {
Try{
$DblBuff = ($_.GetType()).GetProperty("DoubleBuffered", ('Instance','NonPublic'))
$DblBuff.SetValue($MainForm, $True, $null)
} catch {}
# }
}
# Switching Page Controls
$SwitchingPageControls = @()
$CheckShowSwitchingCPU = New-Object system.Windows.Forms.CheckBox
$CheckShowSwitchingCPU.Tag = "CPU"
$CheckShowSwitchingCPU.text = "CPU"
$CheckShowSwitchingCPU.AutoSize = $false
$CheckShowSwitchingCPU.width = 60
$CheckShowSwitchingCPU.height = 20
$CheckShowSwitchingCPU.location = New-Object System.Drawing.Point(2,2)
$CheckShowSwitchingCPU.Font = 'Microsoft Sans Serif,10'
$CheckShowSwitchingCPU.Checked = ("CPU" -in $Config.Type)
$SwitchingPageControls += $CheckShowSwitchingCPU
$CheckShowSwitchingCPU | foreach {$_.Add_Click({CheckBoxSwitching_Click($This)})}
$CheckShowSwitchingNVIDIA = New-Object system.Windows.Forms.CheckBox
$CheckShowSwitchingNVIDIA.Tag = "NVIDIA"
$CheckShowSwitchingNVIDIA.text = "NVIDIA"
$CheckShowSwitchingNVIDIA.AutoSize = $false
$CheckShowSwitchingNVIDIA.width = 70
$CheckShowSwitchingNVIDIA.height = 20
$CheckShowSwitchingNVIDIA.location = New-Object System.Drawing.Point(62,2)
$CheckShowSwitchingNVIDIA.Font = 'Microsoft Sans Serif,10'
$CheckShowSwitchingNVIDIA.Checked = ("NVIDIA" -in $Config.Type)
$SwitchingPageControls += $CheckShowSwitchingNVIDIA
$CheckShowSwitchingAMD = New-Object system.Windows.Forms.CheckBox
$CheckShowSwitchingAMD.Tag = "AMD"
$CheckShowSwitchingAMD.text = "AMD"
$CheckShowSwitchingAMD.AutoSize = $false
$CheckShowSwitchingAMD.width = 100
$CheckShowSwitchingAMD.height = 20
$CheckShowSwitchingAMD.location = New-Object System.Drawing.Point(137, 2)
$CheckShowSwitchingAMD.Font = 'Microsoft Sans Serif,10'
$CheckShowSwitchingAMD.Checked = ("AMD" -in $Config.Type)
$SwitchingPageControls += $CheckShowSwitchingAMD
$CheckShowSwitchingAMD | foreach {$_.Add_Click( {CheckBoxSwitching_Click($This)})}
$CheckShowSwitchingNVIDIA | foreach {$_.Add_Click({CheckBoxSwitching_Click($This)})}
Function CheckBoxSwitching_Click {
$SwitchingDisplayTypes = @()
$SwitchingPageControls | foreach {if ($_.Checked){$SwitchingDisplayTypes += $_.Tag}}
# If (Test-Path ".\Logs\switching.log"){$log=Import-Csv ".\Logs\switching.log" | ? {$_.Type -in $SwitchingDisplayTypes} | Select -Last 13}
# $SwitchingArray = [System.Collections.ArrayList]@($Log)
# If (Test-Path ".\Logs\switching.log"){$SwitchingArray = [System.Collections.ArrayList]@(Import-Csv ".\Logs\switching.log" | ? {$_.Type -in $SwitchingDisplayTypes} | Select -Last 13)}
If (Test-Path ".\Logs\switching.log"){$SwitchingArray = [System.Collections.ArrayList]@(@((get-content ".\Logs\switching.log" -First 1) , (get-content ".\logs\switching.log" -last 50)) | ConvertFrom-Csv | ? {$_.Type -in $SwitchingDisplayTypes} | Select -Last 13)}
$SwitchingDGV.DataSource = $SwitchingArray
}