From a4baab103fb9d9be3c0f3c63111c01b71efb3ed7 Mon Sep 17 00:00:00 2001
From: "Jake.Stine" <Jake.Stine@96395faa-99c1-11dd-bbfe-3dabce05a288>
Date: Sun, 15 Nov 2009 06:26:55 +0000
Subject: [PATCH] Mode console logging updates and additions;  * Added support
 for indentation, as a replacement for using \t  (options include methods
 SetIndent and Indent, and a ConsoleIndentScope class for scoped indentation
 of a block of WriteLns.)  * Use of Indent() as a modifier (the abstraction
 optionally allows use of indentation methods besides \t, if ever needed).  *
 Minor header file cleanups: wxWidgets standard headers are now always first
 in PrecompiledHeader.h files (is recommended due to cross platform setup code
 by wx).

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2198 96395faa-99c1-11dd-bbfe-3dabce05a288
---
 .../wxWidgets/build/msw/wx_config_2008.vcproj |   8 +-
 common/build/x86emitter/x86emitter.vcproj     |  30 ++++
 common/include/Utilities/Console.h            | 126 +++++++++++--
 common/include/Utilities/Dependencies.h       |  10 +-
 common/include/Utilities/pxRadioPanel.h       |   4 +-
 common/src/Utilities/Console.cpp              | 166 +++++++++++++-----
 common/src/Utilities/PrecompiledHeader.h      |   3 +
 common/src/x86emitter/PrecompiledHeader.h     |  10 +-
 pcsx2/CDVD/CDVD.cpp                           |   4 +-
 pcsx2/CDVD/CDVDisoReader.cpp                  |   4 +-
 pcsx2/Memory.cpp                              |   1 -
 pcsx2/Patch.cpp                               |   2 +-
 pcsx2/PluginManager.cpp                       |  15 +-
 pcsx2/RecoverySystem.cpp                      |   4 +-
 pcsx2/SaveState.cpp                           |   9 +-
 pcsx2/System.cpp                              |  29 ++-
 pcsx2/gui/AppInit.cpp                         |   2 +-
 pcsx2/gui/ConsoleLogger.cpp                   |  96 ++++------
 pcsx2/gui/ConsoleLogger.h                     |   2 +-
 pcsx2/gui/IniInterface.cpp                    |  10 +-
 pcsx2/gui/i18n.cpp                            |   9 +-
 pcsx2/windows/VCprojects/pcsx2_2008.vcproj    |   5 +-
 pcsx2/x86/sVU_zerorec.cpp                     |   1 -
 23 files changed, 360 insertions(+), 190 deletions(-)

diff --git a/3rdparty/wxWidgets/build/msw/wx_config_2008.vcproj b/3rdparty/wxWidgets/build/msw/wx_config_2008.vcproj
index 55b89659b3..b72227fede 100644
--- a/3rdparty/wxWidgets/build/msw/wx_config_2008.vcproj
+++ b/3rdparty/wxWidgets/build/msw/wx_config_2008.vcproj
@@ -127,10 +127,6 @@
 					/>
 				</FileConfiguration>
 			</File>
-			<File
-				RelativePath="..\..\include\wx\setup.h"
-				>
-			</File>
 			<File
 				RelativePath="..\..\include\wx\msw\setup.h"
 				>
@@ -165,6 +161,10 @@
 					/>
 				</FileConfiguration>
 			</File>
+			<File
+				RelativePath="..\..\include\wx\setup.h"
+				>
+			</File>
 		</Filter>
 		<Filter
 			Name="Resource Files"
diff --git a/common/build/x86emitter/x86emitter.vcproj b/common/build/x86emitter/x86emitter.vcproj
index 5fd01c446b..33ae52e1ab 100644
--- a/common/build/x86emitter/x86emitter.vcproj
+++ b/common/build/x86emitter/x86emitter.vcproj
@@ -41,6 +41,8 @@
 				Name="VCCLCompilerTool"
 				Optimization="0"
 				PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
+				UsePrecompiledHeader="2"
+				PrecompiledHeaderThrough="PrecompiledHeader.h"
 			/>
 			<Tool
 				Name="VCManagedResourceCompilerTool"
@@ -97,6 +99,8 @@
 				Optimization="2"
 				EnableIntrinsicFunctions="true"
 				PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
+				UsePrecompiledHeader="2"
+				PrecompiledHeaderThrough="PrecompiledHeader.h"
 			/>
 			<Tool
 				Name="VCManagedResourceCompilerTool"
@@ -153,6 +157,8 @@
 				Optimization="2"
 				EnableIntrinsicFunctions="true"
 				PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
+				UsePrecompiledHeader="2"
+				PrecompiledHeaderThrough="PrecompiledHeader.h"
 			/>
 			<Tool
 				Name="VCManagedResourceCompilerTool"
@@ -226,6 +232,30 @@
 			<File
 				RelativePath="..\..\src\x86emitter\PrecompiledHeader.cpp"
 				>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Devel|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"
+					/>
+				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\..\src\x86emitter\simd.cpp"
diff --git a/common/include/Utilities/Console.h b/common/include/Utilities/Console.h
index 563d5cc781..43c6520d48 100644
--- a/common/include/Utilities/Console.h
+++ b/common/include/Utilities/Console.h
@@ -53,39 +53,50 @@ enum ConsoleColors
 	ConsoleColors_Count
 };
 
+static const ConsoleColors DefaultConsoleColor = Color_Default;
+
+
 // Use fastcall for the console; should be helpful in most cases
 #define __concall	__fastcall
 
 // ----------------------------------------------------------------------------------------
 //  IConsoleWriter -- For printing messages to the console.
 // ----------------------------------------------------------------------------------------
