Skip to content

Commit

Permalink
Fix: Fixed some null ref warnings in decompress helper (#14086)
Browse files Browse the repository at this point in the history
Co-authored-by: hishitetsu <[email protected]>
  • Loading branch information
yaira2 and hishitetsu authored Nov 27, 2023
1 parent e1be096 commit d4ec2a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public DecompressArchive()

public override Task ExecuteAsync()
{
if (context.ShellPage is null)
return Task.CompletedTask;

return DecompressHelper.DecompressArchiveAsync(context.ShellPage);
}

Expand Down
16 changes: 8 additions & 8 deletions src/Files.App/Utils/Archives/DecompressHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ public static async Task DecompressArchiveAsync(IShellPage associatedInstance)
if (associatedInstance == null)
return;

BaseStorageFile archive = await StorageHelpers.ToStorageItem<BaseStorageFile>(associatedInstance.SlimContentPage.SelectedItems.Count != 0
? associatedInstance.SlimContentPage.SelectedItem.ItemPath
: associatedInstance.FilesystemViewModel.WorkingDirectory);
BaseStorageFile archive = await StorageHelpers.ToStorageItem<BaseStorageFile>(associatedInstance.SlimContentPage?.SelectedItems?.Count is null or 0
? associatedInstance.FilesystemViewModel.WorkingDirectory
: associatedInstance.SlimContentPage.SelectedItem.ItemPath);

if (archive is null)
if (archive?.Path is null)
return;

var isArchiveEncrypted = await FilesystemTasks.Wrap(() => DecompressHelper.IsArchiveEncrypted(archive));
Expand Down Expand Up @@ -177,7 +177,7 @@ public static async Task DecompressArchiveAsync(IShellPage associatedInstance)

public static async Task DecompressArchiveHereAsync(IShellPage associatedInstance)
{
if (associatedInstance?.SlimContentPage == null)
if (associatedInstance?.SlimContentPage?.SelectedItems == null)
return;

foreach (var selectedItem in associatedInstance.SlimContentPage.SelectedItems)
Expand All @@ -186,7 +186,7 @@ public static async Task DecompressArchiveHereAsync(IShellPage associatedInstanc
BaseStorageFile archive = await StorageHelpers.ToStorageItem<BaseStorageFile>(selectedItem.ItemPath);
BaseStorageFolder currentFolder = await StorageHelpers.ToStorageItem<BaseStorageFolder>(associatedInstance.FilesystemViewModel.CurrentFolder.ItemPath);

if (archive is null)
if (archive?.Path is null)
return;

if (await FilesystemTasks.Wrap(() => IsArchiveEncrypted(archive)))
Expand Down Expand Up @@ -216,7 +216,7 @@ public static async Task DecompressArchiveHereAsync(IShellPage associatedInstanc

public static async Task DecompressArchiveToChildFolderAsync(IShellPage associatedInstance)
{
if (associatedInstance?.SlimContentPage == null)
if (associatedInstance?.SlimContentPage?.SelectedItems == null)
return;

foreach (var selectedItem in associatedInstance.SlimContentPage.SelectedItems)
Expand All @@ -227,7 +227,7 @@ public static async Task DecompressArchiveToChildFolderAsync(IShellPage associat
BaseStorageFolder currentFolder = await StorageHelpers.ToStorageItem<BaseStorageFolder>(associatedInstance.FilesystemViewModel.CurrentFolder.ItemPath);
BaseStorageFolder destinationFolder = null;

if (archive is null)
if (archive?.Path is null)
return;

if (await FilesystemTasks.Wrap(() => DecompressHelper.IsArchiveEncrypted(archive)))
Expand Down

0 comments on commit d4ec2a0

Please sign in to comment.