Esempio n. 1
0
        protected virtual bool CheckRegistry(RemoteAppcast appcast)
        {
            if (IsThisFirstRun)
            {
                EnsureNotFirstRun();
                _logger.Log("App is running for the first time. Skipping further checks.");
                return(false);
            }
            _logger.Log("This is not app's first run. Continuing with other registry checks.");

            var skipVersion = SkipVersion;

            if (!string.IsNullOrWhiteSpace(skipVersion))
            {
                Version ver;
                if (Version.TryParse(skipVersion, out ver) && appcast.Version == ver)
                {
                    _logger.Log(string.Format("User has asked to skip version: {0}. Skipping further checks.", ver));
                    return(false);
                }
            }
            _logger.Log("Seems like user doesn\'t want to skip this version. Continuing with other registry checks.");

            var lastCheckDate = LastCheckDate;

            if (DateTime.Now.Subtract(lastCheckDate).TotalDays < 1)
            {
                _logger.Log("Last check was done less than a day ago. Skipping further checks");
                return(false);
            }
            _logger.Log(string.Format("Last check was done on: {0}", lastCheckDate.ToShortDateString()));
            return(true);
        }
Esempio n. 2
0
        protected virtual bool CheckVersion(RemoteAppcast appcast)
        {
            var curVer = Assembly.GetEntryAssembly().GetName().Version;
            var isHigherVersionAvailable = appcast.Version.IsHigherThan(curVer);

            _logger.Log(string.Format("Higher version of app is {0}available", isHigherVersionAvailable ? "" : "not "));
            return(isHigherVersionAvailable);
        }
Esempio n. 3
0
        public void MakeFromJsonReturnsEmptyAppcastForEmptyJson()
        {
            var appcast = RemoteAppcast.MakeFromJson(string.Empty);

            Assert.IsNotNull(appcast);
            Assert.AreEqual(0, appcast.Channels.Count);
            Assert.AreEqual(0, appcast.RawDictionary.Count);
        }
Esempio n. 4
0
        public void AllValuesAreAddedToRawDictionary()
        {
            var appcast = RemoteAppcast.MakeFromJson(_oneChannelJson);

            Assert.AreEqual(2, appcast.RawDictionary.Count);
            Assert.IsTrue(appcast.RawDictionary.ContainsKey("foo"));
            Assert.AreEqual("bar", appcast.RawDictionary["foo"]);
        }
Esempio n. 5
0
 internal async Task StartAsync(RemoteAppcast appcast)
 {
     InitializeCommands(appcast);
     Title        = string.Format(Resources.NewVersionAvailable, appcast.Title).ToUpperInvariant();
     OldVersion   = GetOldVersion();
     NewVersion   = appcast.Version.ToString();
     ReleaseNotes = await FetchReleaseNotesAsync(appcast.ReleaseNotesUrl).ConfigureAwait(false);
 }
Esempio n. 6
0
        private RemoteAppcast ParseAppcast(string content)
        {
            _logger.Log("Started deserializing remote channel content");
            var appcast = RemoteAppcast.MakeFromJson(content);

            _logger.Log("Finished deserializing remote channel content");
            return(appcast);
        }
Esempio n. 7
0
        public void WhenChannelsHaveNoIdsReturnsChannelWithHighestVersion()
        {
            var sut             = new BestChannelFinder(Substitute.For <IDebuggingInfoLogger>());
            var appcast         = RemoteAppcast.MakeFromJson(_twoChannelJson);
            var selectedChannel = sut.Find(4, appcast.Channels);

            Assert.IsNotNull(selectedChannel);
            Assert.AreEqual(appcast.Channels[1], selectedChannel);
        }
Esempio n. 8
0
        private RemoteAppcast ParseAppcast(string content)
        {
            _logger.Log("Started deserializing remote channel content");
            var appcast = RemoteAppcast.MakeFromJson(content);

            _logger.Log("Finished deserializing remote channel content");
            OnRemoteAppcastAvailableEvent(new SingleEventArgs <RemoteAppcast>(appcast));
            return(appcast);
        }
