Ejemplo n.º 1
0
        private void startButton_Click(object sender, EventArgs e)
        {
            if (m_selectedSessionSettings == null)
            {
                return;
            }

            if (MyFakes.ENABLE_BATTLE_SYSTEM && battleButton.Checked && m_selectedSessionSettings != null)
            {
                MyBattleHelper.FillDefaultBattleServerSettings(m_selectedSessionSettings, true);
            }

            saveConfigButton_Click(sender, e);

            if (m_isService) // Service
            {
                RefreshWorldsList();
                if (startGameButton.Checked)
                {
                    // fix for new game selected - new game will be started and not last saved game instead
                    MyLocalCache.SaveLastSessionInfo("");
                }
                startService();
            }
            else // Local / Console
            {
                // When running without host process, console is not properly attached on debug (no console output)
                string[] cmdLine = Environment.GetCommandLineArgs();
                Process.Start(cmdLine[0].Replace(".vshost.exe", ".exe"), ((cmdLine.Length > 1) ? cmdLine[1] : "") + " -console -ignorelastsession");
                Close();
            }
        }
Ejemplo n.º 2
0
        public MyGuiScreenMainMenu()
            : base(Vector2.Zero, null, null)
        {
            if (MyGuiScreenGamePlay.Static == null)
            {
                m_closeOnEsc = false;
            }

            //if (MyGuiScreenGamePlay.Static.GetGameType() == MyGuiScreenGamePlayType.MAIN_MENU) m_closeOnEsc = false;
            //if (MyGuiScreenGamePlay.Static.IsPausable()) MySandboxGame.SwitchPause();

            //Because then it is visible under credits, help, etc..
            m_drawEvenWithoutFocus = false;

            if (MyGuiScreenGamePlay.Static == null)
            {
                //We dont want to load last session if we end up game in main menu
                MyLocalCache.SaveLastSessionInfo(null);
            }

            try
            {
                m_newsSerializer = new XmlSerializer(typeof(MyNews));
            }
            catch { };
        }
Ejemplo n.º 3
0
 void ServerResponded(object sender, MyGameServerItem serverItem)
 {
     //CloseHandlers();
     //m_progressScreen.CloseScreen();
     MyLocalCache.SaveLastSessionInfo(null, true, false, serverItem.Name, serverItem.ConnectionString);
     MyJoinGameHelper.JoinGame(serverItem);
 }
Ejemplo n.º 4
0
        public bool Save()
        {
            bool success = true;

            using (m_savingLock.AcquireExclusiveUsing())
            {
                MySandboxGame.Log.WriteLine("Session snapshot save - START");
                using (var indent = MySandboxGame.Log.IndentUsing(LoggingOptions.NONE))
                {
                    Debug.Assert(!string.IsNullOrWhiteSpace(TargetDir), "TargetDir should always be correctly set!");

                    Directory.CreateDirectory(TargetDir);

                    MySandboxGame.Log.WriteLine("Checking file access for files in target dir.");
                    if (!CheckAccessToFiles())
                    {
                        return(false);
                    }

                    var saveAbsPath = SavingDir;
                    if (Directory.Exists(saveAbsPath))
                    {
                        Directory.Delete(saveAbsPath, true);
                    }
                    Directory.CreateDirectory(saveAbsPath);

                    try
                    {
                        ulong sectorSizeInBytes     = 0;
                        ulong checkpointSizeInBytes = 0;
                        ulong voxelSizeInBytes      = 0;
                        success = MyLocalCache.SaveSector(SectorSnapshot, SavingDir, Vector3I.Zero, out sectorSizeInBytes) &&
                                  MyLocalCache.SaveCheckpoint(CheckpointSnapshot, SavingDir, out checkpointSizeInBytes) &&
                                  MyLocalCache.SaveLastLoadedTime(TargetDir, DateTime.Now);
                        if (success)
                        {
                            foreach (var entry in CompressedVoxelSnapshots)
                            {
                                voxelSizeInBytes += (ulong)entry.Value.Length;
                                success           = success && SaveVoxelSnapshot(entry.Key, entry.Value);
                            }
                        }
                        if (success && Sync.IsServer)
                        {
                            success = MyLocalCache.SaveLastSessionInfo(TargetDir);
                        }

                        if (success)
                        {
                            SavedSizeInBytes = sectorSizeInBytes + checkpointSizeInBytes + voxelSizeInBytes;
                        }
                    }
                    catch (Exception ex)
                    {
                        MySandboxGame.Log.WriteLine("There was an error while saving snapshot.");
                        MySandboxGame.Log.WriteLine(ex);
                        ReportFileError(ex);
                        success = false;
                    }

                    if (success)
                    {
                        HashSet <string> saveFiles = new HashSet <string>();
                        foreach (var filepath in Directory.GetFiles(saveAbsPath))
                        {
                            string filename = Path.GetFileName(filepath);

                            var targetFile = Path.Combine(TargetDir, filename);
                            if (File.Exists(targetFile))
                            {
                                File.Delete(targetFile);
                            }

                            File.Move(filepath, targetFile);
                            saveFiles.Add(filename);
                        }

                        // Clean leftovers from previous saves
                        foreach (var filepath in Directory.GetFiles(TargetDir))
                        {
                            string filename = Path.GetFileName(filepath);
                            if (saveFiles.Contains(filename) || filename == MyTextConstants.SESSION_THUMB_NAME_AND_EXTENSION)
                            {
                                continue;
                            }

                            File.Delete(filepath);
                        }

                        Directory.Delete(saveAbsPath);

                        //Backup Saves Functionality
                        Backup();
                    }
                    else
                    {
                        // We don't delete previous save, just the new one.
                        if (Directory.Exists(saveAbsPath))
                        {
                            Directory.Delete(saveAbsPath, true);
                        }
                    }
                }
                MySandboxGame.Log.WriteLine("Session snapshot save - END");
            }
            return(success);
        }