Skip to content

Commit

Permalink
Merge pull request #176 from MrPig91/AddPlotandCopy
Browse files Browse the repository at this point in the history
Add plotand copy
  • Loading branch information
MrPig91 authored Jul 16, 2021
2 parents 8b3e24f + ba0f990 commit 35d7088
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 15 deletions.
2 changes: 2 additions & 0 deletions PSChiaPlotter/Classes/ChiaClasses.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace PSChiaPlotter
public string AlternativePlotterPath { get; set; }
public int PhaseThreeFourBuckets { get; set; }
public bool Phase3and4BucketsEnabled { get; set; }
public bool PlotWhileCopy { get; set; }
public ChiaParameters()
{
Expand Down Expand Up @@ -134,6 +135,7 @@ namespace PSChiaPlotter
AutoPlotCheckEnabled = chiaParameters.AutoPlotCheckEnabled;
PhaseThreeFourBuckets = chiaParameters.PhaseThreeFourBuckets;
Phase3and4BucketsEnabled = chiaParameters.Phase3and4BucketsEnabled;
PlotWhileCopy = chiaParameters.PlotWhileCopy;
}
public event PropertyChangedEventHandler PropertyChanged;
Expand Down
10 changes: 10 additions & 0 deletions PSChiaPlotter/Private/ButtonClicks/Invoke-NewJobButtonClick.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ function Invoke-NewJobButtonClick {
}
}

if ($DataHash.NewJobViewModel.NewChiaJob.InitialChiaParameters.PlotWhileCopy -and $DataHash.NewJobViewModel.NewChiaJob.InitialChiaParameters.AlternativePlotterEnabled -eq $false){
$Response = Show-MessageBox -Text "I advise to check 'Exclude Final Directory' when using 'Plot While Copy'. This is because the OG chia plotter will add the temp directory to your farming directories instead of the final directory`n`nDo you want to continue and start the job?" -Icon Warning -Buttons YesNo
if ($Response -eq [System.Windows.MessageBoxResult]::No){
return
}
}

