Subversion Repositories spk

Rev

Rev 196 | Rev 218 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include <spk.h>

void Error()
{
#ifdef _DEBUG
        char pause;
        scanf ( "%s", &pause );
#endif
        exit(1);
}
/*
        Main entry point to program
*/
int main ( int argc, char **argv )
{
        printf ( "XModDiff V1.00 (SPK Library Version %.2f) 01/04/2011 Created by Cycrow\n\n", (float)GetLibraryVersion() );

        // parse the cmd name
        Utils::WString cmd (argv[0]);
        Utils::WString dir = CFileIO(cmd).dir();
        cmd = CFileIO(cmd).filename();

        bool verbose = false;

        if ( argc < 3 )
        {
                wprintf ( L"Syntax: %s [-v] <modfile.cat> <diff file> [gamedirectory]\n", cmd.c_str() );
                printf ( "\t<modfile.cat>:\t\tThe mod file you want to generate the diff for\n" );
                printf ( "\t<diff file>:\t\tThe file to save the diff to\n" );
                printf ( "\t[gamedirectory]:\tThe game directory to compare the mod against, without this will assume current directory\n" );
        }
        else
        {
                // check for switches
                int startPos = 1;
                for ( startPos = 1; startPos < argc; startPos++ )
                {
                        CyString checkFlags(argv[startPos]);
                        if ( !checkFlags.Left(1).Compare("-") )
                                break;

                        if ( checkFlags.Left(2) != "--" ) // not a single long flag (compare each character
                        {
                                checkFlags.ToLower();
                                for ( unsigned int i = 1; i < checkFlags.Length(); i++ )
                                {
                                        switch (checkFlags[i])
                                        {
                                                case 'v':
                                                        verbose = true;
                                                        break;
                                        }
                                }
                        }
                        else if ( checkFlags.Compare("--verbose") )
                                verbose = true;
                }

                Utils::String modfile(argv[startPos]);
                Utils::String difffile(argv[startPos + 1]);
                Utils::WString gamedir;
                if ( argc > (startPos + 2) ) gamedir = argv[startPos + 2];
                if ( gamedir.empty() ) gamedir = ".";
                gamedir = CFileIO(gamedir).fullFilename();

                CModDiff Diff(gamedir.toString(), "addon");
                if ( !Diff.IsLoaded() ) 
                {
                        wprintf  (L"Error: Unable to load game directory, %s\n", gamedir.c_str());
                        Error();
                }

                if ( gamedir.Compare(L".") )
                        printf ( "Game Directory: 'CURRENT' loaded\n");
                else
                        wprintf ( L"Game Directory: '%s' loaded\n", gamedir.c_str());

                if ( !Diff.CreateDiff(modfile) )
                {
                        printf("Error: Unable to create diff for mod file, %s (%d)\n", modfile.c_str(), Diff.Error());
                        Error();
                }

                if ( Diff.GetDiffFiles().empty() )
                {
                        printf("No diff entries found\n" );
                        Error();
                }
                printf("Diff generated\n");

                if ( verbose )
                {
                        for ( SDiffFile *d = Diff.GetDiffFiles().First(); d; d = Diff.GetDiffFiles().Next() )
                        {
                                wprintf(L"Changes to File: %s\n", d->sFile.c_str() );
                                for ( SDiffEntry *e = d->m_lEntries.First(); e; e = d->m_lEntries.Next() )
                                {
                                        switch(e->iType)
                                        {
                                                case DIFFTYPE_CHANGE:
                                                        wprintf(L"\tPosition(%d) Entry(%d) %s => %s\n", e->iID, ((SDiffEntryChange *)e)->iPos, ((SDiffEntryChange *)e)->sFrom.c_str(), ((SDiffEntryChange *)e)->sEntry.c_str());
                                                        break;
                                                case DIFFTYPE_ADDITION:
                                                        wprintf(L"\tPosition(%d) Add Entry: ...%s\n", e->iID, ((SDiffEntryAddition *)e)->sEntry.token(L";", -2).c_str());
                                                        break;
                                        }
                                }
                        }
                }

                if ( Diff.WriteDiff(difffile) )
                        printf("Diff file: %s, written\n", difffile.c_str());
                else
                        printf("Error: Unable to write diff file: %s\n", difffile.c_str());
        }

#ifdef _DEBUG
        char pause;
        scanf ( "%s", &pause );
#endif

        return 0;
}