+// General ConsoleWrite Threading Guideline:
+//   PCSX2 is a threaded environment and multiple threads can write to the console asynchronously.
+//   Individual calls to ConsoleWriter APIs will be written in atomic fashion, however "partial"
+//   logs may end up interrupted by logs on other threads.  This is usually not a problem for
+//   WriteLn, but may be undesirable for typical uses of Write.  In cases where you want to
+//   print multi-line blocks of uninterrupted logs, compound the entire log into a single large
+//   string and issue that to WriteLn.
 //
 struct IConsoleWriter
 {
-	// Write implementation for internal use only.
+	// Write implementation for internal use only. (can be NULL)
 	void (__concall *DoWrite)( const wxString& fmt );
 
-	// WriteLn implementation for internal use only.
+	// WriteLn implementation for internal use only.  (can be NULL)
 	void (__concall *DoWriteLn)( const wxString& fmt );
 
+	// SetColor implementation for internal use only.
+	void (__concall *DoSetColor)( ConsoleColors color );
+
 	void (__concall *Newline)();
-
 	void (__concall *SetTitle)( const wxString& title );
 
-	// Changes the active console color.
-	// This color will be unset by calls to colored text methods
-	// such as ErrorMsg and Notice.
-	void (__concall *SetColor)( ConsoleColors color );
-
-	// Restores the console color to default (usually low-intensity white on Win32)
-	void (__concall *ClearColor)();
-
 	// ----------------------------------------------------------------------------
 	// Public members; call these to print stuff to console!
 	//
 	// All functions always return false.  Return value is provided only so that we can easily
 	// disable logs at compile time using the "0&&action" macro trick.
 
+	ConsoleColors GetColor() const;
+	const IConsoleWriter& SetColor( ConsoleColors color ) const;
+	const IConsoleWriter& ClearColor() const;
+	const IConsoleWriter& SetIndent( int tabcount=1 ) const;
+
+	IConsoleWriter Indent( int tabcount=1 ) const;
+
 	bool Write( ConsoleColors color, const char* fmt, ... ) const;
 	bool WriteLn( ConsoleColors color, const char* fmt, ... ) const;
 	bool Write( const char* fmt, ... ) const;
@@ -99,6 +110,97 @@ struct IConsoleWriter
 	bool WriteLn( const wxChar* fmt, ... ) const;
 	bool Error( const wxChar* fmt, ... ) const;
 	bool Warning( const wxChar* fmt, ... ) const;
+
+	// internal value for indentation of individual lines.  Use the Indent() member to invoke.
+	int _imm_indentation;
+	
+	// For internal use only.
+	wxString _addIndentation( const wxString& src, int glob_indent ) const;
+};
+
+extern IConsoleWriter	Console;
+
+// --------------------------------------------------------------------------------------
+//  ConsoleIndentScope
+// --------------------------------------------------------------------------------------
+// Provides a scoped indentation of the IConsoleWriter interface for the current thread.
+// Any console writes performed from this scope will be indented by the specified number
+// of tab characters.
+//
+// Scoped Object Notes:  Like most scoped objects, this is intended to be used as a stack
+// or temporary object only.  Using it in a situation where the object's lifespan out-lives
+// a scope will almost certainly result in unintended /undefined side effects.
+//
+class ConsoleIndentScope
+{
+	DeclareNoncopyableObject( ConsoleIndentScope );
+
+protected:
+	int m_amount;
+
+public:
+	// Constructor: The specified number of tabs will be appended to the current indentation
+	// setting.  The tabs will be unrolled when the object leaves scope or is destroyed.
+	ConsoleIndentScope( int tabs=1 )
+	{
+		Console.SetIndent( m_amount = tabs );
+	}
+
+	virtual ~ConsoleIndentScope() throw()
+	{
+		Console.SetIndent( -m_amount );
+	}
+};
+
+// --------------------------------------------------------------------------------------
+//  ConsoleColorScope
+// --------------------------------------------------------------------------------------
+class ConsoleColorScope
+{
+	DeclareNoncopyableObject( ConsoleColorScope );
+
+protected:
+	ConsoleColors m_old_color;
+
+public:
+	ConsoleColorScope( ConsoleColors newcolor )
+	{
+		m_old_color = Console.GetColor();
+		Console.SetColor( newcolor );
+	}
+
+	virtual ~ConsoleColorScope() throw()
+	{
+		Console.SetColor( m_old_color );
+	}
+};
+
+// --------------------------------------------------------------------------------------
+//  ConsoleAttrScope
+// --------------------------------------------------------------------------------------
+// Applies both color and tab attributes in a single object constructor.
+//
+class ConsoleAttrScope
+{
+	DeclareNoncopyableObject( ConsoleAttrScope );
+
+protected:
+	ConsoleColors	m_old_color;
+	int				m_tabsize;
+
+public:
+	ConsoleAttrScope( ConsoleColors newcolor, int indent=0 )
+	{
+		m_old_color = Console.GetColor();
+		Console.SetIndent( m_tabsize = indent );
+		Console.SetColor( newcolor );
+	}
+
+	virtual ~ConsoleAttrScope() throw()
+	{
+		Console.SetColor( m_old_color );
+		Console.SetIndent( -m_tabsize );
+	}
 };
 
 extern void Console_SetActiveHandler( const IConsoleWriter& writer, FILE* flushfp=NULL );
@@ -112,8 +214,6 @@ extern const IConsoleWriter		ConsoleWriter_Assert;
 extern const IConsoleWriter		ConsoleWriter_Buffered;
 extern const IConsoleWriter		ConsoleWriter_wxError;
 
-extern IConsoleWriter	Console;
-
 #ifdef PCSX2_DEVBUILD
 	extern IConsoleWriter	DevConWriter;
 #	define DevCon			DevConWriter
diff --git a/common/include/Utilities/Dependencies.h b/common/include/Utilities/Dependencies.h
index 7f5a37d003..7753b886e8 100644
--- a/common/include/Utilities/Dependencies.h
+++ b/common/include/Utilities/Dependencies.h
@@ -53,24 +53,20 @@
 //
 #define wxLt(a)		(a)
 
-// must include wx/setup.h first, otherwise we get warnings/errors regarding __LINUX__
-#include <wx/setup.h>
-
-class wxString;
-
-#include "Pcsx2Defs.h"
-
 #include <wx/string.h>
 #include <wx/gdicmn.h>		// for wxPoint/wxRect stuff
 #include <wx/intl.h>
 #include <wx/log.h>
 
+#include "Pcsx2Defs.h"
+
 #include <stdexcept>
 #include <algorithm>
 #include <string>
 #include <cstring>		// string.h under c++
 #include <cstdio>		// stdio.h under c++
 #include <cstdlib>
+#include <vector>
 #include <list>
 
 #include "Utilities/Assertions.h"
diff --git a/common/include/Utilities/pxRadioPanel.h b/common/include/Utilities/pxRadioPanel.h
index 2e09575f75..51a2050246 100644
--- a/common/include/Utilities/pxRadioPanel.h
+++ b/common/include/Utilities/pxRadioPanel.h
@@ -79,13 +79,13 @@ class pxRadioPanel : public wxPanelWithHelpers
 protected:
 	typedef std::vector<RadioPanelItem>		ButtonArray;
 	typedef SafeArray<RadioPanelObjects>	ButtonObjArray;
-	
+
 	ButtonArray		m_buttonStrings;
 	ButtonObjArray	m_objects;
 	
 	bool			m_IsRealized;
 	int				m_idealWidth;
-	
+
 	wxSize			m_padding;
 	int				m_Indentation;
 
diff --git a/common/src/Utilities/Console.cpp b/common/src/Utilities/Console.cpp
index 7478febf23..b1ce539415 100644
--- a/common/src/Utilities/Console.cpp
+++ b/common/src/Utilities/Console.cpp
@@ -30,7 +30,7 @@ void Console_SetActiveHandler( const IConsoleWriter& writer, FILE* flushfp )
 	pxAssertDev(
 		(writer.DoWrite != NULL)	&& (writer.DoWriteLn != NULL) &&
 		(writer.Newline != NULL)	&& (writer.SetTitle != NULL) &&
-		(writer.SetColor != NULL)	&& (writer.ClearColor != NULL),
+		(writer.DoSetColor != NULL),
 		"Invalid IConsoleWriter object!  All function pointer interfaces must be implemented."
 	);
 
@@ -53,22 +53,20 @@ void Console_SetActiveHandler( const IConsoleWriter& writer, FILE* flushfp )
 // --------------------------------------------------------------------------------------
 
 static void __concall ConsoleNull_SetTitle( const wxString& title ) {}
