private async void CheckForUpdates() { using (var mgr = new UpdateManager("http://arkmanager.teamitf.co.uk/iNGen/Releases/", "iNGen")) { SquirrelAwareApp.HandleEvents( onInitialInstall: v => mgr.CreateShortcutForThisExe(), onAppUpdate: v => mgr.CreateShortcutForThisExe(), onAppUninstall: v => mgr.RemoveShortcutForThisExe()); try { UpdateInfo updateInfo = await mgr.CheckForUpdate(); if (updateInfo.FutureReleaseEntry != null) { if (updateInfo.CurrentlyInstalledVersion != null) { XElement xelement = XElement.Load("http://arkmanager.teamitf.co.uk/iNGen/version.xml"); StringReader reader = new StringReader(xelement.ToString()); System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Models.AppUpdates)); Models.AppUpdates appUpdates = (Models.AppUpdates)xmlSerializer.Deserialize(reader); string changes = MakeChangeLog(appUpdates); if (updateInfo.CurrentlyInstalledVersion.Version == updateInfo.FutureReleaseEntry.Version) return; var updateDialog = new Views.AppUpdate(updateInfo, changes) { Owner = this }; var result = updateDialog.ShowDialog(); if (result == false) return; await mgr.UpdateApp(); var oldPath = System.IO.Path.Combine(mgr.RootAppDirectory, "app-" + updateInfo.CurrentlyInstalledVersion.Version.ToString(), "UserData"); var newPath = System.IO.Path.Combine(mgr.RootAppDirectory, "app-" + updateInfo.FutureReleaseEntry.Version.ToString(), "UserData"); DirectoryInfo d = new DirectoryInfo(oldPath); var files = d.GetFiles(); foreach (var file in files) { file.CopyTo(System.IO.Path.Combine(newPath, file.Name), true); } MessageBox.Show("iNGen Has been Updated. Please Re-Launch It."); Application.Current.Shutdown(0); } else { await mgr.UpdateApp(); MessageBox.Show("iNGen Has been Updated. Please Re-Launch It."); Application.Current.Shutdown(0); } } } catch (Exception ex) { Console.WriteLine("Checking for Updates Failed: " + ex.Message); } } }
private async void CheckForUpdates() { using (var mgr = new UpdateManager("http://arkmanager.teamitf.co.uk/iNGen/Releases/", "iNGen")) { SquirrelAwareApp.HandleEvents( onInitialInstall: v => mgr.CreateShortcutForThisExe(), onAppUpdate: v => mgr.CreateShortcutForThisExe(), onAppUninstall: v => mgr.RemoveShortcutForThisExe()); try { UpdateInfo updateInfo = await mgr.CheckForUpdate(); if (updateInfo.FutureReleaseEntry != null) { if (updateInfo.CurrentlyInstalledVersion != null) { XElement xelement = XElement.Load("http://arkmanager.teamitf.co.uk/iNGen/version.xml"); StringReader reader = new StringReader(xelement.ToString()); System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Models.AppUpdates)); Models.AppUpdates appUpdates = (Models.AppUpdates)xmlSerializer.Deserialize(reader); string changes = MakeChangeLog(appUpdates); if (updateInfo.CurrentlyInstalledVersion.Version == updateInfo.FutureReleaseEntry.Version) { return; } var updateDialog = new Views.AppUpdate(updateInfo, changes) { Owner = this }; var result = updateDialog.ShowDialog(); if (result == false) { return; } await mgr.UpdateApp(); var oldPath = System.IO.Path.Combine(mgr.RootAppDirectory, "app-" + updateInfo.CurrentlyInstalledVersion.Version.ToString(), "UserData"); var newPath = System.IO.Path.Combine(mgr.RootAppDirectory, "app-" + updateInfo.FutureReleaseEntry.Version.ToString(), "UserData"); DirectoryInfo d = new DirectoryInfo(oldPath); var files = d.GetFiles(); foreach (var file in files) { file.CopyTo(System.IO.Path.Combine(newPath, file.Name), true); } MessageBox.Show("iNGen Has been Updated. Please Re-Launch It."); Application.Current.Shutdown(0); } else { await mgr.UpdateApp(); MessageBox.Show("iNGen Has been Updated. Please Re-Launch It."); Application.Current.Shutdown(0); } } } catch (Exception ex) { Console.WriteLine("Checking for Updates Failed: " + ex.Message); } } }