$Results = Test-ChiaParameters $DataHash.NewJobViewModel.NewChiaJob
if ($Results -ne $true){
Show-Messagebox -Text $Results -Title "Invalid Parameters" -Icon Warning
Expand Down Expand Up @@ -199,6 +206,9 @@ function Invoke-NewJobButtonClick {
Show-MessageBox "$($DataHash.NewJobViewModel.NewChiaJob.JobName) job saved to $PSChiaPlotterFolderPath"
return
}
else {
return
}
}
$DataHash.NewJobViewModel | Export-Clixml -Path $SaveJobPath -Depth 10
Show-MessageBox "$($DataHash.NewJobViewModel.NewChiaJob.JobName) job saved to $PSChiaPlotterFolderPath"
Expand Down
27 changes: 26 additions & 1 deletion PSChiaPlotter/Private/Start-GUIChiaPlotting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,28 @@ function Start-GUIChiaPlotting {
$AlternativePlotterPath = $PlottingParameters.AlternativePlotterPath
$Phase3and4Buckets = $PlottingParameters.PhaseThreeFourBuckets
$Phase3and4BucketsEnabled = $PlottingParameters.Phase3and4BucketsEnabled
$PlotWhileCopy = $PlottingParameters.PlotWhileCopy

#used for replotting
$OldPlotDeleted = $false

$E = if ($DisableBitfield){"-e"}
$X = if ($ExcludeFinalDirectory){"-x"}

if ($PlotWhileCopy -eq $true){
if ($AlternativePlotterEnabled -eq $true){
$FinalDirectoryPath = $TempDirectoryPath
}
else{
if (-not[string]::IsNullOrWhiteSpace($SecondTempDirectoryPath)){
$FinalDirectoryPath = $SecondTempDirectoryPath
}
else{
$FinalDirectoryPath = $TempDirectoryPath
}
}
}

#remove any trailing '\' since chia.exe hates them
$TempDirectoryPath = $TempDirectoryPath.TrimEnd(@('\','/'))
$FinalDirectoryPath = $FinalDirectoryPath.TrimEnd(@('\','/'))
Expand Down Expand Up @@ -177,6 +192,16 @@ function Start-GUIChiaPlotting {
}
} #while

if ($PlotWhileCopy -eq $true -and ($ChiaRun.ChiaProcess.ExitCode -eq 0)){
if (-not$ChiaJob.BasicPlotting){
Start-PlotCopyPhase -RunToCopy $ChiaRun -FinalVol $FinalMasterVolume -TempVol $TempMasterVolume
}
else{
Start-PlotCopyPhase -RunToCopy $ChiaRun
}
return #need to return so that the next plot can start
}

$ChiaJob.RunsInProgress.Remove($ChiaRun)
$ChiaJob.CompletedRunCount++

Expand All @@ -190,7 +215,7 @@ function Start-GUIChiaPlotting {
$ChiaRun.ExitTime = $ChiaProcess.ExitTime
}

if ($ChiaRun.ChiaPRocess.ExitCode -ne 0){
if ($ChiaRun.ChiaProcess.ExitCode -ne 0){
$ChiaRun.Status = "Failed"
$ChiaQueue.FailedPlotCount++
$ChiaJob.FailedPlotCount++
Expand Down
95 changes: 95 additions & 0 deletions PSChiaPlotter/Private/Start-PlotCopyPhase.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
function Start-PlotCopyPhase {
[CmdletBinding()]
param(
$RunToCopy,
$FinalVol,
$TempVol
)

$StartCopyPhaseScript = [powershell]::Create().AddScript{
Param (
$RunToCopy,
$FinalVol,
$TempVol
)
$ErrorActionPreference = "Stop"
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms

#Import required assemblies and private functions
Get-childItem -Path $DataHash.PrivateFunctions -File -Recurse | ForEach-Object {Import-Module $_.FullName}
Get-childItem -Path $DataHash.Classes -File | ForEach-Object {Import-Module $_.FullName}
try{
$RunToCopy.Phase = "Copy"
$RunToCopy.CurrentPhaseProgress = 0
$RunToCopy.Progress = 98
if ($RunToCopy.PlottingParameters.AlternativePlotterEnabled -eq $true){
$tempFinalPath = $RunToCopy.PlottingParameters.TempVolume.DirectoryPath
}
else{
if (-not[string]::IsNullOrEmpty($RunToCopy.PlottingParameters.SecondTempVolume.DirectoryPath)){
$tempFinalPath = $RunToCopy.PlottingParameters.SecondTempVolume.DirectoryPath
}
else{
$tempFinalPath = $RunToCopy.PlottingParameters.TempVolume.DirectoryPath
}
}
$plotPath = Join-Path $tempFinalPath -ChildPath "*$($RunToCopy.PlotId)*"
$PlotItem = Get-Item -Path $plotPath
$newplotItem = Rename-Item -Path $PlotItem -NewName "$($PlotItem.Name).tmp" -Force -PassThru
$MovedItem = Move-Item -Path $NewPlotItem.FullName -Destination $RunToCopy.PlottingParameters.FinalVolume.DirectoryPath -PassThru
Rename-Item -Path $MovedItem.FullName -NewName $MovedItem.Name.Replace('.tmp','')

$RunToCopy.Progress = 100
$RunToCopy.CurrentPhaseProgress = 100

$CopyRunJob = $RunToCopy.ParentQueue.ParentJob
$CopyRunJob.RunsInProgress.Remove($RunToCopy)
$CopyRunJob.CompletedRunCount++

if (-not$CopyRunJob.BasicPlotting){
$FinalVol.PendingFinalRuns.Remove($RunToCopy)
$TempVol.CurrentChiaRuns.Remove($RunToCopy)
}
$RunToCopy.ExitCode = $RunToCopy.ChiaPRocess.ExitCode
$RunToCopy.ExitTime = [datetime]::Now

$RunToCopy.Status = "Completed"
$CopyRunJob.CompletedPlotCount++
$RunToCopy.ParentQueue.CompletedPlotCount++
$DataHash.MainViewModel.CompletedRuns.Add($RunToCopy)
$RunToCopy.CheckPlotPowershellCommand = "&'$ChiaPath' plots check -g $plotid"
Update-ChiaGUISummary -Success
if ($RunToCopy.PlottingParameters.AutoPlotCheckEnabled){
$PlotCheckResults = Test-ChiaPlot -Path $plotid -ErrorAction Continue
if ($Null -ne $PlotCheckResults){
$RunToCopy.PlotCheckRatio = [math]::Round($PlotCheckResults.Ratio,2)
}
} #if autoplotcheck

$RunToCopy.ParentQueue.CurrentRun = $null
$DataHash.MainViewModel.CurrentRuns.Remove($RunToCopy)
}
catch{
Write-PSChiaPlotterLog -LogType ERROR -ErrorObject $_
if (-not$DataHash.MainViewModel.FailedRuns.Contains($RunToCopy)){
$DataHash.MainViewModel.FailedRuns.Add($RunToCopy)
}
if ($DataHash.MainViewModel.CurrentRuns.Contains($RunToCopy)){
$DataHash.MainViewModel.CurrentRuns.Remove($RunToCopy)
}
if ($CopyRunJob.RunsInProgress.Contains($RunToCopy)){
$CopyRunJob.RunsInProgress.Remove($RunToCopy)
}
if (-not$CopyRunJob.BasicPlotting){
if ($FinalVol){
if ($FinalVol.PendingFinalRuns.Contains($RunToCopy)){
$FinalVol.PendingFinalRuns.Remove($RunToCopy)
}
}
}
}
}.AddParameters($PSBoundParameters)
$StartCopyPhaseScript.RunspacePool = $ScriptsHash.RunspacePool
[void]$StartCopyPhaseScript.BeginInvoke()
}
31 changes: 17 additions & 14 deletions PSChiaPlotter/WPFWindows/NewJobWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PSChiaPlotter"
Title="New Job" Height="725" Width="675">
Title="New Job" Height="725" Width="680">
<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<Style TargetType="Label">
Expand Down Expand Up @@ -95,6 +95,11 @@
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="WrapCheckBox" TargetType="CheckBox">
<Setter Property="IsThreeState" Value="False" />
<Setter Property="Margin" Value="5,0,5,5" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -228,26 +233,24 @@
Text="{Binding Path=NewChiaJob.InitialChiaParameters.Threads}"/>
<TextBox x:Name="Buckets_TextBox" Grid.Row="2" Grid.Column="4" Text="{Binding Path=NewChiaJob.InitialChiaParameters.Buckets}" />
<Separator Grid.Column="1" Grid.ColumnSpan="4" Grid.Row="3" Height="1" VerticalAlignment="Center" Margin="5"/>
<UniformGrid Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="4" Rows="1">
<WrapPanel Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="4" HorizontalAlignment="Center">
<CheckBox Content="Plot Infinite"
x:Name="PlotInfiniteCheckBox"
IsChecked="{Binding Path=NewChiaJob.PlotInfinite}"
Margin="5,0,0,0" IsThreeState="False"
VerticalAlignment="Center"/>
Style="{StaticResource WrapCheckBox}"/>
<CheckBox Content="Auto Check Plots"
IsThreeState="False"
IsChecked="{Binding Path=NewChiaJob.InitialChiaParameters.AutoPlotCheckEnabled}"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
Style="{StaticResource WrapCheckBox}"/>
<CheckBox Content="Disable Bitfield"
HorizontalAlignment="Center"
IsChecked="{Binding Path=NewChiaJob.InitialChiaParameters.DisableBitField}" IsThreeState="False"
VerticalAlignment="Center"/>
Style="{StaticResource WrapCheckBox}"
IsChecked="{Binding Path=NewChiaJob.InitialChiaParameters.DisableBitField}"/>
<CheckBox Content="Exclude Final Directory"
HorizontalAlignment="Center"
IsChecked="{Binding Path=NewChiaJob.InitialChiaParameters.ExcludeFinalDirectory}"
Margin="5,0,0,0" IsThreeState="False"
VerticalAlignment="Center"/>
</UniformGrid>
IsChecked="{Binding Path=NewChiaJob.InitialChiaParameters.ExcludeFinalDirectory}"
Style="{StaticResource WrapCheckBox}"/>
<CheckBox Content="Plot While Copy"
Style="{StaticResource ResourceKey=WrapCheckBox}"
IsChecked="{Binding Path=NewChiaJob.InitialChiaParameters.PlotWhileCopy}" />
</WrapPanel>

</Grid>
</GroupBox>
Expand Down

0 comments on commit 35d7088

Please sign in to comment.