-static void __concall ConsoleNull_SetColor( ConsoleColors color ) {}
-static void __concall ConsoleNull_ClearColor() {}
+static void __concall ConsoleNull_DoSetColor( ConsoleColors color ) {}
 static void __concall ConsoleNull_Newline() {}
 static void __concall ConsoleNull_DoWrite( const wxString& fmt ) {}
 static void __concall ConsoleNull_DoWriteLn( const wxString& fmt ) {}
 
 const IConsoleWriter ConsoleWriter_Null =
 {
-	ConsoleNull_DoWrite,
-	ConsoleNull_DoWriteLn,
+	NULL, //ConsoleNull_DoWrite,
+	NULL, //ConsoleNull_DoWriteLn,
+	ConsoleNull_DoSetColor,
 
 	ConsoleNull_Newline,
 
 	ConsoleNull_SetTitle,
-	ConsoleNull_SetColor,
-	ConsoleNull_ClearColor,
 };
 
 // --------------------------------------------------------------------------------------
@@ -134,17 +132,10 @@ static void __concall ConsoleStdio_Newline()
 	wxPrintf( L"\n" );
 }
 
-static void __concall ConsoleStdio_ClearColor()
+static void __concall ConsoleStdio_DoSetColor( ConsoleColors color )
 {
 #ifdef __LINUX__
 	wxPrintf(L"\033[0m");
-#endif
-}
-
-static void __concall ConsoleStdio_SetColor( ConsoleColors color )
-{
-#ifdef __LINUX__
-    ConsoleStdio_ClearColor();
     wxPrintf(GetLinuxConsoleColor(color));
 #endif
 }
@@ -160,12 +151,11 @@ const IConsoleWriter ConsoleWriter_Stdio =
 {
 	ConsoleStdio_DoWrite,			// Writes without newlines go to buffer to avoid error log spam.
 	ConsoleStdio_DoWriteLn,
+	ConsoleStdio_DoSetColor,
 
 	ConsoleStdio_Newline,
 
 	ConsoleStdio_SetTitle,
-	ConsoleStdio_SetColor,
-	ConsoleStdio_ClearColor,
 };
 
 // --------------------------------------------------------------------------------------
@@ -186,12 +176,11 @@ const IConsoleWriter ConsoleWriter_Assert =
 {
 	ConsoleAssert_DoWrite,
 	ConsoleAssert_DoWriteLn,
+	ConsoleNull_DoSetColor,
 
 	ConsoleNull_Newline,
 
 	ConsoleNull_SetTitle,
-	ConsoleNull_SetColor,
-	ConsoleNull_ClearColor,
 };
 
 // --------------------------------------------------------------------------------------
@@ -233,12 +222,11 @@ const IConsoleWriter ConsoleWriter_Buffered =
 {
 	ConsoleBuffer_DoWrite,			// Writes without newlines go to buffer to avoid assertion spam.
 	ConsoleBuffer_DoWriteLn,
+	ConsoleNull_DoSetColor,
 
 	ConsoleNull_Newline,
 
 	ConsoleNull_SetTitle,
-	ConsoleNull_SetColor,
-	ConsoleNull_ClearColor,
 };
 
 // --------------------------------------------------------------------------------------
@@ -259,12 +247,11 @@ const IConsoleWriter ConsoleWriter_wxError =
 {
 	ConsoleBuffer_DoWrite,			// Writes without newlines go to buffer to avoid error log spam.
 	Console_wxLogError_DoWriteLn,
+	ConsoleNull_DoSetColor,
 
 	ConsoleNull_Newline,
 
 	ConsoleNull_SetTitle,
-	ConsoleNull_SetColor,
-	ConsoleNull_ClearColor,
 };
 
 // Sanity check: truncate strings if they exceed 512k in length.  Anything like that
