OpenBve.Interface.SaveLogs C# (CSharp) Method

SaveLogs() static private method

Saves the current in-game black box log
static private SaveLogs ( ) : void
return void
		internal static void SaveLogs()
		{
			if (Interface.CurrentOptions.BlackBox == false)
			{
				return;
			}
			string BlackBoxFile = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "logs.bin");
			using (System.IO.FileStream Stream = new System.IO.FileStream(BlackBoxFile, System.IO.FileMode.Create, System.IO.FileAccess.Write))
			{
				//TODO: This code recreates the file every frame.....
				//It should be possible to spin up a stream in a separate thread which then continously appends
				using (System.IO.BinaryWriter Writer = new System.IO.BinaryWriter(Stream, System.Text.Encoding.UTF8))
				{
					byte[] Identifier = new byte[] { 111, 112, 101, 110, 66, 86, 69, 95, 76, 79, 71, 83 };
					const short Version = 1;
					Writer.Write(Identifier);
					Writer.Write(Version);
					Writer.Write(Game.LogRouteName);
					Writer.Write(Game.LogTrainName);
					Writer.Write(Game.LogDateTime.ToBinary());
					Writer.Write((short)Interface.CurrentOptions.GameMode);
					Writer.Write(Game.BlackBoxEntryCount);
					for (int i = 0; i < Game.BlackBoxEntryCount; i++)
					{
						Writer.Write(Game.BlackBoxEntries[i].Time);
						Writer.Write(Game.BlackBoxEntries[i].Position);
						Writer.Write(Game.BlackBoxEntries[i].Speed);
						Writer.Write(Game.BlackBoxEntries[i].Acceleration);
						Writer.Write(Game.BlackBoxEntries[i].ReverserDriver);
						Writer.Write(Game.BlackBoxEntries[i].ReverserSafety);
						Writer.Write((short)Game.BlackBoxEntries[i].PowerDriver);
						Writer.Write((short)Game.BlackBoxEntries[i].PowerSafety);
						Writer.Write((short)Game.BlackBoxEntries[i].BrakeDriver);
						Writer.Write((short)Game.BlackBoxEntries[i].BrakeSafety);
						Writer.Write((short)Game.BlackBoxEntries[i].EventToken);
					}
					Writer.Write(Game.ScoreLogCount);
					for (int i = 0; i < Game.ScoreLogCount; i++)
					{
						Writer.Write(Game.ScoreLogs[i].Time);
						Writer.Write(Game.ScoreLogs[i].Position);
						Writer.Write(Game.ScoreLogs[i].Value);
						Writer.Write((short)Game.ScoreLogs[i].TextToken);
					}
					Writer.Write(Game.CurrentScore.Maximum);
					Identifier = new byte[] { 95, 102, 105, 108, 101, 69, 78, 68 };
					Writer.Write(Identifier);
					Writer.Close();
				} Stream.Close();
			}
		}

Usage Example

Esempio n. 1
0
        protected override void OnClosing(CancelEventArgs e)
        {
            // Minor hack:
            // If we are currently loading, catch the first close event, and terminate the loader threads
            // before actually closing the game-window.
            if (Loading.Cancel)
            {
                return;
            }
            if (!Loading.Complete)
            {
                e.Cancel       = true;
                Loading.Cancel = true;
            }

            try
            {
                //Force-save the black-box log, as otherwise we may be missing upto 30s of data
                Interface.SaveLogs(true);
            }
            catch
            {
                //Saving black-box failed, not really important
            }
            for (int i = 0; i < Program.TrainManager.Trains.Length; i++)
            {
                if (Program.TrainManager.Trains[i].State != TrainState.Bogus)
                {
                    Program.TrainManager.Trains[i].UnloadPlugin();
                }
            }
            Program.Renderer.TextureManager.UnloadAllTextures();
            for (int i = 0; i < InputDevicePlugin.AvailablePluginInfos.Count; i++)
            {
                InputDevicePlugin.CallPluginUnload(i);
            }
            if (MainLoop.Quit == MainLoop.QuitMode.ContinueGame && Program.CurrentHost.MonoRuntime)
            {
                //More forcefully close under Mono, stuff *still* hanging around....
                Environment.Exit(0);
            }
            base.OnClosing(e);
        }
All Usage Examples Of OpenBve.Interface::SaveLogs