Ejemplo n.º 1
0
        private static void Update(InstallerInfo installerInfo)
        {
            if (null == installerInfo)
            {
                throw new ArgumentNullException("installerInfo");
            }

            if (!IsConnectedToInternet)
            {
                throw new UpdateNoInternetException();
            }

            string tempPath = Path.GetTempPath();

            string msiPath = Path.Combine(tempPath, "MzingaSetup.msi");

            if (File.Exists(msiPath))
            {
                File.Delete(msiPath);
            }

            using (WebClient client = new WebClient())
            {
                client.Headers["User-Agent"] = _userAgent;
                SecurityProtocolType oldType = ServicePointManager.SecurityProtocol;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // Fix since Github only supports TLS1.2
                client.DownloadFile(installerInfo.Url, msiPath);
                ServicePointManager.SecurityProtocol = oldType;
            }

            string cmdFile = Path.Combine(tempPath, "UpdateMzinga.cmd");

            using (StreamWriter sw = new StreamWriter(new FileStream(cmdFile, FileMode.Create)))
            {
                sw.WriteLine("msiexec /i \"{0}\" /qb", msiPath);
            }

            AppVM.DoOnUIThread(() =>
            {
                Process p = new Process
                {
                    StartInfo = new ProcessStartInfo("cmd.exe", string.Format("/c {0}", cmdFile))
                    {
                        CreateNoWindow = true
                    }
                };
                p.Start();

                System.Windows.Application.Current.Shutdown();
            });
        }
Ejemplo n.º 2
0
        public static void UpdateCheck(bool confirmUpdate, bool showUpToDate)
        {
            try
            {
                IsCheckingforUpdate = true;

                List <InstallerInfo> installerInfos = GetLatestInstallerInfos();

                ReleaseChannel targetReleaseChannel = GetReleaseChannel();

                ulong maxVersion = LongVersion(AppViewModel.FullVersion);

                InstallerInfo latestVersion = null;

                bool updateAvailable = false;
                foreach (InstallerInfo installerInfo in installerInfos)
                {
                    if (installerInfo.ReleaseChannel == targetReleaseChannel)
                    {
                        ulong installerVersion = LongVersion(installerInfo.Version);

                        if (installerVersion > maxVersion)
                        {
                            updateAvailable = true;
                            latestVersion   = installerInfo;
                            maxVersion      = installerVersion;
                        }
                    }
                }

                SetLastUpdateCheck(DateTime.Now);

                if (updateAvailable)
                {
                    if (confirmUpdate)
                    {
                        string message = string.Format("Mzinga v{0} is available. Would you like to update now?", latestVersion.Version);
                        AppVM.DoOnUIThread(() =>
                        {
                            Messenger.Default.Send(new ConfirmationMessage(message, (confirmed) =>
                            {
                                try
                                {
                                    if (confirmed)
                                    {
                                        Update(latestVersion);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    ExceptionUtils.HandleException(new UpdateException(ex));
                                }
                            }));
                        });
                    }
                    else
                    {
                        Update(latestVersion);
                    }
                }
                else
                {
                    if (showUpToDate)
                    {
                        AppVM.DoOnUIThread(() =>
                        {
                            Messenger.Default.Send(new InformationMessage("Mzinga is up-to-date."));
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(new UpdateException(ex));
            }
            finally
            {
                IsCheckingforUpdate = false;
            }
        }