Skip to content

Commit 4ba5194

Browse files
authored
Codebase: Remove unnecessary casts (#11015)
1 parent 3a9fc54 commit 4ba5194

File tree

10 files changed

+27
-29
lines changed

10 files changed

+27
-29
lines changed

src/Files.App/Filesystem/FileTagsHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static void UpdateTagsDb()
8181
{
8282
var frn = GetFileFRN(file.FilePath);
8383
dbInstance.UpdateTag(file.FilePath, frn, null);
84-
dbInstance.SetTags(file.FilePath, (ulong?)frn, tag);
84+
dbInstance.SetTags(file.FilePath, frn, tag);
8585
}, App.Logger))
8686
{
8787
dbInstance.SetTags(file.FilePath, null, null);

src/Files.App/Filesystem/StorageItems/ZipStorageFile.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public override IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode ac
122122
var ms = new MemoryStream();
123123
await zipFile.ExtractFileAsync(entry.Index, ms);
124124
ms.Position = 0;
125-
return new NonSeekableRandomAccessStreamForRead(ms, (ulong)entry.Size)
125+
return new NonSeekableRandomAccessStreamForRead(ms, entry.Size)
126126
{
127127
DisposeCallback = () => zipFile.Dispose()
128128
};
@@ -167,7 +167,7 @@ public override IAsyncOperation<IRandomAccessStreamWithContentType> OpenReadAsyn
167167
var ms = new MemoryStream();
168168
await zipFile.ExtractFileAsync(entry.Index, ms);
169169
ms.Position = 0;
170-
var nsStream = new NonSeekableRandomAccessStreamForRead(ms, (ulong)entry.Size)
170+
var nsStream = new NonSeekableRandomAccessStreamForRead(ms, entry.Size)
171171
{
172172
DisposeCallback = () => zipFile.Dispose()
173173
};
@@ -205,7 +205,7 @@ public override IAsyncOperation<IInputStream> OpenSequentialReadAsync()
205205
var ms = new MemoryStream();
206206
await zipFile.ExtractFileAsync(entry.Index, ms);
207207
ms.Position = 0;
208-
return new NonSeekableRandomAccessStreamForRead(ms, (ulong)entry.Size)
208+
return new NonSeekableRandomAccessStreamForRead(ms, entry.Size)
209209
{
210210
DisposeCallback = () => zipFile.Dispose()
211211
};
@@ -245,7 +245,7 @@ public override IAsyncOperation<BaseStorageFile> CopyAsync(IStorageFolder destin
245245
var ms = new MemoryStream();
246246
await zipFile.ExtractFileAsync(entry.Index, ms);
247247
ms.Position = 0;
248-
using var inStream = new NonSeekableRandomAccessStreamForRead(ms, (ulong)entry.Size);
248+
using var inStream = new NonSeekableRandomAccessStreamForRead(ms, entry.Size);
249249
return await cwsf.CreateFileAsync(inStream.AsStreamForRead(), desiredNewName, option.Convert());
250250
}
251251
else
@@ -469,7 +469,7 @@ private IAsyncOperation<Stream> OpenZipFileAsync(FileAccessMode accessMode)
469469
{
470470
return null;
471471
}
472-
return (Stream)new FileStream(hFile, readWrite ? FileAccess.ReadWrite : FileAccess.Read);
472+
return new FileStream(hFile, readWrite ? FileAccess.ReadWrite : FileAccess.Read);
473473
}
474474
});
475475
}
@@ -518,7 +518,7 @@ private class ZipFileBasicProperties : BaseBasicProperties
518518

519519
public override DateTimeOffset ItemDate => entry.CreationTime == DateTime.MinValue ? DateTimeOffset.MinValue : entry.CreationTime;
520520

521-
public override ulong Size => (ulong)entry.Size;
521+
public override ulong Size => entry.Size;
522522
}
523523
}
524524
}

src/Files.App/Filesystem/StorageItems/ZipStorageFolder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ private IAsyncOperation<Stream> OpenZipFileAsync(FileAccessMode accessMode)
563563
{
564564
return null;
565565
}
566-
return (Stream)new FileStream(hFile, readWrite ? FileAccess.ReadWrite : FileAccess.Read);
566+
return new FileStream(hFile, readWrite ? FileAccess.ReadWrite : FileAccess.Read);
567567
}
568568
});
569569
}
@@ -631,7 +631,7 @@ private class ZipFolderBasicProperties : BaseBasicProperties
631631

632632
public override DateTimeOffset ItemDate => entry.CreationTime == DateTime.MinValue ? DateTimeOffset.MinValue : entry.CreationTime;
633633

634-
public override ulong Size => (ulong)entry.Size;
634+
public override ulong Size => entry.Size;
635635
}
636636
}
637637
}

src/Files.App/Helpers/AdaptiveLayoutHelpers.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, str
9292
foldersCount = filesAndFolders.Where((item) => item.PrimaryItemAttribute == StorageItemTypes.Folder).Count();
9393
miscFilesCount = allItemsCount - (mediaCount + imagesCount + foldersCount);
9494

95-
mediaPercentage = (float)((float)mediaCount / (float)allItemsCount) * 100.0f;
96-
imagesPercentage = (float)((float)imagesCount / (float)allItemsCount) * 100.0f;
97-
foldersPercentage = (float)((float)foldersCount / (float)allItemsCount) * 100.0f;
98-
miscFilesPercentage = (float)((float)miscFilesCount / (float)allItemsCount) * 100.0f;
95+
mediaPercentage = mediaCount * 100.0f / allItemsCount;
96+
imagesPercentage = imagesCount * 100.0f / allItemsCount;
97+
foldersPercentage = foldersCount * 100.0f / allItemsCount;
98+
miscFilesPercentage = miscFilesCount * 100.0f / allItemsCount;
9999

