forked from tutulino/Megaminer
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathWrapper.ps1
80 lines (68 loc) · 2.6 KB
/
Wrapper.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
param(
[Parameter(Mandatory = $true)]
[Int]$ControllerProcessID,
[Parameter(Mandatory = $true)]
[String]$Id,
[Parameter(Mandatory = $true)]
[String]$FilePath,
[Parameter(Mandatory = $false)]
[String]$ArgumentList = "",
[Parameter(Mandatory = $false)]
[String]$WorkingDirectory = ""
)
Set-Location (Split-Path $script:MyInvocation.MyCommand.Path)
0 | Set-Content ".\Wrapper_$Id.txt"
$PowerShell = [PowerShell]::Create()
if ($WorkingDirectory -ne "") {$PowerShell.AddScript("Set-Location '$WorkingDirectory'") | Out-Null}
$Command = ". '$FilePath'"
if ($ArgumentList -ne "") {$Command += " $ArgumentList"}
$PowerShell.AddScript("$Command 2>&1 | Write-Verbose -Verbose") | Out-Null
$Result = $PowerShell.BeginInvoke()
Write-Host "Wrapper Started" -BackgroundColor Yellow -ForegroundColor Black
do {
Start-Sleep -Seconds 1
$PowerShell.Streams.Verbose.ReadAll() | ForEach-Object {
$Line = $_
if ($Line -like "*accepted*" -or
$Line -like "*Mining on #*" -or
$Line -like "*diff*yes!*" -or
$Line -like ">*Rej*" -or
$Line -like "*overall*" -or
$Line -like "*Average*" -or
$Line -like "*Total*"
) {
$Line = $Line `
-replace "\smh/s", "mh/s" `
-replace "\skh/s", "kh/s" `
-replace "\sgh/s", "gh/s" `
-replace "\sth/s", "th/s" `
-replace "\sph/s", "ph/s" `
-replace "\sh/s", "h/s" `
-replace "\ssol/s", "h/s" `
-replace "\sHash/s", "h/s"
$Words = $Line -split " " -like "*/s*" -replace ","
if ($Command -notlike '*mkxminer.exe*') {
$Words = $Words | Select-Object -Last 1
}
if ($Words) {
$HashRate = 0
foreach ($Word in $Words) {
if ($Word -match "([0-9.]+)([kmgtp]?h)/s") {
$HashRate += [decimal]$Matches[1] * $(switch ($Matches[2]) {
'kh' { 1e3 }
'mh' { 1e6 }
'gh' { 1e9 }
'th' { 1e12 }
'ph' { 1e15 }
Default { 1 }
})
}
}
}
$HashRate -replace ',', '.' | Set-Content ".\Wrapper_$Id.txt"
}
$Line
}
if ((Get-Process | Where-Object Id -EQ $ControllerProcessID) -eq $null) {$PowerShell.Stop() | Out-Null}
}
until($Result.IsCompleted)