Skip to content

Commit a38471f

Browse files
authored
Ignore case when checking zip extension (#6674)
1 parent 2bccabe commit a38471f

File tree

7 files changed

+32
-16
lines changed

7 files changed

+32
-16
lines changed

Files.Launcher/Helpers/ShellFolderHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static ShellFileItem GetShellFileItem(ShellItem folderItem)
3434
{
3535
return null;
3636
}
37-
bool isFolder = folderItem.IsFolder && Path.GetExtension(folderItem.Name) != ".zip";
37+
bool isFolder = folderItem.IsFolder && !".zip".Equals(Path.GetExtension(folderItem.Name), StringComparison.OrdinalIgnoreCase);
3838
if (folderItem.Properties == null)
3939
{
4040
return new ShellFileItem(isFolder, folderItem.FileSystemPath, Path.GetFileName(folderItem.Name), folderItem.Name, DateTime.Now, DateTime.Now, DateTime.Now, null, 0, null);

Files/Filesystem/ListedItem.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,14 @@ private void Img_ImageOpened(object sender, Windows.UI.Xaml.RoutedEventArgs e)
204204

205205
if (image.PixelWidth > 0)
206206
{
207-
LoadFileIcon = true;
208-
PlaceholderDefaultIcon = null;
209-
NeedsPlaceholderGlyph = false;
210-
LoadDefaultIcon = false;
211-
LoadWebShortcutGlyph = false;
207+
Common.Extensions.IgnoreExceptions(() =>
208+
{
209+
LoadFileIcon = true;
210+
PlaceholderDefaultIcon = null;
211+
NeedsPlaceholderGlyph = false;
212+
LoadDefaultIcon = false;
213+
LoadWebShortcutGlyph = false;
214+
}, App.Logger); // 2009482836u
212215
}
213216
}
214217
}

Files/Filesystem/StorageEnumerators/Win32StorageEnumerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ CancellationToken cancellationToken
319319
opacity = Constants.UI.DimItemOpacity;
320320
}
321321

322-
if (itemFileExtension == ".zip" && await ZipStorageFolder.CheckDefaultZipApp(itemPath))
322+
if (".zip".Equals(itemFileExtension, StringComparison.OrdinalIgnoreCase) && await ZipStorageFolder.CheckDefaultZipApp(itemPath))
323323
{
324324
return new ZipItem(null, dateReturnFormat)
325325
{

Files/Filesystem/StorageItems/ZipStorageFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public override IAsyncOperation<BaseStorageFolder> GetParentAsync()
391391

392392
public static IAsyncOperation<BaseStorageFile> FromPathAsync(string path)
393393
{
394-
var marker = path.IndexOf(".zip");
394+
var marker = path.IndexOf(".zip", StringComparison.OrdinalIgnoreCase);
395395
if (marker != -1)
396396
{
397397
var containerPath = path.Substring(0, marker + ".zip".Length);

Files/Filesystem/StorageItems/ZipStorageFolder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public static IAsyncOperation<BaseStorageFolder> FromPathAsync(string path)
507507
{
508508
return AsyncInfo.Run<BaseStorageFolder>(async (cancellationToken) =>
509509
{
510-
var marker = path.IndexOf(".zip");
510+
var marker = path.IndexOf(".zip", StringComparison.OrdinalIgnoreCase);
511511
if (marker != -1)
512512
{
513513
var containerPath = path.Substring(0, marker + ".zip".Length);
@@ -526,7 +526,7 @@ public static IAsyncOperation<BaseStorageFolder> FromPathAsync(string path)
526526

527527
public static bool IsZipPath(string path)
528528
{
529-
var marker = path.IndexOf(".zip");
529+
var marker = path.IndexOf(".zip", StringComparison.OrdinalIgnoreCase);
530530
if (marker != -1)
531531
{
532532
marker += ".zip".Length;

Files/Helpers/ZipHelpers.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,26 @@ public static async Task ExtractArchive(BaseStorageFile archive, BaseStorageFold
112112
{
113113
int currentBlockSize = 0;
114114

115-
using (Stream entryStream = zipFile.GetInputStream(entry))
115+
try
116116
{
117-
while ((currentBlockSize = await entryStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
117+
using (Stream entryStream = zipFile.GetInputStream(entry))
118118
{
119-
await destinationStream.WriteAsync(buffer, 0, currentBlockSize);
120-
121-
if (cancellationToken.IsCancellationRequested) // Check if cancelled
119+
while ((currentBlockSize = await entryStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
122120
{
123-
return;
121+
await destinationStream.WriteAsync(buffer, 0, currentBlockSize);
122+
123+
if (cancellationToken.IsCancellationRequested) // Check if cancelled
124+
{
125+
return;
126+
}
124127
}
125128
}
126129
}
130+
catch (Exception ex)
131+
{
132+
App.Logger.Warn(ex, $"Error extracting file: {filePath}");
133+
return; // TODO: handle error
134+
}
127135
}
128136

129137
entriesFinished++;

Files/Services/Implementation/FileTagsSettingsService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public IList<FileTag> FileTagList
3333

3434
public FileTag GetTagById(string uid)
3535
{
36+
if (FileTagList.Any(x => x.Uid == null))
37+
{
38+
// Tags file is invalid, regenerate
39+
FileTagList = s_defaultFileTags;
40+
}
3641
var tag = FileTagList.SingleOrDefault(x => x.Uid == uid);
3742
if (!string.IsNullOrEmpty(uid) && tag == null)
3843
{

0 commit comments

Comments
 (0)