Esempio n. 9
0
        private async Task DownloadArtifact(RemoteAppcast appcast, string destinationPath)
        {
            _logger.Log("Starting to download artifact");
            using (var client = new WebClient())
            {
                client.DownloadProgressChanged += (sender, args) => { ProgressPercent = args.ProgressPercentage; };
                await _contentDownloader.DownloadFile(appcast.ArtifactUrl, destinationPath, client).ConfigureAwait(false);

                _logger.Log(string.Format("Artifact downloaded to {0}", destinationPath));
            }
        }
Esempio n. 10
0
        private bool FailedToEnroll(RemoteAppcast appcast, int channelId)
        {
            var channel    = appcast.Channels.FirstOrDefault(c => c.Id == channelId);
            var enrollment = new Enrollment(channel);

            if (channel != null && channel.RequiresEnrollment)
            {
                enrollment.IsRequired = true;
                ShowEnrollmentWindow(enrollment);
            }
            _analyticsLogger.LogEnrollment(enrollment);
            OnEnrollmentAvailableEvent(new SingleEventArgs <Enrollment>(enrollment));
            return(enrollment.IsRequired && !enrollment.IsEnrolled);
        }
Esempio n. 11
0
        public void WhenChannelsHaveMixIdsReturnsChannelWithHighestVersionLessThanSubscribedId()
        {
            var sut     = new BestChannelFinder(Substitute.For <IDebuggingInfoLogger>());
            var appcast = RemoteAppcast.MakeFromJson(_threeChannelJson);
            // subscribed to 3, and there is an id of 2 in the json
            var selectedChannel = sut.Find(3, appcast.Channels);

            Assert.IsNotNull(selectedChannel);
            Assert.AreEqual(appcast.Channels[1], selectedChannel);

            // subscribed to 1, but because there is id that matches it, it returns the highest version of all
            selectedChannel = sut.Find(1, appcast.Channels);
            Assert.IsNotNull(selectedChannel);
            Assert.AreEqual(appcast.Channels[2], selectedChannel);
        }
Esempio n. 12
0
        public void CanBeSerializedFromJsonWithMultipleChannelInfo()
        {
            var appcast = RemoteAppcast.MakeFromJson(_twoChannelJson);

            Assert.AreEqual(2, appcast.Channels.Count);
            var channel = appcast.Channels[1];

            Assert.AreEqual(3, channel.Id);
            Assert.AreEqual("5.9.9", channel.Version.ToString());
            Assert.AreEqual("release_notes_url_http_3", channel.ReleaseNotesUrl);
            Assert.AreEqual("artifact_url_http_3", channel.ArtifactUrl);
            Assert.AreEqual(02, channel.BuildDate.Month);
            Assert.AreEqual(18, channel.BuildDate.Day);
            Assert.AreEqual(2017, channel.BuildDate.Year);
        }
Esempio n. 13
0
        public void CanBeSerializedFromJsonWithOnlyOneChannelInfo()
        {
            var appcast = RemoteAppcast.MakeFromJson(_oneChannelJson);

            Assert.AreEqual(1, appcast.Channels.Count);
            var channel = appcast.Channels.First();

            Assert.AreEqual(2, channel.Id);
            Assert.AreEqual("5.8.8", channel.Version.ToString());
            Assert.AreEqual("release_notes_url_http", channel.ReleaseNotesUrl);
            Assert.AreEqual("artifact_url_http", channel.ArtifactUrl);
            Assert.AreEqual(01, channel.BuildDate.Month);
            Assert.AreEqual(28, channel.BuildDate.Day);
            Assert.AreEqual(2017, channel.BuildDate.Year);
        }
Esempio n. 14
0
        protected virtual async void ShowUpdateWindow(RemoteAppcast appcast)
        {
            var viewModel = new MainWindowViewModel(_appInfo, _logger, RemoteContentDownloader, _analyticsLogger);
            await viewModel.StartAsync(appcast).ConfigureAwait(true);

            var window = new MainWindow {
                ViewModel = viewModel
            };

            viewModel.DownloadNowCommand = new DelegateCommand(e =>
            {
                _analyticsLogger.LogDownloadNow();
                _logger.Log("Continuing with downloading the artifact");
                window.Close();
                ShowDownloadWindow(appcast);
            });
            SetOwner(window);
            window.ShowDialog();
        }
