Skip to content

Commit 66bb116

Browse files
authored
Bug Fixes (#6097)
1 parent e55b9fe commit 66bb116

File tree

7 files changed

+35
-65
lines changed

7 files changed

+35
-65
lines changed

Files/Extensions/GenericsExtensions.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

Files/Extensions/LinqExtensions.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,6 @@ internal static class LinqExtensions
2121
/// <returns></returns>
2222
public static bool IsEmpty<T>(this IEnumerable<T> enumerable) => enumerable == null || !enumerable.Any();
2323

24-
public static T PreventNull<T>(this T element, T defaultValue, bool throwOnNullDefaultValue = true)
25-
{
26-
if (element.IsNull()) // Is null
27-
{
28-
if (defaultValue.IsNull() && throwOnNullDefaultValue) // Default value is null
29-
{
30-
Debugger.Break();
31-
throw new NullReferenceException($"[PreventNull] Provided defautValue was null! Type: {typeof(T)}");
32-
}
33-
else
34-
{
35-
return defaultValue;
36-
}
37-
}
38-
else
39-
{
40-
return element;
41-
}
42-
}
43-
4424
/// <summary>
4525
/// Enumerates through <see cref="IEnumerable{T}"/> of elements and executes <paramref name="action"/>
4626
/// </summary>

Files/Files.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@
168168
<Compile Include="Extensions\DateTimeExtensions.cs" />
169169
<Compile Include="Extensions\EnumExtensions.cs" />
170170
<Compile Include="Extensions\FileIconInfoExtensions.cs" />
171-
<Compile Include="Extensions\GenericsExtensions.cs" />
172171
<Compile Include="Extensions\ImageSourceExtensions.cs" />
173172
<Compile Include="Extensions\KeyboardAcceleratorExtensions.cs" />
174173
<Compile Include="Filesystem\FilesystemOperations\ShellFilesystemOperations.cs" />

Files/Filesystem/FilesystemOperations/Helpers/FilesystemHelpers.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public async Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPat
202202
"StatusDeletionCancelled".GetLocalized(),
203203
string.Format(source.Count() > 1 ?
204204
itemsDeleted > 1 ? "StatusDeleteCanceledDetails_Plural".GetLocalized() : "StatusDeleteCanceledDetails_Plural2".GetLocalized()
205-
: "StatusDeleteCanceledDetails_Singular".GetLocalized(), source.Count(), sourceDir, itemsDeleted),
205+
: "StatusDeleteCanceledDetails_Singular".GetLocalized(), source.Count(), sourceDir, null, itemsDeleted),
206206
0,
207207
ReturnResult.Cancelled,
208208
FileOperationType.Delete);
@@ -987,6 +987,12 @@ public async Task<ReturnResult> RecycleItemsFromClipboard(DataPackageView packag
987987
var itemPathOrName = string.IsNullOrEmpty(source.ElementAt(i).Path) ?
988988
(string.IsNullOrEmpty(source.ElementAt(i).Item.Path) ? source.ElementAt(i).Item.Name : source.ElementAt(i).Item.Path) : source.ElementAt(i).Path;
989989
incomingItems.Add(new FilesystemItemsOperationItemModel(operationType, itemPathOrName, destination.ElementAt(i)));
990+
if (collisions.ContainsKey(incomingItems.ElementAt(i).SourcePath))
991+
{
992+
// Something strange happened, log
993+
App.Logger.Warn($"Duplicate key when resolving conflicts: {incomingItems.ElementAt(i).SourcePath}, {source.ElementAt(i).Name}\n" +
994+
$"Source: {string.Join(", ", source.Select(x => string.IsNullOrEmpty(x.Path) ? (string.IsNullOrEmpty(x.Item.Path) ? x.Item.Name : x.Item.Path) : x.Path))}");
995+
}
990996
collisions.AddIfNotPresent(incomingItems.ElementAt(i).SourcePath, FileNameConflictResolveOptionType.GenerateNewName);
991997

992998
if (destination.Count() > 0 && StorageItemHelpers.Exists(destination.ElementAt(i))) // Same item names in both directories
@@ -1026,23 +1032,25 @@ public async Task<ReturnResult> RecycleItemsFromClipboard(DataPackageView packag
10261032
List<IFilesystemOperationItemModel> itemsResult = dialog.ViewModel.GetResult();
10271033
foreach (var item in itemsResult)
10281034
{
1029-
collisions.Add(item.SourcePath, item.ConflictResolveOption);
1035+
collisions.AddIfNotPresent(item.SourcePath, item.ConflictResolveOption);
10301036
}
10311037
}
10321038

10331039
// Since collisions are scrambled, we need to sort them PATH--PATH
10341040
List<FileNameConflictResolveOptionType> newCollisions = new List<FileNameConflictResolveOptionType>();
10351041

1036-
for (int i = 0; i < collisions.Count; i++)
1042+
for (int i = 0; i < source.Count(); i++)
10371043
{
1038-
for (int j = 0; j < source.Count(); j++)
1044+
var itemPathOrName = string.IsNullOrEmpty(source.ElementAt(i).Path) ?
1045+
(string.IsNullOrEmpty(source.ElementAt(i).Item.Path) ? source.ElementAt(i).Item.Name : source.ElementAt(i).Item.Path) : source.ElementAt(i).Path;
1046+
var match = collisions.SingleOrDefault(x => x.Key == itemPathOrName);
1047+
if (match.Key != null)
10391048
{
1040-
var itemPathOrName = string.IsNullOrEmpty(source.ElementAt(j).Path) ?
1041-
(string.IsNullOrEmpty(source.ElementAt(j).Item.Path) ? source.ElementAt(j).Item.Name : source.ElementAt(j).Item.Path) : source.ElementAt(j).Path;
1042-
if (collisions.ElementAt(i).Key == itemPathOrName)
1043-
{
1044-
newCollisions.Add(collisions.ElementAt(j).Value);
1045-
}
1049+
newCollisions.Add(match.Value);
1050+
}
1051+
else
1052+
{
1053+
newCollisions.Add(FileNameConflictResolveOptionType.Skip);
10461054
}
10471055
}
10481056

Files/Filesystem/StorageItems/BaseStorageItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public class BaseBasicProperties : BaseStorageItemExtraProperties
115115

116116
public abstract class BaseStorageFolder : IBaseStorageFolder
117117
{
118-
public static implicit operator BaseStorageFolder(StorageFolder value) => new SystemStorageFolder(value);
118+
public static implicit operator BaseStorageFolder(StorageFolder value) => value != null ? new SystemStorageFolder(value) : null;
119119

120120
public abstract IAsyncOperation<BaseStorageFile> CreateFileAsync(string desiredName);
121121
public abstract IAsyncOperation<BaseStorageFile> CreateFileAsync(string desiredName, CreationCollisionOption options);
@@ -332,7 +332,7 @@ StorageItemContentProperties IStorageItemProperties.Properties
332332

333333
public abstract class BaseStorageFile : IBaseStorageFile
334334
{
335-
public static implicit operator BaseStorageFile(StorageFile value) => new SystemStorageFile(value);
335+
public static implicit operator BaseStorageFile(StorageFile value) => value != null ? new SystemStorageFile(value) : null;
336336

337337
public abstract IAsyncOperation<StorageFile> ToStorageFileAsync();
338338
public abstract IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode accessMode);

Files/Helpers/ZipHelpers.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Files.Filesystem.StorageItems;
2+
using ICSharpCode.SharpZipLib.Core;
23
using ICSharpCode.SharpZipLib.Zip;
34
using System;
45
using System.Collections.Generic;
@@ -38,8 +39,19 @@ public static async Task ExtractArchive(BaseStorageFile archive, BaseStorageFold
3839
var wnt = new WindowsNameTransform(destinationFolder.Path);
3940

4041
var directories = new List<string>();
41-
directories.AddRange(directoryEntries.Select((item) => wnt.TransformDirectory(item.Name)));
42-
directories.AddRange(fileEntries.Select((item) => Path.GetDirectoryName(wnt.TransformFile(item.Name))));
42+
try
43+
{
44+
directories.AddRange(directoryEntries.Select((item) => wnt.TransformDirectory(item.Name)));
45+
directories.AddRange(fileEntries.Select((item) => Path.GetDirectoryName(wnt.TransformFile(item.Name))));
46+
}
47+
catch (InvalidNameException ex)
48+
{
49+
App.Logger.Warn(ex, $"Error transforming zip names into: {destinationFolder.Path}\n" +
50+
$"Directories: {directoryEntries.Select(x => x.Name)}\n" +
51+
$"Files: {fileEntries.Select(x => x.Name)}");
52+
return;
53+
}
54+
4355
foreach (var dir in directories.Distinct().OrderBy(x => x.Length))
4456
{
4557
if (!NativeFileOperationsHelper.CreateDirectoryFromApp(dir, IntPtr.Zero))

Files/Views/MainPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ private void UpdatePreviewPaneProperties()
191191
LoadPreviewPaneChanged();
192192
if (PreviewPane != null)
193193
{
194-
PreviewPane.Model = SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn.SlimContentPage?.PreviewPaneViewModel;
194+
PreviewPane.Model = SidebarAdaptiveViewModel.PaneHolder?.ActivePaneOrColumn?.SlimContentPage?.PreviewPaneViewModel;
195195
}
196196
}
197197

0 commit comments

Comments
 (0)