private void InitializeMediaTester() { UpdateOptionsFromUi(); _mediaTester = new MediaTesterLib.MediaTester(_mediaTesterOptions); _mediaTester.OnException += OnMediaTesterException; _mediaTester.AfterQuickTest += AfterQuickTest; _mediaTester.AfterVerifyBlock += AfterVerifyBlock; _mediaTester.AfterWriteBlock += AfterWriteBlock; ClearLog(null, null); WriteLog(_mediaTester, $"MediaTester v{Assembly.GetEntryAssembly().GetName().Version}"); WriteLog(_mediaTester, $"Temporary data path: '{_mediaTester.GetTestDirectory()}'"); _startDateTime = DateTime.Now; }
private void LogTestCompletion(bool success) { if (_averageWriteBytesPerSecond > 0) { WriteLog(_mediaTester, $"Averge write speed: {_averageWriteBytesPerSecond.ToString("#,##0")}{BYTES_PER_SECOND}"); } if (_averageReadBytesPerSecond > 0) { WriteLog(_mediaTester, $"Averge read speed: {_averageReadBytesPerSecond.ToString("#,##0")}{BYTES_PER_SECOND}"); } if (_mediaTesterOptions.RemoveTempDataFilesUponCompletion) { RemoveTempDataFiles(); } if (success) { long lTargetAvailableBytes = MediaTesterLib.MediaTester.GetAvailableBytes(_mediaTester.GetTestDirectory(), out long lTargetTotalBytes, actual: true); WriteLog(_mediaTester, $"Verified {_mediaTester.TotalBytesVerified.ToString("#,##0")}{BYTES} of {lTargetTotalBytes.ToString("#,##0")}{BYTES} total."); WriteLog(_mediaTester, $"Media test PASSED!"); // WriteLog(_mediaTester, $"Information: Not all bytes are directly testable because directory and filenames take up additional space on the media."); if (!_mediaTesterOptions.RemoveTempDataFilesUponCompletion) { WriteLog(_mediaTester, $"Notice: Be sure to delete the temporary directory before using the media. '{_mediaTester.GetTestDirectory()}'"); } } else { WriteLog(_mediaTester, $"Media test FAILED! First failing byte: {_mediaTester.FirstFailingByteIndex.ToString("#,##0")}. Verified {_mediaTester.TotalBytesVerified.ToString("#,##0")}{BYTES}."); } if (_mediaTesterOptions.SaveTestResultsFileToMedia && (success || _mediaTesterOptions.RemoveTempDataFilesUponCompletion)) { string dateTime = DateTime.Now.ToString(TEST_RESULTS_FILENAME_DATETIME_FORMAT); string testResultsFilePath = Path.Combine(_mediaTester.Options.TestDirectory, string.Format(TEST_RESULTS_FILENAME_TEMPLATE, dateTime, success ? "PASS" : "FAIL")); string testResultsLog = ActivityLogTextBox.Text; long lTargetAvailableBytes = MediaTesterLib.MediaTester.GetAvailableBytes(_mediaTester.GetTestDirectory(), out long lTargetTotalBytes, actual: true); int spaceNeeded = testResultsLog.Length + (int)Math.Pow(2, 16); bool enoughSpace = true; while (spaceNeeded > MediaTesterLib.MediaTester.GetAvailableBytes(_mediaTester.GetTestDirectory(), out lTargetTotalBytes, actual: true)) { if (_mediaTester.RemoveTempDataFiles(1) < 1) { enoughSpace = false; break; // No files deleted } } if (enoughSpace) { File.WriteAllText(testResultsFilePath, testResultsLog); WriteLog(_mediaTester, $"Wrote test results file '{testResultsFilePath}'"); } else { WriteLog(_mediaTester, $"Not enough free space to write test results file '{testResultsFilePath}'"); } } }