enable nullables

This commit is contained in:
Pilzinsel64
2024-08-30 09:06:57 +02:00
parent d49329c868
commit 638cbb7b2c
6 changed files with 19 additions and 21 deletions

View File

@@ -6,7 +6,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, Channels
{
// E v e n t s
public event UpdateClientStatusChangedEventHandler OnStatusChanged;
public event UpdateClientStatusChangedEventHandler? OnStatusChanged;
// F i e l d s
@@ -18,8 +18,8 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, Channels
public string UpdateUrl { get; private set; } = updateUrl;
public AppVersion CurrentVersion { get; private set; } = currentVersion;
public Channels MinimumChannel { get; private set; } = (Channels)Math.Max((int)minimumChannel, (int)currentVersion.Channel);
public UpdateInfo UpdateInfo { get; private set; } = null;
public UpdatePackageInfo UpdatePackageInfo { get; private set; } = null;
public UpdateInfo? UpdateInfo { get; private set; }
public UpdatePackageInfo? UpdatePackageInfo { get; private set; }
public string HostApplicationPath { get; set; } = string.Empty;
public string ApplicationName { get; set; } = string.Empty;
public bool InstallAsAdmin { get; set; } = false;
@@ -51,7 +51,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, Channels
{
var latestVersion = await CheckForUpdate();
if (HasUpdates)
if (HasUpdates && latestVersion is not null)
await UpdateInteractive(latestVersion);
}
@@ -63,14 +63,14 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, Channels
// F e a t u r e s
public async Task<UpdateInfo> GetUpdateInfo()
public async Task<UpdateInfo?> GetUpdateInfo()
{
string str = await WebClient.GetStringAsync(UpdateUrl);
var info = UpdateInfo.Parse(str);
return info;
}
private async Task<UpdatePackageInfo> CheckForUpdate()
private async Task<UpdatePackageInfo?> CheckForUpdate()
{
RaiseStatusChanged(UpdateStatus.Searching, UpdateStatusEvent.PreEvent);
@@ -82,29 +82,26 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, Channels
return CheckForUpdate(UpdateInfo);
}
private UpdatePackageInfo CheckForUpdate(UpdateInfo updateInfo)
private UpdatePackageInfo? CheckForUpdate(UpdateInfo updateInfo)
{
UpdatePackageInfo foundPkgInfo = null;
var latestVersion = CurrentVersion;
foreach (UpdatePackageInfo pkgInfo in updateInfo.Packages)
{
if (pkgInfo.Version.Channel <= MinimumChannel && pkgInfo.Version > latestVersion)
{
foundPkgInfo = pkgInfo;
UpdatePackageInfo = pkgInfo;
latestVersion = pkgInfo.Version;
}
}
UpdatePackageInfo = foundPkgInfo;
if (!RaiseStatusChanged(UpdateStatus.Searching, UpdateStatusEvent.PostEvent, true))
{
UpdatePackageInfo = null;
return null;
}
return foundPkgInfo;
return UpdatePackageInfo;
}
public async Task<bool> DownloadPackageAsync(UpdatePackageInfo package)
@@ -171,7 +168,7 @@ public class UpdateClient(string updateUrl, AppVersion currentVersion, Channels
RaiseStatusChanged(UpdateStatus.Copying, UpdateStatusEvent.PreEvent);
var dataPathDir = new DirectoryInfo(dataPath);
var destDir = new DirectoryInfo(HostApplicationPath);
General.CopyFiles(dataPathDir, destDir);
Utils.CopyFiles(dataPathDir, destDir);
RaiseStatusChanged(UpdateStatus.Copying, UpdateStatusEvent.PostEvent);
// Delete Package