SEToolbox.CoreToolbox.Load C# (CSharp) Method

Load() public method

public Load ( string args ) : bool
args string
return bool
        public bool Load(string[] args)
        {
            // Fetch the game version and store, so it can be retrieved during crash if the toolbox makes it this far.
            GlobalSettings.Default.SEVersion = SpaceEngineersConsts.GetSEVersion();

            // Test the Space Engineers version to make sure users are using an version that is new enough for SEToolbox to run with!
            // This is usually because a user has not updated a manual install of a Dedicated Server, or their Steam did not update properly.
            if (GlobalSettings.Default.SEVersion < GlobalSettings.GetAppVersion(true))
            {
                MessageBox.Show(string.Format(Res.DialogOldSEVersionMessage, SpaceEngineersConsts.GetSEVersion(), GlobalSettings.Default.SEBinPath, GlobalSettings.GetAppVersion()), Res.DialogOldSEVersionTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                Application.Current.Shutdown();
                return false;
            }

            // Force pre-loading of any Space Engineers resources.
            SpaceEngineersCore.LoadDefinitions();

            // Load the Space Engineers assemblies, or dependant classes after this point.
            var explorerModel = new ExplorerModel();

            if (args.Any(a => a.ToUpper() == "/WR" || a.ToUpper() == "-WR"))
            {
                ResourceReportModel.GenerateOfflineReport(explorerModel, args);
                Application.Current.Shutdown();
                return false;
            }

            var eViewModel = new ExplorerViewModel(explorerModel);
            var eWindow = new WindowExplorer(eViewModel);
            //if (allowClose)
            //{
            eViewModel.CloseRequested += (sender, e) =>
            {
                SaveSettings(eWindow);
                Application.Current.Shutdown();
            };
            //}
            eWindow.Loaded += (sender, e) =>
            {
                Splasher.CloseSplash();
                if (GlobalSettings.Default.WindowLeft.HasValue) eWindow.Left = GlobalSettings.Default.WindowLeft.Value;
                if (GlobalSettings.Default.WindowTop.HasValue) eWindow.Top = GlobalSettings.Default.WindowTop.Value;
                if (GlobalSettings.Default.WindowWidth.HasValue) eWindow.Width = GlobalSettings.Default.WindowWidth.Value;
                if (GlobalSettings.Default.WindowHeight.HasValue) eWindow.Height = GlobalSettings.Default.WindowHeight.Value;
                if (GlobalSettings.Default.WindowState.HasValue) eWindow.WindowState = GlobalSettings.Default.WindowState.Value;
            };
            eWindow.ShowDialog();

            return true;
        }

Usage Example

Example #1
0
        private void OnStartup(Object sender, StartupEventArgs e)
        {
            if ((Native.GetKeyState(System.Windows.Forms.Keys.ShiftKey) & KeyStates.Down) == KeyStates.Down)
            {
                // Reset User Settings when Shift is held down during start up.
                GlobalSettings.Default.Reset();
                GlobalSettings.Default.PromptUser = true;

                // Clear app bin cache.
                var binCache = ToolboxUpdater.GetBinCachePath();
                if (Directory.Exists(binCache))
                {
                    try
                    {
                        Directory.Delete(binCache, true);
                    }
                    catch
                    {
                        // File is locked and cannot be deleted at this time.
                    }
                }
            }

            LocalizeDictionary.Instance.SetCurrentThreadCulture = false;
            LocalizeDictionary.Instance.Culture   = CultureInfo.GetCultureInfoByIetfLanguageTag(GlobalSettings.Default.LanguageCode);
            Thread.CurrentThread.CurrentUICulture = LocalizeDictionary.Instance.Culture;

            Splasher.Splash = new WindowSplashScreen();
            Splasher.ShowSplash();

            log4net.Config.XmlConfigurator.Configure();

            var update = CodeplexReleases.CheckForUpdates();

            if (update != null)
            {
                var dialogResult = MessageBox.Show(string.Format(Res.DialogNewVersionMessage, update.Version), Res.DialogNewVersionTitle, MessageBoxButton.YesNo, MessageBoxImage.Information);
                if (dialogResult == MessageBoxResult.Yes)
                {
                    Process.Start(update.Link);
                    GlobalSettings.Default.Save();
                    Application.Current.Shutdown();
                    return;
                }

                if (dialogResult == MessageBoxResult.No)
                {
                    GlobalSettings.Default.IgnoreUpdateVersion = update.Version.ToString();
                }
            }

            // Configure service locator.
            ServiceLocator.RegisterSingleton <IDialogService, DialogService>();
            ServiceLocator.Register <IOpenFileDialog, OpenFileDialogViewModel>();
            ServiceLocator.Register <ISaveFileDialog, SaveFileDialogViewModel>();
            ServiceLocator.Register <IColorDialog, ColorDialogViewModel>();
            ServiceLocator.Register <IFolderBrowserDialog, FolderBrowserDialogViewModel>();

            _toolboxApplication = new CoreToolbox();
            if (_toolboxApplication.Init(e.Args))
            {
                _toolboxApplication.Load(e.Args);
            }
            else
            {
                Application.Current.Shutdown();
            }
        }
All Usage Examples Of SEToolbox.CoreToolbox::Load