clowd / Clowd.Squirrel

Quick and easy installer and automatic updates for cross-platform dotnet applications
426 stars 39 forks source link

Move package retrieval code into new IUpdateSource abstraction #58

Closed caesay closed 2 years ago

caesay commented 2 years ago

In UpdateManager, there is currently added complexity around checking for, and downloading updates as there are two codepaths that can be followed. One for packages on the file system and one for packages at a remote URL.

Additionally, the GitHub implementation tries to hack an implementation into the "remote URL" path, even though this is not optimal, as it's not possible for us to customize how UpdateManager performs the actual web request for the package (such as adding a header). This means private repositories are not supported, as we can't just follow the browser url's to download files. (https://github.com/clowd/Clowd.Squirrel/issues/50)

This pull request creates a new abstraction, IUpdateSource containing the following two methods: GetReleaseFeed and DownloadReleaseEntry.

All of the code within UpdateManager to handle the specifics of retrieving packages has been removed, resulting in a dramatic simplification of that class. There are now a handful of package sources, SimpleFileSource, SimpleWebSource, and GithubSource. It is also extremely easy for a third party developer to create a new package source and customize every detail about how metadata and packages are downloaded.

GithubUpdateManager is no longer needed, but it's not harming anything so I have left it for backwards compatibility. For now it's just a short-cut to perform the following:

new UpdateManager(new GithubSource("repoUrl", "accessToken", prerelease));

Mat-Stevenson-Simworx commented 2 years ago

I have tested the changes for my use case and they seem to be working as expected. Changes looks good, I like the IUpdateSource. I was wondering whether IFileDownloader serves much perpose anymore and it might be good to depricate it from the public api. Just seems like an added complexity now. For example if i was to implement another source that used a web api i feel i might have to by pass it and just juse a http client directly to get access to more functionallity.

caesay commented 2 years ago

I am glad that it is working for you! I also considered removing IFileDownloader like you suggest, however I believe it can still be useful:

So the approach to extending Squirrel in general should be:

If you are writing a new IUpdateSource, you do not need to use the FileDownloader for anything, but it still serves a purpose for providing an easy way to extend built-in functionality.