示例#1
0
文件: App.cs 项目: calintx3/calin
        public bool Initialize(ToolkitType type)
        {
            _log.Open(Path.Combine(AppData.Path, "ParkitectNexusLauncher.log"));
            _log.MinimumLogLevel = LogLevel.Debug;

            Application.Initialize(type);

            _window = _presenterFactory.InstantiatePresenter <MainWindow>();
            _window.Show();

            var update = _updateManager.CheckForUpdates <App>();

            if (update != null)
            {
                if (
                    MessageDialog.AskQuestion("ParkitectNexus Client Update",
                                              "A required update for the ParkitectNexus Client needs to be installed.\n" +
                                              "Without this update you won't be able to install blueprints, savegames or mods trough this application. The update should take less than a minute.\n" +
                                              $"Would you like to install it now?\n\nYou are currently running v{typeof (App).Assembly.GetName().Version}. The newest version is v{update.Version}",
                                              Command.Yes, Command.No) !=
                    Command.Yes)
                {
                    return(false);
                }

                if (!_updateManager.InstallUpdate(update))
                {
                    MessageDialog.ShowError(_window, "ParkitectNexus Client Update", "Failed installing the update! Please try again later.");
                }

                return(false);
            }

            if (!_parkitect.DetectInstallationPath())
            {
                if (
                    !MessageDialog.Confirm(
                        "We couldn't automatically detect Parkitect on your machine!\nPlease press OK and manually select the installation folder of Parkitect.",
                        Command.Ok))
                {
                    _window.Dispose();
                    Application.Dispose();
                    return(false);
                }

                do
                {
                    var dlg = new SelectFolderDialog("Select your Parkitect installation folder.")
                    {
                        CanCreateFolders = false,
                        Multiselect      = false
                    };


                    if (dlg.Run(_window))
                    {
                        if (_parkitect.SetInstallationPathIfValid(dlg.Folder))
                        {
                            break;
                        }
                    }
                    else
                    {
                        _window.Dispose();
                        Application.Dispose();
                        return(false);
                    }
                } while (!_parkitect.IsInstalled);
            }

            _migrator.Migrate();
            ModLoaderUtil.InstallModLoader(_parkitect, _log);
            _taskManager.Add <CheckForUpdatesTask>();
            return(true);
        }