示例#1
0
 private void checkForUpdateLabel_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     try
     {
         var result = CheckUpdate.Run(SB.updateUrl);
         if (result.Update)
         {
             var notesWindow = new NotesWindow()
             {
                 DontShowMainWindow = true,
                 SBUrl = result.Url,
             };
             notesWindow.titleLabel.Content += " " + result.Version;
             for (var i = 0; i < result.Notes.Count; i++)
             {
                 notesWindow.richTextBox.AppendText(result.Notes[i].Note + "\n");
             }
             notesWindow.Show();
         }
         else
         {
             MessageBox.Show("there are currently no updates available", "SilverBullet", MessageBoxButton.OK, MessageBoxImage.Information);
         }
     }
     catch { }
 }
        public void CheckForUpdate()
        {
            try
            {
                Dispatcher.Invoke(() => richTextBox.Document.Blocks.Clear());
                Dispatcher.Invoke(() => richTextBoxDonate.Document.Blocks.Clear());
                var result         = CheckUpdate.Run <SBUpdate>();
                var releasesLatest = CheckUpdate.Run <Release>("https://api.github.com/repos/mohamm4dx/SilverBullet/releases/latest");
                if (releasesLatest.Assets != null && releasesLatest.Assets.Length > 0)
                {
                    result.DownloadUrl = releasesLatest.Assets.First().Browser_Download_Url;
                }
                result.Available = releasesLatest.Available;
                releasesLatest.Body.Split('\n')
                .ToList().ForEach(re =>
                {
                    re = re.Replace("•", string.Empty)
                         .Replace("•", string.Empty).Trim();
                    if (result.ReleaseNotes.Any(r => r.Note.Trim()
                                                .Replace("•", string.Empty)
                                                .Replace("•", string.Empty) != re))
                    {
                        result.ReleaseNotes.Add(new ReleaseNotes()
                        {
                            Note = re
                        });
                    }
                });

                Dispatcher.Invoke(() => DataContext = result);
                try
                {
                    for (var i = 0; i < result.Donate.Length; i++)
                    {
                        Dispatcher.Invoke(() => AppendParagraph(richTextBoxDonate, new[] { result.Donate[i].Address }));
                    }
                }
                catch { }
                if (result.Available)
                {
                    try
                    {
                        for (var i = 0; i < result.ReleaseNotes.Count; i++)
                        {
                            Dispatcher.Invoke(() => AppendParagraph(richTextBox, new[] { result.ReleaseNotes[i].Note }));
                        }
                    }
                    catch { }
                    if (!string.IsNullOrWhiteSpace(result.Message))
                    {
                        Dispatcher.Invoke(() => CustomMsgBox.Show(result.Message));
                    }
                }
                else
                {
                    Dispatcher.Invoke(() => CustomMsgBox.Show("there are currently no updates available"));
                }
            }
            catch { }
        }
        public void AllFilesAreTheSameLastWriteTime()
        {
            // Arrange
            var target = new CheckUpdate();

            // Act
            var result = target.Run(SourceDirPath, InstallDirPath, new List <string>());

            // Assert
            Assert.AreEqual(ResultCode.Success, result.ResultCode);
            Assert.IsFalse(result.Updated);
        }
        public void AllFilesAreDifferentLastWriteTime()
        {
            // Arrange
            SourceDirPath.ToDirectoryPath().SetLastWriteTimeToAllFiles(UpdateDateTime2);
            var target = new CheckUpdate();

            // Act
            var result = target.Run(SourceDirPath, InstallDirPath, new List <string>());

            // Assert
            Assert.AreEqual(ResultCode.Success, result.ResultCode);
            Assert.IsTrue(result.Updated);
        }
        public void OneOfTheFileIsUpdated()
        {
            // Arrange
            var updatedFilePath = Path.Combine(SourceDirPath, "a.txt");

            File.SetLastWriteTime(updatedFilePath, UpdateDateTime2);

            var target = new CheckUpdate();

            // Act
            var result = target.Run(SourceDirPath, InstallDirPath, new List <string>());

            // Assert
            Assert.AreEqual(ResultCode.Success, result.ResultCode);
            Assert.IsTrue(result.Updated);
        }
        public void UserFilesAreUpdate()
        {
            // Arrange
            var userDataFilePath = Path.Combine(InstallDirPath, UserDataDirFolderName, "u_a.txt");

            File.SetLastWriteTime(userDataFilePath, UpdateDateTime2);

            var target = new CheckUpdate();

            // Act
            var result = target.Run(
                SourceDirPath,
                InstallDirPath,
                new List <string> {
                UserDataDirFolderName + @"\\" + @".*"
            });

            // Assert
            Assert.AreEqual(ResultCode.Success, result.ResultCode);
            Assert.IsFalse(result.Updated);
        }