public OperationFinishedEventArgs(bool done, bool success, OperationFinishedState operationState, DiskOperation diskOperation, Exception exception) { Done = done; Success = success; OperationState = operationState; DiskOperation = diskOperation; Exception = exception; }
public override void BeginVerifyImageAndDevice(ulong numBytesToVerify) { cancelPending = false; currentDiskOperation = DiskOperation.Verify; numSectors = numBytesToVerify / sectorSize; workingThread = new Thread(async() => { bool result = false; OperationFinishedState state = OperationFinishedState.Error; Exception exception = null; try { if (useEncryption) { result = await VerifyImageAndDeviceCryptoWorkerAsync(fileHandle, sectorSize, numSectors); } else { result = await VerifyImageAndDeviceWorkerAsync(fileHandle, sectorSize, numSectors); } Dispose(); state = OperationFinishedState.Success; } catch (Exception e) { result = false; state = OperationFinishedState.Error; exception = e; } finally { if (cancelPending) { state = OperationFinishedState.Canceled; } if (!result && !cancelPending) { state = OperationFinishedState.Error; } Dispose(); OperationFinished?.Invoke(this, new OperationFinishedEventArgs(true, result && !cancelPending, state, currentDiskOperation, exception)); } }); workingThread.Start(); }
public override void BeginWriteImageToDevice(bool verify, bool cropData = false) { cancelPending = false; currentDiskOperation = DiskOperation.Write; if (verify) { currentDiskOperation |= DiskOperation.Verify; } if (cropData) { numSectors = availibleSectors; } workingThread = new Thread(async() => { bool result = false; OperationFinishedState state = OperationFinishedState.Error; Exception exception = null; try { if (useEncryption) { result = await WriteImageToDeviceCryptoWorker(sectorSize, numSectors); } else { result = await WriteImageToDeviceWorker(sectorSize, numSectors); } if (verify && !cancelPending) { OperationFinished?.Invoke(this, new OperationFinishedEventArgs(false, result && !cancelPending, state, currentDiskOperation, null)); if (useEncryption) { result = await VerifyImageAndDeviceCryptoWorkerAsync(fileHandle, sectorSize, numSectors); } else { result = await VerifyImageAndDeviceWorkerAsync(fileHandle, sectorSize, numSectors); } } Dispose(); state = OperationFinishedState.Success; } catch (Exception e) { result = false; state = OperationFinishedState.Error; exception = e; } finally { if (cancelPending) { state = OperationFinishedState.Canceled; } if (!result && !cancelPending) { state = OperationFinishedState.Error; } Dispose(); OperationFinished?.Invoke(this, new OperationFinishedEventArgs(true, result && !cancelPending, state, currentDiskOperation, exception)); } }); workingThread.Start(); }