コード例 #1
0
 protected override void ExecuteTask(CancellationToken token)
 {
     if (token.IsCancellationRequested)
     {
         return;
     }
     _mutex = UpdaterUtilities.CheckAndSetGlobalMutex(MutexName);
 }
コード例 #2
0
        public MainWindow()
        {
            InitializeComponent();

            lvLogs.ItemsSource = _logEvents;

            LogExtensions.LogEvent          += OnLogEvent;
            UpdaterUtilities.UpdateResponse += UpdaterUtilities_UpdateResponse;

            var driverVersion = GeforceUtilities.GetDriverVersion();

            Logging.GetFileLogger().Log(Level.Info, $"Driver Version: {(driverVersion != null ? driverVersion.ToString() : "N/A")}");

            var gfeVersion = GeforceUtilities.GetGeForceExperienceVersion();

            Logging.GetFileLogger().Log(Level.Info, $"GeForce Experience Version: {(gfeVersion != null ? gfeVersion.ToString() : "N/A")}");

            CheckBackgroundTask();

            chkFileLogging.IsChecked    = Settings.Default.FileLogging;
            chkUpdates.IsChecked        = Settings.Default.StartupUpdate;
            cbTaskTrigger.SelectedIndex = Settings.Default.BackgroundTaskTrigger;

            if (Logging.IsReadOnly)
            {
                chkFileLogging.IsEnabled = false;
                chkFileLogging.Content  += $" ({Properties.Resources.Logging_disabled_on_read_only_device})";
            }

            if (Settings.Default.StartupUpdate)
            {
                btnUpdateCheck.IsEnabled = false;
                UpdaterUtilities.UpdateCheck(false);
            }

            var version = AppUtils.GetVersion();

            tbVersion.Inlines.Clear();
            tbVersion.Inlines.Add(new Run($"{Properties.Resources.Version} {version.ToString(ExtendedVersionFormatFlags.BuildString | ExtendedVersionFormatFlags.Truncated)} "));

            Title += $" v{version.ToString(ExtendedVersionFormatFlags.BuildString | ExtendedVersionFormatFlags.Truncated)} ";

            if (version.Commit != null)
            {
                var link = new Hyperlink(new Run(version.Commit.ToShorthandString()))
                {
                    NavigateUri = new Uri($"{Properties.Resources.GithubUrl}/commit/{AppUtils.GetVersion().Commit}")
                };
                link.RequestNavigate += Hyperlink_OnRequestNavigate;
                tbVersion.Inlines.Add(link);
            }

#if PORTABLE
            Title += $" ({Properties.Resources.Portable})";
#endif
        }
コード例 #3
0
 protected override Version?GetComponentVersion(IComponent component)
 {
     try
     {
         return(UpdaterUtilities.GetAssemblyFileVersion(component.GetFilePath()));
     }
     catch
     {
         return(null);
     }
 }
コード例 #4
0
 protected override DownloadSummary DownloadCore(Uri uri, Stream outputStream, ProgressUpdateCallback progress,
                                                 CancellationToken cancellationToken, IComponent?component)
 {
     if (!uri.IsFile && !uri.IsUnc)
     {
         throw new ArgumentException("Expected file or UNC path", nameof(uri));
     }
     return(new DownloadSummary
     {
         DownloadedSize = UpdaterUtilities.CopyFileToStream(uri.LocalPath, outputStream, progress, cancellationToken)
     });
 }
コード例 #5
0
        public async Task VersionNotSpecifiedShaNotEqual()
        {
            var dependency = new Dependency();

            dependency.Name        = "FocLauncher.dll";
            dependency.Destination = ApplicationBasePath;
            dependency.Sha2        = UpdaterUtilities.HexToArray("d32b568cd1b96d459e7291ebf4b25d007f275c9f13149beeb782fac0716613f8");
            dependency.Origin      = "https://example.com";

            var component = CatalogExtensions.DependencyToComponent(dependency);

            const ComponentAction expected = ComponentAction.Update;
            await _updateManager.CalculateComponentStatusAsync(component);

            Assert.AreEqual(expected, component.RequiredAction);
        }
