feat: persist batch attempt proof before CAD mutations

This commit is contained in:
阿白叔 committed 2026-10-21 14:28:25 +08:00
1 parent e15ee259f8
commit 832ab5d563
6 files changed
+457 -1

No files matched your search

@@ -930,6 +930,7 @@ Sub QPFinishBatchItem()
Next
End If
If FinalState = "restored_ok" Then
QPMarkBatchMutation Command
QPCloseBatchProject TargetPath, True
QP_BatchSaveCommitted = True
ElseIf Not QP_SessionMode Then
@@ -975,6 +976,42 @@ Sub QPFinishBatchItem()
QPProgress "finished", 1, 1
End Sub
Sub QPMarkBatchMutation(ByRef Command)
Dim Shell, Entry, Required, CommandLine, Key, Value, ExitCode
Set Shell = CreateObject("WScript.Shell")
Required = False
For Each Entry In Shell.Environment("Process")
If InStr(1, CStr(Entry), "DXPART_ATTEMPT_FILE=", vbTextCompare) = 1 Or _
InStr(1, CStr(Entry), "DXPART_BATCH_SESSION_ID=", vbTextCompare) = 1 Or _
InStr(1, CStr(Entry), "DXPART_BATCH_GENERATION=", vbTextCompare) = 1 Or _
InStr(1, CStr(Entry), "DXPART_ATTEMPT_ID=", vbTextCompare) = 1 Then Required = True
Next
If Not Required Then Exit Sub
If Len(QP_HelperExecutable) = 0 Or Not QP_Fso.FileExists(QP_HelperExecutable) Then _
Err.Raise vbObjectError + 879, "QuickPartReplace.Attempt", "mutation proof helper is unavailable"
CommandLine = Chr(34) & QP_HelperExecutable & Chr(34)
If Len(QP_HelperScript) > 0 Then
If Not QP_Fso.FileExists(QP_HelperScript) Then _
Err.Raise vbObjectError + 879, "QuickPartReplace.Attempt", "mutation proof script is unavailable"
CommandLine = CommandLine & " " & Chr(34) & QP_HelperScript & Chr(34)
End If
CommandLine = CommandLine & " --mark-batch-attempt"
For Each Key In Array("job_id", "task_id", "project_path")
Value = CStr(Command(Key))
If Len(Value) = 0 Or InStr(Value, Chr(34)) > 0 Or InStr(Value, vbCr) > 0 Or InStr(Value, vbLf) > 0 Then _
Err.Raise vbObjectError + 879, "QuickPartReplace.Attempt", "invalid mutation proof identity"
Select Case Key
Case "job_id": CommandLine = CommandLine & " --attempt-job "
Case "task_id": CommandLine = CommandLine & " --attempt-task "
Case "project_path": CommandLine = CommandLine & " --attempt-project "
End Select
CommandLine = CommandLine & Chr(34) & Value & Chr(34)
Next
ExitCode = Shell.Run(CommandLine, 0, True)
If ExitCode <> 0 Then Err.Raise vbObjectError + 879, "QuickPartReplace.Attempt", _
"durable mutation proof failed; no CAD write allowed"
End Sub
Sub QPAutomaticReplaceAndRestore(ByRef Command, ByVal SnapshotPath)
Dim ErrorNumber, ErrorSource, ErrorDescription
QPRequireCommandSnapshot Command, SnapshotPath
@@ -1590,6 +1627,7 @@ Sub QPRestoreAfterOperatorReplace(ByRef Command, ByVal SnapshotPath)
QPProgress "restore_preflight", Index + 1, Records.Item("components").Count
Next
QPProgress "before_restore_transaction", 0, Plans.Count
QPMarkBatchMutation Command
QP_RestoreTransactionOpen = True
QP_App.ActiveView.Block.StartUndoTransaction
On Error Resume Next