Skip to content

Codebase: Remove unnecessary casts #11015

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 5 commits into from
Jan 16, 2023
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
2 changes: 1 addition & 1 deletion src/Files.App/Filesystem/FileTagsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static void UpdateTagsDb()
{
var frn = GetFileFRN(file.FilePath);
dbInstance.UpdateTag(file.FilePath, frn, null);
dbInstance.SetTags(file.FilePath, (ulong?)frn, tag);
dbInstance.SetTags(file.FilePath, frn, tag);
}, App.Logger))
{
dbInstance.SetTags(file.FilePath, null, null);
Expand Down
12 changes: 6 additions & 6 deletions src/Files.App/Filesystem/StorageItems/ZipStorageFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public override IAsyncOperation<IRandomAccessStream> OpenAsync(FileAccessMode ac
var ms = new MemoryStream();
await zipFile.ExtractFileAsync(entry.Index, ms);
ms.Position = 0;
return new NonSeekableRandomAccessStreamForRead(ms, (ulong)entry.Size)
return new NonSeekableRandomAccessStreamForRead(ms, entry.Size)
{
DisposeCallback = () => zipFile.Dispose()
};
Expand Down Expand Up @@ -167,7 +167,7 @@ public override IAsyncOperation<IRandomAccessStreamWithContentType> OpenReadAsyn
var ms = new MemoryStream();
await zipFile.ExtractFileAsync(entry.Index, ms);
ms.Position = 0;
var nsStream = new NonSeekableRandomAccessStreamForRead(ms, (ulong)entry.Size)
var nsStream = new NonSeekableRandomAccessStreamForRead(ms, entry.Size)
{
DisposeCallback = () => zipFile.Dispose()
};
Expand Down Expand Up @@ -205,7 +205,7 @@ public override IAsyncOperation<IInputStream> OpenSequentialReadAsync()
var ms = new MemoryStream();
await zipFile.ExtractFileAsync(entry.Index, ms);
ms.Position = 0;
return new NonSeekableRandomAccessStreamForRead(ms, (ulong)entry.Size)
return new NonSeekableRandomAccessStreamForRead(ms, entry.Size)
{
DisposeCallback = () => zipFile.Dispose()
};
Expand Down Expand Up @@ -245,7 +245,7 @@ public override IAsyncOperation<BaseStorageFile> CopyAsync(IStorageFolder destin
var ms = new MemoryStream();
await zipFile.ExtractFileAsync(entry.Index, ms);
ms.Position = 0;
using var inStream = new NonSeekableRandomAccessStreamForRead(ms, (ulong)entry.Size);
using var inStream = new NonSeekableRandomAccessStreamForRead(ms, entry.Size);
return await cwsf.CreateFileAsync(inStream.AsStreamForRead(), desiredNewName, option.Convert());
}
else
Expand Down Expand Up @@ -469,7 +469,7 @@ private IAsyncOperation<Stream> OpenZipFileAsync(FileAccessMode accessMode)
{
return null;
}
return (Stream)new FileStream(hFile, readWrite ? FileAccess.ReadWrite : FileAccess.Read);
return new FileStream(hFile, readWrite ? FileAccess.ReadWrite : FileAccess.Read);
}
});
}
Expand Down Expand Up @@ -518,7 +518,7 @@ private class ZipFileBasicProperties : BaseBasicProperties

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

public override ulong Size => (ulong)entry.Size;
public override ulong Size => entry.Size;
}
}
}
4 changes: 2 additions & 2 deletions src/Files.App/Filesystem/StorageItems/ZipStorageFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ private IAsyncOperation<Stream> OpenZipFileAsync(FileAccessMode accessMode)
{
return null;
}
return (Stream)new FileStream(hFile, readWrite ? FileAccess.ReadWrite : FileAccess.Read);
return new FileStream(hFile, readWrite ? FileAccess.ReadWrite : FileAccess.Read);
}
});
}
Expand Down Expand Up @@ -631,7 +631,7 @@ private class ZipFolderBasicProperties : BaseBasicProperties

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

public override ulong Size => (ulong)entry.Size;
public override ulong Size => entry.Size;
}
}
}
8 changes: 4 additions & 4 deletions src/Files.App/Helpers/AdaptiveLayoutHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, str
foldersCount = filesAndFolders.Where((item) => item.PrimaryItemAttribute == StorageItemTypes.Folder).Count();
miscFilesCount = allItemsCount - (mediaCount + imagesCount + foldersCount);

mediaPercentage = (float)((float)mediaCount / (float)allItemsCount) * 100.0f;
imagesPercentage = (float)((float)imagesCount / (float)allItemsCount) * 100.0f;
foldersPercentage = (float)((float)foldersCount / (float)allItemsCount) * 100.0f;
miscFilesPercentage = (float)((float)miscFilesCount / (float)allItemsCount) * 100.0f;
mediaPercentage = mediaCount * 100.0f / allItemsCount;
imagesPercentage = imagesCount * 100.0f / allItemsCount;
foldersPercentage = foldersCount * 100.0f / allItemsCount;
miscFilesPercentage = miscFilesCount * 100.0f / allItemsCount;

