Subversion Repositories spk

Rev

Rev 226 | 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() );

        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 <modfile.cat> <diff file> [gamedirectory]\n", cmd.c_str() );
                wprintf ( L"\t<modfile.cat>:\t\tThe mod file you want to create/add to\n" );
                wprintf ( L"\t<diff file>:\t\tThe file to to read from\n" );
                wprintf ( L"\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++ )
                {
                        Utils::WString 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::WString modfile = Utils::WString::FromString(argv[startPos]);
                Utils::WString difffile = Utils::WString::FromString(argv[startPos + 1]);
                Utils::WString gamedir;
                if ( argc > 3 ) gamedir = Utils::WString::FromString(argv[startPos + 2]);
                if ( gamedir.empty() ) gamedir = L".";
                gamedir = CFileIO(gamedir).fullFilename();

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

                Diff.ApplyMod(modfile);

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

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

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

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