100100
// Decide layout mode
101101

src/Files.App/Helpers/FileOperationsHelpers.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
6767
{
6868
Succeeded = false,
6969
Destination = filePath,
70-
HResult = (int)-1
70+
HResult = -1
7171
});
7272
}
7373

@@ -132,7 +132,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
132132
{
133133
Succeeded = false,
134134
Source = fileToDeletePath[i],
135-
HResult = (int)-1
135+
HResult = -1
136136
});
137137
}
138138
}
@@ -146,7 +146,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
146146
{
147147
Succeeded = false,
148148
Source = e.SourceItem.GetParsingPath(),
149-
HResult = (int)HRESULT.COPYENGINE_E_RECYCLE_BIN_NOT_FOUND
149+
HResult = HRESULT.COPYENGINE_E_RECYCLE_BIN_NOT_FOUND
150150
});
151151
throw new Win32Exception(HRESULT.COPYENGINE_E_RECYCLE_BIN_NOT_FOUND); // E_FAIL, stops operation
152152
}
@@ -156,7 +156,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
156156
{
157157
Succeeded = true,
158158
Source = e.SourceItem.GetParsingPath(),
159-
HResult = (int)HRESULT.COPYENGINE_E_USER_CANCELLED
159+
HResult = HRESULT.COPYENGINE_E_USER_CANCELLED
160160
});
161161
throw new Win32Exception(HRESULT.COPYENGINE_E_USER_CANCELLED); // E_FAIL, stops operation
162162
}
@@ -211,7 +211,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
211211
{
212212
Succeeded = false,
213213
Source = fileToDeletePath[i],
214-
HResult = (int)-1
214+
HResult = -1
215215
});
216216
}
217217
}
@@ -289,7 +289,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
289289
{
290290
Succeeded = false,
291291
Source = fileToRenamePath,
292-
HResult = (int)-1
292+
HResult = -1
293293
});
294294
}
295295

@@ -359,7 +359,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
359359
Succeeded = false,
360360
Source = fileToMovePath[i],
361361
Destination = moveDestination[i],
362-
HResult = (int)-1
362+
HResult = -1
363363
});
364364
}
365365
}
@@ -440,7 +440,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
440440
Succeeded = false,
441441
Source = fileToCopyPath[i],
442442
Destination = copyDestination[i],
443-
HResult = (int)-1
443+
HResult = -1
444444
});
445445
}
446446
}

src/Files.App/Helpers/Fractions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static string ToFractions(this double number, int precision = 4)
2828

2929
private static void RoundToMixedFraction(double input, int accuracy, out int whole, out int numerator, out int denominator)
3030
{
31-
double dblAccuracy = (double)accuracy;
31+
double dblAccuracy = accuracy;
3232
whole = (int)(Math.Truncate(input));
3333
var fraction = Math.Abs(input - whole);
3434
if (fraction == 0)

src/Files.App/Helpers/NaturalStringComparer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ public class NaturalStringComparer
3939
{
4040
public static IComparer<object> GetForProcessor()
4141
{
42-
return NativeWinApiHelper.IsRunningOnArm ?
43-
(IComparer<object>)new StringComparerArm64() :
44-
(IComparer<object>)new StringComparerDefault();
42+
return NativeWinApiHelper.IsRunningOnArm ? new StringComparerArm64() : new StringComparerDefault();
4543
}
4644

4745
private class StringComparerArm64 : IComparer<object>

src/Files.App/Helpers/StorageHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileFromPathA
149149
public static IStorageItemWithPath FromPathAndType(string customPath, FilesystemItemType? itemType)
150150
{
151151
return (itemType == FilesystemItemType.File) ?
152-
(IStorageItemWithPath)new StorageFileWithPath(null, customPath) :
153-
(IStorageItemWithPath)new StorageFolderWithPath(null, customPath);
152+
new StorageFileWithPath(null, customPath) :
153+
new StorageFolderWithPath(null, customPath);
154154
}
155155

156156
public static async Task<FilesystemItemType> GetTypeFromPath(string path)

src/Files.App/UserControls/Selection/RectangleSelection_ListViewBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private void RectangleSelection_PointerPressed(object sender, PointerRoutedEvent
137137
selectionStrategy = e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control) ?
138138
new InvertPreviousItemSelectionStrategy(uiElement.SelectedItems, prevSelectedItems) :
139139
e.KeyModifiers.HasFlag(VirtualKeyModifiers.Shift) ?
140-
(ItemSelectionStrategy)new ExtendPreviousItemSelectionStrategy(uiElement.SelectedItems, prevSelectedItems) :
140+
new ExtendPreviousItemSelectionStrategy(uiElement.SelectedItems, prevSelectedItems) :
141141
new IgnorePreviousItemSelectionStrategy(uiElement.SelectedItems);
142142

143143
selectionStrategy.HandleNoItemSelected();

src/Files.App/ViewModels/SelectedItemsPropertiesViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public bool DriveCapacityVisibility
425425

426426
public double DrivePercentageValue
427427
{
428-
get => DriveCapacityValue > 0 ? (double)DriveUsedSpaceValue / (double)DriveCapacityValue * 100 : 0;
428+
get => DriveCapacityValue > 0 ? DriveUsedSpaceValue / (double)DriveCapacityValue * 100 : 0;
429429
}
430430

431431
private bool itemAttributesVisibility = true;

0 commit comments

Comments
 (0)