@@ -301,6 +288,7 @@ static FormatBuffer<wxChar>	unicode_buffer( unicode_buffer_is_deleted );
 
 static void format_that_ascii_mess( SafeArray<char>& buffer, const char* fmt, va_list argptr )
 {
+	
 	while( true )
 	{
 		int size = buffer.GetLength();
@@ -357,6 +345,12 @@ static void format_that_unicode_mess( SafeArray<wxChar>& buffer, const wxChar* f
 	// though it'd be kinda nice if we did.
 }
 
+// thread-local console indentation setting.
+static __threadlocal int conlog_Indent = 0;
+
+// thread-local console color storage.
+static __threadlocal ConsoleColors conlog_Color = DefaultConsoleColor;
+
 static wxString ascii_format_string(const char* fmt, va_list argptr)
 {
 	if( ascii_buffer_is_deleted )
@@ -396,12 +390,76 @@ static wxString unicode_format_string(const wxChar* fmt, va_list argptr)
 // (all non-virtual members that do common work and then pass the result through DoWrite
 //  or DoWriteLn)
 
+// Parameters:
+//   glob_indent - this parameter is used to specify a global indentation setting.  It is used by
+//      WriteLn function, but defaults to 0 for Notice and Error calls.  Local indentation always
+//      applies to all writes.
+wxString IConsoleWriter::_addIndentation( const wxString& src, int glob_indent=0 ) const
+{
+	const int indent = glob_indent + _imm_indentation;
+	if( indent == 0 ) return src;
+
+	wxArrayString pieces;
+	SplitString( pieces, src, L'\n' );
+	const wxString indentStr( L'\t', indent );
+	wxString result;
+	result.reserve( src.Length() + 24 );
+	JoinString( result, pieces, L'\n' + indentStr );
+	return indentStr + result;
+}
+
+// Sets the indentation to be applied to all WriteLn's.  The indentation is added to the
+// primary write, and to any newlines specified within the write.  Note that this applies
+// to calls to WriteLn *only* -- calls to Write bypass the indentation parser.
+const IConsoleWriter& IConsoleWriter::SetIndent( int tabcount ) const
+{
+	conlog_Indent += tabcount;
+	pxAssert( conlog_Indent >= 0 );
+	return *this;
+}
+
+IConsoleWriter IConsoleWriter::Indent( int tabcount ) const
+{
+	IConsoleWriter retval = *this;
+	retval._imm_indentation = tabcount;
+	return retval;
+}
+
+// Changes the active console color.
+// This color will be unset by calls to colored text methods
+// such as ErrorMsg and Notice.
+const IConsoleWriter& IConsoleWriter::SetColor( ConsoleColors color ) const
+{
+	pxAssertMsg( color >= Color_Current && color < ConsoleColors_Count, "Invalid ConsoleColor specified." );
+	
+	if( conlog_Color != color )
+		DoSetColor( conlog_Color = color );
+		
+	return *this;
+}
+
+ConsoleColors IConsoleWriter::GetColor() const
+{
+	return conlog_Color;
+}
+
+// Restores the console color to default (usually black, or low-intensity white if the console uses a black background)
+const IConsoleWriter& IConsoleWriter::ClearColor() const
+{
+	if( conlog_Color != DefaultConsoleColor )
+		DoSetColor( conlog_Color = DefaultConsoleColor );
+
+	return *this;
+}
+
 // --------------------------------------------------------------------------------------
 //  ASCII/UTF8 (char*)
 // --------------------------------------------------------------------------------------
 
 bool IConsoleWriter::Write( const char* fmt, ... ) const
 {
+	if( DoWrite == NULL ) return false;
+
 	va_list args;
 	va_start(args,fmt);
 	DoWrite( ascii_format_string(fmt, args) );
@@ -412,11 +470,12 @@ bool IConsoleWriter::Write( const char* fmt, ... ) const
 
 bool IConsoleWriter::Write( ConsoleColors color, const char* fmt, ... ) const
 {
+	if( DoWrite == NULL ) return false;
+
 	va_list args;
 	va_start(args,fmt);
-	SetColor( color );
+	ConsoleColorScope cs( color );
 	DoWrite( ascii_format_string(fmt, args) );
-	ClearColor();
 	va_end(args);
 
 	return false;
@@ -424,9 +483,11 @@ bool IConsoleWriter::Write( ConsoleColors color, const char* fmt, ... ) const
 
 bool IConsoleWriter::WriteLn( const char* fmt, ... ) const
 {
+	if( DoWriteLn == NULL ) return false;
+
 	va_list args;
 	va_start(args,fmt);
-	DoWriteLn( ascii_format_string(fmt, args) );
+	DoWriteLn( _addIndentation( ascii_format_string(fmt, args), conlog_Indent ) );
 	va_end(args);
 
 	return false;
@@ -434,11 +495,11 @@ bool IConsoleWriter::WriteLn( const char* fmt, ... ) const
 
 bool IConsoleWriter::WriteLn( ConsoleColors color, const char* fmt, ... ) const
 {
+	if( DoWriteLn == NULL ) return false;
 	va_list args;
 	va_start(args,fmt);
-	SetColor( color );
-	DoWriteLn( ascii_format_string(fmt, args) );
-	ClearColor();
+	ConsoleColorScope cs( color );
+	DoWriteLn( _addIndentation( ascii_format_string(fmt, args), conlog_Indent ) );
 	va_end(args);
 
 	return false;
@@ -446,11 +507,12 @@ bool IConsoleWriter::WriteLn( ConsoleColors color, const char* fmt, ... ) const
 
 bool IConsoleWriter::Error( const char* fmt, ... ) const
 {
+	if( DoWriteLn == NULL ) return false;
+
 	va_list args;
 	va_start(args,fmt);
-	SetColor( Color_StrongRed );
-	DoWriteLn( ascii_format_string(fmt, args) );
-	ClearColor();
+	ConsoleColorScope cs( Color_StrongRed );
+	DoWriteLn( _addIndentation( ascii_format_string(fmt, args) ) );
 	va_end(args);
 
 	return false;
@@ -458,11 +520,12 @@ bool IConsoleWriter::Error( const char* fmt, ... ) const
 
 bool IConsoleWriter::Warning( const char* fmt, ... ) const
 {
+	if( DoWriteLn == NULL ) return false;
+
 	va_list args;
 	va_start(args,fmt);
-	SetColor( Color_StrongOrange );
-	DoWriteLn( ascii_format_string(fmt, args) );
-	ClearColor();
+	ConsoleColorScope cs( Color_StrongOrange );
+	DoWriteLn( _addIndentation( ascii_format_string(fmt, args) ) );
 	va_end(args);
 
 	return false;
@@ -474,6 +537,8 @@ bool IConsoleWriter::Warning( const char* fmt, ... ) const
 
 bool IConsoleWriter::Write( const wxChar* fmt, ... ) const
 {
+	if( DoWrite == NULL ) return false;
+
 	va_list args;
 	va_start(args,fmt);
 	DoWrite( unicode_format_string( fmt, args ) );
@@ -484,11 +549,12 @@ bool IConsoleWriter::Write( const wxChar* fmt, ... ) const
 
 bool IConsoleWriter::Write( ConsoleColors color, const wxChar* fmt, ... ) const
 {
+	if( DoWrite == NULL ) return false;
+
 	va_list args;
 	va_start(args,fmt);
-	SetColor( color );
+	ConsoleColorScope cs( color );
 	DoWrite( unicode_format_string( fmt, args ) );
-	ClearColor();
 	va_end(args);
 
 	return false;
@@ -496,9 +562,11 @@ bool IConsoleWriter::Write( ConsoleColors color, const wxChar* fmt, ... ) const
 
 bool IConsoleWriter::WriteLn( const wxChar* fmt, ... ) const
 {
+	if( DoWriteLn == NULL ) return false;
+
 	va_list args;
 	va_start(args,fmt);
-	DoWriteLn( unicode_format_string( fmt, args ) );
+	DoWriteLn( _addIndentation( unicode_format_string( fmt, args ), conlog_Indent ) );
 	va_end(args);
 
 	return false;
@@ -506,11 +574,12 @@ bool IConsoleWriter::WriteLn( const wxChar* fmt, ... ) const
 
 bool IConsoleWriter::WriteLn( ConsoleColors color, const wxChar* fmt, ... ) const
 {
+	if( DoWriteLn == NULL ) return false;
+
 	va_list args;
 	va_start(args,fmt);
-	SetColor( color );
-	DoWriteLn( unicode_format_string( fmt, args ) );
-	ClearColor();
+	ConsoleColorScope cs( color );
+	DoWriteLn( _addIndentation( unicode_format_string( fmt, args ), conlog_Indent ) );
 	va_end(args);
 
 	return false;
@@ -518,11 +587,12 @@ bool IConsoleWriter::WriteLn( ConsoleColors color, const wxChar* fmt, ... ) cons
 
 bool IConsoleWriter::Error( const wxChar* fmt, ... ) const
 {
+	if( DoWriteLn == NULL ) return false;
+
 	va_list args;
 	va_start(args,fmt);
-	SetColor( Color_StrongRed );
-	DoWriteLn( unicode_format_string( fmt, args ) );
-	ClearColor();
+	ConsoleColorScope cs( Color_StrongRed );
+	DoWriteLn( _addIndentation( unicode_format_string( fmt, args ) ) );
 	va_end(args);
 
 	return false;
@@ -530,17 +600,17 @@ bool IConsoleWriter::Error( const wxChar* fmt, ... ) const
 
 bool IConsoleWriter::Warning( const wxChar* fmt, ... ) const
 {
+	if( DoWriteLn == NULL ) return false;
+
 	va_list args;
 	va_start(args,fmt);
-	SetColor( Color_StrongOrange );
-	DoWriteLn( unicode_format_string( fmt, args ) );
-	ClearColor();
+	ConsoleColorScope cs( Color_StrongOrange );
+	DoWriteLn( _addIndentation( unicode_format_string( fmt, args ) ) );
 	va_end(args);
 
 	return false;
 }
 
-
 // --------------------------------------------------------------------------------------
 //  Default Writer for C++ init / startup:
 // --------------------------------------------------------------------------------------
diff --git a/common/src/Utilities/PrecompiledHeader.h b/common/src/Utilities/PrecompiledHeader.h
index 81362ff7f8..10e33c3096 100644
--- a/common/src/Utilities/PrecompiledHeader.h
+++ b/common/src/Utilities/PrecompiledHeader.h
@@ -1,3 +1,6 @@
+
+// Can't use #pragma once in the precompiled header, as it won't work correctly with GCC PCH.
+
 #ifndef UTILITIES_PRECOMPILED_HEADER
 #define UTILITIES_PRECOMPILED_HEADER
 
diff --git a/common/src/x86emitter/PrecompiledHeader.h b/common/src/x86emitter/PrecompiledHeader.h
index 8495f7e0d3..bb9541eb17 100644
--- a/common/src/x86emitter/PrecompiledHeader.h
+++ b/common/src/x86emitter/PrecompiledHeader.h
@@ -1,17 +1,17 @@
+
+// Can't use #pragma once in the precompiled header, as it won't work correctly with GCC PCH.
+
 #ifndef EMITTER_PRECOMPILED_HEADER
 #define EMITTER_PRECOMPILED_HEADER
 
-// must include wx/setup.h first, otherwise we get warnings/errors regarding __LINUX__
-#include <wx/setup.h>
-
-#include "Pcsx2Defs.h"
-
 #include <wx/string.h>
 #include <wx/tokenzr.h>
 #include <wx/gdicmn.h>		// for wxPoint/wxRect stuff
 #include <wx/intl.h>
 #include <wx/log.h>
 
+#include "Pcsx2Defs.h"
+
 #include <stdexcept>
 #include <algorithm>
 #include <string>
diff --git a/pcsx2/CDVD/CDVD.cpp b/pcsx2/CDVD/CDVD.cpp
index 0bb6e2c970..646267432b 100644
--- a/pcsx2/CDVD/CDVD.cpp
+++ b/pcsx2/CDVD/CDVD.cpp
@@ -90,7 +90,7 @@ FILE *_cdvdOpenMechaVer()
 		fd = fopen(file, "wb");
 		if (fd == NULL)
 		{
-			Console.Error( "\tMEC File Creation failed!" );
+			Console.Error( "MEC File Creation failed!" );
 			throw Exception::CreateStream( file );
 			//Msgbox::Alert( "_cdvdOpenMechaVer: Error creating %s", file);
 			//exit(1);
@@ -130,7 +130,7 @@ FILE *_cdvdOpenNVM()
 		fd = fopen(file, "wb");
 		if (fd == NULL)
 		{
-			Console.Error( "\tNVM File Creation failed!" );
+			Console.Error( "NVM File Creation failed!" );
 			throw Exception::CreateStream( file );
 		}
 		for (int i=0; i<1024; i++) fputc(0, fd);
diff --git a/pcsx2/CDVD/CDVDisoReader.cpp b/pcsx2/CDVD/CDVDisoReader.cpp
index 01cf82a1a1..0566b177ed 100644
--- a/pcsx2/CDVD/CDVDisoReader.cpp
+++ b/pcsx2/CDVD/CDVDisoReader.cpp
@@ -150,12 +150,12 @@ static void FindLayer1Start()
 
 		if(layer1start == 0x200010)
 		{
-			Console.WriteLn("\tCouldn't find second layer on dual layer... ignoring");
+			Console.Warning("CDVDiso: Couldn't find second layer... ignoring");
 			layer1start=-2;
 		}
 
 		if(layer1start>=0)
-			Console.WriteLn("\tfound at 0x%8.8x", layer1start);
+			Console.WriteLn("CDVDiso: second layer found at 0x%8.8x", layer1start);
 	}
 }
 
diff --git a/pcsx2/Memory.cpp b/pcsx2/Memory.cpp
index 7d09930586..881d4a9c34 100644
--- a/pcsx2/Memory.cpp
+++ b/pcsx2/Memory.cpp
@@ -39,7 +39,6 @@ BIOS
 
 #pragma warning(disable:4799) // No EMMS at end of function
 
-#include <vector>
 #include <wx/file.h>
 
 #include "VUmicro.h"
diff --git a/pcsx2/Patch.cpp b/pcsx2/Patch.cpp
index f5cf589f8f..e11d108879 100644
--- a/pcsx2/Patch.cpp
+++ b/pcsx2/Patch.cpp
@@ -667,7 +667,7 @@ namespace PatchFunc
 		catch( wxString& exmsg )
 		{
 			Console.Error( L"(Patch) Error Parsing: %s=%s", cmd.c_str(), param.c_str() );
-			Console.Error( L"\t" + exmsg );
+			Console.Indent().Error( exmsg );
 		}
     }
 
diff --git a/pcsx2/PluginManager.cpp b/pcsx2/PluginManager.cpp
index b251b501ab..998c2af256 100644
--- a/pcsx2/PluginManager.cpp
+++ b/pcsx2/PluginManager.cpp
@@ -668,9 +668,10 @@ PluginManager::PluginManager( const wxString (&folders)[PluginId_Count] )
 
 	const PluginInfo* pi = tbl_PluginInfo; do
 	{
+		ConsoleIndentScope indent;
 		const PluginsEnum_t pid = pi->id;
 
-		Console.WriteLn( L"\tBinding %s\t: %s ", tbl_PluginInfo[pid].GetShortname().c_str(), folders[pid].c_str() );
+		Console.WriteLn( L"Binding %s\t: %s ", tbl_PluginInfo[pid].GetShortname().c_str(), folders[pid].c_str() );
 
 		if( folders[pid].IsEmpty() )
 			throw Exception::InvalidArgument( "Empty plugin filename." );
@@ -902,7 +903,7 @@ void PluginManager::Open( PluginsEnum_t pid )
 {
 	if( m_info[pid].IsOpened ) return;
 
-	Console.WriteLn( "\tOpening %s", tbl_PluginInfo[pid].shortname );
+	Console.Indent().WriteLn( "Opening %s", tbl_PluginInfo[pid].shortname );
 
 	// Each Open needs to be called explicitly. >_<
 
@@ -944,7 +945,7 @@ void PluginManager::Open()
 void PluginManager::Close( PluginsEnum_t pid )
 {
 	if( !m_info[pid].IsOpened ) return;
-	Console.WriteLn( "\tClosing %s", tbl_PluginInfo[pid].shortname );
+	Console.Indent().WriteLn( "Closing %s", tbl_PluginInfo[pid].shortname );
 
 	if( pid == PluginId_GS )
 	{
@@ -996,7 +997,7 @@ void PluginManager::Init()
 			Console.WriteLn( Color_StrongBlue, "Initializing plugins..." );
 			printlog = true;
 		}
-		Console.WriteLn( "\tInit %s", tbl_PluginInfo[pid].shortname );
+		Console.Indent().WriteLn( "Init %s", tbl_PluginInfo[pid].shortname );
 		if( 0 != m_info[pid].CommonBindings.Init() )
 			throw Exception::PluginInitError( pid );
 
@@ -1037,7 +1038,7 @@ void PluginManager::Shutdown()
 	{
 		const PluginsEnum_t pid = tbl_PluginInfo[i].id;
 		if( !m_info[pid].IsInitialized ) continue;
-		DevCon.WriteLn( "\tShutdown %s", tbl_PluginInfo[pid].shortname );
+		DevCon.Indent().WriteLn( "Shutdown %s", tbl_PluginInfo[pid].shortname );
 		m_info[pid].IsInitialized = false;
 		m_info[pid].CommonBindings.Shutdown();
 	}
@@ -1078,7 +1079,7 @@ bool PluginManager::DoFreeze( PluginsEnum_t pid, int mode, freezeData* data )
 //
 void PluginManager::Freeze( PluginsEnum_t pid, SaveStateBase& state )
 {
-	Console.WriteLn( "\t%s %s", state.IsSaving() ? "Saving" : "Loading",
+	Console.Indent().WriteLn( "%s %s", state.IsSaving() ? "Saving" : "Loading",
 		tbl_PluginInfo[pid].shortname );
 
 	freezeData fP = { 0, NULL };
@@ -1093,7 +1094,7 @@ void PluginManager::Freeze( PluginsEnum_t pid, SaveStateBase& state )
 		// no state data to read, but the plugin expects some state data.
 		// Issue a warning to console...
 		if( fP.size != 0 )
-			Console.Warning( "\tWarning: No data for this plugin was found. Plugin status may be unpredictable." );
+			Console.Indent().Warning( "Warning: No data for this plugin was found. Plugin status may be unpredictable." );
 		return;
 
 		// Note: Size mismatch check could also be done here on loading, but
diff --git a/pcsx2/RecoverySystem.cpp b/pcsx2/RecoverySystem.cpp
index dbd731ba14..ce37e796b2 100644
--- a/pcsx2/RecoverySystem.cpp
+++ b/pcsx2/RecoverySystem.cpp
@@ -377,7 +377,7 @@ void StateCopy_SaveToSlot( uint num )
 	zip_dest_filename = SaveStateBase::GetFilename( num );
 	(new StateThread_Freeze( OnFinished_ZipToDisk ))->Start();
 	Console.WriteLn( Color_StrongGreen, "Saving savestate to slot %d...", num );
-	Console.WriteLn( Color_StrongGreen, L"\tfilename: %s", zip_dest_filename.c_str() );
+	Console.Indent().WriteLn( Color_StrongGreen, L"filename: %s", zip_dest_filename.c_str() );
 }
 
 void StateCopy_LoadFromSlot( uint slot )
@@ -392,7 +392,7 @@ void StateCopy_LoadFromSlot( uint slot )
 	}
 
 	Console.WriteLn( Color_StrongGreen, "Loading savestate from slot %d...", slot );
-	Console.WriteLn( Color_StrongGreen, L"\tfilename: %s", file.c_str() );
+	Console.Indent().WriteLn( Color_StrongGreen, L"filename: %s", file.c_str() );
 
 	CoreThread.Pause();
 	(new StateThread_UnzipFromDisk( OnFinished_Restore, file ))->Start();
diff --git a/pcsx2/SaveState.cpp b/pcsx2/SaveState.cpp
index ef20c706ec..a72a6c5d1d 100644
--- a/pcsx2/SaveState.cpp
+++ b/pcsx2/SaveState.cpp
@@ -112,10 +112,11 @@ void SaveStateBase::FreezeBios()
 	{
 		if( memcmp( descin, desccmp, 128 ) != 0 )
 		{
-			Console.Error(
-				"\n\tWarning: BIOS Version Mismatch, savestate may be unstable!\n"
-				"\t\tCurrent Version:   %s\n"
-				"\t\tSavestate Version: %s\n",
+			Console.Newline();
+			Console.Indent(1).Error( "Warning: BIOS Version Mismatch, savestate may be unstable!" );
+			Console.Indent(2).Error(
+				"Current Version:   %s\n"
+				"Savestate Version: %s\n",
 				descout.ToUTF8().data(), descin
 			);
 		}
diff --git a/pcsx2/System.cpp b/pcsx2/System.cpp
index b1e9f2f06a..078874bd54 100644
--- a/pcsx2/System.cpp
+++ b/pcsx2/System.cpp
@@ -47,21 +47,20 @@ void SysDetect()
 
 	cpudetectInit();
 
-	//Console.SetColor( Color_Gray );
-
 	Console.WriteLn( Color_StrongBlack, "x86-32 Init:" );
-	Console.WriteLn(
-		L"\tCPU vendor name  =  %s\n"
-		L"\tFamilyID         =  %x\n"
-		L"\tx86Family        =  %s\n"
-		L"\tCPU speed        =  %d.%03d ghz\n"
-		L"\tCores            =  %d physical [%d logical]\n"
-		L"\tx86PType         =  %s\n"
-		L"\tx86Flags         =  %8.8x %8.8x\n"
-		L"\tx86EFlags        =  %8.8x\n",
+	
+	Console.Indent().WriteLn(
+		L"CPU vendor name  =  %s\n"
+		L"FamilyID         =  %x\n"
+		L"x86Family        =  %s\n"
+		L"CPU speed        =  %d.%03d ghz\n"
+		L"Cores            =  %d physical [%d logical]\n"
+		L"x86PType         =  %s\n"
+		L"x86Flags         =  %8.8x %8.8x\n"
+		L"x86EFlags        =  %8.8x\n",
 			fromUTF8( x86caps.VendorName ).c_str(), x86caps.StepID,
 			fromUTF8( x86caps.FamilyName ).Trim().Trim(false).c_str(),
-			x86caps.Speed / 1000, x86caps.Speed%1000,
+			x86caps.Speed / 1000, x86caps.Speed % 1000,
 			x86caps.PhysicalCores, x86caps.LogicalCores,
 			fromUTF8( x86caps.TypeName ).c_str(),
 			x86caps.Flags, x86caps.Flags2,
@@ -87,12 +86,10 @@ void SysDetect()
 	JoinString( result[0], features[0], L".. " );
 	JoinString( result[1], features[1], L".. " );
 
-	Console.ClearColor();
-
 	Console.WriteLn( Color_StrongBlack,	L"x86 Features Detected:" );
-	Console.WriteLn( L"\t" + result[0] + (result[1].IsEmpty() ? L"" : (L"\n\t" + result[1])) + L"\n" );
+	Console.Indent().WriteLn( result[0] + (result[1].IsEmpty() ? L"" : (L"\n" + result[1])) + L"\n" );
 
-	//if ( x86caps.VendorName[0] == 'A' ) //AMD cpu
+	Console.Newline();
 }
 
 // returns the translated error message for the Virtual Machine failing to allocate!
diff --git a/pcsx2/gui/AppInit.cpp b/pcsx2/gui/AppInit.cpp
index c8985c2387..3cb23baa99 100644
--- a/pcsx2/gui/AppInit.cpp
+++ b/pcsx2/gui/AppInit.cpp
@@ -452,7 +452,7 @@ struct CrtDebugBreak
 {
 	CrtDebugBreak( int spot )
 	{
-#ifndef __LINUX__
+#ifdef __WXMSW__
 		_CrtSetBreakAlloc( spot );
 #endif
 	}
diff --git a/pcsx2/gui/ConsoleLogger.cpp b/pcsx2/gui/ConsoleLogger.cpp
index ffb9f63731..bc3b8ab1ea 100644
--- a/pcsx2/gui/ConsoleLogger.cpp
+++ b/pcsx2/gui/ConsoleLogger.cpp
@@ -181,17 +181,17 @@ void ConsoleLogFrame::ColorArray::Create( int fontsize )
 
 	// Standard R, G, B format:
 	new (&m_table[Color_Default])		wxTextAttr( wxColor(   0,   0,   0 ), wxNullColour, fixed );
-	new (&m_table[Color_Black])		wxTextAttr( wxColor(   0,   0,   0 ), wxNullColour, fixed );
-	new (&m_table[Color_Red])		wxTextAttr( wxColor( 128,   0,   0 ), wxNullColour, fixed );
-	new (&m_table[Color_Green])		wxTextAttr( wxColor(   0, 128,   0 ), wxNullColour, fixed );
-	new (&m_table[Color_Blue])		wxTextAttr( wxColor(   0,   0, 128 ), wxNullColour, fixed );
-	new (&m_table[Color_Magenta])	wxTextAttr( wxColor( 160,   0, 160 ), wxNullColour, fixed );
-	new (&m_table[Color_Orange])	wxTextAttr( wxColor( 160, 120,   0 ), wxNullColour, fixed );
-	new (&m_table[Color_Gray])		wxTextAttr( wxColor( 108, 108, 108 ), wxNullColour, fixed );
+	new (&m_table[Color_Black])			wxTextAttr( wxColor(   0,   0,   0 ), wxNullColour, fixed );
+	new (&m_table[Color_Red])			wxTextAttr( wxColor( 128,   0,   0 ), wxNullColour, fixed );
+	new (&m_table[Color_Green])			wxTextAttr( wxColor(   0, 128,   0 ), wxNullColour, fixed );
+	new (&m_table[Color_Blue])			wxTextAttr( wxColor(   0,   0, 128 ), wxNullColour, fixed );
+	new (&m_table[Color_Magenta]	)	wxTextAttr( wxColor( 160,   0, 160 ), wxNullColour, fixed );
+	new (&m_table[Color_Orange])		wxTextAttr( wxColor( 160, 120,   0 ), wxNullColour, fixed );
+	new (&m_table[Color_Gray])			wxTextAttr( wxColor( 108, 108, 108 ), wxNullColour, fixed );
 
-	new (&m_table[Color_Cyan])		wxTextAttr( wxColor( 128, 180, 180 ), wxNullColour, fixed );
-	new (&m_table[Color_Yellow])	wxTextAttr( wxColor( 180, 180, 128 ), wxNullColour, fixed );
-	new (&m_table[Color_White])		wxTextAttr( wxColor( 160, 160, 160 ), wxNullColour, fixed );
+	new (&m_table[Color_Cyan])			wxTextAttr( wxColor( 128, 180, 180 ), wxNullColour, fixed );
+	new (&m_table[Color_Yellow])		wxTextAttr( wxColor( 180, 180, 128 ), wxNullColour, fixed );
+	new (&m_table[Color_White])			wxTextAttr( wxColor( 160, 160, 160 ), wxNullColour, fixed );
 
 	new (&m_table[Color_StrongBlack])	wxTextAttr( wxColor(   0,   0,   0 ), wxNullColour, fixedB );
 	new (&m_table[Color_StrongRed])		wxTextAttr( wxColor( 128,   0,   0 ), wxNullColour, fixedB );
@@ -228,8 +228,6 @@ void ConsoleLogFrame::ColorArray::SetFont( int fontsize )
 	Create( fontsize );
 }
 
-static const ConsoleColors DefaultConsoleColor = Color_Black;
-
 enum MenuIDs_t
 {
 	MenuID_FontSize_Small = 0x10,
@@ -321,7 +319,6 @@ ConsoleLogFrame::ConsoleLogFrame( MainEmuFrame *parent, const wxString& title, A
 
 ConsoleLogFrame::~ConsoleLogFrame()
 {
-	safe_delete( m_threadlogger );
 	wxGetApp().OnProgramLogClosed();
 }
 
@@ -454,7 +451,7 @@ void ConsoleLogFrame::OnCloseWindow(wxCloseEvent& event)
 		DoClose();
 	else
 	{
-		safe_delete( m_threadlogger );
+		m_threadlogger = NULL;
 		wxGetApp().OnProgramLogClosed();
 		event.Skip();
 	}
@@ -681,31 +678,22 @@ static void __concall ConsoleToFile_SetTitle( const wxString& title )
     ConsoleWriter_Stdio.SetTitle(title);
 }
 
-static void __concall ConsoleToFile_SetColor( ConsoleColors color )
+static void __concall ConsoleToFile_DoSetColor( ConsoleColors color )
 {
     ConsoleWriter_Stdio.SetColor(color);
 }
 
-static void __concall ConsoleToFile_ClearColor()
-{
-    ConsoleWriter_Stdio.ClearColor();
-}
-
 extern const IConsoleWriter	ConsoleWriter_File;
 const IConsoleWriter    ConsoleWriter_File =
 {
 	ConsoleToFile_DoWrite,
 	ConsoleToFile_DoWriteLn,
+	ConsoleToFile_DoSetColor,
+
 	ConsoleToFile_Newline,
-
 	ConsoleToFile_SetTitle,
-	ConsoleToFile_SetColor,
-	ConsoleToFile_ClearColor,
 };
 
-// thread-local console color storage.
-static __threadlocal ConsoleColors th_CurrentColor = DefaultConsoleColor;
-
 // --------------------------------------------------------------------------------------
 //  ConsoleToWindow Implementations
 // --------------------------------------------------------------------------------------
@@ -719,17 +707,9 @@ static void __concall ConsoleToWindow_SetTitle( const wxString& title )
 }
 
 template< const IConsoleWriter& secondary >
-static void __concall ConsoleToWindow_SetColor( ConsoleColors color )
+static void __concall ConsoleToWindow_DoSetColor( ConsoleColors color )
 {
     secondary.SetColor(color);
-	th_CurrentColor = color;
-}
-
-template< const IConsoleWriter& secondary >
-static void __concall ConsoleToWindow_ClearColor()
-{
-    secondary.ClearColor();
-	th_CurrentColor = DefaultConsoleColor;
 }
 
 template< const IConsoleWriter& secondary >
@@ -743,14 +723,14 @@ template< const IConsoleWriter& secondary >
 static void __concall ConsoleToWindow_DoWrite( const wxString& fmt )
 {
 	secondary.DoWrite( fmt );
-	((Pcsx2App&)*wxTheApp).GetProgramLog()->Write( th_CurrentColor, fmt );
+	((Pcsx2App&)*wxTheApp).GetProgramLog()->Write( Console.GetColor(), fmt );
 }
 
 template< const IConsoleWriter& secondary >
 static void __concall ConsoleToWindow_DoWriteLn( const wxString& fmt )
 {
 	secondary.DoWriteLn( fmt );
-	((Pcsx2App&)*wxTheApp).GetProgramLog()->Write( th_CurrentColor, fmt + L"\n" );
+	((Pcsx2App&)*wxTheApp).GetProgramLog()->Write( Console.GetColor(), fmt + L"\n" );
 }
 
 typedef void __concall DoWriteFn(const wxString&);
@@ -759,22 +739,20 @@ static const IConsoleWriter	ConsoleWriter_Window =
 {
 	ConsoleToWindow_DoWrite<ConsoleWriter_Null>,
 	ConsoleToWindow_DoWriteLn<ConsoleWriter_Null>,
-	ConsoleToWindow_Newline<ConsoleWriter_Null>,
+	ConsoleToWindow_DoSetColor<ConsoleWriter_Null>,
 
+	ConsoleToWindow_Newline<ConsoleWriter_Null>,
 	ConsoleToWindow_SetTitle<ConsoleWriter_Null>,
-	ConsoleToWindow_SetColor<ConsoleWriter_Null>,
-	ConsoleToWindow_ClearColor<ConsoleWriter_Null>,
-};
+};	
 
 static const IConsoleWriter	ConsoleWriter_WindowAndFile =
 {
 	ConsoleToWindow_DoWrite<ConsoleWriter_File>,
 	ConsoleToWindow_DoWriteLn<ConsoleWriter_File>,
-	ConsoleToWindow_Newline<ConsoleWriter_File>,
+	ConsoleToWindow_DoSetColor<ConsoleWriter_File>,
 
+	ConsoleToWindow_Newline<ConsoleWriter_File>,
 	ConsoleToWindow_SetTitle<ConsoleWriter_File>,
-	ConsoleToWindow_SetColor<ConsoleWriter_File>,
-	ConsoleToWindow_ClearColor<ConsoleWriter_File>,
 };
 
 void Pcsx2App::EnableAllLogging() const
@@ -851,29 +829,29 @@ protected:
 	long				m_Flags;
 
 public:
-	pxMessageBoxEvent() :
-		wxEvent( 0, pxEVT_MSGBOX )
-	,	m_Instdata( *(MsgboxEventResult*)NULL )
-	,	m_Title()
-	,	m_Content()
+	pxMessageBoxEvent()
+		: wxEvent( 0, pxEVT_MSGBOX )
+		, m_Instdata( *(MsgboxEventResult*)NULL )
+		, m_Title()
+		, m_Content()
 	{
 		m_Flags = 0;
 	}
 
-	pxMessageBoxEvent( MsgboxEventResult& instdata, const wxString& title, const wxString& content, long flags ) :
-		wxEvent( 0, pxEVT_MSGBOX )
-	,	m_Instdata( instdata )
-	,	m_Title( title )
-	,	m_Content( content )
+	pxMessageBoxEvent( MsgboxEventResult& instdata, const wxString& title, const wxString& content, long flags )
+		: wxEvent( 0, pxEVT_MSGBOX )
+		, m_Instdata( instdata )
+		, m_Title( title )
+		, m_Content( content )
 	{
 		m_Flags = flags;
 	}
 
-	pxMessageBoxEvent( const pxMessageBoxEvent& event ) :
-		wxEvent( event )
-	,	m_Instdata( event.m_Instdata )
-	,	m_Title( event.m_Title )
-	,	m_Content( event.m_Content )
+	pxMessageBoxEvent( const pxMessageBoxEvent& event )
+		: wxEvent( event )
+		, m_Instdata( event.m_Instdata )
+		, m_Title( event.m_Title )
+		, m_Content( event.m_Content )
 	{
 		m_Flags = event.m_Flags;
 	}
diff --git a/pcsx2/gui/ConsoleLogger.h b/pcsx2/gui/ConsoleLogger.h
index 8a1c47874c..7d65b7afbe 100644
--- a/pcsx2/gui/ConsoleLogger.h
+++ b/pcsx2/gui/ConsoleLogger.h
@@ -182,7 +182,7 @@ protected:
 	// Threaded log spammer, useful for testing console logging performance.
 	// (alternatively you can enable Disasm logging in any recompiler and achieve
 	// a similar effect)
-	ConsoleTestThread*		m_threadlogger;
+	ScopedPtr<ConsoleTestThread>	m_threadlogger;
 
 public:
 	// ctor & dtor
diff --git a/pcsx2/gui/IniInterface.cpp b/pcsx2/gui/IniInterface.cpp
index 4fa96df9bd..6ba10bf4d5 100644
--- a/pcsx2/gui/IniInterface.cpp
+++ b/pcsx2/gui/IniInterface.cpp
@@ -270,11 +270,11 @@ void IniSaver::_EnumEntry( const wxString& var, int& value, const wxChar* const*
 
 	if( value >= cnt )
 	{
-		Console.Warning( 
-			L"(SaveSettings) An illegal enumerated index was detected when saving '%s'\n"
-			L"\tIllegal Value: %d\n"
-			L"\tUsing Default: %d (%s)\n",
-			var.c_str(), value, defvalue, enumArray[defvalue]
+		Console.Warning(  L"(SaveSettings) An illegal enumerated index was detected when saving '%s'", var.c_str() );
+		Console.Indent().Warning( 
+			L"Illegal Value: %d\n"
+			L"Using Default: %d (%s)\n",
+			value, defvalue, enumArray[defvalue]
 		);
 
 		// Cause a debug assertion, since this is a fully recoverable error.
diff --git a/pcsx2/gui/i18n.cpp b/pcsx2/gui/i18n.cpp
index 14869f0d36..b30487e32c 100644
--- a/pcsx2/gui/i18n.cpp
+++ b/pcsx2/gui/i18n.cpp
@@ -141,7 +141,7 @@ const wxChar* __fastcall pxGetTranslation( const wxChar* message )
 		if( wxStrlen( message ) > 96 )
 		{
 			Console.Warning( "pxGetTranslation: Long message detected, maybe use pxE() instead?" );
-			Console.WriteLn( Color_Green, L"\tMessage: %s", message );
+			Console.Indent().WriteLn( Color_Green, L"Message: %s", message );
 		}
 	}
 	return wxGetTranslation( message );
@@ -156,15 +156,13 @@ bool i18n_SetLanguage( int wxLangId )
 		return false;
 	}
 
-	wxLocale* locale = new wxLocale( wxLangId, wxLOCALE_CONV_ENCODING );
+	ScopedPtr<wxLocale> locale( new wxLocale( wxLangId, wxLOCALE_CONV_ENCODING ) );
 
 	if( !locale->IsOk() )
 	{
 		Console.Warning( L"SetLanguage: '%s' [%s] is not supported by the operating system",
 			wxLocale::GetLanguageName( locale->GetLanguage() ).c_str(), locale->GetCanonicalName().c_str()
 		);
-
-		safe_delete( locale );
 		return false;
 	}
 
@@ -173,8 +171,9 @@ bool i18n_SetLanguage( int wxLangId )
 		Console.Warning( L"SetLanguage: Cannot find pcsx2main.mo file for language '%s' [%s]",
 			wxLocale::GetLanguageName( locale->GetLanguage() ).c_str(), locale->GetCanonicalName().c_str()
 		);
-		safe_delete( locale );
 		return false;
 	}
+
+	locale.DetachPtr();
 	return true;
 }
diff --git a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj
index 1d93fcf256..4c65355015 100644
--- a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj
+++ b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="windows-1253"?>
 <VisualStudioProject
 	ProjectType="Visual C++"
-	Version="9,00"
+	Version="9.00"
 	Name="pcsx2"
 	ProjectGUID="{1CEFD830-2B76-4596-A4EE-BCD7280A60BD}"
 	RootNamespace="pcsx2"
@@ -55,7 +55,6 @@
 				ExceptionHandling="2"
 				UsePrecompiledHeader="2"
 				PrecompiledHeaderThrough="PrecompiledHeader.h"
-				PrecompiledHeaderFile="$(IntDir)\$(TargetName).pch"
 				CompileAs="2"
 			/>
 			<Tool
@@ -133,7 +132,6 @@
 				ExceptionHandling="2"
 				UsePrecompiledHeader="2"
 				PrecompiledHeaderThrough="PrecompiledHeader.h"
-				PrecompiledHeaderFile="$(IntDir)\$(TargetName).pch"
 				WarningLevel="3"
 				CompileAs="2"
 			/>
@@ -213,7 +211,6 @@
 				EnableEnhancedInstructionSet="0"
 				UsePrecompiledHeader="2"
 				PrecompiledHeaderThrough="PrecompiledHeader.h"
-				PrecompiledHeaderFile="$(IntDir)\$(TargetName).pch"
 				CompileAs="2"
 			/>
 			<Tool
diff --git a/pcsx2/x86/sVU_zerorec.cpp b/pcsx2/x86/sVU_zerorec.cpp
index 9692e2e647..be69b19025 100644
--- a/pcsx2/x86/sVU_zerorec.cpp
+++ b/pcsx2/x86/sVU_zerorec.cpp
@@ -18,7 +18,6 @@
 #include "PrecompiledHeader.h"
 
 #include <float.h>
-#include <vector>
 #include <list>
 #include <map>