libpsxsave/qt-test-cli/main.cpp
2010-08-10 09:40:01 -04:00

97 lines
3.3 KiB
C++

#include <iostream>
#include <fstream>
#include <string>
#include <QtGui>
#include <map>
using namespace std;
#include "memcard.h"
char* decode_sjis( char* sjis ) {
QTextCodec *codec = QTextCodec::codecForName("Shift-JIS");
if( codec == 0 ) { return "Shift-JIS Not Supported"; }
QString unicode = codec->toUnicode( sjis );
return unicode.toUtf8().data();
}
int main( int argc, char * argv[] )
{
QCoreApplication app( argc, argv );
char* filename;
char buffer[256];
string name;
string code;
map<string, string> games;
if( argc > 1 ) {
filename = argv[1];
} else {
cout << "No filename provided, exiting.\n";
return 1;
}
fstream db;
db.open( "db", ios::in );
while( !db.eof() ) {
db.getline( buffer, 256 );
code = buffer;
int offset = code.find( ";" );
if( offset > 0 ) {
name = code.substr( offset + 1 );
code = code.substr( 0, offset );
games[code] = name;
}
}
db.close();
MemoryCard *memCard = new MemoryCard();
memCard->loadFile( filename );
if( argc > 2 ) {
for( int i = 2; i < argc; i++ ) {
cout << "Loading MCS (" << argv[i] << ")\n";
memCard->loadMCS( argv[i] );
}
}
DirectoryBlock *directory = (DirectoryBlock*)memCard->getBlock( 0 );
cout << "Loaded " << games.size() << " unique entries from the game database.\n";
cout << "================================================================================\n";
cout << "Initial block\n";
cout << "================================================================================\n";
cout << "ID Frame\n";
cout << "--------------------------------------------------------------------------------\n";
printf( "ID: %s\n", directory->IDFrame()->id() );
printf( "XOR Valid: %s\n", directory->IDFrame()->getXOR() ? "Yes" : "No" );
printf( "Block Valid: %s\n", directory->IDFrame()->isValid() ? "Yes" : "No" );
for( int i = 1; i < 16; i++ ) {
cout << "================================================================================\n";
cout << "Block " << i << "\n";
cout << "================================================================================\n";
SaveHeaderFrame *h = ( ( (InitialBlock*)memCard->getBlock( i ) )->Header() );
DirectoryFrame *dir = directory->Directory( i - 1 );
string code = dir->licenseCode();
if( code.size() > 5 ) { code.replace( 4, 1, "-" ); }
printf( "Type: %d\n", dir->blockType() );
printf( "Size: %d\n", dir->size() );
printf( "Next Block: %d\n", dir->nextBlock() );
printf( "Territory: %s\n", dir->territoryCode() );
printf( "License: %s (%s)\n", dir->licenseCode(), games[code].c_str() );
printf( "Save: %s\n", dir->saveCode() );
printf( "XOR Valid: %s\n", dir->getXOR() ? "Yes" : "No" );
switch( dir->blockType() ) {
case 81:
cout << "--------------------------------------------------------------------------------\n";
printf( "Magic Number: %s\n", h->magicNumber() );
printf( "Icon Display Type: %d\n", h->iconDisplayType() );
printf( "Blocks Used: %d\n", h->blocksUsed() );
printf( "SJIS Save Title: %s\n", decode_sjis( h->SJISSaveTitle() ) );
break;
}
}
cout << "\n\nNext Open Block: " << directory->nextOpenBlock() << "\n";
memCard->saveFile( "test.mcr" );
memCard->saveBlockToFile( "test.mcs", 4 );
( (InitialBlock*)memCard->getBlock( 4 ) )->getIcon( 0 )->exportXPM( "test.xpm" );
return 0;
}