// Decide layout mode

Expand Down
16 changes: 8 additions & 8 deletions src/Files.App/Helpers/FileOperationsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
{
Succeeded = false,
Destination = filePath,
HResult = (int)-1
HResult = -1
});
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
{
Succeeded = false,
Source = fileToDeletePath[i],
HResult = (int)-1
HResult = -1
});
}
}
Expand All @@ -146,7 +146,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
{
Succeeded = false,
Source = e.SourceItem.GetParsingPath(),
HResult = (int)HRESULT.COPYENGINE_E_RECYCLE_BIN_NOT_FOUND
HResult = HRESULT.COPYENGINE_E_RECYCLE_BIN_NOT_FOUND
});
throw new Win32Exception(HRESULT.COPYENGINE_E_RECYCLE_BIN_NOT_FOUND); // E_FAIL, stops operation
}
Expand All @@ -156,7 +156,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
{
Succeeded = true,
Source = e.SourceItem.GetParsingPath(),
HResult = (int)HRESULT.COPYENGINE_E_USER_CANCELLED
HResult = HRESULT.COPYENGINE_E_USER_CANCELLED
});
throw new Win32Exception(HRESULT.COPYENGINE_E_USER_CANCELLED); // E_FAIL, stops operation
}
Expand Down Expand Up @@ -211,7 +211,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
{
Succeeded = false,
Source = fileToDeletePath[i],
HResult = (int)-1
HResult = -1
});
}
}
Expand Down Expand Up @@ -289,7 +289,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
{
Succeeded = false,
Source = fileToRenamePath,
HResult = (int)-1
HResult = -1
});
}

Expand Down Expand Up @@ -359,7 +359,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
Succeeded = false,
Source = fileToMovePath[i],
Destination = moveDestination[i],
HResult = (int)-1
HResult = -1
});
}
}
Expand Down Expand Up @@ -440,7 +440,7 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
Succeeded = false,
Source = fileToCopyPath[i],
Destination = copyDestination[i],
HResult = (int)-1
HResult = -1
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/Fractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static string ToFractions(this double number, int precision = 4)

private static void RoundToMixedFraction(double input, int accuracy, out int whole, out int numerator, out int denominator)
{
double dblAccuracy = (double)accuracy;
double dblAccuracy = accuracy;
whole = (int)(Math.Truncate(input));
var fraction = Math.Abs(input - whole);
if (fraction == 0)
Expand Down
4 changes: 1 addition & 3 deletions src/Files.App/Helpers/NaturalStringComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public class NaturalStringComparer
{
public static IComparer<object> GetForProcessor()
{
return NativeWinApiHelper.IsRunningOnArm ?
(IComparer<object>)new StringComparerArm64() :
(IComparer<object>)new StringComparerDefault();
return NativeWinApiHelper.IsRunningOnArm ? new StringComparerArm64() : new StringComparerDefault();
}

private class StringComparerArm64 : IComparer<object>
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Helpers/StorageHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileFromPathA
public static IStorageItemWithPath FromPathAndType(string customPath, FilesystemItemType? itemType)
{
return (itemType == FilesystemItemType.File) ?
(IStorageItemWithPath)new StorageFileWithPath(null, customPath) :
(IStorageItemWithPath)new StorageFolderWithPath(null, customPath);
new StorageFileWithPath(null, customPath) :
new StorageFolderWithPath(null, customPath);
}

public static async Task<FilesystemItemType> GetTypeFromPath(string path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void RectangleSelection_PointerPressed(object sender, PointerRoutedEvent
selectionStrategy = e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control) ?
new InvertPreviousItemSelectionStrategy(uiElement.SelectedItems, prevSelectedItems) :
e.KeyModifiers.HasFlag(VirtualKeyModifiers.Shift) ?
(ItemSelectionStrategy)new ExtendPreviousItemSelectionStrategy(uiElement.SelectedItems, prevSelectedItems) :
new ExtendPreviousItemSelectionStrategy(uiElement.SelectedItems, prevSelectedItems) :
new IgnorePreviousItemSelectionStrategy(uiElement.SelectedItems);

selectionStrategy.HandleNoItemSelected();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public bool DriveCapacityVisibility

public double DrivePercentageValue
{
get => DriveCapacityValue > 0 ? (double)DriveUsedSpaceValue / (double)DriveCapacityValue * 100 : 0;
get => DriveCapacityValue > 0 ? DriveUsedSpaceValue / (double)DriveCapacityValue * 100 : 0;
}

private bool itemAttributesVisibility = true;
Expand Down