Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace RayCarrot.RCP.Metro;

Expand Down
5 changes: 1 addition & 4 deletions src/RayCarrot.RCP.Metro/Helpers/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using System.Reflection;
using System.Reflection;

namespace RayCarrot.RCP.Metro;

Expand Down Expand Up @@ -91,8 +90,6 @@ public static T[] GetValues<T>(this T input)
return EnumHelpers.GetValues<T>();
}

#nullable enable

/// <summary>
/// Gets the first attribute of specified type for the enum value
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
namespace RayCarrot.RCP.Metro;
namespace RayCarrot.RCP.Metro;

/// <summary>
/// Extension methods for an <see cref="IEnumerable{T}"/>
Expand Down Expand Up @@ -116,7 +115,7 @@ public static int FindItemIndex<T>(this IList<T> list, Predicate<T> match)
/// Disposes all items in the collection
/// </summary>
/// <param name="disposables">The collection of disposable items</param>
public static void DisposeAll(this IEnumerable<IDisposable> disposables)
public static void DisposeAll(this IEnumerable<IDisposable>? disposables)
{
disposables?.ForEach(x => x?.Dispose());
}
Expand Down
3 changes: 1 addition & 2 deletions src/RayCarrot.RCP.Metro/Helpers/Extensions/TaskExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
namespace RayCarrot.RCP.Metro;
namespace RayCarrot.RCP.Metro;

public static class TaskExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable disable
//#nullable disable
using System.Diagnostics.CodeAnalysis;
using System.Windows;
using System.Windows.Media;

