Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove NRE workaround and implement progress completion via event handlers #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion 7Zip4Powershell/Compress7Zip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,15 @@ public override void Execute() {
Progress.PercentComplete = args.PercentDone;
WriteProgress(Progress);
};

compressor.FileCompressionStarted += (sender, args) => {
currentStatus = $"Compressing {args.FileName}";
Write($"Compressing \"{args.FileName}\"");
};
compressor.CompressionFinished += (sender, args) => {
Progress.StatusDescription = "Finished";
Progress.RecordType = ProgressRecordType.Completed;
WriteProgress(Progress);
};

if (directoryOrFiles.Any(path => new FileInfo(path).Exists)) {
var notFoundFiles = directoryOrFiles.Where(path => !new FileInfo(path).Exists).ToArray();
Expand Down
6 changes: 5 additions & 1 deletion 7Zip4Powershell/Expand7Zip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ public override void Execute() {
Progress.PercentComplete = args.PercentDone;
WriteProgress(Progress);
};

extractor.FileExtractionStarted += (sender, args) => {
statusDescription = $"Extracting file \"{args.FileInfo.FileName}\"";
Write(statusDescription);
};
extractor.ExtractionFinished += (sender, args) => {
Progress.StatusDescription = "Finished";
Progress.RecordType = ProgressRecordType.Completed;
WriteProgress(Progress);
};
extractor.ExtractArchive(targetPath);
}

Expand Down
9 changes: 0 additions & 9 deletions 7Zip4Powershell/ThreadedCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ protected override void EndProcessing() {
}

_thread.Join();

try {
worker.Progress.StatusDescription = "Finished";
worker.Progress.RecordType = ProgressRecordType.Completed;
WriteProgress(worker.Progress);
} catch (NullReferenceException) {
// Possible bug in PowerShell 7.4.0 leading to a null reference exception being thrown on ProgressPane completion
// This is not happening on PowerShell 5.1
}
}

private static Thread StartBackgroundThread(CmdletWorker worker) {
Expand Down