Skip to content

Fix crash when "show folder sizes" is enabled #8716

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

Merged
merged 3 commits into from
Mar 27, 2022
Merged
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
1 change: 0 additions & 1 deletion src/Files.Uwp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ sealed partial class App : Application
public static LibraryManager LibraryManager { get; private set; }
public static FileTagsManager FileTagsManager { get; private set; }
public static ExternalResourcesHelper ExternalResourcesHelper { get; private set; }
public static OptionalPackageManager OptionalPackageManager { get; private set; } = new OptionalPackageManager();

public static ILogger Logger { get; private set; }
private static readonly UniversalLogWriter logWriter = new UniversalLogWriter();
Expand Down
5 changes: 1 addition & 4 deletions src/Files.Uwp/Files.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
<Compile Include="Helpers\ColorHelpers.cs" />
<Compile Include="Helpers\CommonPaths.cs" />
<Compile Include="Helpers\FileExtensionHelpers.cs" />
<Compile Include="Helpers\ItemListDisplayHelpers\BlockingListEnumerator.cs" />
<Compile Include="Helpers\LocalizedEnumHelper.cs" />
<Compile Include="Helpers\ResourceHelpers.cs" />
<Compile Include="Helpers\FtpHelpers.cs" />
Expand All @@ -195,7 +196,6 @@
<Compile Include="Helpers\StorageSenseHelper.cs" />
<Compile Include="Helpers\WindowDecorationsHelper.cs" />
<Compile Include="Helpers\UniversalLogWriter.cs" />
<Compile Include="Helpers\SaveImageToFile.cs" />
<Compile Include="Filesystem\FolderHelpers.cs" />
<Compile Include="Filesystem\LibraryLocationItem.cs" />
<Compile Include="Filesystem\LibraryManager.cs" />
Expand All @@ -216,7 +216,6 @@
<Compile Include="Helpers\Fractions.cs" />
<Compile Include="Helpers\ItemModelListToContextFlyoutHelper.cs" />
<Compile Include="Helpers\FilePropertiesHelpers.cs" />
<Compile Include="Helpers\OptionalPackageManager.cs" />
<Compile Include="Helpers\ShellContextMenuHelper.cs" />
<Compile Include="Helpers\ItemListDisplayHelpers\SortingHelper.cs" />
<Compile Include="Helpers\UIFilesystemHelpers.cs" />
Expand Down Expand Up @@ -286,7 +285,6 @@
<Compile Include="Helpers\BitmapHelper.cs" />
<Compile Include="Helpers\CollectionDebugView.cs" />
<Compile Include="Helpers\DynamicDialogFactory.cs" />
<Compile Include="Helpers\Extension.cs" />
<Compile Include="Helpers\FileListCache\FileListCacheController.cs" />
<Compile Include="Helpers\FileListCache\IFileListCache.cs" />
<Compile Include="Helpers\IntervalSampler.cs" />
Expand Down Expand Up @@ -333,7 +331,6 @@
<DependentUpon>SearchBox.xaml</DependentUpon>
</Compile>
<Compile Include="UserControls\Selection\ExtendPreviousItemSelectionStrategy.cs" />
<Compile Include="Helpers\GenericItemsCollection.cs" />
<Compile Include="UserControls\Selection\IgnorePreviousItemSelectionStrategy.cs" />
<Compile Include="UserControls\Selection\InvertPreviousItemSelectionStrategy.cs" />
<Compile Include="UserControls\Selection\ItemSelectionStrategy.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public async Task<ReturnResult> CopyItemsFromClipboard(DataPackageView packageVi
// Get the SoftwareBitmap representation of the file
softwareBitmap = await decoder.GetSoftwareBitmapAsync();

await Helpers.SaveImageToFile.SaveSoftwareBitmapToFile(softwareBitmap, file, BitmapEncoder.PngEncoderId);
await Helpers.BitmapHelper.SaveSoftwareBitmapToFile(softwareBitmap, file, BitmapEncoder.PngEncoderId);
return ReturnResult.Success;
}
catch (Exception)
Expand Down
43 changes: 43 additions & 0 deletions src/Files.Uwp/Helpers/BitmapHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Files.Filesystem;
using Files.Filesystem.StorageItems;
using System;
using System.IO;
using System.Threading.Tasks;
Expand Down Expand Up @@ -68,5 +69,47 @@ public static async Task Rotate(string filePath, BitmapRotation rotation)

await RandomAccessStream.CopyAsync(memStream, fileStream);
}

/// <summary>
/// This function encodes a software bitmap with the specified encoder and saves it to a file
/// </summary>
/// <param name="softwareBitmap"></param>
/// <param name="outputFile"></param>
/// <param name="encoderId">The guid of the image encoder type</param>
/// <returns></returns>
public static async Task SaveSoftwareBitmapToFile(SoftwareBitmap softwareBitmap, BaseStorageFile outputFile, Guid encoderId)
{
using IRandomAccessStream stream = await outputFile.OpenAsync(FileAccessMode.ReadWrite);
// Create an encoder with the desired format
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(encoderId, stream);

// Set the software bitmap
encoder.SetSoftwareBitmap(softwareBitmap);

try
{
await encoder.FlushAsync();
}
catch (Exception err)
{
const int WINCODEC_ERR_UNSUPPORTEDOPERATION = unchecked((int)0x88982F81);
switch (err.HResult)
{
case WINCODEC_ERR_UNSUPPORTEDOPERATION:
// If the encoder does not support writing a thumbnail, then try again
// but disable thumbnail generation.
encoder.IsThumbnailGenerated = false;
break;

default:
throw;
}
}

if (encoder.IsThumbnailGenerated == false)
{
await encoder.FlushAsync();
}
}
}
}
283 changes: 0 additions & 283 deletions src/Files.Uwp/Helpers/Extension.cs

This file was deleted.

Loading