* 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; bool color = true;
QByteArray sysMenuResource; 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 #define LEN_STR_PAIR(s) sizeof (s) - 1, s
enum indicator_no enum indicator_no
{ {
@ -71,7 +93,7 @@ static void put_indicator( const struct bin_str *ind )
{ {
fwrite( ind->string, ind->len, 1, stdout ); fwrite( ind->string, ind->len, 1, stdout );
} }
#endif
void PrintColoredString( const char *msg, int highlite ) void PrintColoredString( const char *msg, int highlite )
{ {
if( !color ) if( !color )
@ -84,13 +106,21 @@ void PrintColoredString( const char *msg, int highlite )
QString m2 = m.trimmed(); QString m2 = m.trimmed();
m.resize( m.indexOf( m2 ) ); m.resize( m.indexOf( m2 ) );
printf( "%s", m.toLatin1().data() ); //print all leading whitespace 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[ C_LEFT ] );
put_indicator( &color_indicator[ highlite ] ); //change color put_indicator( &color_indicator[ highlite ] ); //change color
put_indicator( &color_indicator[ C_RIGHT ] ); put_indicator( &color_indicator[ C_RIGHT ] );
#endif
printf( "%s", m2.toLatin1().data() ); //print text 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_LEFT ] );
put_indicator( &color_indicator[ C_NORM ] ); //reset color put_indicator( &color_indicator[ C_NORM ] ); //reset color
put_indicator( &color_indicator[ C_RIGHT ] ); put_indicator( &color_indicator[ C_RIGHT ] );
#endif
printf( "\n" ); printf( "\n" );
} }
fflush( stdout ); fflush( stdout );
@ -103,7 +133,6 @@ void DebugHandler( QtMsgType type, const char *msg )
{ {
case QtDebugMsg: case QtDebugMsg:
printf( "%s\n", msg ); printf( "%s\n", msg );
fflush( stdout );
break; break;
case QtWarningMsg: case QtWarningMsg:
PrintColoredString( msg, C_STICKY ); PrintColoredString( msg, C_STICKY );
@ -117,7 +146,6 @@ void DebugHandler( QtMsgType type, const char *msg )
break; break;
} }
} }
#endif
bool CheckTitleIntegrity( quint64 tid ); bool CheckTitleIntegrity( quint64 tid );
@ -146,10 +174,8 @@ void Usage()
qDebug() << " -v increase verbosity"; qDebug() << " -v increase verbosity";
qDebug() << ""; qDebug() << "";
qDebug() << " -continue try to keep going as fas as possible on errors that should be fatal"; qDebug() << " -continue try to keep going as fas as possible on errors that should be fatal";
#ifndef Q_WS_WIN
qDebug() << ""; qDebug() << "";
qDebug() << " -nocolor don\'t use terminal color trickery"; qDebug() << " -nocolor don\'t use terminal color trickery";
#endif
exit( 1 ); exit( 1 );
} }
@ -295,8 +321,8 @@ QTreeWidgetItem *ItemFromPath( const QString &path )
item = FindItem( lookingFor, item ); item = FindItem( lookingFor, item );
if( !item ) if( !item )
{ {
// if( verbose ) // if( verbose )
// qWarning() << "ItemFromPath ->item not found" << path; // qWarning() << "ItemFromPath ->item not found" << path;
return NULL; return NULL;
} }
slash = nextSlash + 1; slash = nextSlash + 1;
@ -1093,7 +1119,7 @@ void CheckSettingTxt()
qDebug() << qPrintable( str ); qDebug() << qPrintable( str );
} }
return; return;
error: error:
qCritical() << "Something is wrong with this setting.txt"; qCritical() << "Something is wrong with this setting.txt";
if( !shownSetting ) if( !shownSetting )
{ {
@ -1105,9 +1131,11 @@ error:
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
QCoreApplication a( argc, argv ); QCoreApplication a( argc, argv );
#ifndef Q_WS_WIN #ifdef Q_WS_WIN
qInstallMsgHandler( DebugHandler ); origColor = GetColor();
hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
#endif #endif
qInstallMsgHandler( DebugHandler );
args = QCoreApplication::arguments(); args = QCoreApplication::arguments();
if( args.contains( "-nocolor", Qt::CaseInsensitive ) ) if( args.contains( "-nocolor", Qt::CaseInsensitive ) )

View File

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