Subversion Repositories spk

Rev

Rev 197 | Rev 226 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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