Skip to content

Commit

Permalink
Make Configuration.InstalledVersion nullable
Browse files Browse the repository at this point in the history
Closes #607
  • Loading branch information
Deadpikle committed Aug 18, 2024
1 parent f3a7c82 commit bbc2766
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
22 changes: 16 additions & 6 deletions src/NetSparkle/AppCastHandlers/AppCastHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public AppCastHelper()
/// <param name="installedVersion">installed version of the software</param>
/// <param name="signatureVerifier">Object to check signatures of app cast information</param>
/// <param name="logWriter">object that you can utilize to do any necessary logging</param>
public virtual void SetupAppCastHelper(IAppCastDataDownloader dataDownloader, string castUrl, string? installedVersion, ISignatureVerifier? signatureVerifier, ILogger? logWriter = null)
public virtual void SetupAppCastHelper(IAppCastDataDownloader dataDownloader, string castUrl,
string? installedVersion, ISignatureVerifier? signatureVerifier, ILogger? logWriter = null)
{
_dataDownloader = dataDownloader;
_installedVersion = installedVersion;
Expand Down Expand Up @@ -245,7 +246,9 @@ public virtual List<AppCastItem> FilterUpdates(List<AppCastItem> items)
}

var signatureNeeded = IsSignatureNeeded();
_logWriter?.PrintMessage("Looking for available updates; our installed version is {0}; do we need a signature? {1}; are we filtering out smaller versions than our current version? {2}", installedVersion, signatureNeeded, shouldFilterOutSmallerVersions);
_logWriter?.PrintMessage("Looking for available updates; our installed version is {0}; " +
"do we need a signature? {1}; are we filtering out smaller versions than our " +
"current version? {2}", installedVersion, signatureNeeded, shouldFilterOutSmallerVersions);
return items.Where((item) =>
{
var filterResult = FilterAppCastItem(installedVersion, shouldFilterOutSmallerVersions, signatureNeeded, item);
Expand All @@ -262,7 +265,8 @@ public virtual List<AppCastItem> FilterUpdates(List<AppCastItem> items)
return false;
}
// accept all valid items
_logWriter?.PrintMessage("Item with version {0} ({1}) is a valid update! It can be downloaded at {2}", item.Version ?? "[Unknown version]", item.ShortVersion ?? "[Unknown short version]", item.DownloadLink ?? "[Unknown download link]");
_logWriter?.PrintMessage("Item with version {0} ({1}) is a valid update! It can be downloaded at {2}",
item.Version ?? "[Unknown version]", item.ShortVersion ?? "[Unknown short version]", item.DownloadLink ?? "[Unknown download link]");
return true;
}
return false;
Expand Down Expand Up @@ -337,17 +341,23 @@ protected FilterItemResult FilterAppCastItemByOS(AppCastItem item)
// operating system
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !item.IsWindowsUpdate)
{
_logWriter?.PrintMessage("Rejecting update for {0} ({1}, {2}) because it isn't a Windows update and we're on Windows", item.Version ?? "[Unknown version]", item.ShortVersion ?? "[Unknown short version]", item.DownloadLink ?? "[Unknown download link]");
_logWriter?.PrintMessage("Rejecting update for {0} ({1}, {2}) because it isn't a Windows " +
"update and we're on Windows", item.Version ?? "[Unknown version]",
item.ShortVersion ?? "[Unknown short version]", item.DownloadLink ?? "[Unknown download link]");
return FilterItemResult.NotThisPlatform;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && !item.IsMacOSUpdate)
{
_logWriter?.PrintMessage("Rejecting update for {0} ({1}, {2}) because it isn't a macOS update and we're on macOS", item.Version ?? "[Unknown version]", item.ShortVersion ?? "[Unknown short version]", item.DownloadLink ?? "[Unknown download link]");
_logWriter?.PrintMessage("Rejecting update for {0} ({1}, {2}) because it isn't a macOS " +
"update and we're on macOS", item.Version ?? "[Unknown version]",
item.ShortVersion ?? "[Unknown short version]", item.DownloadLink ?? "[Unknown download link]");
return FilterItemResult.NotThisPlatform;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && !item.IsLinuxUpdate)
{
_logWriter?.PrintMessage("Rejecting update for {0} ({1}, {2}) because it isn't a Linux update and we're on Linux", item.Version ?? "[Unknown version]", item.ShortVersion ?? "[Unknown short version]", item.DownloadLink ?? "[Unknown download link]");
_logWriter?.PrintMessage("Rejecting update for {0} ({1}, {2}) because it isn't a Linux " +
"update and we're on Linux", item.Version ?? "[Unknown version]",
item.ShortVersion ?? "[Unknown short version]", item.DownloadLink ?? "[Unknown download link]");
return FilterItemResult.NotThisPlatform;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/NetSparkle/Configurations/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class Configuration
/// <summary>
/// The currently-installed version, e.g. "1.4.3"
/// </summary>
public string InstalledVersion { get; protected set; }
public string? InstalledVersion { get; protected set; }
/// <summary>
/// Flag to indicate if we should check for updates
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion src/NetSparkle/Configurations/RegistryConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ private bool SaveValuesToPath(string regPath)
key.SetValue("SkipThisVersion", LastVersionSkipped ?? "", RegistryValueKind.String);
key.SetValue("DidRunOnce", DidRunOnce.ToString(), RegistryValueKind.String);
key.SetValue("LastProfileUpdate", ConvertDateToString(LastConfigUpdate), RegistryValueKind.String);
key.SetValue("PreviousVersionRun", InstalledVersion, RegistryValueKind.String);
if (InstalledVersion != null)
{
key.SetValue("PreviousVersionRun", InstalledVersion, RegistryValueKind.String);
}

return true;
}
Expand Down
8 changes: 5 additions & 3 deletions src/NetSparkle/SparkleUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ protected async Task<UpdateInfo> GetUpdateStatus(Configuration config, bool igno
// check if the version will be the same then the installed version
if (updates.Count == 0)
{
LogWriter?.PrintMessage("Installed version is latest, no update needed ({0})", config.InstalledVersion);
LogWriter?.PrintMessage("Installed version is latest, no update needed ({0})", config.InstalledVersion ?? "[no installed version]");
return new UpdateInfo(UpdateStatus.UpdateNotAvailable, updates);
}
LogWriter?.PrintMessage("Latest version on the server is {0}", updates[0].Version ?? "[Unknown]");
Expand Down Expand Up @@ -1789,7 +1789,8 @@ private async Task<UpdateInfo> CheckForUpdates(bool isUserManuallyCheckingForUpd
if (_latestDownloadedUpdateInfo.Status == UpdateStatus.UpdateAvailable)
{
// there's an update available!
LogWriter?.PrintMessage("Update needed from version {0} to version {1}", config.InstalledVersion, updates[0].Version ?? "[unknown version]");
LogWriter?.PrintMessage("Update needed from version {0} to version {1}",
config.InstalledVersion ?? "[no installed version]", updates[0].Version ?? "[unknown version]");

UpdateDetectedEventArgs ev = new UpdateDetectedEventArgs(
NextUpdateAction.ShowStandardUserInterface,
Expand Down Expand Up @@ -1979,7 +1980,8 @@ private async void OnWorkerDoWork()
{
List<AppCastItem> updates = _latestDownloadedUpdateInfo.Updates;
// show the update window
LogWriter?.PrintMessage("Update needed from version {0} to version {1}", config.InstalledVersion, updates[0].Version ?? "[Unknown version]");
LogWriter?.PrintMessage("Update needed from version {0} to version {1}",
config.InstalledVersion ?? "[no installed version]", updates[0].Version ?? "[Unknown version]");

// send notification if needed
UpdateDetectedEventArgs ev = new UpdateDetectedEventArgs(
Expand Down

0 comments on commit bbc2766

Please sign in to comment.