Subversion Repositories spk

Rev

Rev 226 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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 ( "XModPatch V1.00 (SPK Library Version %.2f) 01/04/2011 Created by Cycrow\n\n", (float)GetLibraryVersion() );
17
 
196 cycrow 18
	Utils::WString cmd (argv[0]);
19
	Utils::WString dir = CFileIO(cmd).dir();
102 cycrow 20
	cmd = CFileIO(cmd).filename();
1 cycrow 21
 
22
	bool verbose = false;
23
 
24
	if ( argc < 3 )
25
	{
196 cycrow 26
		wprintf ( L"Syntax: %s <modfile.cat> <diff file> [gamedirectory]\n", cmd.c_str() );
27
		wprintf ( L"\t<modfile.cat>:\t\tThe mod file you want to create/add to\n" );
28
		wprintf ( L"\t<diff file>:\t\tThe file to to read from\n" );
29
		wprintf ( L"\t[gamedirectory]:\tThe game directory to compare the mod against, without this will assume current directory\n" );
1 cycrow 30
	}
31
	else
32
	{
33
	// check for switches
34
		int startPos = 1;
35
		for ( startPos = 1; startPos < argc; startPos++ )
36
		{
298 cycrow 37
			Utils::WString checkFlags(argv[startPos]);
38
			if ( !checkFlags.left(1).Compare("-") )
1 cycrow 39
				break;
40
 
298 cycrow 41
			if ( checkFlags.left(2) != "--" ) // not a single long flag (compare each character
1 cycrow 42
			{
298 cycrow 43
				checkFlags.toLower();
44
				for ( unsigned int i = 1; i < checkFlags.length(); i++ )
1 cycrow 45
				{
46
					switch (checkFlags[i])
47
					{
48
						case 'v':
49
							verbose = true;
50
							break;
51
					}
52
				}
53
			}
54
			else if ( checkFlags.Compare("--verbose") )
55
				verbose = true;
56
		}
57
 
226 cycrow 58
		Utils::WString modfile = Utils::WString::FromString(argv[startPos]);
59
		Utils::WString difffile = Utils::WString::FromString(argv[startPos + 1]);
196 cycrow 60
		Utils::WString gamedir;
226 cycrow 61
		if ( argc > 3 ) gamedir = Utils::WString::FromString(argv[startPos + 2]);
213 cycrow 62
		if ( gamedir.empty() ) gamedir = L".";
102 cycrow 63
		gamedir = CFileIO(gamedir).fullFilename();
1 cycrow 64
 
226 cycrow 65
		CModDiff Diff(gamedir, L"addon");
1 cycrow 66
		if ( !Diff.IsLoaded() ) 
67
		{
196 cycrow 68
			wprintf  (L"Error: Unable to load game directory, %s\n", gamedir.c_str());
1 cycrow 69
			Error();
70
		}
71
 
185 cycrow 72
		Diff.ApplyMod(modfile);
1 cycrow 73
 
196 cycrow 74
		wprintf ( L"Game Directory: '%s' loaded\n", gamedir.c_str());
185 cycrow 75
		if ( !Diff.ReadDiff(difffile) )
1 cycrow 76
		{
226 cycrow 77
			wprintf(L"Error: Unable to load diff file, %s\n", difffile.c_str());
1 cycrow 78
			Error();
79
		}
80
 
185 cycrow 81
		if ( !Diff.ApplyDiff(modfile) )
1 cycrow 82
		{
226 cycrow 83
			wprintf(L"Error: Unable to write to mod file, %s\n", modfile.c_str());
1 cycrow 84
			Error();
85
		}
86
 
226 cycrow 87
		wprintf(L"Diff has been applied to mod, %s\n", modfile.c_str());
1 cycrow 88
	}
89
 
90
#ifdef _DEBUG
91
	char pause;
92
	scanf ( "%s", &pause );
93
#endif
94
	return 0;
95
}