Skip to content

Commit e8a4aa2

Browse files
committed
Fix nullability
1 parent 5041f17 commit e8a4aa2

3 files changed

Lines changed: 30 additions & 34 deletions

File tree

CollapseLauncher/Classes/GamePresetProperty.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal static GamePresetProperty Create(UIElement uiElementParent, ILauncherAp
5353
property.GameSettings = new HonkaiSettings(property.GameVersion);
5454
property.GameCache = new HonkaiCache(uiElementParent, property.GameVersion, property.GameSettings);
5555
property.GameRepair = new HonkaiRepairV2(uiElementParent, property.GameVersion, property.GameSettings);
56-
property.GameInstall = new HonkaiInstall(uiElementParent, property.GameVersion, property.GameSettings);
56+
property.GameInstall = new HonkaiInstall(uiElementParent, property.GameVersion, property.GameSettings, property.GameRepair);
5757
break;
5858
case GameNameType.StarRail:
5959
property.GameVersion = new GameTypeStarRailVersion(launcherApis, gamePreset);

CollapseLauncher/Classes/InstallManagement/Honkai/HonkaiInstall.cs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,30 @@
2727
// ReSharper disable IdentifierTypo
2828
// ReSharper disable SwitchStatementMissingSomeEnumCasesNoDefault
2929
// ReSharper disable SwitchStatementHandlesSomeKnownEnumValuesWithDefault
30+
#pragma warning disable IDE0130
3031

32+
#nullable enable
3133
namespace CollapseLauncher.InstallManager.Honkai
3234
{
3335
internal sealed partial class HonkaiInstall : InstallManagerBase
3436
{
3537
#region Override Properties
3638

37-
protected override bool _canDeltaPatch => GameVersionManager.IsGameHasDeltaPatch();
38-
protected override DeltaPatchProperty _gameDeltaPatchProperty => GameVersionManager.GetDeltaPatchInfo();
39+
protected override bool _canDeltaPatch => GameVersionManager.IsGameHasDeltaPatch();
40+
protected override DeltaPatchProperty? _gameDeltaPatchProperty => GameVersionManager.GetDeltaPatchInfo();
3941

4042
#endregion
4143

4244
#region Properties
4345

44-
private HonkaiRepairV2 _gameRepairManager { get; set; }
46+
private HonkaiRepairV2 _gameRepairManager { get; }
4547

4648
#endregion
4749

48-
public HonkaiInstall(UIElement parentUI, IGameVersion gameVersionManager, IGameSettings gameSettings)
50+
public HonkaiInstall(UIElement parentUI, IGameVersion gameVersionManager, IGameSettings gameSettings, IRepair gameRepairManager)
4951
: base(parentUI, gameVersionManager, gameSettings)
5052
{
53+
_gameRepairManager = (HonkaiRepairV2)gameRepairManager;
5154
}
5255

5356
#region Public Methods
@@ -64,7 +67,7 @@ public override async ValueTask<int> StartPackageVerification(List<GameInstallPa
6467

6568
// If the confirm is 1 (verified) or -1 (cancelled), then return the code
6669
int deltaPatchConfirm = await ConfirmDeltaPatchDialog(_gameDeltaPatchProperty,
67-
_gameRepairManager ??= GetGameRepairInstance(_gameDeltaPatchProperty.SourceVer));
70+
_gameRepairManager);
6871
if (deltaPatchConfirm is -1 or 1)
6972
{
7073
return deltaPatchConfirm;
@@ -74,16 +77,14 @@ public override async ValueTask<int> StartPackageVerification(List<GameInstallPa
7477
return await base.StartPackageVerification(gamePackage);
7578
}
7679

77-
#nullable enable
7880
protected override HonkaiRepairV2 GetGameRepairInstance(string? versionString) =>
79-
new HonkaiRepairV2(ParentUI,
80-
GameVersionManager,
81-
GameSettings!,
82-
versionString,
83-
true);
84-
#nullable restore
85-
86-
protected override async Task StartPackageInstallationInner(List<GameInstallPackage> gamePackage = null,
81+
new(ParentUI,
82+
GameVersionManager,
83+
GameSettings!,
84+
versionString,
85+
true);
86+
87+
protected override async Task StartPackageInstallationInner(List<GameInstallPackage>? gamePackage = null,
8788
bool isOnlyInstallPackage = false,
8889
bool doNotDeleteZipExplicit = false)
8990
{
@@ -100,8 +101,8 @@ protected override async Task StartPackageInstallationInner(List<GameInstallPack
100101
public override async ValueTask<bool> TryShowFailedGameConversionState()
101102
{
102103
// Get the target and source path
103-
string gamePath = GameVersionManager.GameDirPath;
104-
string gamePathIngredients = GetFailedGameConversionFolder(gamePath);
104+
string gamePath = GameVersionManager.GameDirPath;
105+
string? gamePathIngredients = GetFailedGameConversionFolder(gamePath);
105106
// If path doesn't exist or null, then return false
106107
if (gamePathIngredients is null || !Directory.Exists(gamePathIngredients))
107108
{
@@ -136,24 +137,24 @@ public override async ValueTask<bool> TryShowFailedGameConversionState()
136137

137138
#region Private Methods - Utilities
138139

139-
private string GetFailedGameConversionFolder(string basepath)
140+
private string? GetFailedGameConversionFolder(string basepath)
140141
{
141142
try
142143
{
143144
// Step back once from the game directory
144-
string ParentPath = Path.GetDirectoryName(basepath);
145+
string? parentPath = Path.GetDirectoryName(basepath);
145146
// Get the ingredient path
146-
if (ParentPath != null)
147+
if (!string.IsNullOrEmpty(parentPath))
147148
{
148-
string IngredientPath = Directory
149-
.EnumerateDirectories(ParentPath,
149+
string? ingredientPath = Directory
150+
.EnumerateDirectories(parentPath,
150151
$"{GameVersionManager.GamePreset.GameDirectoryName}*_ConvertedTo-*_Ingredients",
151152
SearchOption.TopDirectoryOnly)
152153
.FirstOrDefault();
153154
// If the path is not null, then return
154-
if (IngredientPath is not null)
155+
if (ingredientPath is not null)
155156
{
156-
return IngredientPath;
157+
return ingredientPath;
157158
}
158159
}
159160
}

CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
// - HomePage.Misc.cs
7070
// Contains miscellaneous method that doesn't fit into other categories and is not big enough to be in its own file
7171

72+
#nullable enable
7273
namespace CollapseLauncher.Pages
7374
{
7475
[GeneratedBindableCustomProperty]
@@ -167,7 +168,7 @@ private void InitializeConsoleValues()
167168

168169
private void ReturnToHomePage()
169170
{
170-
if (!(m_mainPage?.TryGetCurrentPageObject(out object typeOfPage) ?? false) ||
171+
if (!(m_mainPage?.TryGetCurrentPageObject(out object? typeOfPage) ?? false) ||
171172
typeOfPage is not Type asTypePage ||
172173
asTypePage != typeof(HomePage) ||
173174
GamePropertyVault.GetCurrentGameProperty() != CurrentGameProperty)
@@ -305,19 +306,13 @@ private async void Page_Loaded(object sender, RoutedEventArgs e)
305306
break;
306307
case GameInstallStateEnum.InstalledHavePlugin:
307308
case GameInstallStateEnum.NeedsUpdate:
308-
if (CurrentGameProperty.GameInstall != null)
309-
{
310-
CurrentGameProperty.GameInstall.PostInstallBehaviour = PostInstallBehaviour.StartGame;
311-
}
309+
CurrentGameProperty.GameInstall?.PostInstallBehaviour = PostInstallBehaviour.StartGame;
312310

313311
UpdateGameDialog(null, null);
314312
break;
315313
case GameInstallStateEnum.NotInstalled:
316314
case GameInstallStateEnum.GameBroken:
317-
if (CurrentGameProperty.GameInstall != null)
318-
{
319-
CurrentGameProperty.GameInstall.PostInstallBehaviour = PostInstallBehaviour.StartGame;
320-
}
315+
CurrentGameProperty.GameInstall?.PostInstallBehaviour = PostInstallBehaviour.StartGame;
321316

322317
InstallGameDialog(null, null);
323318
break;
@@ -951,7 +946,7 @@ private async void CleanupFilesButton_Click(object sender, RoutedEventArgs e)
951946
Locale.Current.Lang?._FileCleanupPage?.LoadingSubtitle2);
952947

953948
GameStartupSetting.Flyout.Hide();
954-
if (CurrentGameProperty?.GameInstall != null)
949+
if (CurrentGameProperty.GameInstall != null)
955950
await CurrentGameProperty.GameInstall.CleanUpGameFiles();
956951
}
957952
catch (Exception ex)

0 commit comments

Comments
 (0)