* nandChecker: don't use bundle crap on OSx. add color stuff for win32

This commit is contained in:
giantpune 2011-01-20 03:22:30 +00:00
parent b45b4dfd83
commit 14f32c8fd6
2 changed files with 532 additions and 504 deletions

View File

@ -22,7 +22,29 @@ bool tryToKeepGoing = false;
bool color = true;
QByteArray sysMenuResource;
#ifndef Q_WS_WIN
#ifdef Q_WS_WIN
#include <windows.h> // WinApi header
#define C_STICKY 31
#define C_CAP 192
int origColor;
HANDLE hConsole;
int GetColor()
{
WORD wColor = 0;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
//We use csbi for the wAttributes word.
if( GetConsoleScreenBufferInfo(hStdOut, &csbi ) )
{
wColor = csbi.wAttributes;
}
return wColor;
}
#else
#define LEN_STR_PAIR(s) sizeof (s) - 1, s
enum indicator_no
{
@ -71,7 +93,7 @@ static void put_indicator( const struct bin_str *ind )
{
fwrite( ind->string, ind->len, 1, stdout );
}
#endif
void PrintColoredString( const char *msg, int highlite )
{
if( !color )
@ -84,13 +106,21 @@ void PrintColoredString( const char *msg, int highlite )
QString m2 = m.trimmed();
m.resize( m.indexOf( m2 ) );
printf( "%s", m.toLatin1().data() ); //print all leading whitespace
#ifdef Q_WS_WIN
SetConsoleTextAttribute( hConsole, highlite );
#else
put_indicator( &color_indicator[ C_LEFT ] );
put_indicator( &color_indicator[ highlite ] ); //change color
put_indicator( &color_indicator[ C_RIGHT ] );
#endif
printf( "%s", m2.toLatin1().data() ); //print text
#ifdef Q_WS_WIN
SetConsoleTextAttribute( hConsole, origColor );
#else
put_indicator( &color_indicator[ C_LEFT ] );
put_indicator( &color_indicator[ C_NORM ] ); //reset color
put_indicator( &color_indicator[ C_RIGHT ] );
#endif
printf( "\n" );
}
fflush( stdout );
@ -103,7 +133,6 @@ void DebugHandler( QtMsgType type, const char *msg )
{
case QtDebugMsg:
printf( "%s\n", msg );
fflush( stdout );
break;
case QtWarningMsg:
PrintColoredString( msg, C_STICKY );
@ -117,7 +146,6 @@ void DebugHandler( QtMsgType type, const char *msg )
break;
}
}
#endif
bool CheckTitleIntegrity( quint64 tid );
@ -146,10 +174,8 @@ void Usage()
qDebug() << " -v increase verbosity";
qDebug() << "";
qDebug() << " -continue try to keep going as fas as possible on errors that should be fatal";
#ifndef Q_WS_WIN
qDebug() << "";
qDebug() << " -nocolor don\'t use terminal color trickery";
#endif
exit( 1 );
}
@ -1105,9 +1131,11 @@ error:
int main( int argc, char *argv[] )
{
QCoreApplication a( argc, argv );
#ifndef Q_WS_WIN
qInstallMsgHandler( DebugHandler );
#ifdef Q_WS_WIN
origColor = GetColor();
hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
#endif
qInstallMsgHandler( DebugHandler );
args = QCoreApplication::arguments();
if( args.contains( "-nocolor", Qt::CaseInsensitive ) )

View File

@ -8,8 +8,8 @@
# gui
TARGET = nandBinCheck
#CONFIG += console
#CONFIG -= app_bundle
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app