Hi all, I have a scenario that requires client to be on the latest released version to guarantee comparability with back-end services. Is it possible to force update to latest version before app starts up using Squirrel.Windows? If not, can this features be added in the future? Any suggestions on short-term workaround would be highly appreciated as well. Thanks a lot!
When my app starts, I check to see if I have the latest version and if I do not then I force the update before I go any further. So you can absolutely do it.
I apologize for resurrecting this issue, but could I please trouble @stefanolson to expand his answer? The approach you describe is exactly what I'm attempting to do, and it would be a huge help if you could please elaborate on your approach
In my main window, the first thing I do is run my update application function, before I load the rest of the application that then just calls the update manager as you would normally:
using (
var updateManager =
new UpdateManager(LoginStatus.Current.CurrentUser.BaseAddress.TrimEnd('/') + "/setup",
"AppName"))
{
etc.
Let me know if there are any areas you need more detail on.
@stefanolson Can you elaborate some more on what you are doing to actually apply the update. I see in the documentation that you can check for updates, download releases and apply releases. I guess the next step is to restart the app. How are you accomplishing this?
Hi @brianswart . I imagine that @stefanolson has a much cleaner solution (I'm somewhat of a beginner in desktop dev). However what worked for me is the following:
I have the two following methods:
//Check if there's an update available, then return the version
private async Task < string > checkForUpdates() {
//Check for updates
using(var mgr = new UpdateManager("http://" + IpAdress.GeIpAddressFromName("SERVER-OLS-PRODUCTION-V1") + "/ProductionService/updates")) {
var updateInfo = await mgr.CheckForUpdate(progress: x => Console.WriteLine(x / 3));
string futureVersion = updateInfo.FutureReleaseEntry.Version.ToString();
return futureVersion;
}
}
//Proceed with the update, then restart the app
private async Task<int> proceedUpdate(string version)
{
using (var mgr = new UpdateManager("http://" + IpAdress.GeIpAddressFromName("SERVER-OLS-PRODUCTION-V1") + "/ProductionService/updates"))
{
await mgr.UpdateApp();
System.IO.File.WriteAllText(@System.AppDomain.CurrentDomain.BaseDirectory + "..\\update.bak", version);
UpdateManager.RestartApp();
}
return 0;
}
And then, in my App.xaml.cs, specifically in the OnStartup method, I have this:
protected override void OnStartup(StartupEventArgs e)
{
//Some code
Task<string> task = Task.Run(() => checkForUpdates());
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
string localVersion = fvi.FileVersion;
var version1 = new Version(task.Result);
var version2 = new Version(localVersion);
var t = version1.CompareTo(version2);
if (t > 0)
{
//Remote version is greater
Task<int> task2 = Task.Run(() => proceedUpdate(version1.ToString()));
int up = task2.Result;
}
}
I get my local version and test it against the remote, if it is older, I do the update, otherwise it's _equality for all_.
The reason why it's written this way is because Squirrel's update system runs asynchronously by default, and I wanted the update (and restart) to happen before the App started (or at the very beginning)
The way it works now is that when I start the app, it checks for an update before anything else, if there isn't, it launches, otherwise, it fetches it, updates then restarts. In my particular case the update server is located in the local network which makes this viable.
You can ignore the "update.bak" part, it's only there to trigger an alert the next time the app is launched saying "the app has been updated to version ... " (The file is then deleted)
There it is, I hope this helps.
We were hoping for something similar out of the box with #584
@grandtiger @stefanolson I believe the comment above https://github.com/Squirrel/Squirrel.Windows/issues/687#issuecomment-222982079 answers your questions. If yes, could we close this issue? :)
@gojanpaolo That's fine with me