Esempio n. 1
0
        public async Task <bool> CheckForUpdatesAsync(IReadOnlyList <IInstallUnitDescriptor> installUnitsToCheck, bool applyUpdates)
        {
            try
            {
                IUpdateCheckResult updateCheckResult = await _updateCoordinator.CheckForUpdatesAsync(installUnitsToCheck);

                if (updateCheckResult.Updates.Count == 0)
                {
                    DisplayNoUpdatesFoundMessage();
                    return(true);
                }

                if (applyUpdates)
                {
                    return(TryApplyUpdates(updateCheckResult.Updates));
                }
                else
                {
                    ListUpdates(updateCheckResult.Updates);
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 2
0
        public async Task CheckAsync_NewerVersion_UpdateAvailable()
        {
            UpdateChecker updates = GetUpdateChecker(_repoNewerVersion);

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsTrue(result.Available, $"{nameof(updates.CheckAsync)}() should say there's an update available when the latest version is newer than the current version.");
        }
Esempio n. 3
0
        public async Task CheckAsync_NotFoundException_NoUpdateNoReleases()
        {
            UpdateChecker updates = GetUpdateChecker("notFound", GetHttpWebException(HttpStatusCode.NotFound));

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsFalse(result.Available, $"{nameof(updates.CheckAsync)}() should say there's no update available when there are no releases for the repo or it doesn't exist.");
            Assert.AreEqual(Messages.NoUpdateNoReleases, result.Description, $"{nameof(updates.CheckAsync)}() should use the {nameof(Messages.NoUpdateNoReleases)} message when there are no releases for the repo or it doesn't exist.");
        }
Esempio n. 4
0
        public async Task CheckAsync_NoFiles_NoUpdateNoFiles()
        {
            UpdateChecker updates = GetUpdateChecker(_repoNoFiles);

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsFalse(result.Available, $"{nameof(updates.CheckAsync)}() should say there's no update available when the latest version has no files.");
            Assert.AreEqual(Messages.NoUpdateNoFiles, result.Description, $"{nameof(updates.CheckAsync)}() should use the {nameof(Messages.NoUpdateNoFiles)} message when the latest version has no files.");
        }
Esempio n. 5
0
        public async Task CheckAsync_SameVersion_NoUpdateAlreadyLatest()
        {
            UpdateChecker updates = GetUpdateChecker(_repoSameVersion);

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsFalse(result.Available, $"{nameof(updates.CheckAsync)}() should say there's no update available when the latest version matches the current version.");
            Assert.AreEqual(Messages.NoUpdateAlreadyLatest, result.Description, $"{nameof(updates.CheckAsync)}() should use the {nameof(Messages.NoUpdateAlreadyLatest)} message when the latest version matches the current version.");
        }
Esempio n. 6
0
        public async Task CheckAsync_OtherProtocolException_NoUpdateError(HttpStatusCode status)
        {
            WebException  ex      = GetHttpWebException(status);
            UpdateChecker updates = GetUpdateChecker("otherProtocolException", ex);

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsFalse(result.Available, $"{nameof(updates.CheckAsync)}() should say there's no update available when the API returns an error response other than 404 not found.");
            Assert.AreEqual(string.Format(Messages.NoUpdateError, ex.Message), result.Description, $"{nameof(updates.CheckAsync)}() should use the {nameof(Messages.NoUpdateError)} message when the API returns an error response other than 404 not found.");
        }
Esempio n. 7
0
        public async Task CheckAsync_UnexpectedException_NoUpdateError(WebExceptionStatus status)
        {
            WebException  ex      = GetWebException(status);
            UpdateChecker updates = GetUpdateChecker("otherException", ex);

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsFalse(result.Available, $"{nameof(updates.CheckAsync)}() should say there's no update available when the API does not return a response.");
            Assert.AreEqual(string.Format(Messages.NoUpdateError, ex.Message), result.Description, $"{nameof(updates.CheckAsync)}() should use the {nameof(Messages.NoUpdateError)} message when the API does not return a response.");
        }
Esempio n. 8
0
        public async Task CheckAsync_CannotConnect_NoUpdateCannotConnect(WebExceptionStatus status)
        {
            WebException  ex      = GetWebException(status);
            UpdateChecker updates = GetUpdateChecker("otherException", ex);

            IUpdateCheckResult result = await updates.CheckAsync().ConfigureAwait(false);

            Assert.IsFalse(result.Available, $"{nameof(updates.CheckAsync)}() should say there's no update available when unable to connect to the API server.");
            Assert.AreEqual(Messages.NoUpdateCannotConnect, result.Description, $"{nameof(updates.CheckAsync)}() should use the {nameof(Messages.NoUpdateCannotConnect)} message when unable to connect to the API server.");
        }
Esempio n. 9
0
 public bool CheckForUpdates()
 {
     //if (NetTools.IsConnected()) {
     // Load the installed package list
     updater.LoadInstalledPackageList();
     updater.InstallationComplete += new EventHandler(updater_InstallationComplete);
     lastCheckResult = updater.CheckForUpdates(UpdateURL);
     return (lastCheckResult.PackagesToUpdate.Count != 0);
     //} else {
     //    return false;
     //}
 }
Esempio n. 10
0
        void OnUpdateChecked(object o, IUpdateCheckResult checkResult)
        {
	        if(null != checkResult)
            {
		        // Has result:
		        if(checkResult.IsUpdated) 
                {
			        // Updated:

                    m_LastUpdateGuid = checkResult.Guid;

                    Guid ignoreGuid = GlobalConfig.Instance.Settings.IgnoreUpdateGuid;

                    bool notIgnored = null == ignoreGuid || ignoreGuid != checkResult.Guid;

                    statusLabelIgnore.Visible = notIgnored;
                    statusStrip.Visible = statusStrip.Visible || notIgnored;
			        statusLabelUpdate.IsLink = true;
			        statusLabelUpdate.Tag = null != checkResult.Uri ? checkResult.Uri.ToString() : "http://advancedfx.org/";
			        statusLabelUpdate.Text = "Update available!";
			        statusLabelUpdate.ForeColor = Color.Black;
			        statusLabelUpdate.BackColor = Color.Orange;
		        }
		        else
                {
			        // Is recent:
                    statusLabelIgnore.Visible = false;
                    statusLabelUpdate.IsLink = false;
			        statusLabelUpdate.Text = "Your version is up to date :)";
			        statusLabelUpdate.ForeColor = Color.Black;
			        statusLabelUpdate.BackColor = Color.LightGreen;
		        }
	        }
	        else
            {
		        // Has no result (s.th. went wrong):
                statusLabelIgnore.Visible = false;
                statusStrip.Visible = true;
		        statusLabelUpdate.IsLink = true;
		        statusLabelUpdate.Tag = "http://advancedfx.org/";
		        statusLabelUpdate.Text = "Update check failed :(";
		        statusLabelUpdate.ForeColor = Color.Black;
		        statusLabelUpdate.BackColor = Color.LightCoral;
	        }
        }
Esempio n. 11
0
        /// <summary>
        /// Prompt to update if there's a newer version available.
        /// </summary>
        /// <param name="owner">Owner window for dialogs</param>
        /// <param name="showIfNoUpdate">True to show update check results even if there's no update available</param>
        public async Task PromptForUpdate(IWin32Window owner, bool showIfNoUpdate)
        {
            IUpdateCheckResult update = await _updates.CheckAsync();

            if (update.Available)
            {
                TaskDialogButton response = TaskDialog.ShowDialog(owner, new TaskDialogPage {
                    Caption = Dialog.UpdateAvailableTitle,
                    Heading = string.Format(Dialog.UpdateAvailableDescription, update.Name),
                    Text    = update.Description,                   // note:  description can contain markdown, which will be shown to the user
                    Buttons = GetUpdateDialogButtons(update.Url),
                });

                switch (response.Tag as UpdateDialogResponse?)
                {
                case UpdateDialogResponse.DownloadInstall:
                    string installerFilename = Path.Combine(KnownFolders.Temp, Path.GetFileName(update.Url.LocalPath));
                    await DownloadUpdate(update.Url, installerFilename).ConfigureAwait(false);

                    Process.Start("msiexec", $"/i \"{installerFilename}\" RESTART=1");                              // installer should have a custom action to launch the application with the condition RESTART=1
                    Application.Exit();
                    break;

                case UpdateDialogResponse.DownloadOnly:
                    string downloadFilename = PromptForSaveLocation(owner, update.Url);
                    if (!string.IsNullOrEmpty(downloadFilename))
                    {
                        await DownloadUpdate(update.Url, downloadFilename).ConfigureAwait(false);
                    }
                    break;

                case UpdateDialogResponse.Cancel:
                    // Nothing to do because user chose not to update
                    break;
                }
            }
            else if (showIfNoUpdate)
            {
                MessageBox.Show(owner, update.Description, update.Name, MessageBoxButtons.OK, EventLevelToMessageBoxIcon(update.Level));
            }
        }
Esempio n. 12
0
 public void PerformUpdate(IUpdateCheckResult result)
 {
     if (result.PackagesToUpdate.Count != 0) {
         updater.PerformUpdate(result);
     }
 }
Esempio n. 13
0
 public void PerformUpdate(IUpdateCheckResult result)
 {
     if (result.PackagesToUpdate.Count > 0) {
         DownloadPackage(result, 0);
     }
 }
Esempio n. 14
0
 public void Notify(object o, IUpdateCheckResult checkResult)
 {
     m_Target.Invoke(m_UpdateChecked, new object[]{o, checkResult});
 }
Esempio n. 15
0
 private void DownloadPackage(IUpdateCheckResult result, int currentPackage)
 {
     IPackageInfo package = result.PackagesToUpdate[currentPackage];
     string updaterCache = this.packageListDirectory + "UpdaterCache/";
     if (Directory.Exists(updaterCache) == false) {
         Directory.CreateDirectory(updaterCache);
     }
     string tempPath = updaterCache + package.FullID + ".uprtmp";//Path.GetTempFileName();
     FileDownload download = new FileDownload(result.UpdateDirectory + "Packages/" + package.FullID + "/" + package.FullID + ".zip", tempPath);
     if (PackageDownloadStart != null) {
         PackageDownloadStart(this, new PackageDownloadStartEventArgs(package, download));
     }
     download.DownloadUpdate += delegate(System.Object o, FileDownloadingEventArgs e)
     {
         //if (UpdateDownloading != null) {
         //    UpdateDownloading(this, new UpdateInstallingEventArgs(e, fileNum, fileList.Count));
         //}
     };
     download.DownloadComplete += delegate(System.Object o, FileDownloadingEventArgs e)
     {
         InstallDownloadedPackage(result, currentPackage, tempPath);
     };
     download.Download();
 }
Esempio n. 16
0
        private void InstallDownloadedPackage(IUpdateCheckResult result, int currentPackage, string packagePath)
        {
            string tempFolder = packagePath + ".extracted/";
            if (Directory.Exists(tempFolder)) {
                Directory.Delete(tempFolder, true);
            }
            using (ZipFile zip = new ZipFile(packagePath)) {
                foreach (ZipEntry entry in zip) {
                    if (!entry.FileName.Contains("/")) {
                        entry.Extract(tempFolder, ExtractExistingFileAction.OverwriteSilently);
                    }
                }
            }
            string uninstallPackagePath = this.packageListDirectory + "UpdaterCache/" + result.PackagesToUpdate[currentPackage].FullID + ".udruninsta_";
            if (System.IO.File.Exists(uninstallPackagePath)) {
                // An uninstall package exists!
                // Try to uninstall it
                UninstallPackage(result.PackagesToUpdate[currentPackage], uninstallPackagePath);
            }
            PackageLoader loader = new PackageLoader();
            loader.LoadPackage(tempFolder + result.PackagesToUpdate[currentPackage].FullID + ".dll");
            loader.Package.Initialize(this);
            PackageInstaller installer = new PackageInstaller(packagePath, tempFolder, this.packageListDirectory, result.PackagesToUpdate[currentPackage], loader);
            // Start installing the package
            loader.Package.Install(installer);
            // Installation complete! Add this package to the installed packages list
            MarkPackageInstalled(installer.Package.FullID, installer.Package.Version);
            SaveInstalledPackageList();
            // Close all resources used by the package installer
            installer.Close();
            loader.Unload();

            if (Directory.Exists(System.IO.Path.GetDirectoryName(uninstallPackagePath)) == false) {
                Directory.CreateDirectory(Path.GetDirectoryName(uninstallPackagePath));
            }
            using (ZipFile zip = new ZipFile()) {
                zip.AddFile(tempFolder + "FileList.xml", "\\");
                zip.AddFile(tempFolder + result.PackagesToUpdate[currentPackage].FullID + ".dll", "\\");
                zip.AddFile(tempFolder + "Updater.Linker.dll", "\\");

                zip.Save(uninstallPackagePath);
            }

            // Delete the temporary files
            if (Directory.Exists(tempFolder)) {
                Directory.Delete(tempFolder, true);
            }
            if (File.Exists(packagePath)) {
                File.Delete(packagePath);
            }
            OnPackageInstallationComplete(result, currentPackage);
        }
Esempio n. 17
0
 private void OnPackageInstallationComplete(IUpdateCheckResult result, int currentPackage)
 {
     if (PackageInstallationComplete != null) {
         PackageInstallationComplete(this, new PackageInstallationCompleteEventArgs(result.PackagesToUpdate[currentPackage], currentPackage));
     }
     if (currentPackage + 1 < result.PackagesToUpdate.Count) {
         DownloadPackage(result, currentPackage + 1);
     } else {
         // Done the update!
         if (InstallationComplete != null) {
             InstallationComplete(this, EventArgs.Empty);
         }
     }
 }