Expand All @@ -15,7 +16,7 @@ public static class VisualExtensions
/// <typeparam name="T">The type of element to get</typeparam>
/// <param name="element">The element to get the type from</param>
/// <returns>The element</returns>
public static T GetDescendantByType<T>(this Visual element)
public static T? GetDescendantByType<T>(this Visual element)
where T : class
{
return element.GetDescendantByType(typeof(T)) as T;
Expand All @@ -27,7 +28,7 @@ public static T GetDescendantByType<T>(this Visual element)
/// <param name="element">The element to get the type from</param>
/// <param name="descendantType">The type of element to get</param>
/// <returns>The element</returns>
public static object GetDescendantByType(this Visual element, Type descendantType)
public static object? GetDescendantByType(this Visual? element, Type descendantType)
{
if (element == null)
return default;
Expand All @@ -38,7 +39,7 @@ public static object GetDescendantByType(this Visual element, Type descendantTyp
if (element is FrameworkElement frameworkElement)
frameworkElement.ApplyTemplate();

object foundElement = null;
object? foundElement = null;

for (var i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
{
Expand Down
10 changes: 7 additions & 3 deletions src/RayCarrot.RCP.Metro/Helpers/Extensions/WindowExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using System.Reflection;
using System.Reflection;
using System.Windows;

namespace RayCarrot.RCP.Metro;
Expand All @@ -8,6 +7,11 @@ public static class WindowExtensions
{
public static bool IsModal(this Window window)
{
return (bool)typeof(Window).GetField("_showingAsDialog", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(window);
FieldInfo? fieldInfo = typeof(Window).GetField("_showingAsDialog", BindingFlags.Instance | BindingFlags.NonPublic);

if (fieldInfo == null)
throw new Exception("Unable to get field info for '_showingAsDialog'");

return (bool)fieldInfo.GetValue(window);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
namespace RayCarrot.RCP.Metro;
namespace RayCarrot.RCP.Metro;

/// <summary>
/// Contains information for keeping track of the status of a running operation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
#nullable disable
namespace RayCarrot.RCP.Metro;
namespace RayCarrot.RCP.Metro;

/// <summary>
/// Contains information for an item during an ongoing operation
/// </summary>
public class ItemsOperationProgress
{
public ItemsOperationProgress(
Progress totalProgress,
Progress itemProgress,
object currentItem,
string operationName)
{
TotalProgress = totalProgress;
ItemProgress = itemProgress;
CurrentItem = currentItem;
OperationName = operationName;
}

/// <summary>
/// The total progress of the operation
/// </summary>
public Progress TotalProgress { get; set; }
public Progress TotalProgress { get; }

/// <summary>
/// The item progress for the currently processed item in the operation
/// </summary>
public Progress ItemProgress { get; set; }
public Progress ItemProgress { get; }

/// <summary>
/// The current item being processed in the operation
/// </summary>
public object CurrentItem { get; set; }
public object CurrentItem { get; }

/// <summary>
/// The name of the current operation,
/// usually the name of the method
/// </summary>
public string OperationName { get; set; }
public string OperationName { get; }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using System.ComponentModel;
using System.ComponentModel;
using System.Globalization;
using System.IO;

Expand Down Expand Up @@ -70,7 +69,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
/// <returns>An <see cref="Object"/> that represents the converted value.</returns>
/// <exception cref="ArgumentNullException">The destinationType parameter is null.</exception>
/// <exception cref="NotSupportedException">The conversion cannot be performed.</exception>
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
public override object? ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (!(value is FileSystemPath path))
return base.ConvertTo(context, culture, value, destinationType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using System.IO;
using System.IO;
using System.Security.Cryptography;

namespace RayCarrot.RCP.Metro;
Expand All @@ -21,7 +20,7 @@ public static class FileSystemPathExtensions
/// <exception cref="PathTooLongException">The specified path, file name, or both exceed the system-defined maximum length.
/// For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.</exception>
/// <exception cref="NotSupportedException">The path contains a colon (:) in the middle of the string</exception>
public static FileSystemInfo GetFileSystemInfo(this FileSystemPath path)
public static FileSystemInfo? GetFileSystemInfo(this FileSystemPath path)
{
switch (path.FileSystemType)
{
Expand Down
21 changes: 7 additions & 14 deletions src/RayCarrot.RCP.Metro/Installer/GameInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,13 @@ protected int TotalItems
/// <param name="itemProgress">The item progress</param>
private void OnStatusUpdated(OperationState operationState = OperationState.Running, Progress? itemProgress = null)
{
OnStatusUpdated(new OperationProgressEventArgs(new ItemsOperationProgress()
{
// Set the name to the install method
OperationName = nameof(InstallAsync),

// Set the item progress
ItemProgress = itemProgress ?? new Progress(0),

// Set the total progress
TotalProgress = new Progress((CurrentItem * 100) + (itemProgress?.Percentage_100 ?? 0), TotalPercentage),

// Set the current item
CurrentItem = CurrentObject
}, operationState));
// Set the total progress, item progress, current item and name to the install method
OnStatusUpdated(new OperationProgressEventArgs(new ItemsOperationProgress(
new Progress((CurrentItem * 100) + (itemProgress?.Percentage_100 ?? 0), TotalPercentage),
itemProgress ?? new Progress(0),
CurrentObject,
nameof(InstallAsync)
), operationState));
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
namespace RayCarrot.RCP.Metro;
namespace RayCarrot.RCP.Metro;

public class ConstLocString : LocalizedString
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
namespace RayCarrot.RCP.Metro;
namespace RayCarrot.RCP.Metro;

/// <summary>
/// A localized string which gets generated from a func when the culture changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using System.Globalization;
using System.Globalization;

namespace RayCarrot.RCP.Metro;

Expand All @@ -24,7 +23,7 @@ protected LocalizedString(bool refreshOnCultureChanged = true)
/// <summary>
/// The current string value
/// </summary>
public string Value { get; protected set; }
public string Value { get; protected set; } = null!;

#endregion

Expand Down
8 changes: 4 additions & 4 deletions src/RayCarrot.RCP.Metro/Pages/Progression/GameViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ private async Task LoadBackupInfoAsync(GameBackups_ExistingBackup? backup)
text: backup.IsCompressed.ToString(),
minUserLevel: UserLevel.Debug));

DateTime lastWriteTime = backup.Path.GetFileSystemInfo().LastWriteTime;
DateTime backupDate = backup.Path.GetFileSystemInfo()?.LastWriteTime ?? throw new Exception("Can't get backup info");

// Get the backup date
BackupInfoItems.Add(new DuoGridItemViewModel(
header: new ResourceLocString(nameof(Resources.Backup_LastBackupDate)),
text: new GeneratedLocString(() => lastWriteTime.ToShortDateString())));
header: new ResourceLocString(nameof(Resources.Backup_LastBackupDate)),
text: new GeneratedLocString(() => backupDate.ToShortDateString())));

// Get the backup size
BackupInfoItems.Add(new DuoGridItemViewModel(
Expand Down Expand Up @@ -242,7 +242,7 @@ private async Task<BackupStatus> GetBackupStatusAsync(GameBackups_ExistingBackup
if (backup.IsCompressed)
compressedBackup = new ZipArchive(File.OpenRead(backup.Path));

DateTime backupDate = backup.Path.GetFileSystemInfo().LastWriteTime;
DateTime backupDate = backup.Path.GetFileSystemInfo()?.LastWriteTime ?? throw new Exception("Can't get backup info");
BackupSearchPattern[] backupDirs = BackupInfo.BackupDirectories!;

// Get the current progress files
Expand Down
Loading