示例#1
0
        private static async void BackgroundInitialization()
        {
            try {
#if DEBUG
                CupClient.Instance?.LoadRegistries().Forget();
#endif

                await Task.Delay(500);

                AppArguments.Set(AppFlag.SimilarThreshold, ref CarAnalyzer.OptionSimilarThreshold);

                if (SettingsHolder.Drive.ScanControllersAutomatically)
                {
                    try {
                        InitializeDirectInputScanner();
                    } catch (Exception e) {
                        VisualCppTool.OnException(e, null);
                    }
                }

                string additional = null;
                AppArguments.Set(AppFlag.SimilarAdditionalSourceIds, ref additional);
                if (!string.IsNullOrWhiteSpace(additional))
                {
                    CarAnalyzer.OptionSimilarAdditionalSourceIds = additional.Split(';', ',').Select(x => x.Trim()).Where(x => x.Length > 0).ToArray();
                }

                await Task.Delay(500);

                if (AppArguments.Has(AppFlag.TestIfAcdAvailable) && !Acd.IsAvailable)
                {
                    NonfatalError.NotifyBackground(@"This build can’t work with encrypted ACD-files");
                }

                if (AppUpdater.JustUpdated && SettingsHolder.Common.ShowDetailedChangelog)
                {
                    List <ChangelogEntry> changelog;
                    try {
                        changelog = await Task.Run(() =>
                                                   AppUpdater.LoadChangelog().Where(x => x.Version.IsVersionNewerThan(AppUpdater.PreviousVersion)).ToList());
                    } catch (WebException e) {
                        NonfatalError.NotifyBackground(AppStrings.Changelog_CannotLoad, ToolsStrings.Common_MakeSureInternetWorks, e);
                        return;
                    } catch (Exception e) {
                        NonfatalError.NotifyBackground(AppStrings.Changelog_CannotLoad, e);
                        return;
                    }

                    Logging.Write("Changelog entries: " + changelog.Count);
                    if (changelog.Any())
                    {
                        Toast.Show(AppStrings.App_AppUpdated, AppStrings.App_AppUpdated_Details, () => {
                            ModernDialog.ShowMessage(changelog.Select(x => $@"[b]{x.Version}[/b]{Environment.NewLine}{x.Changes}")
                                                     .JoinToString(Environment.NewLine.RepeatString(2)), AppStrings.Changelog_RecentChanges_Title,
                                                     MessageBoxButton.OK);
                        });
                    }
                }

                await Task.Delay(1500);

                RevertFileChanges();

                await Task.Delay(1500);

                CustomUriSchemeHelper.Initialize();

#if !DEBUG
                CupClient.Instance?.LoadRegistries().Forget();
#endif

                await Task.Delay(5000);

                await Task.Run(() => {
                    foreach (var f in from file in Directory.GetFiles(FilesStorage.Instance.GetDirectory("Logs"))
                             where file.EndsWith(@".txt") || file.EndsWith(@".log") || file.EndsWith(@".json")
                             let info = new FileInfo(file)
                                        where info.LastWriteTime < DateTime.Now - TimeSpan.FromDays(3)
                                        select info)
                    {
                        f.Delete();
                    }
                });
            } catch (Exception e) {
                Logging.Error(e);
            }
        }
示例#2
0
        private async void BackgroundInitialization()
        {
            try {
                await Task.Delay(1000);

                if (AppArguments.Has(AppFlag.TestIfAcdAvailable) && !Acd.IsAvailable())
                {
                    NonfatalError.NotifyBackground(@"This build can’t work with encrypted ACD-files");
                }

                if (AppUpdater.JustUpdated && SettingsHolder.Common.ShowDetailedChangelog)
                {
                    List <ChangelogEntry> changelog;
                    try {
                        changelog =
                            await Task.Run(() => AppUpdater.LoadChangelog().Where(x => x.Version.IsVersionNewerThan(AppUpdater.PreviousVersion)).ToList());
                    } catch (WebException e) {
                        NonfatalError.NotifyBackground(AppStrings.Changelog_CannotLoad, ToolsStrings.Common_MakeSureInternetWorks, e);
                        return;
                    } catch (Exception e) {
                        NonfatalError.NotifyBackground(AppStrings.Changelog_CannotLoad, e);
                        return;
                    }

                    Logging.Debug("Changelog entries: " + changelog.Count);
                    if (changelog.Any())
                    {
                        Toast.Show(AppStrings.App_AppUpdated, AppStrings.App_AppUpdated_Details, () => {
                            ModernDialog.ShowMessage(changelog.Select(x => $@"[b]{x.Version}[/b]{Environment.NewLine}{x.Changes}")
                                                     .JoinToString(Environment.NewLine.RepeatString(2)), AppStrings.Changelog_RecentChanges_Title,
                                                     MessageBoxButton.OK);
                        });
                    }
                }

                await Task.Delay(1500);

                PresetsPerModeBackup.Revert();
                WeatherSpecificCloudsHelper.Revert();
                WeatherSpecificTyreSmokeHelper.Revert();
                WeatherSpecificVideoSettingsHelper.Revert();
                CarSpecificControlsPresetHelper.Revert();
                CopyFilterToSystemForOculusHelper.Revert();

                await Task.Delay(1500);

                CustomUriSchemeHelper.EnsureRegistered();

                await Task.Delay(5000);

                await Task.Run(() => {
                    foreach (var f in from file in Directory.GetFiles(FilesStorage.Instance.GetDirectory("Logs"))
                             where file.EndsWith(@".txt") || file.EndsWith(@".log") || file.EndsWith(@".json")
                             let info = new FileInfo(file)
                                        where info.LastWriteTime < DateTime.Now - TimeSpan.FromDays(3)
                                        select info)
                    {
                        f.Delete();
                    }
                });
            } catch (Exception e) {
                Logging.Error(e);
            }
        }