상속: BaseModel
예제 #1
0
 public ExplorerModel()
 {
     Structures = new ObservableCollection <IStructureBase>();
     _timer     = new Stopwatch();
     SetActiveStatus();
     Default = this;
 }
예제 #2
0
        public ExplorerViewModel(ExplorerModel dataModel, IDialogService dialogService, Func<IOpenFileDialog> openFileDialogFactory, Func<ISaveFileDialog> saveFileDialogFactory)
            : base(null)
        {
            Contract.Requires(dialogService != null);
            Contract.Requires(openFileDialogFactory != null);
            Contract.Requires(saveFileDialogFactory != null);

            _dialogService = dialogService;
            _openFileDialogFactory = openFileDialogFactory;
            _saveFileDialogFactory = saveFileDialogFactory;
            _dataModel = dataModel;

            Selections = new ObservableCollection<IStructureViewBase>();
            Selections.CollectionChanged += (sender, e) => RaisePropertyChanged(() => IsMultipleSelections);

            Structures = new ObservableCollection<IStructureViewBase>();
            foreach (var item in _dataModel.Structures)
            {
                AddViewModel(item);
            }

            UpdateLanguages();

            _dataModel.Structures.CollectionChanged += Structures_CollectionChanged;
            // Will bubble property change events from the Model to the ViewModel.
            _dataModel.PropertyChanged += (sender, e) => OnPropertyChanged(e.PropertyName);
        }
예제 #3
0
        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;
        }
예제 #4
0
        /// <summary>
        /// Command line driven method.
        /// <example>
        /// /WR "Easy Start Report" "c:\temp\Easy Start Report.txt"
        /// /WR "C:\Users\%USERNAME%\AppData\Roaming\SpaceEngineersDedicated\Saves\Super Excellent Map\sandbox.sbc" "c:\temp\Super Excellent Map.txt"
        /// /WR "C:\Users\%USERNAME%\AppData\Roaming\SpaceEngineersDedicated\Saves\Super Excellent Map" "c:\temp\Super Excellent Map.txt"
        /// /WR "\\SERVER\Dedicated Saves\Super Excellent Map" "\\SERVER\Reports\Super Excellent Map.txt"
        /// </example>
        /// </summary>
        /// <param name="baseModel"></param>
        /// <param name="args"></param>
        public static void GenerateOfflineReport(ExplorerModel baseModel, string[] args)
        {
            var argList = args.ToList();
            var comArgs = args.Where(a => a.ToUpper() == "/WR" || a.ToUpper() == "-WR").Select(a => { return a; }).ToArray();
            foreach (var a in comArgs) argList.Remove(a);

            if (argList.Count < 2)
            {
                Environment.Exit(2);
                return;
            }

            var findSession = argList[0].ToUpper();
            var reportFile = argList[1];
            var reportExtension = Path.GetExtension(reportFile).ToUpper();

            if (reportExtension != ".HTM" &&
                reportExtension != ".HTML" &&
                reportExtension != ".TXT" &&
                reportExtension != ".XML")
            {
                Environment.Exit(1);
                return;
            }

            if (File.Exists(findSession))
            {
                findSession = Path.GetDirectoryName(findSession);
            }

            WorldResource world;

            if (Directory.Exists(findSession))
            {
                world = SelectWorldModel.LoadSession(findSession);
            }
            else
            {
                world = SelectWorldModel.FindSaveSession(SpaceEngineersConsts.BaseLocalPath.SavesPath, findSession);
            }

            if (world == null)
            {
                Environment.Exit(3);
                return;
            }

            baseModel.ActiveWorld = world;
            baseModel.ActiveWorld.LoadDefinitionsAndMods();
            baseModel.ActiveWorld.LoadSector(true);
            baseModel.ParseSandBox();

            var model = new ResourceReportModel();
            model.Load(baseModel.ActiveWorld.Savename, baseModel.Structures);
            model.GenerateReport();
            TempfileUtil.Dispose();

            if (reportExtension == ".HTM" || reportExtension == ".HTML")
                File.WriteAllText(reportFile, model.CreateHtmlReport());

            if (reportExtension == ".TXT")
                File.WriteAllText(reportFile, model.CreateTextReport());

            if (reportExtension == ".XML")
                File.WriteAllText(reportFile, model.CreateXmlReport());

            Environment.Exit(0);
        }
예제 #5
0
 public ExplorerViewModel(ExplorerModel dataModel)
     : this(dataModel, ServiceLocator.Resolve<IDialogService>(), ServiceLocator.Resolve<IOpenFileDialog>, ServiceLocator.Resolve<ISaveFileDialog>)
 {
 }