public static void Write(string format, params object[] args)
{
int timeLength = 0;
// if the cvar system is not initialized
if(idE.CvarSystem.IsInitialized == false)
{
return;
}
// optionally put a timestamp at the beginning of each print,
// so we can see how long different init sections are taking
// TODO
/*if ( com_timestampPrints.GetInteger() ) {
int t = Sys_Milliseconds();
if ( com_timestampPrints.GetInteger() == 1 ) {
t /= 1000;
}
sprintf( msg, "[%i]", t );
timeLength = strlen( msg );
} else {
timeLength = 0;
}*/
// don't overflow
string msg = string.Format(format, args);
if(msg.Length >= (idE.MaxPrintMessageSize - timeLength))
{
msg = msg.Substring(0, idE.MaxPrintMessageSize - timeLength - 2);
msg += Environment.NewLine;
WriteLine("idConsole.Write: truncated to {0} characters", msg.Length);
}
if(_redirectBuffer != null)
{
if((_redirectBuffer.Length + msg.Length) >= _redirectBuffer.MaxCapacity)
{
_redirectFlushHandler(null, new RedirectBufferEventArgs(_redirectBuffer.ToString()));
_redirectBuffer.Clear();
}
_redirectBuffer.Append(msg);
return;
}
// echo to console buffer
AddToConsoleBuffer(msg);
AddToDedicatedBuffer(idHelper.RemoveColors(msg));
// print to script debugger server
// DebuggerServerPrint( msg );
// logFile
if((idE.CvarSystem.GetInteger("logFile") != 0) && (_logFileFailed == false) && (idE.FileSystem.IsInitialized == true))
{
if((_logFile == null) && (_recursingLogFileOpen == false))
{
string fileName = "qconsole.log";
if(idE.CvarSystem.GetString("logFileName") != string.Empty)
{
fileName = idE.CvarSystem.GetString("logFileName");
}
// fileSystem->OpenFileWrite can cause recursive prints into here
_recursingLogFileOpen = true;
Stream s = idE.FileSystem.OpenFileWrite(fileName);
if(s == null)
{
_logFileFailed = true;
FatalError("failed to open log file '{0}'", fileName);
}
_recursingLogFileOpen = false;
_logFile = new StreamWriter(s);
_logFile.AutoFlush = true;
WriteLine("log file '{0}' opened on {1}", fileName, DateTime.Now.ToString());
}
if(_logFile != null)
{
_logFile.Write(idHelper.RemoveColors(msg));
}
}
// TODO
// don't trigger any updates if we are in the process of doing a fatal error
/*if ( com_errorEntered != ERP_FATAL ) {
// update the console if we are in a long-running command, like dmap
if ( com_refreshOnPrint ) {
session->UpdateScreen();
}
// let session redraw the animated loading screen if necessary
session->PacifierUpdate();
}*/
}