Exemple #1
0
        /// <summary>
        /// start auto update after download
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void Wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                GithubRelease release = Newtonsoft.Json.JsonConvert.DeserializeObject <GithubRelease>(e.Result);

                // generate update information object
                UpdaterXml.item update = new UpdaterXml.item();
                update.url       = release.assets.Where(w => w.browser_download_url.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)).First().browser_download_url;
                update.version   = release.tag_name;
                update.changelog = releaseUrl;
                update.mandatory = false;

                // generate xml file
                string updateUrl = null;
                do
                {
                    updateUrl = System.IO.Path.Combine(System.IO.Path.GetTempPath(), string.Format("{0}.xml", Guid.NewGuid().ToString("N")));
                } while (System.IO.File.Exists(updateUrl));

                // add file to cleanup job
                Cleanup.GetInstance().FilesToDelete.AddIfNotExist <string>(updateUrl);

                // serialize to file
                using (TextWriter writer = new StreamWriter(updateUrl, false))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(UpdaterXml.item));
                    serializer.Serialize(writer, update);
                    writer.Close();
                }

                // start update procedure
                if (Properties.Settings.Default.CheckForUpdates)
                {
                    Logging.WriteLine("AutoUpdater feature enabled - checking for update in the background.");

                    AutoUpdater.ShowRemindLaterButton = true;
                    AutoUpdater.ReportErrors          = false;
                    AutoUpdater.Mandatory             = false;
                    AutoUpdater.ShowSkipButton        = true;
                    AutoUpdater.Start(updateUrl);
                }

                // we cannot delete the xml file because we have no idea when the check is done by the auto updater
                //try
                //{
                //    System.IO.File.Delete(updateUrl);
                //}
                //catch { }
            }
            catch (Exception ex)
            {
                Logging.WriteLine(string.Format("Unable to start update procedure:{0}{1}", Environment.NewLine, ex.ToString()));
            }
        }