/[pcsx2_0.9.7]/trunk/common/src/Utilities/Exceptions.cpp
ViewVC logotype

Diff of /trunk/common/src/Utilities/Exceptions.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/common/src/Utilities/Exceptions.cpp	2010/12/23 11:48:33	279
+++ trunk/common/src/Utilities/Exceptions.cpp	2010/12/23 12:02:12	280
@@ -23,6 +23,9 @@
 #include <signal.h>
 #endif
 
+// for lack of a better place...
+Fnptr_OutOfMemory pxDoOutOfMemory = NULL;
+
 static wxString GetTranslation( const wxChar* msg )
 {
 	return msg ? wxGetTranslation( msg ) : wxEmptyString;
@@ -68,12 +71,6 @@
 }
 
 
-bool pxAssertImpl_LogIt( const DiagnosticOrigin& origin, const wxChar *msg )
-{
-	wxLogError( L"%s", origin.ToString( msg ).c_str() );
-	return false;
-}
-
 // Because wxTrap isn't available on Linux builds of wxWidgets (non-Debug, typically)
 void pxTrap()
 {
@@ -94,6 +91,16 @@
 #endif // Win/Unix
 }
 
+
+bool pxAssertImpl_LogIt( const DiagnosticOrigin& origin, const wxChar *msg )
+{
+	//wxLogError( L"%s", origin.ToString( msg ).c_str() );
+	wxMessageOutputDebug().Printf( L"%s", origin.ToString( msg ).c_str() );
+	pxTrap();
+	return false;
+}
+
+
 DEVASSERT_INLINE void pxOnAssert( const DiagnosticOrigin& origin, const wxChar* msg )
 {
 	// Recursion guard: Allow at least one recursive call.  This is useful because sometimes
@@ -191,19 +198,69 @@
 Exception::OutOfMemory::OutOfMemory( const wxString& allocdesc )
 {
 	AllocDescription	= allocdesc;
-	m_message_diag		= L"Out of memory exception, while allocating the %s.";
-	m_message_user		= _("Memory allocation failure!  Your system has insufficient memory or resources to meet PCSX2's lofty needs.");
 }
 
 wxString Exception::OutOfMemory::FormatDiagnosticMessage() const
 {
-	return wxsFormat(m_message_diag, AllocDescription.c_str());
+	FastFormatUnicode retmsg;
+	retmsg.Write(L"Out of memory");
+	if (!AllocDescription.IsEmpty())
+		retmsg.Write(L" while allocating '%s'", AllocDescription.c_str());
+
+	if (!m_message_diag.IsEmpty())
+		retmsg.Write(L":\n%s", m_message_diag.c_str());
+	
+	return retmsg;
 }
 
 wxString Exception::OutOfMemory::FormatDisplayMessage() const
 {
-	if (m_message_user.IsEmpty()) return FormatDisplayMessage();
-	return m_message_user + pxsFmt( L"\n\nInternal allocation descriptor: %s", AllocDescription.c_str());
+	FastFormatUnicode retmsg;
+	retmsg.Write( L"%s", _("Oh noes! Out of memory!") );
+
+	if (!m_message_diag.IsEmpty())
+		retmsg.Write(L"\n\n%s", m_message_diag.c_str());
+
+	return retmsg;
+}
+
+
+// --------------------------------------------------------------------------------------
+//  Exception::VirtualMemoryMapConflict   (implementations)
+// --------------------------------------------------------------------------------------
+Exception::VirtualMemoryMapConflict::VirtualMemoryMapConflict( const wxString& allocdesc )
+{
+	AllocDescription	= allocdesc;
+	m_message_user		= _("Virtual memory mapping failure!  Your system may have conflicting device drivers, services, or may simply have insufficient memory or resources to meet PCSX2's lofty needs.");
+}
+
+wxString Exception::VirtualMemoryMapConflict::FormatDiagnosticMessage() const
+{
+	FastFormatUnicode retmsg;
+	retmsg.Write(L"Virtual memory map failed");
+	if (!AllocDescription.IsEmpty())
+		retmsg.Write(L" while reserving '%s'", AllocDescription.c_str());
+
+	if (!m_message_diag.IsEmpty())
+		retmsg.Write(L":\n%s", m_message_diag.c_str());
+		
+	return retmsg;
+}
+
+wxString Exception::VirtualMemoryMapConflict::FormatDisplayMessage() const
+{
+	FastFormatUnicode retmsg;
+	retmsg.Write( L"%s",
+		pxE( "!Notice:VirtualMemoryMap",
+			L"There is not enough virtual memory available, or necessary virtual memory "
+			L"mappings have already been reserved by other processes, services, or DLLs."
+		)
+	);
+
+	if (!m_message_diag.IsEmpty())
+		retmsg.Write(L"\n\n%s", m_message_diag.c_str());
+
+	return retmsg;
 }
 
 
@@ -218,20 +275,120 @@
 	return L"Action canceled: " + m_message_diag;
 }
 
