Пример #1
0
        /// <summary>
        /// An optional custom setup to override
        /// </summary>
        /// <param name="args">The launch arguments</param>
        /// <returns>The task</returns>
        protected override async Task OnSetupAsync(string[] args)
        {
            LogStartupTime("RCP setup is starting");

            // Load the user data
            try
            {
                if (CommonPaths.AppUserDataPath.FileExists)
                {
                    JsonConvert.PopulateObject(File.ReadAllText(CommonPaths.AppUserDataPath), RCPServices.Data);
                    RL.Logger?.LogInformationSource($"The app user data has been loaded");
                }
                else
                {
                    // Reset the user data
                    RCPServices.Data.Reset();

                    RL.Logger?.LogInformationSource($"The app user data has been reset");
                }
            }
            catch (Exception ex)
            {
                ex.HandleError($"Loading app user data");

                // NOTE: This is not localized due to the current culture not having been set at this point
                MessageBox.Show($"An error occurred reading saved app data. Some settings have been reset to their default values.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

                // Reset the user data
                RCPServices.Data.Reset();
            }

            Data = RCPServices.Data;

            LogStartupTime("User data has been loaded");

            // Set the theme
            this.SetTheme(Data.DarkMode, Data.SyncTheme);

            // Apply the current culture if defaulted
            if (Data.CurrentCulture == LocalizationManager.DefaultCulture.Name)
            {
                LocalizationManager.SetCulture(LocalizationManager.DefaultCulture.Name);
            }

            // Listen to data binding logs
            WPFTraceListener.Setup(LogLevel.Warning);

            StartupComplete      += BaseApp_StartupComplete_Miscellaneous_Async;
            StartupComplete      += App_StartupComplete_Updater_Async;
            Data.PropertyChanged += Data_PropertyChangedAsync;

            // Run basic startup
            await BasicStartupAsync();

            RL.Logger?.LogInformationSource($"Current version is {RCPServices.App.CurrentAppVersion}");

            // Check if it's a new version
            if (Data.LastVersion < RCPServices.App.CurrentAppVersion)
            {
                // Run post-update code
                await PostUpdateAsync();

                LogStartupTime("Post update has run");

                // Update the last version
                Data.LastVersion = RCPServices.App.CurrentAppVersion;
            }
            // Check if it's a lower version than previously recorded
            else if (Data.LastVersion > RCPServices.App.CurrentAppVersion)
            {
                RL.Logger?.LogWarningSource($"A newer version ({Data.LastVersion}) has been recorded in the application data");

                if (!Data.DisableDowngradeWarning)
                {
                    await Services.MessageUI.DisplayMessageAsync(String.Format(Metro.Resources.DowngradeWarning, RCPServices.App.CurrentAppVersion,
                                                                               Data.LastVersion), Metro.Resources.DowngradeWarningHeader, MessageType.Warning);
                }
            }
        }