Esempio n. 15
0
        internal bool ShouldUpdate(RemoteAppcast appcast, bool shouldIgnoreRegistryChecks = false)
        {
            if (!shouldIgnoreRegistryChecks)
            {
                _logger.Log("Checking registry entries for updates.");
                if (!CheckRegistry(appcast))
                {
                    _logger.Log("Registry entries says not to tell if there is an update available.");
                    return(false);
                }
                _logger.Log("Registry entries says go and tell if there is an update available.");
            }
            else
            {
                _logger.Log("Skipping registry checks. This probably means we are doing forced update checks.");
            }
            UpdateCheckDate();
            var higherVersion = CheckVersion(appcast);

            return(higherVersion);
        }
Esempio n. 16
0
        private bool ShouldOpenArtifact(RemoteAppcast appcast, string artifactPath)
        {
            if (string.IsNullOrEmpty(appcast.DSASignature))
            {
                _logger.Log("No DSASignature provided. Skipping signature verification");
                return(true);
            }
            _logger.Log("DSASignature provided. Verifying artifact's signature");
            if (VerifyArtifact(appcast, artifactPath))
            {
                _logger.Log("Successfully verified artifact's signature");
                return(true);
            }
            _logger.Log("Couldn't verify artifact's signature. The artifact will now be deleted.");
            var signatureWindowViewModel = new SignatureVerificationWindowViewModel(_appInfo, appcast);
            var signatureWindow          = new SignatureVerificationWindow {
                DataContext = signatureWindowViewModel
            };

            signatureWindowViewModel.ContinueCommand = new DelegateCommand(e => { signatureWindow.Close(); });
            SetOwner(signatureWindow);
            signatureWindow.ShowDialog();
            return(false);
        }
Esempio n. 17
0
        protected virtual void ShowDownloadWindow(RemoteAppcast appcast)
        {
            var viewModel    = new DownloadWindowViewModel(_appInfo, _logger, RemoteContentDownloader);
            var artifactPath = CreateTempPath(appcast.ArtifactUrl);
            var window       = new DownloadWindow {
                DataContext = viewModel
            };

            viewModel.ContinueWithInstallationCommand = new DelegateCommand(e =>
            {
                _logger.Log("Continue after downloading artifact");
                _analyticsLogger.LogContinueWithInstallation();
                OnArtifactDownloadedEvent(new SingleEventArgs <string>(artifactPath));
                window.Close();
                if (ShouldOpenArtifact(appcast, artifactPath))
                {
                    OpenArtifact(artifactPath);
                    _logger.Log("Opened artifact");
                }
            });
            SetOwner(window);
            viewModel.StartAsync(appcast, artifactPath);
            window.ShowDialog();
        }
Esempio n. 18
0
 protected override void ShowUpdateWindow(RemoteAppcast appcast)
 {
     // can't do in tests
     _showUpdateWindowFlag = true;
 }
Esempio n. 19
0
        protected virtual bool VerifyArtifact(RemoteAppcast appcast, string artifactPath)
        {
            var verifer = new SignatureVerifier(_appInfo.PublicSignatureFilename);

            return(verifer.VerifyDSASignature(appcast.DSASignature, artifactPath));
        }
Esempio n. 20
0
 internal async void StartAsync(RemoteAppcast appcast, string destinationPath)
 {
     Title = string.Format(Properties.Resources.DownloadingInstaller, appcast.Title);
     await DownloadArtifact(appcast, destinationPath).ConfigureAwait(true);
 }
 public SignatureVerificationWindowViewModel(AppInfo appInfo, RemoteAppcast appcast)
 {
     AppIconPath = appInfo.AppIconPath;
     Title       = string.Format(Properties.Resources.SignatureErrorTitle, appcast.Title);
 }
Esempio n. 22
0
 protected override void OnRemoteAppcastAvailableEvent(SingleEventArgs <RemoteAppcast> args)
 {
     RemoteAppcast = args.Payload;
     base.OnRemoteAppcastAvailableEvent(args);
 }
Esempio n. 23
0
 private void InitializeCommands(RemoteAppcast appcast)
 {
     _remoteVersion         = appcast.Version.ToString();
     SkipThisVersionCommand = new DelegateCommand(SkipThisVersionCommandHandler);
     RemindMeLaterCommand   = new DelegateCommand(RemindMeLaterCommandHandler);
 }