-wxString Exception::Stream::FormatDiagnosticMessage() const
+// --------------------------------------------------------------------------------------
+//  Exception::BadStream  (implementations)
+// --------------------------------------------------------------------------------------
+wxString Exception::BadStream::FormatDiagnosticMessage() const
 {
-	return pxsFmt(
-		L"%s\n\tFile/Object: %s",
-		m_message_diag.c_str(), StreamName.c_str()
-	);
+	FastFormatUnicode retval;
+	_formatDiagMsg(retval);
+	return retval;
+}
+
+wxString Exception::BadStream::FormatDisplayMessage() const
+{
+	FastFormatUnicode retval;
+	_formatUserMsg(retval);
+	return retval;
+}
+
+void  Exception::BadStream::_formatDiagMsg( FastFormatUnicode& dest ) const
+{
+	dest.Write( L"Path: " );
+	if (!StreamName.IsEmpty())
+		dest.Write( L"%s", StreamName.c_str() );
+	else
+		dest.Write( L"[Unnamed or unknown]" );
+
+	if (!m_message_diag.IsEmpty())
+		dest.Write(L"\n%s", m_message_diag.c_str());
 }
 
-wxString Exception::Stream::FormatDisplayMessage() const
+void Exception::BadStream::_formatUserMsg( FastFormatUnicode& dest ) const
 {
-	wxString retval( m_message_user );
+	dest.Write( _("Path: ") );
 	if (!StreamName.IsEmpty())
-		retval += L"\n\n" + pxsFmt( _("Path: %s"), StreamName.c_str() );
+		dest.Write( L"%s", StreamName.c_str() );
+	else
+		dest.Write( _("[Unnamed or unknown]") );
+
+	if (!m_message_user.IsEmpty())
+		dest.Write(L"\n%s", m_message_user.c_str());
+}
+
+// --------------------------------------------------------------------------------------
+//  Exception::CannotCreateStream  (implementations)
+// --------------------------------------------------------------------------------------
+wxString Exception::CannotCreateStream::FormatDiagnosticMessage() const
+{
+	FastFormatUnicode retval;
+	retval.Write("File could not be created.");
+	_formatDiagMsg(retval);
+	return retval;
+}
+
+wxString Exception::CannotCreateStream::FormatDisplayMessage() const
+{
+	FastFormatUnicode retval;
+	retval.Write(_("A file could not be created."));
+	_formatUserMsg(retval);
+	return retval;
+}
+
+// --------------------------------------------------------------------------------------
+//  Exception::FileNotFound  (implementations)
+// --------------------------------------------------------------------------------------
+wxString Exception::FileNotFound::FormatDiagnosticMessage() const
+{
+	FastFormatUnicode retval;
+	retval.Write("File not found.");
+	_formatDiagMsg(retval);
+	return retval;
+}
 
+wxString Exception::FileNotFound::FormatDisplayMessage() const
+{
+	FastFormatUnicode retval;
+	retval.Write(_("File not found."));
+	_formatUserMsg(retval);
+	return retval;
+}
+
+// --------------------------------------------------------------------------------------
+//  Exception::AccessDenied  (implementations)
+// --------------------------------------------------------------------------------------
+wxString Exception::AccessDenied::FormatDiagnosticMessage() const
+{
+	FastFormatUnicode retval;
+	retval.Write("Permission denied to file.");
+	_formatDiagMsg(retval);
+	return retval;
+}
+
+wxString Exception::AccessDenied::FormatDisplayMessage() const
+{
+	FastFormatUnicode retval;
+	retval.Write(_("Permission denied while trying to open file, likely due to insufficient user account rights."));
+	_formatUserMsg(retval);
+	return retval;
+}
+
+// --------------------------------------------------------------------------------------
+//  Exception::EndOfStream  (implementations)
+// --------------------------------------------------------------------------------------
+wxString Exception::EndOfStream::FormatDiagnosticMessage() const
+{
+	FastFormatUnicode retval;
+	retval.Write("Unexpected end of file or stream.");
+	_formatDiagMsg(retval);
+	return retval;
+}
+
+wxString Exception::EndOfStream::FormatDisplayMessage() const
+{
+	FastFormatUnicode retval;
+	retval.Write(_("Unexpected end of file or stream encountered.  File is probably truncated or corrupted."));
+	_formatUserMsg(retval);
 	return retval;
 }
 
@@ -249,7 +406,7 @@
 	{
 		case EINVAL:
 			pxFailDev( L"Invalid argument" );
-			return &(new Exception::Stream( streamname ))->SetDiagMsg(L"Invalid argument? (likely caused by an unforgivable programmer error!)" );
+			return &(new Exception::BadStream( streamname ))->SetDiagMsg(L"Invalid argument? (likely caused by an unforgivable programmer error!)" );
 
 		case EACCES:	// Access denied!
 			return new Exception::AccessDenied( streamname );
@@ -270,6 +427,6 @@
 			return &(new Exception::BadStream( streamname ))->SetDiagMsg(L"Bad file number");
 
 		default:
-			return &(new Exception::Stream( streamname ))->SetDiagMsg(pxsFmt( L"General file/stream error [errno: %d]", errcode ));
+			return &(new Exception::BadStream( streamname ))->SetDiagMsg(pxsFmt( L"General file/stream error [errno: %d]", errcode ));
 	}
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22