コード例 #6
0
        public async Task VersionEqualShaEqual()
        {
            var dependency = new Dependency();

            dependency.Name        = "FocLauncher.dll";
            dependency.Version     = "1.0.0.0";
            dependency.Destination = ApplicationBasePath;
            dependency.Sha2        = UpdaterUtilities.GetFileHash(Path.Combine(ApplicationBasePath, dependency.Name), HashType.Sha256);
            dependency.Origin      = "https://example.com";

            var component = CatalogExtensions.DependencyToComponent(dependency);

            const ComponentAction expected = ComponentAction.Keep;
            await _updateManager.CalculateComponentStatusAsync(component);

            Assert.AreEqual(expected, component.RequiredAction);
        }
コード例 #7
0
        public FormMain()
        {
            InitializeComponent();

            _tasksControl = new TelemetryControl("Telemetry Tasks")
            {
                Dock = DockStyle.Top
            };
            _tasksControl.CheckStateChanged += telemControl_CheckStateChanged;
            tabPage1.Controls.Add(_tasksControl);
            _servicesControl = new TelemetryControl("Telemetry Services")
            {
                Dock = DockStyle.Top
            };
            _servicesControl.CheckStateChanged += telemControl_CheckStateChanged;
            tabPage1.Controls.Add(_servicesControl);

            txtLicense.Text = Resources.ApplicationLicense;

            LogExtensions.LogEvent          += OnLogEvent;
            UpdaterUtilities.UpdateResponse += UpdaterUtilities_UpdateResponse;

            CheckBackgroundTask();

            chkFileLogging.Checked      = Settings.Default.FileLogging;
            chkUpdates.Checked          = Settings.Default.StartupUpdate;
            cbTaskTrigger.SelectedIndex = Settings.Default.BackgroundTaskTrigger;

            if (Settings.Default.StartupUpdate)
            {
                btnUpdatecheck.Enabled = false;
                UpdaterUtilities.UpdateCheck(false);
            }

            var version = GetVersion();

            lblVersion.Text     = $"{"Version"} {version.ToString(ExtendedVersionFormatFlags.BuildString | ExtendedVersionFormatFlags.CommitShort | ExtendedVersionFormatFlags.Truncated)}";
            lblVersion.LinkArea = version.Commit != null ? new LinkArea(lblVersion.Text.Length - version.Commit.ToShorthandString().Length, version.Commit.ToShorthandString().Length) : new LinkArea(0, 0);
        }
コード例 #8
0
 private void btnUpdatecheck_Click(object sender, RoutedEventArgs e)
 {
     btnUpdateCheck.IsEnabled = false;
     UpdaterUtilities.UpdateCheck(true);
 }
コード例 #9
0
        public void Run(CancellationToken token = default)
        {
            Schedule();
            var installsOrUninstalls = _installsOrUninstalls?.OfType <ComponentInstallTask>() ?? Enumerable.Empty <ComponentInstallTask>();

            using var mutex = UpdaterUtilities.CheckAndSetGlobalMutex();
            try
            {
                try
                {
                    _linkedCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token);
                    _downloads.Run(_linkedCancellationTokenSource.Token);
                    _installs.Run(_linkedCancellationTokenSource.Token);

                    try
                    {
                        _downloads.Wait();
                    }
                    catch (Exception)
                    {
                    }
                }
                finally
                {
                    if (_linkedCancellationTokenSource != null)
                    {
                        _linkedCancellationTokenSource.Dispose();
                        _linkedCancellationTokenSource = null;
                    }

                    Logger.Trace("Completed update operation");
                }

                if (RequiredProcessElevation)
                {
                    throw new ElevationRequireException(_elevationRequests);
                }

                if (IsCancelled)
                {
                    throw new OperationCanceledException(token);
                }
                token.ThrowIfCancellationRequested();

                var failedDownloads = _componentsToDownload.Where(p =>
                                                                  p.Error != null && !p.Error.IsExceptionType <OperationCanceledException>());

                var failedInstalls = installsOrUninstalls
                                     .Where(installTask => !installTask.Result.IsSuccess()).ToList();

                if (failedDownloads.Any() || failedInstalls.Any())
                {
                    throw new ComponentFailedException(
                              "Update failed because one or more downloads or installs had an error.");
                }

                var requiresRestart = LockedFilesWatcher.Instance.LockedFiles.Any();
                if (requiresRestart)
                {
                    Logger.Info("The operation finished. A restart is pedning.");
                }
            }
            finally
            {
                mutex.ReleaseMutex();
                _installMutexTask?.Dispose();
            }
        }