| 1 | cycrow | 1 | #include <spk.h>
 | 
        
           |  |  | 2 |   | 
        
           |  |  | 3 | void Error()
 | 
        
           |  |  | 4 | {
 | 
        
           |  |  | 5 | #ifdef _DEBUG
 | 
        
           |  |  | 6 | 	char pause;
 | 
        
           |  |  | 7 | 	scanf ( "%s", &pause );
 | 
        
           |  |  | 8 | #endif
 | 
        
           |  |  | 9 | 	exit(1);
 | 
        
           |  |  | 10 | }
 | 
        
           |  |  | 11 | /*
 | 
        
           |  |  | 12 | 	Main entry point to program
 | 
        
           |  |  | 13 | */
 | 
        
           |  |  | 14 | int main ( int argc, char **argv )
 | 
        
           |  |  | 15 | {
 | 
        
           |  |  | 16 | 	printf ( "XModDiff V1.00 (SPK Library Version %.2f) 01/04/2011 Created by Cycrow\n\n", (float)GetLibraryVersion() );
 | 
        
           |  |  | 17 |   | 
        
           |  |  | 18 | 	// parse the cmd name
 | 
        
           |  |  | 19 | 	CyString cmd (argv[0]);
 | 
        
           |  |  | 20 | 	CyString dir = CFileIO(cmd).GetDir();
 | 
        
           |  |  | 21 | 	cmd = CFileIO(cmd).GetFilename();
 | 
        
           |  |  | 22 |   | 
        
           |  |  | 23 | 	bool verbose = false;
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 | 	if ( argc < 3 )
 | 
        
           |  |  | 26 | 	{
 | 
        
           |  |  | 27 | 		printf ( "Syntax: %s [-v] <modfile.cat> <diff file> [gamedirectory]\n", cmd.c_str() );
 | 
        
           |  |  | 28 | 		printf ( "\t<modfile.cat>:\t\tThe mod file you want to generate the diff for\n" );
 | 
        
           |  |  | 29 | 		printf ( "\t<diff file>:\t\tThe file to save the diff to\n" );
 | 
        
           |  |  | 30 | 		printf ( "\t[gamedirectory]:\tThe game directory to compare the mod against, without this will assume current directory\n" );
 | 
        
           |  |  | 31 | 	}
 | 
        
           |  |  | 32 | 	else
 | 
        
           |  |  | 33 | 	{
 | 
        
           |  |  | 34 | 		// check for switches
 | 
        
           |  |  | 35 | 		int startPos = 1;
 | 
        
           |  |  | 36 | 		for ( startPos = 1; startPos < argc; startPos++ )
 | 
        
           |  |  | 37 | 		{
 | 
        
           |  |  | 38 | 			CyString checkFlags(argv[startPos]);
 | 
        
           |  |  | 39 | 			if ( !checkFlags.Left(1).Compare("-") )
 | 
        
           |  |  | 40 | 				break;
 | 
        
           |  |  | 41 |   | 
        
           |  |  | 42 | 			if ( checkFlags.Left(2) != "--" ) // not a single long flag (compare each character
 | 
        
           |  |  | 43 | 			{
 | 
        
           |  |  | 44 | 				checkFlags.ToLower();
 | 
        
           |  |  | 45 | 				for ( unsigned int i = 1; i < checkFlags.Length(); i++ )
 | 
        
           |  |  | 46 | 				{
 | 
        
           |  |  | 47 | 					switch (checkFlags[i])
 | 
        
           |  |  | 48 | 					{
 | 
        
           |  |  | 49 | 						case 'v':
 | 
        
           |  |  | 50 | 							verbose = true;
 | 
        
           |  |  | 51 | 							break;
 | 
        
           |  |  | 52 | 					}
 | 
        
           |  |  | 53 | 				}
 | 
        
           |  |  | 54 | 			}
 | 
        
           |  |  | 55 | 			else if ( checkFlags.Compare("--verbose") )
 | 
        
           |  |  | 56 | 				verbose = true;
 | 
        
           |  |  | 57 | 		}
 | 
        
           |  |  | 58 |   | 
        
           |  |  | 59 | 		CyString modfile(argv[startPos]);
 | 
        
           |  |  | 60 | 		CyString difffile(argv[startPos + 1]);
 | 
        
           |  |  | 61 | 		CyString gamedir;
 | 
        
           |  |  | 62 | 		if ( argc > (startPos + 2) ) gamedir = argv[startPos + 2];
 | 
        
           |  |  | 63 | 		if ( gamedir.Empty() ) gamedir = ".";
 | 
        
           |  |  | 64 | 		gamedir = CFileIO(gamedir).GetFullFilename();
 | 
        
           |  |  | 65 |   | 
        
           |  |  | 66 | 		CModDiff Diff(gamedir);
 | 
        
           |  |  | 67 | 		if ( !Diff.IsLoaded() ) 
 | 
        
           |  |  | 68 | 		{
 | 
        
           |  |  | 69 | 			printf  ("Error: Unable to load game directory, %s\n", gamedir.c_str());
 | 
        
           |  |  | 70 | 			Error();
 | 
        
           |  |  | 71 | 		}
 | 
        
           |  |  | 72 |   | 
        
           |  |  | 73 | 		if ( gamedir.Compare(".") )
 | 
        
           |  |  | 74 | 			printf ( "Game Directory: 'CURRENT' loaded\n");
 | 
        
           |  |  | 75 | 		else
 | 
        
           |  |  | 76 | 			printf ( "Game Directory: '%s' loaded\n", gamedir.c_str());
 | 
        
           |  |  | 77 |   | 
        
           |  |  | 78 | 		if ( !Diff.CreateDiff(modfile) )
 | 
        
           |  |  | 79 | 		{
 | 
        
           |  |  | 80 | 			printf("Error: Unable to create diff for mod file, %s (%d)\n", modfile.c_str(), Diff.Error());
 | 
        
           |  |  | 81 | 			Error();
 | 
        
           |  |  | 82 | 		}
 | 
        
           |  |  | 83 |   | 
        
           |  |  | 84 | 		if ( Diff.GetDiffFiles().empty() )
 | 
        
           |  |  | 85 | 		{
 | 
        
           |  |  | 86 | 			printf("No diff entries found\n" );
 | 
        
           |  |  | 87 | 			Error();
 | 
        
           |  |  | 88 | 		}
 | 
        
           |  |  | 89 | 		printf("Diff generated\n");
 | 
        
           |  |  | 90 |   | 
        
           |  |  | 91 | 		if ( verbose )
 | 
        
           |  |  | 92 | 		{
 | 
        
           |  |  | 93 | 			for ( SDiffFile *d = Diff.GetDiffFiles().First(); d; d = Diff.GetDiffFiles().Next() )
 | 
        
           |  |  | 94 | 			{
 | 
        
           |  |  | 95 | 				printf("Changes to File: %s\n", d->sFile.c_str() );
 | 
        
           |  |  | 96 | 				for ( SDiffEntry *e = d->m_lEntries.First(); e; e = d->m_lEntries.Next() )
 | 
        
           |  |  | 97 | 				{
 | 
        
           |  |  | 98 | 					switch(e->iType)
 | 
        
           |  |  | 99 | 					{
 | 
        
           |  |  | 100 | 						case DIFFTYPE_CHANGE:
 | 
        
           |  |  | 101 | 							printf( "\tPosition(%d) Entry(%d) %s => %s\n", e->iID, ((SDiffEntryChange *)e)->iPos, ((SDiffEntryChange *)e)->sFrom.c_str(), ((SDiffEntryChange *)e)->sEntry.c_str());
 | 
        
           |  |  | 102 | 							break;
 | 
        
           |  |  | 103 | 						case DIFFTYPE_ADDITION:
 | 
        
           |  |  | 104 | 							printf( "\tPosition(%d) Add Entry: ...%s\n", e->iID, ((SDiffEntryAddition *)e)->sEntry.GetToken(";", -2).c_str());
 | 
        
           |  |  | 105 | 							break;
 | 
        
           |  |  | 106 | 					}
 | 
        
           |  |  | 107 | 				}
 | 
        
           |  |  | 108 | 			}
 | 
        
           |  |  | 109 | 		}
 | 
        
           |  |  | 110 |   | 
        
           |  |  | 111 | 		if ( Diff.WriteDiff(difffile) )
 | 
        
           |  |  | 112 | 			printf("Diff file: %s, written\n", difffile.c_str());
 | 
        
           |  |  | 113 | 		else
 | 
        
           |  |  | 114 | 			printf("Error: Unable to write diff file: %s\n", difffile.c_str());
 | 
        
           |  |  | 115 | 	}
 | 
        
           |  |  | 116 |   | 
        
           |  |  | 117 | #ifdef _DEBUG
 | 
        
           |  |  | 118 | 	char pause;
 | 
        
           |  |  | 119 | 	scanf ( "%s", &pause );
 | 
        
           |  |  | 120 | #endif
 | 
        
           |  |  | 121 |   | 
        
           |  |  | 122 | 	return 0;
 | 
        
           |  |  | 123 | }
 |