Subversion Repositories spk

Rev

Rev 102 | 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 ( "XModPatch V1.00 (SPK Library Version %.2f) 01/04/2011 Created by Cycrow\n\n", (float)GetLibraryVersion() );

        CyString cmd (argv[0]);
        CyString dir = CFileIO(cmd).GetDir();
        cmd = CFileIO(cmd).GetFilename();

        bool verbose = false;

        if ( argc < 3 )
        {
                printf ( "Syntax: %s <modfile.cat> <diff file> [gamedirectory]\n", cmd.c_str() );
                printf ( "\t<modfile.cat>:\t\tThe mod file you want to create/add to\n" );
                printf ( "\t<diff file>:\t\tThe file to to read from\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;
                }

                CyString modfile(argv[startPos]);
                CyString difffile(argv[startPos + 1]);
                CyString gamedir;
                if ( argc > 3 ) gamedir = argv[startPos + 2];
                if ( gamedir.Empty() ) gamedir = ".";
                gamedir = CFileIO(gamedir).GetFullFilename();

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

                Diff.ApplyMod(modfile);

                printf ( "Game Directory: '%s' loaded\n", gamedir.c_str());
                if ( !Diff.ReadDiff(difffile) )
                {
                        printf ("Error: Unable to load diff file, %s\n", difffile.c_str());
                        Error();
                }

                if ( !Diff.ApplyDiff(modfile) )
                {
                        printf ("Error: Unable to write to mod file, %s\n", modfile.c_str());
                        Error();
                }

                printf("Diff has been applied to mod, %s\n", modfile.c_str());
        }

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