| 1 | cycrow | 1 | /*
 | 
        
           |  |  | 2 |  SPKTool V1.00 Created by Cycrow (Matthew Gravestock)
 | 
        
           |  |  | 3 | */
 | 
        
           |  |  | 4 |   | 
        
           |  |  | 5 | // Main Spk File Library Include
 | 
        
           |  |  | 6 | #ifdef _WIN32
 | 
        
           |  |  | 7 | #include <spk.h>
 | 
        
           |  |  | 8 | #include <MultiSpkFile.h>
 | 
        
           |  |  | 9 | #include <spkcmdprogress.h>
 | 
        
           |  |  | 10 | #else
 | 
        
           |  |  | 11 | #include "../spk/spk.h"
 | 
        
           |  |  | 12 | #include "../spk/MultiSpkFile.h"
 | 
        
           |  |  | 13 | #include "../spk/spkcmdprogress.h"
 | 
        
           |  |  | 14 | #endif
 | 
        
           |  |  | 15 | // Multi Spk File format, required if using Multi Spk files
 | 
        
           |  |  | 16 | // Displays 7Zip compression progress to the command line
 | 
        
           |  |  | 17 | #include <time.h>
 | 
        
           |  |  | 18 | #ifdef _WIN32
 | 
        
           |  |  | 19 | #include <windows.h>
 | 
        
           |  |  | 20 | #include <direct.h>
 | 
        
           |  |  | 21 | #include <shlobj.h>
 | 
        
           |  |  | 22 | #endif
 | 
        
           |  |  | 23 |   | 
        
           | 197 | cycrow | 24 | Utils::WString g_dir;
 | 
        
           | 1 | cycrow | 25 | bool g_read;
 | 
        
           |  |  | 26 |   | 
        
           | 134 | cycrow | 27 | class CFileProgress : public CProgressInfo
 | 
        
           |  |  | 28 | {
 | 
        
           |  |  | 29 | private:
 | 
        
           |  |  | 30 | 	Utils::String _display;
 | 
        
           |  |  | 31 | 	CBaseFile *_package;
 | 
        
           |  |  | 32 | 	CPackages *_packages;
 | 
        
           |  |  | 33 |   | 
        
           |  |  | 34 | public:
 | 
        
           |  |  | 35 | 	CFileProgress(CPackages *packages, CBaseFile *package, const Utils::String &display) : 
 | 
        
           |  |  | 36 | 		_display(display),
 | 
        
           |  |  | 37 | 		_packages(packages),
 | 
        
           |  |  | 38 | 		_package(package)
 | 
        
           |  |  | 39 | 	{
 | 
        
           |  |  | 40 |   | 
        
           |  |  | 41 | 	}
 | 
        
           |  |  | 42 |   | 
        
           |  |  | 43 | protected:
 | 
        
           |  |  | 44 | 	void ProgressUpdated(const long cur, const long max)
 | 
        
           |  |  | 45 | 	{
 | 
        
           |  |  | 46 | 	}
 | 
        
           |  |  | 47 | 	void DoingFile(C_File *file)
 | 
        
           |  |  | 48 | 	{
 | 
        
           | 197 | cycrow | 49 | 		Utils::WString game;
 | 
        
           | 134 | cycrow | 50 |   | 
        
           |  |  | 51 | 		if (!file->game() || file->game() == GAME_ALLNEW)
 | 
        
           | 197 | cycrow | 52 | 			game = L"All Games";
 | 
        
           | 134 | cycrow | 53 | 		else if (_packages)
 | 
        
           |  |  | 54 | 		{
 | 
        
           |  |  | 55 | 			for (unsigned int i = 0; i < 31; ++i)
 | 
        
           |  |  | 56 | 			{
 | 
        
           |  |  | 57 | 				if (file->game() & (1 << i))
 | 
        
           |  |  | 58 | 				{
 | 
        
           | 197 | cycrow | 59 | 					Utils::WString g = _packages->GetGameExe()->gameNameFromType(i - 1);
 | 
        
           | 134 | cycrow | 60 | 					if (!g.empty())
 | 
        
           |  |  | 61 | 					{
 | 
        
           |  |  | 62 | 						if (game.empty())
 | 
        
           |  |  | 63 | 							game = g;
 | 
        
           |  |  | 64 | 						else
 | 
        
           | 197 | cycrow | 65 | 							game = game + L", " + g;
 | 
        
           | 134 | cycrow | 66 | 					}
 | 
        
           |  |  | 67 | 				}
 | 
        
           |  |  | 68 | 			}
 | 
        
           |  |  | 69 | 		}
 | 
        
           |  |  | 70 |   | 
        
           |  |  | 71 | 		if(game.empty())
 | 
        
           | 197 | cycrow | 72 | 			wprintf(L"%hs: %s\n", _display.c_str(), file->getNameDirectory(_package).c_str());
 | 
        
           | 134 | cycrow | 73 | 		else
 | 
        
           | 197 | cycrow | 74 | 			wprintf(L"%hs: %s [%s]\n", _display.c_str(), file->getNameDirectory(_package).c_str(), game.c_str());
 | 
        
           | 134 | cycrow | 75 | 	}
 | 
        
           |  |  | 76 |   | 
        
           |  |  | 77 | };
 | 
        
           |  |  | 78 |   | 
        
           | 1 | cycrow | 79 | /*
 | 
        
           |  |  | 80 | 	Func:	GetInput
 | 
        
           |  |  | 81 | 	Desc:	Gets an input from the user, ie, any settings required to be typed in
 | 
        
           |  |  | 82 | */
 | 
        
           | 197 | cycrow | 83 | Utils::WString GetInput ()
 | 
        
           | 1 | cycrow | 84 | {
 | 
        
           |  |  | 85 | 	g_read = true;
 | 
        
           |  |  | 86 |   | 
        
           | 127 | cycrow | 87 | 	Utils::String line;
 | 
        
           | 1 | cycrow | 88 | 	char c = getchar();
 | 
        
           |  |  | 89 |   | 
        
           |  |  | 90 | 	while ( (c != '\n') && (c != '\0') )
 | 
        
           |  |  | 91 | 	{
 | 
        
           |  |  | 92 | 		line += c;
 | 
        
           |  |  | 93 | 		c = getchar();
 | 
        
           |  |  | 94 | 	}
 | 
        
           |  |  | 95 |   | 
        
           | 197 | cycrow | 96 | 	return line.toWString();
 | 
        
           | 1 | cycrow | 97 | }
 | 
        
           |  |  | 98 |   | 
        
           |  |  | 99 |   | 
        
           |  |  | 100 | /*
 | 
        
           |  |  | 101 | 	Func:	PrintSyntax
 | 
        
           |  |  | 102 | 	Args:	String cmd - The command name to be displayed
 | 
        
           |  |  | 103 | 	Desc:	Displays the syntax for the program
 | 
        
           |  |  | 104 | */
 | 
        
           |  |  | 105 | void PrintSyntax ( CyString cmd )
 | 
        
           |  |  | 106 | {
 | 
        
           |  |  | 107 | 	printf ( "Syntax: %s <command>\n", cmd.c_str() );
 | 
        
           |  |  | 108 | 	printf ( "Commands:\n" );
 | 
        
           | 134 | cycrow | 109 | 	printf ( "\t-v <spkfile>\n\t--view <spkfile>\n\t\tViews the contents of a spk file\n\n" );
 | 
        
           | 1 | cycrow | 110 | 	printf ( "\t-e <spkfile> [destination]\n\t--extractall <spkfile> [destination]\n\t\tExtracts all the files to the destination directory [or current if no destiantion is set]\n\n" );
 | 
        
           |  |  | 111 | 	printf ( "\t-x <spkfile> <type> <file> [destination]\n\t--extract <spkfile> <type> <file> [destination]\n\t\tExtracts a single file of <type> to destination directory\n\n" );
 | 
        
           |  |  | 112 | 	printf ( "\t-x <multispkfile> <file> [destination]\n\t--extractspk <multispkfile> <spkfile> [destination]\n\t\tExtracts a single spk file from a Multi-Spk Package\n\n" );
 | 
        
           |  |  | 113 | 	printf ( "\t-c <spkfile>\n\t--create\n\t\tCreates a new spk file\n\n" );
 | 
        
           |  |  | 114 | 	printf ( "\t-a <spkfile> <type> <filename>\n\t--append <spkfile> <type> <filename>\n\t\tAppends a file to the package of set <type>\n\n" );
 | 
        
           |  |  | 115 | 	printf ( "\t-r <spkfile> <type> <filename>\n\t--remove <spkfile> <type> <filename>\n\t\tRemoves a file from the package of set <type>\n\n" );
 | 
        
           |  |  | 116 | 	printf ( "\t-r <multispkfile> <filename>\n\t--removespk <multispkfile> <filename>\n\t\tRemoves a spk file from the Multi-SPK package\n\n" );
 | 
        
           |  |  | 117 | 	printf ( "\t-m <spkfile> <spkfile>\n\t--mergemulti <spkfile> <spkfile>\n\t\tMerges spk files together, the second file will be merged into the first\n\n" );
 | 
        
           |  |  | 118 | 	printf ( "\t-n <multispkfile>\n\t--createmulti\n\t\tCreates a multi spk file, and adds the spkfiles in\n\n" );
 | 
        
           |  |  | 119 | 	printf ( "\t-s <multispkfile> [destination]\n\t--splitmulti <multispkfile> [destination]\n\t\tSplits a Multi-SPK file up, saves all the spk files to Destination\n\n" );
 | 
        
           |  |  | 120 | 	printf ( "\t--set <setting> [value]\n\t\tChanges the settings of the script\n\n" );
 | 
        
           |  |  | 121 | 	printf ( "\t--convertxsp <oldxsp> [newxsp]\n\t\tConverts an old XSP file into the new format\n\n");
 | 
        
           |  |  | 122 | 	printf ( "\t--createscript <packagescript>\n\t\tCreates a spk file from a packager script\n\n");
 | 
        
           |  |  | 123 | 	printf ( "\t--verifyscript <packagescript>\n\t\tChecks a packager script is valid without creating the resulting file\n\n");
 | 
        
           |  |  | 124 | 	printf ( "\t--generatescript <package> [packagescript]\n\t\tCreates a packager script (.sps) from a spk file\n\n");
 | 
        
           |  |  | 125 | 	printf ( "\t--extractship <modfile> <xspfile> [shipid]\n\t\tCreates an XSP ship file from a mod package\n\n");
 | 
        
           |  |  | 126 | 	printf ( "\t--generateupdatefile <package>\n\t\tCreates an update file for the spk/xsp file\n\n");
 | 
        
           | 126 | cycrow | 127 | 	printf ( "\t--packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n\n");
 | 
        
           |  |  | 128 | 	//	printf ( "\t--convertxspwizard <oldxsp> [newxsp]\n\t\tConverts an old XSP file into the new format\n\n");
 | 
        
           | 1 | cycrow | 129 | }
 | 
        
           |  |  | 130 |   | 
        
           |  |  | 131 | void Settings(CyString filename, CyString settings, int argc, char **argv, CyString cmd)
 | 
        
           |  |  | 132 | {
 | 
        
           |  |  | 133 | 	if ( settings.Compare("author") )
 | 
        
           |  |  | 134 | 	{
 | 
        
           |  |  | 135 | 		if ( argc < 5 )
 | 
        
           |  |  | 136 | 		{
 | 
        
           |  |  | 137 | 			printf ( "Syntax: %s -set <spkfile> Author <authorname>\n\tSets the authors name of the package\n", cmd.c_str() );
 | 
        
           |  |  | 138 | 			return;
 | 
        
           |  |  | 139 | 		}
 | 
        
           |  |  | 140 | 	}
 | 
        
           |  |  | 141 | 	else
 | 
        
           |  |  | 142 | 	{
 | 
        
           |  |  | 143 | 		printf("Error! Unknown settings: %s\n", settings.c_str());
 | 
        
           |  |  | 144 | 		return;
 | 
        
           |  |  | 145 | 	}
 | 
        
           |  |  | 146 |   | 
        
           |  |  | 147 | 	// first chekc if file even exists
 | 
        
           |  |  | 148 | 	FILE *id = fopen ( filename.c_str(), "rb+" );
 | 
        
           |  |  | 149 | 	if ( !id )
 | 
        
           |  |  | 150 | 	{
 | 
        
           |  |  | 151 | 		printf ( "Error: File, %s, doesn't exist\n", filename.c_str() );
 | 
        
           |  |  | 152 | 		return;
 | 
        
           |  |  | 153 | 	}
 | 
        
           |  |  | 154 | 	fclose ( id );
 | 
        
           |  |  | 155 |   | 
        
           | 175 | cycrow | 156 | 	int check = CSpkFile::CheckFile(filename.ToString());
 | 
        
           | 1 | cycrow | 157 | 	if ( check == SPKFILE_SINGLE )
 | 
        
           |  |  | 158 | 	{
 | 
        
           |  |  | 159 | 		CSpkFile spkfile;
 | 
        
           |  |  | 160 | 		printf ( "* Opening SPK File, %s...\n", filename.c_str() );
 | 
        
           | 175 | cycrow | 161 | 		if ( !spkfile.readFile(filename.ToString(), SPKREAD_ALL))
 | 
        
           | 1 | cycrow | 162 | 		{
 | 
        
           |  |  | 163 | 			printf ( "Failed to open the spk files, %s\n", filename.c_str() );
 | 
        
           |  |  | 164 | 			return;
 | 
        
           |  |  | 165 | 		}
 | 
        
           |  |  | 166 |   | 
        
           |  |  | 167 | 		// now do the settings
 | 
        
           |  |  | 168 | 		if ( settings.Compare("author") )
 | 
        
           |  |  | 169 | 		{
 | 
        
           | 50 | cycrow | 170 | 			spkfile.setAuthor(argv[4]);
 | 
        
           | 203 | cycrow | 171 | 			wprintf(L"Settings Author to: %s\n", spkfile.author().c_str());
 | 
        
           | 1 | cycrow | 172 | 		}
 | 
        
           |  |  | 173 |   | 
        
           | 175 | cycrow | 174 | 		spkfile.writeFile(filename.ToString());
 | 
        
           | 1 | cycrow | 175 | 		printf ( "\nSPK file has been written sucessfully\n" );
 | 
        
           |  |  | 176 | 	}
 | 
        
           |  |  | 177 | 	else
 | 
        
           |  |  | 178 | 		printf ( "File, %s, is not a valid SPK file\n", filename.c_str() );
 | 
        
           |  |  | 179 | }
 | 
        
           |  |  | 180 |   | 
        
           |  |  | 181 | void SetRating ( CyString filename, int ease, int changing, int rec )
 | 
        
           |  |  | 182 | {
 | 
        
           |  |  | 183 | 	if ( ease > 5 )
 | 
        
           |  |  | 184 | 		ease = 5;
 | 
        
           |  |  | 185 | 	if ( changing > 5 )
 | 
        
           |  |  | 186 | 		changing = 5;
 | 
        
           |  |  | 187 | 	if ( changing > 5 )
 | 
        
           |  |  | 188 | 		changing = 5;
 | 
        
           |  |  | 189 |   | 
        
           |  |  | 190 | 	FILE *id = fopen ( filename.c_str(), "rb+" );
 | 
        
           |  |  | 191 | 	if ( !id )
 | 
        
           |  |  | 192 | 	{
 | 
        
           |  |  | 193 | 		printf ( "Error: File, %s, doesn't exist\n", filename.c_str() );
 | 
        
           |  |  | 194 | 		return;
 | 
        
           |  |  | 195 | 	}
 | 
        
           |  |  | 196 | 	fclose ( id );
 | 
        
           |  |  | 197 |   | 
        
           | 175 | cycrow | 198 | 	int check = CSpkFile::CheckFile(filename.ToString());
 | 
        
           | 1 | cycrow | 199 | 	if ( check == SPKFILE_SINGLE )
 | 
        
           |  |  | 200 | 	{
 | 
        
           |  |  | 201 | 		CSpkFile spkfile;
 | 
        
           |  |  | 202 | 		printf ( "* Opening SPK File, %s...\n", filename.c_str() );
 | 
        
           | 175 | cycrow | 203 | 		if ( !spkfile.readFile(filename.ToString(), SPKREAD_ALL))
 | 
        
           | 1 | cycrow | 204 | 		{
 | 
        
           |  |  | 205 | 			printf ( "Failed to open the spk files, %s\n", filename.c_str() );
 | 
        
           |  |  | 206 | 			return;
 | 
        
           |  |  | 207 | 		}
 | 
        
           |  |  | 208 |   | 
        
           | 170 | cycrow | 209 | 		printf("File Format Version: %.2f\n", spkfile.fileVersion());
 | 
        
           | 1 | cycrow | 210 |   | 
        
           |  |  | 211 | 		printf ( "Assigning Ease Of Use:\t\t%d\nAssigning Game Changing:\t%d\nAssigning Recommended:\t\t%d\n", ease, changing, rec);
 | 
        
           | 46 | cycrow | 212 | 		spkfile.setEaseOfUse(ease);
 | 
        
           |  |  | 213 | 		spkfile.setGameChanging(changing);
 | 
        
           |  |  | 214 | 		spkfile.setRecommended(rec);
 | 
        
           | 175 | cycrow | 215 | 		spkfile.writeFile(filename.ToString());
 | 
        
           | 1 | cycrow | 216 | 		printf ( "\nSPK file has been written sucessfully\n" );
 | 
        
           |  |  | 217 |   | 
        
           |  |  | 218 | 	}
 | 
        
           |  |  | 219 | 	else
 | 
        
           |  |  | 220 | 		printf ( "File, %s, is not a valid SPK file\n", filename.c_str() );
 | 
        
           |  |  | 221 | }
 | 
        
           |  |  | 222 |   | 
        
           | 197 | cycrow | 223 | Utils::WString GetTerranConflictDir()
 | 
        
           | 1 | cycrow | 224 | {
 | 
        
           |  |  | 225 | 	while ( true )
 | 
        
           |  |  | 226 | 	{
 | 
        
           |  |  | 227 | 		printf ( "\nPlease enter the directory for terran conflict: ");
 | 
        
           | 197 | cycrow | 228 | 		Utils::WString dir = GetInput();
 | 
        
           | 185 | cycrow | 229 | 		if ( dir.empty() )
 | 
        
           | 197 | cycrow | 230 | 			return Utils::WString::Null();
 | 
        
           | 1 | cycrow | 231 |   | 
        
           |  |  | 232 | 		// check if the directory exists
 | 
        
           | 197 | cycrow | 233 | 		if ( CFileIO::Exists(dir + L"/x3tc.exe") )
 | 
        
           | 1 | cycrow | 234 | 			return dir;
 | 
        
           | 197 | cycrow | 235 | 		wprintf(L"\nTerran Conflict installation doesn't exist: %s\n\n", dir.c_str());
 | 
        
           | 1 | cycrow | 236 | 	}
 | 
        
           |  |  | 237 |   | 
        
           | 197 | cycrow | 238 | 	return Utils::WString::Null();
 | 
        
           | 1 | cycrow | 239 | }
 | 
        
           |  |  | 240 |   | 
        
           | 218 | cycrow | 241 | void ConvertXsp(const Utils::WString &filename, const Utils::String &tofile, bool wizard)
 | 
        
           | 1 | cycrow | 242 | {
 | 
        
           |  |  | 243 | 	// first chekc if file even exists
 | 
        
           | 218 | cycrow | 244 | 	FILE *id = _wfopen (filename.c_str(), L"rb+" );
 | 
        
           | 1 | cycrow | 245 | 	if ( !id )
 | 
        
           |  |  | 246 | 	{
 | 
        
           | 218 | cycrow | 247 | 		wprintf(L"Error: File, %s, doesn't exist\n", filename.c_str() );
 | 
        
           | 1 | cycrow | 248 | 		return;
 | 
        
           |  |  | 249 | 	}
 | 
        
           |  |  | 250 | 	fclose ( id );
 | 
        
           |  |  | 251 |   | 
        
           |  |  | 252 | 	// check its not a new format already
 | 
        
           | 185 | cycrow | 253 | 	int check = CSpkFile::CheckFile(filename);
 | 
        
           | 196 | cycrow | 254 | 	if ( check == SPKFILE_INVALID && CFileIO(filename).isFileExtension(L"xsp") )
 | 
        
           | 1 | cycrow | 255 | 	{
 | 
        
           | 218 | cycrow | 256 | 		wprintf(L"* Converting XSP File, %s... ", filename.c_str() );
 | 
        
           | 1 | cycrow | 257 | 		CXspFile xspFile;
 | 
        
           | 218 | cycrow | 258 | 		if ( !xspFile.convertOld(filename) )
 | 
        
           | 1 | cycrow | 259 | 		{
 | 
        
           | 218 | cycrow | 260 | 			wprintf(L"[ERROR]\n\nFailed to convert old xsp file, %s\n", filename.c_str() );
 | 
        
           | 1 | cycrow | 261 | 			return;
 | 
        
           |  |  | 262 | 		}
 | 
        
           |  |  | 263 |   | 
        
           |  |  | 264 | 		printf ( "[DONE]\n");
 | 
        
           |  |  | 265 |   | 
        
           | 197 | cycrow | 266 | 		Utils::WString dir;
 | 
        
           | 1 | cycrow | 267 | 		printf ("Do you want to create weapon masks for Terran conflict? ");
 | 
        
           | 197 | cycrow | 268 | 		Utils::WString input = GetInput();
 | 
        
           |  |  | 269 | 		if ( input.Compare(L"y") || input.Compare(L"yes") )
 | 
        
           | 1 | cycrow | 270 | 		{
 | 
        
           |  |  | 271 | 			dir = GetTerranConflictDir();
 | 
        
           | 197 | cycrow | 272 | 			if (!dir.empty())
 | 
        
           | 1 | cycrow | 273 | 			{
 | 
        
           |  |  | 274 | 			}
 | 
        
           |  |  | 275 | 		}
 | 
        
           |  |  | 276 |   | 
        
           |  |  | 277 | 		printf ( "* Writing XSP File, %s... ", tofile.c_str() );
 | 
        
           |  |  | 278 | 		// now we need to save it
 | 
        
           | 185 | cycrow | 279 | 		if ( !xspFile.writeFile(tofile) )
 | 
        
           | 1 | cycrow | 280 | 			printf ( "[ERROR]\n\nFailed to write file to, %s\n", tofile.c_str() );
 | 
        
           |  |  | 281 | 		else
 | 
        
           | 218 | cycrow | 282 | 			wprintf(L"[DONE]\n\nFile: %s, has been converted to, %hs\n", filename.c_str(), tofile.c_str() );
 | 
        
           | 1 | cycrow | 283 | 	}
 | 
        
           |  |  | 284 | 	else
 | 
        
           | 218 | cycrow | 285 | 		wprintf(L"Error: File, %s, is not an old style XSP file\n", filename.c_str() );
 | 
        
           | 1 | cycrow | 286 | }
 | 
        
           |  |  | 287 |   | 
        
           | 197 | cycrow | 288 | void ExtractShip(const Utils::String &catfile, const Utils::String &to, Utils::WString shipid)
 | 
        
           | 1 | cycrow | 289 | {
 | 
        
           | 185 | cycrow | 290 | 	if ( !CFileIO::Exists(catfile) )
 | 
        
           | 1 | cycrow | 291 | 	{
 | 
        
           |  |  | 292 | 		printf ( "Error: Mod File, %s, does not exist\n", catfile.c_str() );
 | 
        
           |  |  | 293 | 		return;
 | 
        
           |  |  | 294 | 	}
 | 
        
           |  |  | 295 |   | 
        
           | 36 | cycrow | 296 | 	CVirtualFileSystem *pVfs = new CVirtualFileSystem();
 | 
        
           | 185 | cycrow | 297 | 	if ( !pVfs->loadMod(catfile) ) {
 | 
        
           | 1 | cycrow | 298 | 		printf("Error: Unable to read mod file, %s\n", catfile.c_str());
 | 
        
           | 36 | cycrow | 299 | 		delete pVfs;
 | 
        
           | 1 | cycrow | 300 | 		return;
 | 
        
           |  |  | 301 | 	}
 | 
        
           |  |  | 302 |   | 
        
           | 197 | cycrow | 303 | 	Utils::WStringList *ships = pVfs->getTShipsEntries();
 | 
        
           | 1 | cycrow | 304 | 	if ( !ships )
 | 
        
           |  |  | 305 | 	{
 | 
        
           |  |  | 306 | 		printf("Error: Failed to read %s::types\\TShips.pck\n", catfile.c_str());
 | 
        
           | 36 | cycrow | 307 | 		delete pVfs;
 | 
        
           | 1 | cycrow | 308 | 		return;
 | 
        
           |  |  | 309 | 	}
 | 
        
           |  |  | 310 |   | 
        
           |  |  | 311 | 	// now get the ship line to extract
 | 
        
           | 197 | cycrow | 312 | 	Utils::WString tShipsLine;
 | 
        
           | 185 | cycrow | 313 | 	if (shipid.empty())
 | 
        
           | 1 | cycrow | 314 | 	{
 | 
        
           |  |  | 315 | 		// no ship id, lets get one
 | 
        
           | 197 | cycrow | 316 | 		Utils::WString ids[2];
 | 
        
           | 1 | cycrow | 317 | 		int i = 0;
 | 
        
           |  |  | 318 | 		int id = 0;
 | 
        
           | 197 | cycrow | 319 | 		for ( Utils::WStringNode *str = ships->first(); str; str = ships->next() )
 | 
        
           | 1 | cycrow | 320 | 		{
 | 
        
           | 116 | cycrow | 321 | 			ids[i++] = str->data;
 | 
        
           | 1 | cycrow | 322 | 			if ( i >= 2 )
 | 
        
           |  |  | 323 | 			{
 | 
        
           | 197 | cycrow | 324 | 				wprintf(L"[%3d][%30s]\t[%3d][%30s]\n", id - 1, ids[0].c_str(), id, ids[1].c_str());
 | 
        
           | 1 | cycrow | 325 | 				for ( i = 0; i < 2; i++ )
 | 
        
           | 197 | cycrow | 326 | 					ids[i] = L"";
 | 
        
           | 1 | cycrow | 327 | 				i = 0;
 | 
        
           |  |  | 328 | 			}
 | 
        
           |  |  | 329 | 			++id;
 | 
        
           |  |  | 330 | 		}
 | 
        
           |  |  | 331 | 		if ( i == 1 )
 | 
        
           | 197 | cycrow | 332 | 			wprintf(L"[%3d][%30s]\n", id, ids[0].c_str());
 | 
        
           | 1 | cycrow | 333 | 		printf("Enter ID to use > ");
 | 
        
           |  |  | 334 | 		shipid = GetInput();
 | 
        
           |  |  | 335 |   | 
        
           | 185 | cycrow | 336 | 		if ( shipid.isNumber() )
 | 
        
           |  |  | 337 | 			tShipsLine = ships->get(shipid.toInt())->str;
 | 
        
           | 1 | cycrow | 338 | 		else
 | 
        
           | 185 | cycrow | 339 | 			tShipsLine = ships->findData(shipid, true);
 | 
        
           | 1 | cycrow | 340 | 	}
 | 
        
           |  |  | 341 | 	else
 | 
        
           | 185 | cycrow | 342 | 		ships->findData(shipid, true);
 | 
        
           | 1 | cycrow | 343 |   | 
        
           | 101 | cycrow | 344 | 	if ( tShipsLine.empty() )
 | 
        
           | 1 | cycrow | 345 | 	{
 | 
        
           | 197 | cycrow | 346 | 		wprintf(L"Error, %s is not a valid ship id to use\n", shipid.c_str());
 | 
        
           | 36 | cycrow | 347 | 		delete pVfs;
 | 
        
           | 1 | cycrow | 348 | 		return;
 | 
        
           |  |  | 349 | 	}
 | 
        
           |  |  | 350 |   | 
        
           |  |  | 351 | 	// now we have the tships to use, lets start to extract the ship
 | 
        
           | 197 | cycrow | 352 | 	wprintf(L"Extracting ship from %hs, Ship=%s\n", catfile.c_str(), tShipsLine.token(L";", -2).c_str());
 | 
        
           | 1 | cycrow | 353 |   | 
        
           |  |  | 354 | 	CXspFile ship;
 | 
        
           | 197 | cycrow | 355 | 	if ( ship.extractShip(pVfs, tShipsLine.token(L";", -2).toString(), 0))
 | 
        
           | 1 | cycrow | 356 | 	{
 | 
        
           |  |  | 357 | 		printf ( "Ship has been successfully extracted\n" );
 | 
        
           |  |  | 358 |   | 
        
           | 170 | cycrow | 359 | 		printf("\t- Models:\t %d\n", ship.countFiles(FILETYPE_SHIPMODEL));
 | 
        
           |  |  | 360 | 		printf("\t- Textures:\t %d\n", ship.countFiles(FILETYPE_SHIPOTHER));
 | 
        
           | 1 | cycrow | 361 | 		printf("\t- Dummies:\t %d\n", ship.GetDummies()->size());
 | 
        
           |  |  | 362 | 		printf("\t- Components:\t %d\n", ship.GetComponents()->size());
 | 
        
           | 170 | cycrow | 363 | 		printf("\t- Bodies:\t %d\n", ship.getBodies().size());
 | 
        
           | 1 | cycrow | 364 | 		printf("\t- Cockpits:\t %d\n", ship.GetCockpits()->size());
 | 
        
           |  |  | 365 | 		printf("\t- Text Entries:\t %d\n", ship.GetTexts()->size());
 | 
        
           |  |  | 366 |   | 
        
           |  |  | 367 | 		printf("\nEnter the name for the ship: ");
 | 
        
           | 197 | cycrow | 368 | 		ship.setName(GetInput().toString());
 | 
        
           | 1 | cycrow | 369 | 		printf("Enter the author for the ship: ");
 | 
        
           | 197 | cycrow | 370 | 		ship.setAuthor(GetInput().toString());
 | 
        
           | 1 | cycrow | 371 | 		printf("Enter the version for the ship: V");
 | 
        
           | 197 | cycrow | 372 | 		ship.setVersion(GetInput().toString());
 | 
        
           | 1 | cycrow | 373 | 		printf("Enter the description for the ship: ");
 | 
        
           | 197 | cycrow | 374 | 		ship.setDescription(GetInput().toString());
 | 
        
           | 1 | cycrow | 375 |   | 
        
           |  |  | 376 | 		struct tm   *currDate;
 | 
        
           |  |  | 377 | 		char    dateString[100];
 | 
        
           |  |  | 378 | 		time_t now = time(NULL);
 | 
        
           |  |  | 379 | 		currDate = localtime( &now );
 | 
        
           |  |  | 380 | 		strftime(dateString, sizeof dateString, "%d/%m/%Y", currDate);
 | 
        
           | 50 | cycrow | 381 | 		ship.setCreationDate(dateString);
 | 
        
           | 1 | cycrow | 382 |   | 
        
           |  |  | 383 | 		printf("\nWriting file: %s...\n", to.c_str());
 | 
        
           | 185 | cycrow | 384 | 		if ( ship.writeFile(to) )
 | 
        
           | 1 | cycrow | 385 | 			printf("Ship file has been created: %s\n", to.c_str());
 | 
        
           |  |  | 386 | 		else
 | 
        
           |  |  | 387 | 			printf("Error: Unable to write ship file, %s\n", to.c_str());
 | 
        
           |  |  | 388 | 	}
 | 
        
           |  |  | 389 | 	else
 | 
        
           |  |  | 390 | 		printf("Error: Unable to extract the ship\n");
 | 
        
           | 36 | cycrow | 391 |   | 
        
           |  |  | 392 | 	delete pVfs;
 | 
        
           | 1 | cycrow | 393 | }
 | 
        
           |  |  | 394 |   | 
        
           |  |  | 395 | CyString GetGameName(int game)
 | 
        
           |  |  | 396 | {
 | 
        
           |  |  | 397 | 	switch(game)
 | 
        
           |  |  | 398 | 	{
 | 
        
           |  |  | 399 | 		case GAME_X2:
 | 
        
           |  |  | 400 | 			return "X2: The Threat";
 | 
        
           |  |  | 401 | 		case GAME_X3:
 | 
        
           |  |  | 402 | 			return "X3: Reunion";
 | 
        
           |  |  | 403 | 		case GAME_X3TC:
 | 
        
           |  |  | 404 | 			return "X3: Terran Conflict";
 | 
        
           |  |  | 405 | 		case GAME_X3AP:
 | 
        
           |  |  | 406 | 			return "X3: Albion Prelude";
 | 
        
           | 126 | cycrow | 407 | 		case GAME_X3FL:
 | 
        
           |  |  | 408 | 			return "X3: Farnham's Legacy";
 | 
        
           | 1 | cycrow | 409 | 	}
 | 
        
           |  |  | 410 | 	return "Unknown";
 | 
        
           |  |  | 411 | }
 | 
        
           | 134 | cycrow | 412 | void DisplayVersion(const Utils::String &filename)
 | 
        
           | 1 | cycrow | 413 | {
 | 
        
           |  |  | 414 | 	// first chekc if file even exists
 | 
        
           |  |  | 415 | 	FILE *id = fopen ( filename.c_str(), "rb+" );
 | 
        
           |  |  | 416 | 	if ( !id )
 | 
        
           |  |  | 417 | 	{
 | 
        
           |  |  | 418 | 		printf ( "Error: File, %s, doesn't exist\n", filename.c_str() );
 | 
        
           |  |  | 419 | 		return;
 | 
        
           |  |  | 420 | 	}
 | 
        
           |  |  | 421 | 	fclose ( id );
 | 
        
           |  |  | 422 |   | 
        
           |  |  | 423 | 	bool read = false;
 | 
        
           |  |  | 424 | 	CBaseFile *pBaseFile = NULL;
 | 
        
           |  |  | 425 |   | 
        
           |  |  | 426 | 	int check = CSpkFile::CheckFile ( filename );
 | 
        
           |  |  | 427 | 	if ( check == SPKFILE_BASE )
 | 
        
           |  |  | 428 | 	{
 | 
        
           |  |  | 429 | 		pBaseFile = new CBaseFile();
 | 
        
           |  |  | 430 | 		printf ( "* Opening SPK File, %s...\n", filename.c_str() );
 | 
        
           | 175 | cycrow | 431 | 		if ( !pBaseFile->readFile(filename, SPKREAD_NODATA))
 | 
        
           | 1 | cycrow | 432 | 		{
 | 
        
           |  |  | 433 | 			printf ( "Failed to open the spk files, %s\n", filename.c_str() );
 | 
        
           |  |  | 434 | 			return;
 | 
        
           |  |  | 435 | 		}
 | 
        
           |  |  | 436 | 		read = true;
 | 
        
           |  |  | 437 | 	}
 | 
        
           |  |  | 438 | 	else if ( check == SPKFILE_SINGLE )
 | 
        
           |  |  | 439 | 	{
 | 
        
           |  |  | 440 | 		pBaseFile = (CBaseFile *)new CSpkFile();
 | 
        
           |  |  | 441 | 		printf ( "* Opening SPK File, %s...\n", filename.c_str() );
 | 
        
           | 175 | cycrow | 442 | 		if ( !pBaseFile->readFile(filename, SPKREAD_NODATA))
 | 
        
           | 1 | cycrow | 443 | 		{
 | 
        
           |  |  | 444 | 			printf ( "Failed to open the spk files, %s\n", filename.c_str() );
 | 
        
           |  |  | 445 | 			return;
 | 
        
           |  |  | 446 | 		}
 | 
        
           |  |  | 447 | 		read = true;
 | 
        
           |  |  | 448 | 	}
 | 
        
           |  |  | 449 | 	else if ( check == SPKFILE_SINGLESHIP )
 | 
        
           |  |  | 450 | 	{
 | 
        
           |  |  | 451 | 		pBaseFile = (CBaseFile *)new CXspFile();
 | 
        
           |  |  | 452 | 		printf ( "* Opening XSP File, %s...\n", filename.c_str() );
 | 
        
           | 175 | cycrow | 453 | 		if ( !pBaseFile->readFile(filename, SPKREAD_NODATA))
 | 
        
           | 1 | cycrow | 454 | 		{
 | 
        
           |  |  | 455 | 			printf ( "Failed to open the xsp files, %s\n", filename.c_str() );
 | 
        
           |  |  | 456 | 			return;
 | 
        
           |  |  | 457 | 		}
 | 
        
           |  |  | 458 | 		read = true;
 | 
        
           |  |  | 459 | 	}
 | 
        
           |  |  | 460 | 	// otherwise its an old ship file
 | 
        
           | 196 | cycrow | 461 | 	else if ( CFileIO(filename).isFileExtension(L"xsp") )
 | 
        
           | 1 | cycrow | 462 | 	{
 | 
        
           |  |  | 463 | 		printf ( "* Converting XSP File, %s...\n", filename.c_str() );
 | 
        
           |  |  | 464 | 		pBaseFile = new CXspFile;
 | 
        
           | 218 | cycrow | 465 | 		if ( !((CXspFile *)pBaseFile)->convertOld(filename) )
 | 
        
           | 1 | cycrow | 466 | 		{
 | 
        
           |  |  | 467 | 			delete pBaseFile;
 | 
        
           |  |  | 468 | 			pBaseFile = NULL;
 | 
        
           |  |  | 469 | 			printf ( "Failed to convert old xsp file, %s\n", filename.c_str() );
 | 
        
           |  |  | 470 | 			return;
 | 
        
           |  |  | 471 | 		}
 | 
        
           |  |  | 472 | 		check = SPKFILE_SINGLESHIP;
 | 
        
           |  |  | 473 | 		read = true;
 | 
        
           |  |  | 474 | 	}
 | 
        
           |  |  | 475 |   | 
        
           |  |  | 476 | 	if ( pBaseFile && read)
 | 
        
           |  |  | 477 | 	{
 | 
        
           |  |  | 478 | 		CPackages p;
 | 
        
           | 134 | cycrow | 479 | 		p.startup(".", ".", ".");
 | 
        
           | 1 | cycrow | 480 |   | 
        
           |  |  | 481 | 		CSpkFile *pSpkFile = NULL;
 | 
        
           |  |  | 482 | 		CXspFile *pXspFile = NULL;
 | 
        
           |  |  | 483 | 		if ( check == SPKFILE_SINGLE )
 | 
        
           |  |  | 484 | 			pSpkFile = (CSpkFile *)pBaseFile;
 | 
        
           |  |  | 485 | 		else
 | 
        
           |  |  | 486 | 			pXspFile = (CXspFile *)pBaseFile;
 | 
        
           |  |  | 487 |   | 
        
           | 170 | cycrow | 488 | 		printf("File Format Version: %.2f\n", pBaseFile->fileVersion());
 | 
        
           | 1 | cycrow | 489 |   | 
        
           |  |  | 490 | 		CyString sType;
 | 
        
           |  |  | 491 | 		if ( check == SPKFILE_SINGLESHIP )
 | 
        
           |  |  | 492 | 			sType = "Ship";
 | 
        
           |  |  | 493 | 		else
 | 
        
           |  |  | 494 | 			sType = "Package";
 | 
        
           |  |  | 495 |   | 
        
           | 203 | cycrow | 496 | 		wprintf(L"%hs Name: %s\n", sType.c_str(), pBaseFile->name().c_str() );
 | 
        
           | 49 | cycrow | 497 | 		if ( !pBaseFile->email().empty() )
 | 
        
           | 206 | cycrow | 498 | 			wprintf(L"%hs Author: %s (%s)\n", sType.c_str(), pBaseFile->author().c_str(), pBaseFile->email().c_str() );
 | 
        
           | 1 | cycrow | 499 | 		else
 | 
        
           | 203 | cycrow | 500 | 			wprintf(L"%hs Author: %s\n", sType.c_str(), pBaseFile->author().c_str() );
 | 
        
           | 204 | cycrow | 501 | 		if ( !pBaseFile->version().empty() ) wprintf(L"%hs Version: %s\n", sType.c_str(), pBaseFile->version().c_str() );
 | 
        
           | 1 | cycrow | 502 |   | 
        
           |  |  | 503 | 		//for game
 | 
        
           |  |  | 504 | 		printf("For Games: ");
 | 
        
           |  |  | 505 | 		if ( !pBaseFile->AnyGameCompatability() )
 | 
        
           |  |  | 506 | 			printf("All");
 | 
        
           |  |  | 507 | 		else
 | 
        
           | 197 | cycrow | 508 | 			wprintf(L"%s", p.getGameTypesString(pBaseFile, true).c_str());
 | 
        
           | 1 | cycrow | 509 | 		printf("\n");
 | 
        
           |  |  | 510 |   | 
        
           |  |  | 511 | 		if ( pXspFile )
 | 
        
           |  |  | 512 | 		{
 | 
        
           | 203 | cycrow | 513 | 			wprintf(L"Ship Display Name: %s\n", pXspFile->shipName(44).c_str());
 | 
        
           | 1 | cycrow | 514 | 			if ( pXspFile->IsExistingShip() )
 | 
        
           | 217 | cycrow | 515 | 				wprintf(L"Ship ID: %s (Replace Existing Ship)\n", pXspFile->shipID().c_str() );
 | 
        
           | 1 | cycrow | 516 | 			else
 | 
        
           | 217 | cycrow | 517 | 				wprintf(L"Ship ID: %s\n", pXspFile->shipID().c_str() );
 | 
        
           | 1 | cycrow | 518 |   | 
        
           |  |  | 519 | 			if ( pXspFile->AnyShipyards() )
 | 
        
           |  |  | 520 | 			{
 | 
        
           |  |  | 521 | 				printf ( "Add To Shipyards:\n" );
 | 
        
           |  |  | 522 | 				for ( int i = 1; i <= GetMaxShipyards(); i *= 2 )
 | 
        
           |  |  | 523 | 				{
 | 
        
           |  |  | 524 | 					if ( pXspFile->IsShipyard(i) )
 | 
        
           | 216 | cycrow | 525 | 						wprintf(L"\t%s\n", GetShipyardName(i).c_str());
 | 
        
           | 1 | cycrow | 526 | 				}
 | 
        
           |  |  | 527 | 			}
 | 
        
           |  |  | 528 |   | 
        
           |  |  | 529 | 			for ( SWeaponMask *text = pXspFile->GetLaserMasks()->First(); text; text = pXspFile->GetLaserMasks()->Next() )
 | 
        
           |  |  | 530 | 				printf ( "Laser Mask, Game: %s, Mask: %d\n", GetGameName(text->iGame).c_str(), text->iMask);
 | 
        
           |  |  | 531 | 			for ( SWeaponMask *text = pXspFile->GetMissileMasks()->First(); text; text = pXspFile->GetMissileMasks()->Next() )
 | 
        
           |  |  | 532 | 				printf ( "Missile Mask, Game: %s, Mask: %d\n", GetGameName(text->iGame).c_str(), text->iMask);
 | 
        
           |  |  | 533 |   | 
        
           |  |  | 534 | 			if ( pXspFile->GetOriginalDescription() )
 | 
        
           |  |  | 535 | 				printf("Use Existing Text, ID: %d\n", pXspFile->GetOriginalDescription());
 | 
        
           |  |  | 536 |   | 
        
           |  |  | 537 | 			if ( pXspFile->AnyTexts() )
 | 
        
           |  |  | 538 | 			{
 | 
        
           |  |  | 539 | 				for ( SText *text = pXspFile->GetTexts()->First(); text; text = pXspFile->GetTexts()->Next() )
 | 
        
           |  |  | 540 | 				{
 | 
        
           |  |  | 541 | 					printf("Ship Text, Language: %d\n", text->iId);
 | 
        
           | 39 | cycrow | 542 | 					if ( !text->sName.empty() )
 | 
        
           | 216 | cycrow | 543 | 						wprintf(L"\tName: %s\n", text->sName.c_str());
 | 
        
           | 39 | cycrow | 544 | 					if ( !text->sDesc.empty() )
 | 
        
           | 216 | cycrow | 545 | 						wprintf(L"\tDescription: %s\n", text->sDesc.c_str());
 | 
        
           | 1 | cycrow | 546 | 				}
 | 
        
           |  |  | 547 | 			}
 | 
        
           |  |  | 548 |   | 
        
           |  |  | 549 | 			if ( pXspFile->AnyComponents() )
 | 
        
           |  |  | 550 | 			{
 | 
        
           |  |  | 551 | 				printf ( "Component Entries:\n" );
 | 
        
           |  |  | 552 | 				for ( SComponent *c = pXspFile->GetComponents()->First(); c; c = pXspFile->GetComponents()->Next() )
 | 
        
           | 216 | cycrow | 553 | 					wprintf(L"\t%s\n\t\t%s\n\t\t\t%s\n", c->sSection.c_str(), c->sSection2.c_str(), c->sData.c_str());
 | 
        
           | 1 | cycrow | 554 | 			}
 | 
        
           |  |  | 555 | 			if ( pXspFile->AnyDummies() )
 | 
        
           |  |  | 556 | 			{
 | 
        
           |  |  | 557 | 				printf ( "Dummy Entries:\n" );
 | 
        
           |  |  | 558 | 				for ( SDummy *d = pXspFile->GetDummies()->First(); d; d = pXspFile->GetDummies()->Next() )
 | 
        
           | 216 | cycrow | 559 | 					wprintf(L"\t%s\n\t\t%s\n", d->sSection.c_str(), d->sData.c_str());
 | 
        
           | 1 | cycrow | 560 | 			}
 | 
        
           |  |  | 561 | 			if ( pXspFile->AnyCockpits() )
 | 
        
           |  |  | 562 | 			{
 | 
        
           |  |  | 563 | 				printf ( "Cockpit Entries:\n" );
 | 
        
           |  |  | 564 | 				for ( SCockpit *c = pXspFile->GetCockpits()->First(); c; c = pXspFile->GetCockpits()->Next() )
 | 
        
           | 216 | cycrow | 565 | 					wprintf(L"\t%s\n", c->sCockpit.c_str());
 | 
        
           | 1 | cycrow | 566 | 			}
 | 
        
           | 165 | cycrow | 567 | 			if ( pXspFile->anyCutData() )
 | 
        
           | 1 | cycrow | 568 | 			{
 | 
        
           | 165 | cycrow | 569 | 				printf ( "CutData Entries [%d]:\n", pXspFile->getCutData().size() );
 | 
        
           |  |  | 570 | 				for(auto itr = pXspFile->getCutData().begin(); itr != pXspFile->getCutData().end(); itr++)
 | 
        
           | 216 | cycrow | 571 | 					wprintf(L"\t%s\n", (*itr)->str.c_str());
 | 
        
           | 1 | cycrow | 572 | 			}
 | 
        
           |  |  | 573 | 		}
 | 
        
           |  |  | 574 |   | 
        
           | 204 | cycrow | 575 | 		if ( !pBaseFile->creationDate().empty() ) wprintf(L"Creation Date: %s\n", pBaseFile->creationDate().c_str() );
 | 
        
           | 206 | cycrow | 576 | 		if ( !pBaseFile->description().empty() ) wprintf(L"Description: %s\n", pBaseFile->description().c_str() );
 | 
        
           | 1 | cycrow | 577 | 		if ( pSpkFile )
 | 
        
           |  |  | 578 | 		{
 | 
        
           |  |  | 579 | 			if ( pSpkFile->IsLibrary() )
 | 
        
           |  |  | 580 | 				printf ( "Script Type: Library\n" );
 | 
        
           |  |  | 581 | 			else if ( pSpkFile->IsPatch() )
 | 
        
           |  |  | 582 | 				printf ( "Script Type: Patch Mod\n" );
 | 
        
           |  |  | 583 | 			else if ( pSpkFile->IsCustomStart() )
 | 
        
           |  |  | 584 | 				printf ( "Script Type: Custom Start\n" );
 | 
        
           |  |  | 585 | 			else if ( pSpkFile->IsPackageUpdate() )
 | 
        
           |  |  | 586 | 				printf ( "Script Type: Package Update\n" );
 | 
        
           | 214 | cycrow | 587 | 			else if ( !pSpkFile->scriptTypeString(44).empty() )
 | 
        
           |  |  | 588 | 				wprintf(L"Script Type: %s\n", pSpkFile->scriptTypeString(44).c_str() );
 | 
        
           | 1 | cycrow | 589 |   | 
        
           |  |  | 590 | 			if ( !pSpkFile->GetWaresList()->empty() )
 | 
        
           |  |  | 591 | 			{
 | 
        
           |  |  | 592 | 				for ( CListNode<SWares> * wNode = pSpkFile->GetWaresList()->Front(); wNode; wNode = wNode->next() )
 | 
        
           |  |  | 593 | 				{
 | 
        
           |  |  | 594 | 					SWares *w = wNode->Data();
 | 
        
           | 197 | cycrow | 595 | 					wprintf (L"Ware: (%c) %s\n", w->cType, CSpkFile::GetWareText(w, 44).c_str() );
 | 
        
           |  |  | 596 | 					Utils::WString desc = CSpkFile::GetWareDesc(w, 44);
 | 
        
           |  |  | 597 | 					if (!desc.empty())
 | 
        
           |  |  | 598 | 						wprintf(L"\tDescription: %s\n", desc.c_str() );
 | 
        
           | 1 | cycrow | 599 | 				}
 | 
        
           |  |  | 600 | 			}
 | 
        
           |  |  | 601 | 		}
 | 
        
           | 206 | cycrow | 602 | 		if ( !pBaseFile->forumLink().empty() )	wprintf(L"Forum Link: %s\n", pBaseFile->forumLink().c_str() );
 | 
        
           |  |  | 603 | 		if ( !pBaseFile->webSite().empty() )	wprintf(L"Web Site Address: %s\n", pBaseFile->webSite().c_str() );
 | 
        
           |  |  | 604 | 		if ( !pBaseFile->webAddress().empty() ) wprintf(L"Update Address: %s\n", pBaseFile->webAddress().c_str() );
 | 
        
           | 1 | cycrow | 605 |   | 
        
           | 162 | cycrow | 606 | 		if ( pBaseFile->anyWebMirrors() )
 | 
        
           | 1 | cycrow | 607 | 		{
 | 
        
           |  |  | 608 | 			printf("Update Mirror Addresses:\n");
 | 
        
           | 162 | cycrow | 609 | 			for ( int i = 0; i < pBaseFile->getMaxWebMirrors(); i++ )
 | 
        
           | 208 | cycrow | 610 | 				wprintf(L"\t%s\n", pBaseFile->getWebMirror(i).c_str());
 | 
        
           | 1 | cycrow | 611 | 		}
 | 
        
           |  |  | 612 | 		if ( pSpkFile )
 | 
        
           |  |  | 613 | 		{
 | 
        
           | 214 | cycrow | 614 | 			if ( (!pSpkFile->otherName().empty()) && (!pSpkFile->otherAuthor().empty()) )
 | 
        
           |  |  | 615 | 				wprintf(L"Script is a child to the mod: %s by %s\n", pSpkFile->otherName().c_str(), pSpkFile->otherAuthor().c_str() );
 | 
        
           | 1 | cycrow | 616 | 		}
 | 
        
           |  |  | 617 |   | 
        
           |  |  | 618 | 		if ( pBaseFile->AnyDependacies() )
 | 
        
           |  |  | 619 | 		{
 | 
        
           |  |  | 620 | 			printf ( "Required Dependacies:\n" );
 | 
        
           |  |  | 621 | 			for ( SNeededLibrary *needed = pBaseFile->GetNeededLibraries()->First(); needed; needed = pBaseFile->GetNeededLibraries()->Next() )
 | 
        
           | 204 | cycrow | 622 | 				wprintf(L"\t%s by %s (Minimum Version=%s)\n", needed->sName.c_str(), needed->sAuthor.c_str(), needed->sMinVersion.c_str() );
 | 
        
           | 1 | cycrow | 623 | 		}
 | 
        
           | 46 | cycrow | 624 | 		if ( pBaseFile->easeOfUse() != -1 ) printf ( "Ease Of Use Rating: %d\n", pBaseFile->easeOfUse() );
 | 
        
           |  |  | 625 | 		if ( pBaseFile->gameChanging() != -1 ) printf ( "Game Changing Rating: %d\n", pBaseFile->gameChanging() );
 | 
        
           |  |  | 626 | 		if ( pBaseFile->recommended() != -1 ) printf ( "Recommendation Rating: %d\n", pBaseFile->recommended() );
 | 
        
           | 170 | cycrow | 627 | 		if (pBaseFile->icon())
 | 
        
           | 197 | cycrow | 628 | 			wprintf(L"Icon File Found, Type: %s, Size: %s\n", pBaseFile->iconExt().c_str(), pBaseFile->icon()->dataSizeString().c_str() );
 | 
        
           | 1 | cycrow | 629 |   | 
        
           |  |  | 630 | 		if ( pBaseFile->GetFileList()->size() )
 | 
        
           |  |  | 631 | 		{
 | 
        
           | 134 | cycrow | 632 | 			printf("\nListing files in package:\n");
 | 
        
           | 1 | cycrow | 633 | 			CLinkList<C_File> *list = pBaseFile->GetFileList();
 | 
        
           | 134 | cycrow | 634 |   | 
        
           |  |  | 635 | 			for (unsigned int game = 0; game < 31; ++game)
 | 
        
           |  |  | 636 | 			{
 | 
        
           |  |  | 637 | 				bool heading = true;
 | 
        
           |  |  | 638 | 				for (C_File *file = list->First(); file; file = list->Next())
 | 
        
           |  |  | 639 | 				{
 | 
        
           |  |  | 640 | 					bool display = false;
 | 
        
           |  |  | 641 | 					if (game == 0 && (!file->game() || file->game() == GAME_ALLNEW))
 | 
        
           |  |  | 642 | 						display = true;
 | 
        
           |  |  | 643 | 					if (game > 0 && file->game() & (1 << game))
 | 
        
           |  |  | 644 | 						display = true;
 | 
        
           |  |  | 645 |   | 
        
           |  |  | 646 | 					if (display)
 | 
        
           |  |  | 647 | 					{
 | 
        
           |  |  | 648 | 						if (heading)
 | 
        
           |  |  | 649 | 						{
 | 
        
           | 197 | cycrow | 650 | 							Utils::WString sGame = p.GetGameExe()->gameNameFromType(game - 1);
 | 
        
           |  |  | 651 | 							wprintf(L"\tGame: %s\n", sGame.c_str());
 | 
        
           | 134 | cycrow | 652 | 							heading = false;
 | 
        
           |  |  | 653 | 						}
 | 
        
           | 197 | cycrow | 654 | 						wprintf(L"\t\t%s (%s) Size: %s\n", file->getNameDirectory(pBaseFile).c_str(), file->fileTypeString().c_str(), file->dataSizeString().c_str());
 | 
        
           | 134 | cycrow | 655 |   | 
        
           |  |  | 656 | 					}
 | 
        
           |  |  | 657 | 				}
 | 
        
           |  |  | 658 | 			}
 | 
        
           |  |  | 659 |   | 
        
           | 1 | cycrow | 660 | 		}
 | 
        
           |  |  | 661 | 		else
 | 
        
           |  |  | 662 | 			printf ( "\nThere are currently no files in the package\n" );
 | 
        
           |  |  | 663 | 	}
 | 
        
           |  |  | 664 | 	else if ( check == SPKFILE_MULTI )
 | 
        
           |  |  | 665 | 	{
 | 
        
           |  |  | 666 | 		CMultiSpkFile spkfile;
 | 
        
           |  |  | 667 | 		printf ( "* Opening Multi-SPK file, %s...\n", filename.c_str() );
 | 
        
           | 175 | cycrow | 668 | 		if ( !pBaseFile->readFile(filename, false))
 | 
        
           | 1 | cycrow | 669 | 		{
 | 
        
           |  |  | 670 | 			printf ( "Error: Failed to open the Multi-SPK file, %s\n", filename.c_str() );
 | 
        
           |  |  | 671 | 			return;
 | 
        
           |  |  | 672 | 		}
 | 
        
           |  |  | 673 |   | 
        
           | 177 | cycrow | 674 | 		printf ( "Multi Package Name: %s\n", spkfile.name().c_str() );
 | 
        
           | 1 | cycrow | 675 | 		printf ( "Selection Mode: " );
 | 
        
           | 177 | cycrow | 676 | 		if (spkfile.isSelection ())
 | 
        
           | 1 | cycrow | 677 | 			printf ( "On\n" );
 | 
        
           |  |  | 678 | 		else
 | 
        
           |  |  | 679 | 			printf ( "Off\n" );
 | 
        
           |  |  | 680 |   | 
        
           |  |  | 681 | 		CLinkList<SMultiSpkFile> *list = spkfile.GetFileList();
 | 
        
           |  |  | 682 | 		for ( SMultiSpkFile *ms = list->First(); ms; ms = list->Next() )
 | 
        
           |  |  | 683 | 		{
 | 
        
           |  |  | 684 | 			printf ( "File, %s:\n", ms->sName.c_str() );
 | 
        
           | 197 | cycrow | 685 | 			wprintf(L"\tSize: %s\n", SPK::GetSizeString (ms->lSize).c_str() );
 | 
        
           | 176 | cycrow | 686 | 			if ( (!ms->sScriptName.empty()) && (!ms->sScriptAuthor.empty()) )
 | 
        
           | 1 | cycrow | 687 | 				printf ( "\tScript: %s %s by %s\n", ms->sScriptName.c_str(), ms->sScriptVersion.c_str(), ms->sScriptAuthor.c_str() );
 | 
        
           |  |  | 688 | 			printf ( "\tDefault Install: " );
 | 
        
           |  |  | 689 | 			if ( ms->bOn )
 | 
        
           |  |  | 690 | 				printf ( "Yes\n" );
 | 
        
           |  |  | 691 | 			else
 | 
        
           |  |  | 692 | 				printf ( "No\n" );
 | 
        
           |  |  | 693 | 		}
 | 
        
           |  |  | 694 | 	}
 | 
        
           |  |  | 695 | 	else
 | 
        
           |  |  | 696 | 		printf ( "File, %s, is not a valid SPK file\n", filename.c_str() );
 | 
        
           |  |  | 697 |   | 
        
           |  |  | 698 | 	if ( pBaseFile )
 | 
        
           |  |  | 699 | 		delete pBaseFile;
 | 
        
           |  |  | 700 | }
 | 
        
           |  |  | 701 |   | 
        
           |  |  | 702 | void AppendFile ( CyString sfile, CyString type, CyString addfile )
 | 
        
           |  |  | 703 | {
 | 
        
           | 155 | cycrow | 704 | 	int t = GetFileTypeFromString(type.ToString());
 | 
        
           | 1 | cycrow | 705 | 	if ( t == -1 )
 | 
        
           |  |  | 706 | 	{
 | 
        
           |  |  | 707 | 		printf ( "The file type \"%s\" is invalid\n", type.c_str() );
 | 
        
           |  |  | 708 | 		return;
 | 
        
           |  |  | 709 | 	}
 | 
        
           |  |  | 710 |   | 
        
           | 175 | cycrow | 711 | 	int check = CSpkFile::CheckFile(sfile.ToString());
 | 
        
           | 1 | cycrow | 712 | 	CBaseFile *pBaseFile = 0;
 | 
        
           |  |  | 713 | 	if ( check == SPKFILE_SINGLE )
 | 
        
           |  |  | 714 | 		pBaseFile = new CSpkFile();
 | 
        
           |  |  | 715 | 	else if ( check == SPKFILE_SINGLESHIP )
 | 
        
           |  |  | 716 | 		pBaseFile = new CXspFile();
 | 
        
           |  |  | 717 | 	else if ( check == SPKFILE_BASE )
 | 
        
           |  |  | 718 | 		pBaseFile = new CBaseFile();
 | 
        
           |  |  | 719 |   | 
        
           |  |  | 720 | 	if ( !pBaseFile )
 | 
        
           |  |  | 721 | 	{
 | 
        
           |  |  | 722 | 		printf ( "Error: Invalid file format, unable to open\n" );
 | 
        
           |  |  | 723 | 		return;
 | 
        
           |  |  | 724 | 	}
 | 
        
           |  |  | 725 |   | 
        
           |  |  | 726 | 	printf ( "Opening File, %s... ", sfile.c_str() );
 | 
        
           | 175 | cycrow | 727 | 	if ( !pBaseFile->readFile(sfile.ToString()))
 | 
        
           | 1 | cycrow | 728 | 	{
 | 
        
           |  |  | 729 | 		printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
 | 
        
           |  |  | 730 | 		return;
 | 
        
           |  |  | 731 | 	}
 | 
        
           |  |  | 732 | 	printf ( "(Done)\n" );
 | 
        
           |  |  | 733 |   | 
        
           |  |  | 734 | 	MyProgress progress(0);
 | 
        
           |  |  | 735 |   | 
        
           |  |  | 736 | 	printf ( "Adding file %s to package\n\t>", addfile.c_str() );
 | 
        
           |  |  | 737 |   | 
        
           | 155 | cycrow | 738 | 	if ( pBaseFile->appendFile(addfile.ToString(), t, 0, false, Utils::String::Null(), &progress))
 | 
        
           | 1 | cycrow | 739 | 	{
 | 
        
           |  |  | 740 | 		progress.PrintDone();
 | 
        
           |  |  | 741 | 		printf ( "< (Done)\n" );
 | 
        
           |  |  | 742 |   | 
        
           | 175 | cycrow | 743 | 		pBaseFile->writeFile(sfile.ToString());
 | 
        
           | 1 | cycrow | 744 | 		printf ( "\nFile has been written sucessfully\n" );
 | 
        
           |  |  | 745 | 	}
 | 
        
           |  |  | 746 | 	else
 | 
        
           |  |  | 747 | 		printf ( "< (Error)\n" );
 | 
        
           |  |  | 748 | }
 | 
        
           |  |  | 749 |   | 
        
           |  |  | 750 | void RemoveFile ( CyString sfile, CyString type, CyString addfile )
 | 
        
           |  |  | 751 | {
 | 
        
           |  |  | 752 | 	FILE *id = fopen ( sfile.c_str(), "rb+" );
 | 
        
           |  |  | 753 | 	if ( !id )
 | 
        
           |  |  | 754 | 	{
 | 
        
           |  |  | 755 | 		printf ( "Error: File, %s, doesn't exist\n", sfile.c_str() );
 | 
        
           |  |  | 756 | 		return;
 | 
        
           |  |  | 757 | 	}
 | 
        
           |  |  | 758 |   | 
        
           |  |  | 759 | 	if ( addfile.Empty() )
 | 
        
           |  |  | 760 | 	{
 | 
        
           |  |  | 761 | 		printf ( "Error: Remove filename is invalid\n" );
 | 
        
           |  |  | 762 | 		return;
 | 
        
           |  |  | 763 | 	}
 | 
        
           | 172 | cycrow | 764 | 	FileType t = GetFileTypeFromString(type.ToString());
 | 
        
           |  |  | 765 | 	if (t == FileType::FILETYPE_UNKNOWN)
 | 
        
           | 1 | cycrow | 766 | 	{
 | 
        
           |  |  | 767 | 		printf ( "The file type \"%s\" is invalid\n", type.c_str() );
 | 
        
           |  |  | 768 | 		return;
 | 
        
           |  |  | 769 | 	}
 | 
        
           |  |  | 770 |   | 
        
           | 175 | cycrow | 771 | 	int check = CSpkFile::CheckFile(sfile.ToString());
 | 
        
           | 1 | cycrow | 772 | 	CBaseFile *pBaseFile = 0;
 | 
        
           |  |  | 773 | 	if ( check == SPKFILE_SINGLE )
 | 
        
           |  |  | 774 | 		pBaseFile = new CSpkFile();
 | 
        
           |  |  | 775 | 	else if ( check == SPKFILE_SINGLESHIP )
 | 
        
           |  |  | 776 | 		pBaseFile = new CXspFile();
 | 
        
           |  |  | 777 | 	else if ( check == SPKFILE_BASE )
 | 
        
           |  |  | 778 | 		pBaseFile = new CBaseFile();
 | 
        
           |  |  | 779 |   | 
        
           |  |  | 780 | 	if ( pBaseFile )
 | 
        
           |  |  | 781 | 	{
 | 
        
           |  |  | 782 | 		printf ( "Opening File, %s... ", sfile.c_str() );
 | 
        
           | 175 | cycrow | 783 | 		if ( !pBaseFile->readFile(sfile.ToString()))
 | 
        
           | 1 | cycrow | 784 | 		{
 | 
        
           |  |  | 785 | 			printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
 | 
        
           |  |  | 786 | 			return;
 | 
        
           |  |  | 787 | 		}
 | 
        
           |  |  | 788 | 		printf ( "(Done)\n" );
 | 
        
           |  |  | 789 |   | 
        
           |  |  | 790 | 		printf ( "Removing file, %s, from Package\n", addfile.c_str() );
 | 
        
           |  |  | 791 |   | 
        
           | 172 | cycrow | 792 | 		if(pBaseFile->removeFile(addfile.ToString(), t))
 | 
        
           | 1 | cycrow | 793 | 		{
 | 
        
           |  |  | 794 | 			printf ( "File, %s, has been remove from package\n", addfile.c_str() );
 | 
        
           | 175 | cycrow | 795 | 			pBaseFile->writeFile(sfile.ToString());
 | 
        
           | 1 | cycrow | 796 | 			printf ( "File has been written to disk successfully\n" );
 | 
        
           |  |  | 797 | 		}
 | 
        
           |  |  | 798 | 		else
 | 
        
           |  |  | 799 | 			printf ( "Unable to remove the file, %s, from the package\n", addfile.c_str() );
 | 
        
           |  |  | 800 | 	}
 | 
        
           |  |  | 801 | 	else if ( check == SPKFILE_MULTI )
 | 
        
           |  |  | 802 | 	{
 | 
        
           |  |  | 803 | 		CMultiSpkFile spkfile;
 | 
        
           |  |  | 804 | 		printf ( "Opening Multi-SPK file, %s...", sfile.c_str() );
 | 
        
           | 177 | cycrow | 805 | 		if ( !spkfile.readFile(sfile.ToString()))
 | 
        
           | 1 | cycrow | 806 | 		{
 | 
        
           |  |  | 807 | 			printf ( "(Error)\nUnable to open the Multi-SPK file, %s\n", sfile.c_str() );
 | 
        
           |  |  | 808 | 			return;
 | 
        
           |  |  | 809 | 		}
 | 
        
           |  |  | 810 | 		printf ( "(Done)\n" );
 | 
        
           |  |  | 811 |   | 
        
           | 177 | cycrow | 812 | 		const SMultiSpkFile *ms = spkfile.findFile ( type.ToString() );
 | 
        
           | 1 | cycrow | 813 | 		if ( !ms )
 | 
        
           |  |  | 814 | 		{
 | 
        
           |  |  | 815 | 			printf ( "Unable to find the file \"%s\" in the package\n", type.c_str() );
 | 
        
           |  |  | 816 | 			return;
 | 
        
           |  |  | 817 | 		}
 | 
        
           |  |  | 818 |   | 
        
           |  |  | 819 | 		printf ( "Removing file, %s, from Package\n", addfile.c_str() );
 | 
        
           | 177 | cycrow | 820 | 		if (!spkfile.removeFile(ms))
 | 
        
           | 1 | cycrow | 821 | 		{
 | 
        
           |  |  | 822 | 			printf ( "Error: Unable to remove file, %s, from package\n", type.c_str() );
 | 
        
           |  |  | 823 | 			return;
 | 
        
           |  |  | 824 | 		}
 | 
        
           |  |  | 825 |   | 
        
           |  |  | 826 | 		printf ( "Writing SPK File, %s... ", sfile.c_str() );
 | 
        
           | 177 | cycrow | 827 | 		if (spkfile.writeFile(sfile.ToString()))
 | 
        
           | 1 | cycrow | 828 | 			printf ( "(Done)\n" );
 | 
        
           |  |  | 829 | 		else
 | 
        
           |  |  | 830 | 			printf ( "(Error)\n" );
 | 
        
           |  |  | 831 | 	}
 | 
        
           |  |  | 832 | 	else
 | 
        
           |  |  | 833 | 		printf ( "Error: Invalid file format, unable to open\n" );
 | 
        
           |  |  | 834 | }
 | 
        
           |  |  | 835 |   | 
        
           |  |  | 836 |   | 
        
           |  |  | 837 | void CreateMultiFile ( CyString filename )
 | 
        
           |  |  | 838 | {
 | 
        
           |  |  | 839 | 	printf ( "* Creating new Multi-SPK File, %s\n\n", filename.c_str() );
 | 
        
           |  |  | 840 |   | 
        
           |  |  | 841 | 	FILE *id = fopen ( filename.c_str(), "rb+" );
 | 
        
           |  |  | 842 | 	if ( id )
 | 
        
           |  |  | 843 | 	{
 | 
        
           |  |  | 844 | 		fclose ( id );
 | 
        
           |  |  | 845 | 		printf ( "* File already exists, unable to create\n" );
 | 
        
           |  |  | 846 | 		return;
 | 
        
           |  |  | 847 | 	}
 | 
        
           |  |  | 848 |   | 
        
           |  |  | 849 | 	id = fopen ( filename.c_str(), "wb" );
 | 
        
           |  |  | 850 | 	if ( !id )
 | 
        
           |  |  | 851 | 	{
 | 
        
           |  |  | 852 | 		printf ( "* Unable to open file for writing\n" );
 | 
        
           |  |  | 853 | 		return;
 | 
        
           |  |  | 854 | 	}
 | 
        
           |  |  | 855 | 	fclose ( id );
 | 
        
           |  |  | 856 | 	remove ( filename.c_str() );
 | 
        
           |  |  | 857 |   | 
        
           |  |  | 858 | 	CMultiSpkFile spkfile;
 | 
        
           |  |  | 859 |   | 
        
           | 197 | cycrow | 860 | 	Utils::WString sInput;
 | 
        
           | 1 | cycrow | 861 | 	printf ( "Enter Multi-Spk Package Name: " );
 | 
        
           | 197 | cycrow | 862 | 	spkfile.setName(GetInput().toString());
 | 
        
           | 1 | cycrow | 863 |   | 
        
           |  |  | 864 | 	while ( true )
 | 
        
           |  |  | 865 | 	{
 | 
        
           |  |  | 866 | 		printf ( "\nDo you want users to select scripts to install? (Y/N): " );
 | 
        
           | 197 | cycrow | 867 | 		Utils::WString i = GetInput();
 | 
        
           |  |  | 868 | 		i = i.upper();
 | 
        
           |  |  | 869 | 		if ( i == L"Y" )
 | 
        
           | 177 | cycrow | 870 | 			spkfile.setSelection(true);
 | 
        
           | 197 | cycrow | 871 | 		if ( (i == L"Y") || (i == L"N") )
 | 
        
           | 1 | cycrow | 872 | 			break;
 | 
        
           |  |  | 873 | 	}
 | 
        
           |  |  | 874 |   | 
        
           |  |  | 875 | 	while ( true )
 | 
        
           |  |  | 876 | 	{
 | 
        
           |  |  | 877 | 		printf ( "\nEnter Spk File to add (Enter \"0\" to finish): " );
 | 
        
           |  |  | 878 | 		sInput = GetInput();
 | 
        
           |  |  | 879 | 		if ( sInput == "0" )
 | 
        
           |  |  | 880 | 			break;
 | 
        
           |  |  | 881 |   | 
        
           |  |  | 882 | 		// check if file can be opened
 | 
        
           | 197 | cycrow | 883 | 		FILE *id2 = fopen ( sInput.toString().c_str(), "rb+");
 | 
        
           | 1 | cycrow | 884 | 		if ( !id2 )
 | 
        
           | 197 | cycrow | 885 | 			wprintf(L"Error: Unable to open SPK file %s\n", sInput.c_str() );
 | 
        
           | 1 | cycrow | 886 | 		else
 | 
        
           |  |  | 887 | 		{
 | 
        
           |  |  | 888 | 			fclose ( id2 );
 | 
        
           | 197 | cycrow | 889 | 			if ( !spkfile.addFile(sInput.toString()))
 | 
        
           | 1 | cycrow | 890 | 				printf ( "Error: Unable to add SPK file to package\n" );
 | 
        
           |  |  | 891 | 			else
 | 
        
           | 197 | cycrow | 892 | 				wprintf(L"File Added to package (%s)\n", sInput.c_str() );
 | 
        
           | 1 | cycrow | 893 | 		}
 | 
        
           |  |  | 894 | 	}
 | 
        
           |  |  | 895 |   | 
        
           | 177 | cycrow | 896 | 	if ( spkfile.numFiles() < 1 )
 | 
        
           | 1 | cycrow | 897 | 		printf ( "\nError: You have added no files, you must add at least one file to create a package\n" );
 | 
        
           |  |  | 898 | 	else
 | 
        
           |  |  | 899 | 	{
 | 
        
           |  |  | 900 | 		printf ( "Writing MultiSpk file... " );
 | 
        
           | 177 | cycrow | 901 | 		if ( spkfile.writeFile(filename.ToString()))
 | 
        
           | 1 | cycrow | 902 | 			printf ( "(Done)\n" );
 | 
        
           |  |  | 903 | 		else
 | 
        
           |  |  | 904 | 			printf ( "(Error)\n" );
 | 
        
           |  |  | 905 | 	}
 | 
        
           |  |  | 906 |   | 
        
           |  |  | 907 | }
 | 
        
           |  |  | 908 |   | 
        
           |  |  | 909 | void CreateFile ( CyString filename )
 | 
        
           |  |  | 910 | {
 | 
        
           |  |  | 911 | 	printf ( "* Creating new SPK File, %s\n\n", filename.c_str() );
 | 
        
           |  |  | 912 |   | 
        
           |  |  | 913 | 	FILE *id = fopen ( filename.c_str(), "rb+" );
 | 
        
           |  |  | 914 | 	if ( id )
 | 
        
           |  |  | 915 | 	{
 | 
        
           |  |  | 916 | 		fclose ( id );
 | 
        
           |  |  | 917 | 		printf ( "* File already exists, unable to create\n" );
 | 
        
           |  |  | 918 | 		return;
 | 
        
           |  |  | 919 | 	}
 | 
        
           |  |  | 920 |   | 
        
           |  |  | 921 | 	id = fopen ( filename.c_str(), "wb" );
 | 
        
           |  |  | 922 | 	if ( !id )
 | 
        
           |  |  | 923 | 	{
 | 
        
           |  |  | 924 | 		printf ( "* Unable to open file for writing\n" );
 | 
        
           |  |  | 925 | 		return;
 | 
        
           |  |  | 926 | 	}
 | 
        
           |  |  | 927 | 	fclose ( id );
 | 
        
           |  |  | 928 | 	remove ( filename.c_str() );
 | 
        
           |  |  | 929 |   | 
        
           |  |  | 930 | 	CSpkFile spkfile;
 | 
        
           |  |  | 931 |   | 
        
           |  |  | 932 | 	printf ( "Enter Script Name: " );
 | 
        
           | 197 | cycrow | 933 | 	spkfile.setName(GetInput().toString());
 | 
        
           | 1 | cycrow | 934 |   | 
        
           |  |  | 935 | 	printf ( "Enter Script Author: " );
 | 
        
           | 197 | cycrow | 936 | 	spkfile.setAuthor(GetInput().toString());
 | 
        
           | 1 | cycrow | 937 |   | 
        
           |  |  | 938 | 	printf ( "Enter Script Version: " );
 | 
        
           | 197 | cycrow | 939 | 	spkfile.setVersion(GetInput().toString());
 | 
        
           | 1 | cycrow | 940 |   | 
        
           |  |  | 941 | 	printf ( "Enter Script Description: " );
 | 
        
           | 197 | cycrow | 942 | 	spkfile.setDescription(GetInput().toString());
 | 
        
           | 1 | cycrow | 943 |   | 
        
           |  |  | 944 | 	struct tm   *currDate;
 | 
        
           |  |  | 945 | 	char    dateString[100];
 | 
        
           |  |  | 946 | 	time_t now = time(NULL);
 | 
        
           |  |  | 947 |   | 
        
           |  |  | 948 | 	currDate = localtime( &now );
 | 
        
           |  |  | 949 | 	strftime(dateString, sizeof dateString, "%d %m %Y", currDate);
 | 
        
           | 50 | cycrow | 950 | 	spkfile.setCreationDate(dateString);
 | 
        
           | 1 | cycrow | 951 |   | 
        
           | 175 | cycrow | 952 | 	spkfile.writeFile(filename.ToString(), NULL);
 | 
        
           | 1 | cycrow | 953 | 	printf ( "SPK file has been written to disk: %s\n", filename.c_str() );
 | 
        
           |  |  | 954 | }
 | 
        
           |  |  | 955 |   | 
        
           | 129 | cycrow | 956 | void ExtractFiles (const Utils::String &sfile, const Utils::String &dir, int game )
 | 
        
           | 1 | cycrow | 957 | {
 | 
        
           |  |  | 958 | 	// First checks if the file exists by opening it
 | 
        
           |  |  | 959 | 	FILE *id = fopen ( sfile.c_str(), "rb+" );
 | 
        
           |  |  | 960 | 	if ( !id )
 | 
        
           |  |  | 961 | 	{
 | 
        
           |  |  | 962 | 		printf ( "Error: File, %s, doesn't exist\n", sfile.c_str() );
 | 
        
           |  |  | 963 | 		return;
 | 
        
           |  |  | 964 | 	}
 | 
        
           |  |  | 965 | 	fclose ( id );
 | 
        
           |  |  | 966 |   | 
        
           | 129 | cycrow | 967 | 	CPackages packages;
 | 
        
           |  |  | 968 | 	packages.startup(".", ".", ".");
 | 
        
           |  |  | 969 |   | 
        
           | 1 | cycrow | 970 | 	int check = CSpkFile::CheckFile ( sfile );
 | 
        
           |  |  | 971 |   | 
        
           |  |  | 972 | 	// extracts a file from single packages file
 | 
        
           |  |  | 973 | 	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
 | 
        
           |  |  | 974 | 	{
 | 
        
           |  |  | 975 | 		// creates the spkfile object
 | 
        
           |  |  | 976 | 		CBaseFile *pBaseFile = 0;
 | 
        
           |  |  | 977 | 		if ( check == SPKFILE_SINGLE )
 | 
        
           |  |  | 978 | 			pBaseFile = (CBaseFile *)new CSpkFile();
 | 
        
           |  |  | 979 | 		else if ( check == SPKFILE_SINGLESHIP )
 | 
        
           |  |  | 980 | 			pBaseFile = (CBaseFile *)new CXspFile();
 | 
        
           |  |  | 981 | 		else
 | 
        
           |  |  | 982 | 			pBaseFile = new CBaseFile();
 | 
        
           |  |  | 983 |   | 
        
           |  |  | 984 | 		printf ( "Opening File, %s... ", sfile.c_str() );
 | 
        
           |  |  | 985 | 		// reads the file into memory
 | 
        
           |  |  | 986 | 		// the SPKREAD_NODATA flag causes it to just read the settings, and skips the file data
 | 
        
           | 175 | cycrow | 987 | 		if ( !pBaseFile->readFile(sfile, SPKREAD_NODATA))
 | 
        
           | 1 | cycrow | 988 | 		{
 | 
        
           |  |  | 989 | 			printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
 | 
        
           |  |  | 990 | 			return;
 | 
        
           |  |  | 991 | 		}
 | 
        
           |  |  | 992 | 		printf ( "(Done)\n" );
 | 
        
           |  |  | 993 |   | 
        
           | 134 | cycrow | 994 | 		if(game == 0)
 | 
        
           |  |  | 995 | 			printf("Extracting all files from archive...\n\n");
 | 
        
           | 1 | cycrow | 996 | 		else
 | 
        
           | 197 | cycrow | 997 | 			wprintf(L"Extracting %s files from archive...\n\n", packages.GetGameExe()->gameNameFromType(game - 1).c_str());
 | 
        
           | 134 | cycrow | 998 |   | 
        
           |  |  | 999 | 		CFileProgress info(&packages, pBaseFile, "Extracting");
 | 
        
           |  |  | 1000 | 		if (packages.extractAll(pBaseFile, dir, game, true, &info) )
 | 
        
           |  |  | 1001 | 			printf ( "\n(Done)\nFiles have been extracted successfully\n" );
 | 
        
           |  |  | 1002 | 		else
 | 
        
           |  |  | 1003 | 			printf ( "\n(Error)\nThere was a problem extracting the files\n" );
 | 
        
           | 1 | cycrow | 1004 | 	}
 | 
        
           |  |  | 1005 | 	else
 | 
        
           |  |  | 1006 | 		printf("Invalid package file, %s\n", sfile.c_str());
 | 
        
           |  |  | 1007 | }
 | 
        
           |  |  | 1008 |   | 
        
           |  |  | 1009 |   | 
        
           |  |  | 1010 | /*
 | 
        
           |  |  | 1011 | 	Func:	AppendMultiFile
 | 
        
           |  |  | 1012 | 	Args:	String toFile	- The spk file to append onto
 | 
        
           |  |  | 1013 | 			String addfile	- The spk file to append
 | 
        
           |  |  | 1014 | 	Desc:	Appends a spk file into a Multi-Spk Archive
 | 
        
           |  |  | 1015 | 			If toFile is a single spk file, it will be converted to a Multi-Spk File
 | 
        
           |  |  | 1016 | 			if addfile is a Multi-Spk file, all files from it will be appended
 | 
        
           |  |  | 1017 | */
 | 
        
           |  |  | 1018 | void AppendMultiFile ( CyString toFile, CyString addfile )
 | 
        
           |  |  | 1019 | {
 | 
        
           |  |  | 1020 | 	// create destination object
 | 
        
           |  |  | 1021 | 	CMultiSpkFile spkfile;
 | 
        
           |  |  | 1022 |   | 
        
           |  |  | 1023 | 	// checks the destination
 | 
        
           | 175 | cycrow | 1024 | 	int checkto = CSpkFile::CheckFile(toFile.ToString());
 | 
        
           | 1 | cycrow | 1025 |   | 
        
           |  |  | 1026 | 	// if the destination is a single file, then convert it to a Multi-Spk package
 | 
        
           |  |  | 1027 | 	if ( checkto == SPKFILE_SINGLE )
 | 
        
           |  |  | 1028 | 	{
 | 
        
           |  |  | 1029 | 		// adds the single file to the Multi-Spk object
 | 
        
           |  |  | 1030 | 		// Add file also reads it into memory
 | 
        
           | 177 | cycrow | 1031 | 		if ( !spkfile.addFile(toFile.ToString()))
 | 
        
           | 1 | cycrow | 1032 | 		{
 | 
        
           |  |  | 1033 | 			printf ( "Error: Unable to create Multi-Spk file\n" );
 | 
        
           |  |  | 1034 | 			return;
 | 
        
           |  |  | 1035 | 		}
 | 
        
           |  |  | 1036 | 	}
 | 
        
           |  |  | 1037 | 	else
 | 
        
           |  |  | 1038 | 	{
 | 
        
           |  |  | 1039 | 		// if its already a multispk file, then simply open it and read it to memory
 | 
        
           | 177 | cycrow | 1040 | 		if ( !spkfile.readFile(toFile.ToString()))
 | 
        
           | 1 | cycrow | 1041 | 		{
 | 
        
           |  |  | 1042 | 			printf ( "Error: Unable to open Multi-Spk file, %s\n", toFile.c_str() );
 | 
        
           |  |  | 1043 | 			return;
 | 
        
           |  |  | 1044 | 		}
 | 
        
           |  |  | 1045 | 	}
 | 
        
           |  |  | 1046 |   | 
        
           |  |  | 1047 | 	// now add the file into the Multi-Spk Object
 | 
        
           |  |  | 1048 | 	// the AddFile function will handle both single and Multi-Spk files
 | 
        
           |  |  | 1049 | 	// So you dont need to test what the appending file is
 | 
        
           | 177 | cycrow | 1050 | 	if ( spkfile.addFile(addfile.ToString()))
 | 
        
           | 1 | cycrow | 1051 | 	{
 | 
        
           |  |  | 1052 |   | 
        
           |  |  | 1053 | 		// if it added correctly, then simply write the new Multi-Spk Object to disk
 | 
        
           |  |  | 1054 | 		printf ( "File, %s, has been added to Multi-Spk Package\n", addfile.c_str() );
 | 
        
           |  |  | 1055 | 		printf ( "Saving Multi-Spk File: %s... ", toFile.c_str() );
 | 
        
           | 177 | cycrow | 1056 | 		if ( spkfile.writeFile(toFile.ToString()))
 | 
        
           | 1 | cycrow | 1057 | 			printf ( "(Done)\n" );
 | 
        
           |  |  | 1058 | 		else
 | 
        
           |  |  | 1059 | 			printf ( "(Error)\n" );
 | 
        
           |  |  | 1060 | 	}
 | 
        
           |  |  | 1061 | 	else
 | 
        
           |  |  | 1062 | 		printf ( "Error: Unable to add files, %s, to Multi-Spk Package\n", addfile.c_str() );
 | 
        
           |  |  | 1063 | }
 | 
        
           |  |  | 1064 |   | 
        
           |  |  | 1065 | /*
 | 
        
           |  |  | 1066 | 	Func:	ExtractFile
 | 
        
           |  |  | 1067 | 	Args:	String sfile	- the spk file to read from
 | 
        
           |  |  | 1068 | 			String type		- the type of the file to find
 | 
        
           |  |  | 1069 | 			String addfile	- The filename to extract
 | 
        
           |  |  | 1070 | 			String dir		- The directory to extract to
 | 
        
           |  |  | 1071 | 	Desc:	Finds and extracts a file from a Spk Package
 | 
        
           |  |  | 1072 | */
 | 
        
           | 134 | cycrow | 1073 | void ExtractFile (const Utils::String &sfile, const Utils::String &type, const Utils::String &addfile, const Utils::String &dir)
 | 
        
           | 1 | cycrow | 1074 | {
 | 
        
           |  |  | 1075 | 	// First checks if the file exists by opening it
 | 
        
           |  |  | 1076 | 	FILE *id = fopen ( sfile.c_str(), "rb+" );
 | 
        
           |  |  | 1077 | 	if ( !id )
 | 
        
           |  |  | 1078 | 	{
 | 
        
           |  |  | 1079 | 		printf ( "Error: File, %s, doesn't exist\n", sfile.c_str() );
 | 
        
           |  |  | 1080 | 		return;
 | 
        
           |  |  | 1081 | 	}
 | 
        
           |  |  | 1082 | 	fclose ( id );
 | 
        
           |  |  | 1083 |   | 
        
           |  |  | 1084 | 	// now check the type of file it is, using the static function CheckFile(filename).
 | 
        
           |  |  | 1085 | 	// This will return the type of file
 | 
        
           |  |  | 1086 | 	//		SPK_INVALID		- Invalid file format, wont be able to open
 | 
        
           |  |  | 1087 | 	//		SPK_SINGLE		- A Single spk package file
 | 
        
           |  |  | 1088 | 	//		SPK_MULTI		- A Multi-Spk Archive
 | 
        
           |  |  | 1089 | 	//		SPK_BASE		- A Base File
 | 
        
           |  |  | 1090 | 	//		SPK_SINGLESHIP	- A Ship file
 | 
        
           |  |  | 1091 | 	int check = CSpkFile::CheckFile ( sfile );
 | 
        
           |  |  | 1092 |   | 
        
           |  |  | 1093 | 	// extracts a file from single packages file
 | 
        
           |  |  | 1094 | 	if ( check == SPKFILE_SINGLE || check == SPKFILE_BASE || check == SPKFILE_SINGLESHIP )
 | 
        
           |  |  | 1095 | 	{
 | 
        
           |  |  | 1096 | 		// first get the file type is valid
 | 
        
           |  |  | 1097 | 		// converts the string type into its filetype flag
 | 
        
           | 170 | cycrow | 1098 | 		FileType t = GetFileTypeFromString(type);
 | 
        
           | 1 | cycrow | 1099 | 		// incorrect text type, display the error
 | 
        
           | 170 | cycrow | 1100 | 		if (t == FileType::FILETYPE_UNKNOWN)
 | 
        
           | 1 | cycrow | 1101 | 		{
 | 
        
           |  |  | 1102 | 			printf ( "The file type \"%s\" is invalid\n", type.c_str() );
 | 
        
           |  |  | 1103 | 			return;
 | 
        
           |  |  | 1104 | 		}
 | 
        
           |  |  | 1105 |   | 
        
           |  |  | 1106 | 		// creates the spkfile object
 | 
        
           |  |  | 1107 | 		CBaseFile *pBaseFile = 0;
 | 
        
           |  |  | 1108 | 		if ( check == SPKFILE_SINGLE )
 | 
        
           |  |  | 1109 | 			pBaseFile = (CBaseFile *)new CSpkFile();
 | 
        
           |  |  | 1110 | 		else if ( check == SPKFILE_SINGLESHIP )
 | 
        
           |  |  | 1111 | 			pBaseFile = (CBaseFile *)new CXspFile();
 | 
        
           |  |  | 1112 | 		else
 | 
        
           |  |  | 1113 | 			pBaseFile = new CBaseFile();
 | 
        
           |  |  | 1114 |   | 
        
           |  |  | 1115 | 		printf ( "Opening File, %s... ", sfile.c_str() );
 | 
        
           |  |  | 1116 | 		// reads the file into memory
 | 
        
           |  |  | 1117 | 		// the SPKREAD_NODATA flag causes it to just read the settings, and skips the file data
 | 
        
           | 175 | cycrow | 1118 | 		if ( !pBaseFile->readFile(sfile, SPKREAD_NODATA))
 | 
        
           | 1 | cycrow | 1119 | 		{
 | 
        
           |  |  | 1120 | 			printf ( "(Error)\nUnable to open the file, %s\n", sfile.c_str() );
 | 
        
           |  |  | 1121 | 			return;
 | 
        
           |  |  | 1122 | 		}
 | 
        
           |  |  | 1123 |   | 
        
           |  |  | 1124 | 		// No read all the file data into memory
 | 
        
           |  |  | 1125 | 		// This can be done all together in the ReadFile function
 | 
        
           |  |  | 1126 | 		// Doing it seperatly allows you to save time if an error occurs, so you dont have to wait for it to read the whole thing
 | 
        
           |  |  | 1127 | 		pBaseFile->ReadAllFilesToMemory ();
 | 
        
           |  |  | 1128 |   | 
        
           |  |  | 1129 | 		printf ( "(Done)\n" );
 | 
        
           |  |  | 1130 |   | 
        
           |  |  | 1131 | 		// uses the FindFile function to find the selected file in the archive
 | 
        
           |  |  | 1132 | 		// requires the filename, type and custom directory (only for Extra File Type)
 | 
        
           | 170 | cycrow | 1133 | 		C_File *f = pBaseFile->findFile(addfile, t);
 | 
        
           | 1 | cycrow | 1134 | 		if ( !f )
 | 
        
           |  |  | 1135 | 		{
 | 
        
           |  |  | 1136 | 			printf ( "Unable to find the file \"%s\" in the package\n", addfile.c_str() );
 | 
        
           |  |  | 1137 | 			return;
 | 
        
           |  |  | 1138 | 		}
 | 
        
           |  |  | 1139 |   | 
        
           |  |  | 1140 | 		// creates the directory so it can be extracted
 | 
        
           |  |  | 1141 | 		CDirIO Dir(dir);
 | 
        
           | 160 | cycrow | 1142 | 		if ( !Dir.create(f->getDirectory(pBaseFile)) )
 | 
        
           | 1 | cycrow | 1143 | 		{
 | 
        
           |  |  | 1144 | 			printf ( "Unable to create the directory \"%s\" to extract into\n", dir.c_str() );
 | 
        
           |  |  | 1145 | 			return;
 | 
        
           |  |  | 1146 | 		}
 | 
        
           |  |  | 1147 |   | 
        
           |  |  | 1148 | 		// sets up the progress pointer
 | 
        
           |  |  | 1149 | 		// if it uses 7zip, the progress will be displayed in the command prompt
 | 
        
           |  |  | 1150 | 		MyProgress progress(0);
 | 
        
           |  |  | 1151 | 		printf ( "Extracting the file from package\n\t>" );
 | 
        
           |  |  | 1152 |   | 
        
           |  |  | 1153 | 		// Extracts the file to the specified directory
 | 
        
           | 175 | cycrow | 1154 | 		if ( !pBaseFile->extractFile(f, dir, true, &progress))
 | 
        
           | 1 | cycrow | 1155 | 			printf ( "< (Error)\nUnable to extract the file\n" );
 | 
        
           |  |  | 1156 | 		else
 | 
        
           |  |  | 1157 | 		{
 | 
        
           |  |  | 1158 | 			progress.PrintDone ();
 | 
        
           |  |  | 1159 | 			printf ( "< (Done)\nFile has been extracted successfully\n" );
 | 
        
           |  |  | 1160 | 		}
 | 
        
           |  |  | 1161 | 	}
 | 
        
           |  |  | 1162 |   | 
        
           |  |  | 1163 | 	// the file is a Multi-Spk File, extracts a single spk file from the archive
 | 
        
           |  |  | 1164 | 	else if ( check == SPKFILE_MULTI )
 | 
        
           |  |  | 1165 | 	{
 | 
        
           |  |  | 1166 | 		// creates MultiSpkFile object
 | 
        
           |  |  | 1167 | 		CMultiSpkFile spkfile;
 | 
        
           |  |  | 1168 | 		printf ( "Opening Multi-SPK file, %s...", sfile.c_str() );
 | 
        
           |  |  | 1169 |   | 
        
           |  |  | 1170 | 		// reads the MultiSpkFile into memory
 | 
        
           | 177 | cycrow | 1171 | 		if ( !spkfile.readFile(sfile))
 | 
        
           | 1 | cycrow | 1172 | 		{
 | 
        
           |  |  | 1173 | 			printf ( "(Error)\nUnable to open the Multi-SPK file, %s\n", sfile.c_str() );
 | 
        
           |  |  | 1174 | 			return;
 | 
        
           |  |  | 1175 | 		}
 | 
        
           |  |  | 1176 | 		printf ( "(Done)\n" );
 | 
        
           |  |  | 1177 |   | 
        
           |  |  | 1178 | 		// searchs the archive for a matching file
 | 
        
           | 177 | cycrow | 1179 | 		const SMultiSpkFile *ms = spkfile.findFile(type);
 | 
        
           | 1 | cycrow | 1180 | 		if ( !ms )
 | 
        
           |  |  | 1181 | 		{
 | 
        
           |  |  | 1182 | 			printf ( "Unable to find the file \"%s\" in the package\n", type.c_str() );
 | 
        
           |  |  | 1183 | 			return;
 | 
        
           |  |  | 1184 | 		}
 | 
        
           |  |  | 1185 |   | 
        
           |  |  | 1186 | 		// extracts the file from the archive, to the given directory
 | 
        
           |  |  | 1187 | 		printf ( "Extracting SPK file, %s, from package... ", ms->sName.c_str() );
 | 
        
           | 177 | cycrow | 1188 | 		if (spkfile.extractFile(ms, addfile))
 | 
        
           | 1 | cycrow | 1189 | 			printf ( "(Done)\n" );
 | 
        
           |  |  | 1190 | 		else
 | 
        
           |  |  | 1191 | 			printf ( "(Error)\n" );
 | 
        
           |  |  | 1192 | 	}
 | 
        
           |  |  | 1193 | 	else
 | 
        
           |  |  | 1194 | 		printf ( "Error: Invalid file format, unable to open\n" );
 | 
        
           |  |  | 1195 | }
 | 
        
           |  |  | 1196 |   | 
        
           |  |  | 1197 | /*
 | 
        
           |  |  | 1198 | 	Func:	SplitMulti
 | 
        
           |  |  | 1199 | 	Args:	String filename - the filename of the multispk file to open
 | 
        
           |  |  | 1200 | 			String dest		- The destination directory to extract the files to
 | 
        
           |  |  | 1201 | 	Desc:	Splits a multi-spk file into its seperate spk files
 | 
        
           |  |  | 1202 | */
 | 
        
           |  |  | 1203 | void SplitMulti ( CyString filename, CyString dest )
 | 
        
           |  |  | 1204 | {
 | 
        
           |  |  | 1205 | 	// Check the file type, Must return SPKFILE_MULTI, otherwise its not a Multi-Spk Packages
 | 
        
           | 175 | cycrow | 1206 | 	if ( CSpkFile::CheckFile(filename.ToString()) != SPKFILE_MULTI )
 | 
        
           | 1 | cycrow | 1207 | 	{
 | 
        
           |  |  | 1208 | 		printf ( "Error: The file is not a Multi-Spk packages\n" );
 | 
        
           |  |  | 1209 | 		return;
 | 
        
           |  |  | 1210 | 	}
 | 
        
           |  |  | 1211 |   | 
        
           |  |  | 1212 | 	printf ( "Spliting Multi-SPK File to, %s... ", dest.c_str() );
 | 
        
           |  |  | 1213 |   | 
        
           |  |  | 1214 | 	// create the MultiSpkFile object
 | 
        
           |  |  | 1215 | 	CMultiSpkFile spkfile;
 | 
        
           |  |  | 1216 |   | 
        
           |  |  | 1217 | 	// Splits the files to the destination
 | 
        
           | 177 | cycrow | 1218 | 	if ( !spkfile.splitMulti(filename.ToString(), dest.ToString()))
 | 
        
           | 1 | cycrow | 1219 | 	{
 | 
        
           |  |  | 1220 | 		printf ( "(Error)\nUnable to split Multi-SPK package, %s\n", filename.c_str() );
 | 
        
           |  |  | 1221 | 		return;
 | 
        
           |  |  | 1222 | 	}
 | 
        
           |  |  | 1223 |   | 
        
           |  |  | 1224 | 	printf ( "(Done)\n" );
 | 
        
           |  |  | 1225 | }
 | 
        
           |  |  | 1226 |   | 
        
           | 197 | cycrow | 1227 | Utils::WString GetAsk(const Utils::WString &command)
 | 
        
           | 1 | cycrow | 1228 | {
 | 
        
           | 197 | cycrow | 1229 | 	wprintf(L"(ASK) Enter the value for, %s: ", command.c_str());
 | 
        
           | 1 | cycrow | 1230 | 	return GetInput();
 | 
        
           |  |  | 1231 | }
 | 
        
           |  |  | 1232 |   | 
        
           | 126 | cycrow | 1233 | void GenerateUpdateList(int argc, char **argv)
 | 
        
           |  |  | 1234 | {
 | 
        
           | 196 | cycrow | 1235 | 	Utils::WString currentDir = CFileIO(argv[0]).dir();
 | 
        
           | 126 | cycrow | 1236 | 	CDirIO Dir(currentDir);
 | 
        
           |  |  | 1237 |   | 
        
           | 196 | cycrow | 1238 | 	Utils::WStringList list;
 | 
        
           | 126 | cycrow | 1239 | 	for (int i = 2; i < argc; ++i)
 | 
        
           |  |  | 1240 | 	{
 | 
        
           |  |  | 1241 | 		Utils::String file(argv[i]);
 | 
        
           |  |  | 1242 | 		if (CFileIO::Exists(file))
 | 
        
           | 196 | cycrow | 1243 | 			list.pushBack(file, L"file");
 | 
        
           | 126 | cycrow | 1244 | 		else if (CFileIO::Exists(Dir.file(file)))
 | 
        
           | 196 | cycrow | 1245 | 			list.pushBack(Dir.file(file), L"file");
 | 
        
           | 126 | cycrow | 1246 | 		else if (CDirIO::Exists(file))
 | 
        
           | 196 | cycrow | 1247 | 			list.pushBack(file, L"dir");
 | 
        
           | 126 | cycrow | 1248 | 		else if (CDirIO::Exists(Dir.dir(file)))
 | 
        
           | 196 | cycrow | 1249 | 			list.pushBack(Dir.dir(file), L"dir");
 | 
        
           | 126 | cycrow | 1250 | 		else
 | 
        
           | 196 | cycrow | 1251 | 			list.pushBack(file, L"pattern");
 | 
        
           | 126 | cycrow | 1252 | 	}
 | 
        
           |  |  | 1253 |   | 
        
           |  |  | 1254 | 	if (list.empty())
 | 
        
           |  |  | 1255 | 		printf("unable to find any packages");
 | 
        
           |  |  | 1256 | 	else
 | 
        
           |  |  | 1257 | 	{
 | 
        
           | 196 | cycrow | 1258 | 		Utils::WStringList fileList;
 | 
        
           | 126 | cycrow | 1259 | 		for (auto itr = list.begin(); itr != list.end(); itr++)
 | 
        
           |  |  | 1260 | 		{
 | 
        
           | 196 | cycrow | 1261 | 			Utils::WString file = (*itr)->str;
 | 
        
           |  |  | 1262 | 			Utils::WString data = (*itr)->data;
 | 
        
           |  |  | 1263 | 			if (data == L"file")
 | 
        
           | 126 | cycrow | 1264 | 				fileList.pushBack(file);
 | 
        
           | 196 | cycrow | 1265 | 			else if (data == L"dir")
 | 
        
           | 126 | cycrow | 1266 | 			{
 | 
        
           |  |  | 1267 | 				CDirIO dir(file);
 | 
        
           | 196 | cycrow | 1268 | 				Utils::WStringList d;
 | 
        
           | 126 | cycrow | 1269 | 				if (dir.dirList(d))
 | 
        
           |  |  | 1270 | 				{
 | 
        
           |  |  | 1271 | 					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
 | 
        
           |  |  | 1272 | 					{
 | 
        
           | 196 | cycrow | 1273 | 						Utils::WString ext = CFileIO((*itr2)->str).extension().lower();
 | 
        
           |  |  | 1274 | 						if(ext == L"xsp" || ext == L"spk")
 | 
        
           | 126 | cycrow | 1275 | 							fileList.pushBack(dir.file((*itr2)->str));
 | 
        
           |  |  | 1276 | 					}
 | 
        
           |  |  | 1277 | 				}
 | 
        
           |  |  | 1278 | 			}
 | 
        
           |  |  | 1279 | 			else if (data == "pattern")
 | 
        
           |  |  | 1280 | 			{				
 | 
        
           |  |  | 1281 | 				CFileIO f(file);
 | 
        
           |  |  | 1282 | 				CDirIO dir(f.dir());
 | 
        
           |  |  | 1283 |   | 
        
           |  |  | 1284 | 				if (!dir.exists())
 | 
        
           |  |  | 1285 | 					dir = CDirIO(Dir.dir(dir.dir()));
 | 
        
           |  |  | 1286 |   | 
        
           | 196 | cycrow | 1287 | 				Utils::WStringList d;
 | 
        
           |  |  | 1288 | 				if (dir.dirList(d, Utils::WString::Null(), f.filename()))
 | 
        
           | 126 | cycrow | 1289 | 				{
 | 
        
           |  |  | 1290 | 					for (auto itr2 = d.begin(); itr2 != d.end(); itr2++)
 | 
        
           |  |  | 1291 | 					{
 | 
        
           | 196 | cycrow | 1292 | 						Utils::WString ext = CFileIO((*itr2)->str).extension().lower();
 | 
        
           |  |  | 1293 | 						if (ext == L"xsp" || ext == L"spk")
 | 
        
           | 126 | cycrow | 1294 | 							fileList.pushBack(dir.file((*itr2)->str));
 | 
        
           |  |  | 1295 | 					}
 | 
        
           |  |  | 1296 | 				}
 | 
        
           |  |  | 1297 | 			}
 | 
        
           |  |  | 1298 | 		}
 | 
        
           |  |  | 1299 |   | 
        
           |  |  | 1300 | 		if (fileList.empty())
 | 
        
           |  |  | 1301 | 			printf("unable to find any packages");
 | 
        
           |  |  | 1302 | 		else
 | 
        
           |  |  | 1303 | 		{
 | 
        
           |  |  | 1304 | 			CPackages packages;
 | 
        
           |  |  | 1305 |   | 
        
           | 197 | cycrow | 1306 | 			Utils::WStringList filedata;
 | 
        
           | 126 | cycrow | 1307 | 			for (auto itr = fileList.begin(); itr != fileList.end(); itr++)
 | 
        
           |  |  | 1308 | 			{
 | 
        
           | 196 | cycrow | 1309 | 				wprintf(L"Reading file: %s\n", (*itr)->str.c_str());
 | 
        
           | 126 | cycrow | 1310 |   | 
        
           |  |  | 1311 | 				int error = 0;
 | 
        
           | 196 | cycrow | 1312 | 				CBaseFile *p = packages.openPackage((*itr)->str.toString(), &error, 0, SPKREAD_NODATA);
 | 
        
           | 126 | cycrow | 1313 | 				if (!p)
 | 
        
           |  |  | 1314 | 				{
 | 
        
           |  |  | 1315 | 					printf("\tERROR!\n");
 | 
        
           |  |  | 1316 | 					continue;
 | 
        
           |  |  | 1317 | 				}
 | 
        
           | 204 | cycrow | 1318 | 				wprintf(L"\tData extracted: %s %s by %s\n", p->name().c_str(), p->version().c_str(), p->author().c_str());
 | 
        
           | 126 | cycrow | 1319 | 				if (!p->creationDate().empty())
 | 
        
           | 204 | cycrow | 1320 | 					wprintf(L"\t\tCreated: %s\n", p->creationDate().c_str());
 | 
        
           | 126 | cycrow | 1321 | 				if(!p->description().empty())
 | 
        
           | 206 | cycrow | 1322 | 					wprintf(L"\t\t%s\n", p->description().c_str());
 | 
        
           | 126 | cycrow | 1323 |   | 
        
           |  |  | 1324 | 				filedata.pushBack(CPackages::FormatAvailablePackageData(p));
 | 
        
           |  |  | 1325 | 				delete p;
 | 
        
           |  |  | 1326 | 			}
 | 
        
           |  |  | 1327 |   | 
        
           |  |  | 1328 | 			if (filedata.empty())
 | 
        
           |  |  | 1329 | 				printf("unable to find any packages");
 | 
        
           |  |  | 1330 | 			else				
 | 
        
           |  |  | 1331 | 			{
 | 
        
           | 196 | cycrow | 1332 | 				Utils::WString dest = Dir.file("xpackagedata.dat");
 | 
        
           | 126 | cycrow | 1333 | 				if (CFileIO(dest).writeFile(&filedata))
 | 
        
           |  |  | 1334 | 					printf("web update file, xpackagedata.dat, generated");
 | 
        
           |  |  | 1335 | 				else
 | 
        
           |  |  | 1336 | 					printf("unable to write update file");
 | 
        
           |  |  | 1337 | 			}
 | 
        
           |  |  | 1338 | 		}
 | 
        
           |  |  | 1339 | 	}
 | 
        
           |  |  | 1340 | }
 | 
        
           |  |  | 1341 |   | 
        
           | 196 | cycrow | 1342 | void GenerateUpdateFile(const Utils::WString &spkfile)
 | 
        
           | 1 | cycrow | 1343 | {
 | 
        
           | 182 | cycrow | 1344 | 	if (!CFileIO::Exists(spkfile))
 | 
        
           | 1 | cycrow | 1345 | 	{
 | 
        
           | 196 | cycrow | 1346 | 		wprintf(L"Error: The package file, %s, does not exist", spkfile.c_str());
 | 
        
           | 1 | cycrow | 1347 | 		return;
 | 
        
           |  |  | 1348 | 	}
 | 
        
           |  |  | 1349 |   | 
        
           | 197 | cycrow | 1350 | 	int check = CSpkFile::CheckFile(spkfile);
 | 
        
           | 1 | cycrow | 1351 | 	if ( check == SPKFILE_MULTI )
 | 
        
           |  |  | 1352 | 	{
 | 
        
           |  |  | 1353 | 		printf("Error: Multi-Package files currently not supported\n");
 | 
        
           |  |  | 1354 | 		return;
 | 
        
           |  |  | 1355 | 	}
 | 
        
           |  |  | 1356 | 	else if ( check == SPKFILE_OLD )
 | 
        
           |  |  | 1357 | 	{
 | 
        
           |  |  | 1358 | 		printf("Error: unable to read old format spk file, try spkconvert first\n");
 | 
        
           |  |  | 1359 | 		return;
 | 
        
           |  |  | 1360 | 	}
 | 
        
           |  |  | 1361 | 	else if ( check == SPKFILE_INVALID )
 | 
        
           |  |  | 1362 | 	{
 | 
        
           | 196 | cycrow | 1363 | 		wprintf(L"Error: %s doesn't appear to be a valid package file\n", spkfile.c_str());
 | 
        
           | 1 | cycrow | 1364 | 		return;
 | 
        
           |  |  | 1365 | 	}
 | 
        
           |  |  | 1366 |   | 
        
           |  |  | 1367 | 	CPackages p;
 | 
        
           |  |  | 1368 | 	int error;
 | 
        
           | 196 | cycrow | 1369 | 	CBaseFile *package = p.openPackage(spkfile.toString(), &error, 0, SPKREAD_NODATA);
 | 
        
           | 1 | cycrow | 1370 | 	if ( !package )
 | 
        
           |  |  | 1371 | 	{
 | 
        
           | 196 | cycrow | 1372 | 		wprintf(L"Error: unable to open package file, %s, Error=%d\n", spkfile.c_str(), error);
 | 
        
           | 1 | cycrow | 1373 | 		return;
 | 
        
           |  |  | 1374 | 	}
 | 
        
           |  |  | 1375 |   | 
        
           | 196 | cycrow | 1376 | 	Utils::WString file = package->createUpdateFile(CFileIO(spkfile).dir());
 | 
        
           | 102 | cycrow | 1377 | 	if ( file.empty() )
 | 
        
           | 196 | cycrow | 1378 | 		wprintf(L"Error: unable to create update file for: %s, Directory=%s\n", spkfile.c_str(), CFileIO(spkfile).dir().c_str());
 | 
        
           | 1 | cycrow | 1379 | 	else
 | 
        
           | 196 | cycrow | 1380 | 		wprintf(L"Update file: %s has been created for package, %s\n", file.c_str(), spkfile.c_str());
 | 
        
           | 1 | cycrow | 1381 |   | 
        
           |  |  | 1382 | 	delete package;
 | 
        
           |  |  | 1383 |   | 
        
           |  |  | 1384 | }
 | 
        
           |  |  | 1385 |   | 
        
           | 126 | cycrow | 1386 | void GeneratePackagerScript(const Utils::String &spkfile, CyString toFile, int game)
 | 
        
           | 1 | cycrow | 1387 | {
 | 
        
           | 126 | cycrow | 1388 | 	if (!CFileIO::Exists(spkfile))
 | 
        
           | 1 | cycrow | 1389 | 	{
 | 
        
           |  |  | 1390 | 		printf("Error: The package file, %s, does not exist", spkfile.c_str());
 | 
        
           |  |  | 1391 | 		return;
 | 
        
           |  |  | 1392 | 	}
 | 
        
           |  |  | 1393 |   | 
        
           |  |  | 1394 | 	int check = CSpkFile::CheckFile(spkfile);
 | 
        
           |  |  | 1395 | 	if ( check == SPKFILE_MULTI )
 | 
        
           |  |  | 1396 | 	{
 | 
        
           |  |  | 1397 | 		printf("Error: Cant generate a script from a multi-spk file\n");
 | 
        
           |  |  | 1398 | 		return;
 | 
        
           |  |  | 1399 | 	}
 | 
        
           |  |  | 1400 | 	else if ( check == SPKFILE_OLD )
 | 
        
           |  |  | 1401 | 	{
 | 
        
           |  |  | 1402 | 		printf("Error: unable to read old format spk file, try spkconvert first\n");
 | 
        
           |  |  | 1403 | 		return;
 | 
        
           |  |  | 1404 | 	}
 | 
        
           |  |  | 1405 | 	else if ( check == SPKFILE_INVALID )
 | 
        
           |  |  | 1406 | 	{
 | 
        
           |  |  | 1407 | 		printf("Error: %s doesn't appear to be a spk file\n", spkfile.c_str());
 | 
        
           |  |  | 1408 | 		return;
 | 
        
           |  |  | 1409 | 	}
 | 
        
           |  |  | 1410 |   | 
        
           |  |  | 1411 | 	CPackages p;
 | 
        
           | 127 | cycrow | 1412 | 	p.startup(".", ".", ".");
 | 
        
           | 1 | cycrow | 1413 | 	int error;
 | 
        
           | 182 | cycrow | 1414 | 	CBaseFile *package = p.openPackage(spkfile, &error, 0, SPKREAD_NODATA);
 | 
        
           | 1 | cycrow | 1415 | 	if ( !package )
 | 
        
           |  |  | 1416 | 	{
 | 
        
           |  |  | 1417 | 		printf("Error: unable to open package files, %s, Error=%d\n", spkfile.c_str(), error);
 | 
        
           |  |  | 1418 | 		return;
 | 
        
           |  |  | 1419 | 	}
 | 
        
           |  |  | 1420 |   | 
        
           | 210 | cycrow | 1421 | 	Utils::WStringList list;
 | 
        
           | 127 | cycrow | 1422 | 	if ( !p.generatePackagerScript(package, true, &list, game) )
 | 
        
           | 1 | cycrow | 1423 | 	{
 | 
        
           |  |  | 1424 | 		printf("Error: Unable to generate packager script\n");
 | 
        
           |  |  | 1425 | 		return;
 | 
        
           |  |  | 1426 | 	}
 | 
        
           |  |  | 1427 |   | 
        
           |  |  | 1428 | 	if ( toFile.Empty() )
 | 
        
           | 210 | cycrow | 1429 | 		toFile = CFileIO(spkfile).GetDirIO().file(package->name() + L"_" + package->author() + L".sps").toString();
 | 
        
           | 1 | cycrow | 1430 |   | 
        
           |  |  | 1431 | 	// save package file
 | 
        
           | 185 | cycrow | 1432 | 	if ( CFileIO(toFile.ToString()).writeFile(&list) )
 | 
        
           | 1 | cycrow | 1433 | 		printf("Packager script, %s, has been geenrated\n", toFile.c_str());
 | 
        
           |  |  | 1434 | 	else
 | 
        
           |  |  | 1435 | 		printf("Error: unable to write packager script, %s\n", toFile.c_str());
 | 
        
           |  |  | 1436 |   | 
        
           |  |  | 1437 | 	delete package;
 | 
        
           |  |  | 1438 | }
 | 
        
           |  |  | 1439 |   | 
        
           |  |  | 1440 | /*
 | 
        
           |  |  | 1441 | 	Func:	LoadPackagerScript
 | 
        
           |  |  | 1442 | 	Args:	String filename	-	The filename of the packager script to load
 | 
        
           |  |  | 1443 | 	Desc:	Loads the packager scripts and creates a spk/xsp file from it
 | 
        
           |  |  | 1444 | */
 | 
        
           | 197 | cycrow | 1445 | void LoadPackagerScript(const Utils::WString &filename, bool verify)
 | 
        
           | 1 | cycrow | 1446 | {
 | 
        
           | 131 | cycrow | 1447 | 	if ( !CFileIO::Exists(filename) )
 | 
        
           | 1 | cycrow | 1448 | 	{
 | 
        
           | 197 | cycrow | 1449 | 		wprintf(L"Error: The packager script, %s, does not exist", filename.c_str());
 | 
        
           | 1 | cycrow | 1450 | 		return;
 | 
        
           |  |  | 1451 | 	}
 | 
        
           |  |  | 1452 |   | 
        
           | 197 | cycrow | 1453 | 	Utils::WString myDoc;
 | 
        
           | 1 | cycrow | 1454 | #ifdef _WIN32
 | 
        
           |  |  | 1455 | 	TCHAR pszPath[MAX_PATH];
 | 
        
           |  |  | 1456 | 	if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, pszPath)))
 | 
        
           |  |  | 1457 | 	{
 | 
        
           |  |  | 1458 | 		myDoc = (char *)pszPath;
 | 
        
           |  |  | 1459 | 	}
 | 
        
           |  |  | 1460 | #endif
 | 
        
           |  |  | 1461 |   | 
        
           |  |  | 1462 | 	if ( verify )
 | 
        
           | 197 | cycrow | 1463 | 		wprintf(L"Verifying Packager Script: %s\n", filename.c_str());
 | 
        
           | 1 | cycrow | 1464 |   | 
        
           |  |  | 1465 | 	CPackages p;
 | 
        
           | 197 | cycrow | 1466 | 	p.startup(L".", L".", myDoc);
 | 
        
           |  |  | 1467 | 	Utils::WStringList malformed, unknown;
 | 
        
           | 1 | cycrow | 1468 |   | 
        
           | 197 | cycrow | 1469 | 	Utils::WString curDir = CFileIO(filename).dir();
 | 
        
           | 196 | cycrow | 1470 | 	if ( curDir.empty() ) curDir = L"./";
 | 
        
           | 1 | cycrow | 1471 |   | 
        
           | 197 | cycrow | 1472 | 	Utils::WStringList variables;
 | 
        
           |  |  | 1473 | 	variables.pushBack(L"$PATH", curDir);
 | 
        
           | 1 | cycrow | 1474 |   | 
        
           | 134 | cycrow | 1475 | 	CFileProgress info(&p, NULL, "Adding File");
 | 
        
           | 197 | cycrow | 1476 | 	CBaseFile *package = p.loadPackagerScript(filename, -1, (verify) ? NULL : &GetAsk, &malformed, &unknown, &variables, &info);
 | 
        
           | 1 | cycrow | 1477 |   | 
        
           | 134 | cycrow | 1478 | 	printf("\n");
 | 
        
           |  |  | 1479 |   | 
        
           | 1 | cycrow | 1480 | 	if ( verify )
 | 
        
           |  |  | 1481 | 	{
 | 
        
           | 131 | cycrow | 1482 | 		if ( !malformed.empty() )
 | 
        
           | 1 | cycrow | 1483 | 		{
 | 
        
           | 131 | cycrow | 1484 | 			printf("Malformed Lines (%d):\n", malformed.size());
 | 
        
           |  |  | 1485 | 			for(auto itr = malformed.begin(); itr != malformed.end(); itr++)				
 | 
        
           | 197 | cycrow | 1486 | 				wprintf(L"\t(Line %3d) %s\n", (*itr)->data.toInt(), (*itr)->str.c_str());
 | 
        
           | 1 | cycrow | 1487 | 		}
 | 
        
           | 131 | cycrow | 1488 | 		if ( !unknown.empty() )
 | 
        
           | 1 | cycrow | 1489 | 		{
 | 
        
           | 131 | cycrow | 1490 | 			printf("Unknown Commands (%d):\n", unknown.size());
 | 
        
           |  |  | 1491 | 			for (auto itr = unknown.begin(); itr != unknown.end(); itr++)
 | 
        
           | 197 | cycrow | 1492 | 				wprintf(L"\t* Command: %s = %s\n", (*itr)->str.c_str(), (*itr)->data.c_str());
 | 
        
           | 1 | cycrow | 1493 | 		}
 | 
        
           |  |  | 1494 | 	}
 | 
        
           |  |  | 1495 |   | 
        
           |  |  | 1496 | 	if ( !package )
 | 
        
           |  |  | 1497 | 	{
 | 
        
           |  |  | 1498 | 		if ( verify )
 | 
        
           |  |  | 1499 | 			printf("Error: There are errors in the packager script which prevents it from being created\n");
 | 
        
           |  |  | 1500 | 		else
 | 
        
           | 197 | cycrow | 1501 | 			wprintf(L"Error: Unable to create package, from script: %s\n", filename.c_str());
 | 
        
           | 1 | cycrow | 1502 | 	}
 | 
        
           |  |  | 1503 | 	else
 | 
        
           |  |  | 1504 | 	{
 | 
        
           | 197 | cycrow | 1505 | 		Utils::WString saveto = package->filename();
 | 
        
           |  |  | 1506 | 		saveto = saveto.findReplace(L"$DEFAULTDIR", curDir + L"/");
 | 
        
           |  |  | 1507 | 		saveto = saveto.findReplace(L"$PATH", curDir);
 | 
        
           |  |  | 1508 | 		saveto = saveto.findReplace(L"\\", L"/");
 | 
        
           |  |  | 1509 | 		saveto = saveto.findReplace(L"//", L"/");
 | 
        
           |  |  | 1510 | 		if ( !saveto.right(4).Compare(L".spk") && package->GetType() != TYPE_XSP )
 | 
        
           |  |  | 1511 | 			saveto += L".spk";
 | 
        
           |  |  | 1512 | 		else if ( !saveto.right(4).Compare(L".xsp") && package->GetType() == TYPE_XSP )
 | 
        
           |  |  | 1513 | 			saveto += L".xsp";
 | 
        
           | 196 | cycrow | 1514 | 		wprintf(L"Saving file to: %s\n", CFileIO(saveto).fullFilename().c_str());
 | 
        
           | 1 | cycrow | 1515 | 		if ( verify )
 | 
        
           |  |  | 1516 | 			printf("Package can be created from this script\n");
 | 
        
           |  |  | 1517 | 		else
 | 
        
           |  |  | 1518 | 		{
 | 
        
           |  |  | 1519 | 			// write script
 | 
        
           | 197 | cycrow | 1520 | 			if ( package->writeFile(saveto.toString()) )
 | 
        
           | 1 | cycrow | 1521 | 			{
 | 
        
           |  |  | 1522 | 				if ( package->AutoGenerateUpdateFile() )
 | 
        
           | 134 | cycrow | 1523 | 					package->createUpdateFile(CFileIO(saveto).dir());
 | 
        
           | 197 | cycrow | 1524 | 				wprintf(L"Package: %s was created\n", saveto.c_str());
 | 
        
           | 1 | cycrow | 1525 | 			}
 | 
        
           |  |  | 1526 | 			else
 | 
        
           |  |  | 1527 | 				printf("Error! There was a problem writing the package\n");
 | 
        
           |  |  | 1528 | 		}
 | 
        
           |  |  | 1529 |   | 
        
           | 204 | cycrow | 1530 | 		saveto = package->exportFilename();
 | 
        
           | 131 | cycrow | 1531 | 		if ( !saveto.empty() ) {
 | 
        
           | 197 | cycrow | 1532 | 			saveto = saveto.findReplace(L"$DEFAULTDIR", curDir + L"/");
 | 
        
           |  |  | 1533 | 			saveto = saveto.findReplace(L"$PATH", curDir);
 | 
        
           |  |  | 1534 | 			saveto = saveto.findReplace(L"\\", L"/");
 | 
        
           |  |  | 1535 | 			saveto = saveto.findReplace(L"//", L"/");
 | 
        
           | 196 | cycrow | 1536 | 			wprintf(L"Exporting file to: %s\n", CFileIO(saveto).fullFilename().c_str());
 | 
        
           | 1 | cycrow | 1537 | 			if ( verify )
 | 
        
           |  |  | 1538 | 				printf("Package can be exported from this script\n");
 | 
        
           |  |  | 1539 | 			else
 | 
        
           |  |  | 1540 | 			{
 | 
        
           |  |  | 1541 | 				// export
 | 
        
           | 197 | cycrow | 1542 | 				if ( package->saveToArchive(saveto.toString(), 0, p.GetGameExe())) {
 | 
        
           | 1 | cycrow | 1543 | 					if ( package->IsAnyGameInPackage() ) {
 | 
        
           | 197 | cycrow | 1544 | 						for ( int i = 0; i < p.GetGameExe()->numGames(); i++ ) {
 | 
        
           | 1 | cycrow | 1545 | 							if ( package->IsGameInPackage(i + 1) ) {								
 | 
        
           | 197 | cycrow | 1546 | 								Utils::WString exportFile = CFileIO(saveto).dir() + L"/" + CFileIO(saveto).baseName() + L"_" + CBaseFile::ConvertGameToString(i + 1) + L"." + CFileIO(saveto).extension();
 | 
        
           | 196 | cycrow | 1547 | 								package->saveToArchive(exportFile.toString(), i + 1, p.GetGameExe());
 | 
        
           | 1 | cycrow | 1548 | 							}
 | 
        
           |  |  | 1549 | 						}
 | 
        
           |  |  | 1550 | 					}
 | 
        
           | 197 | cycrow | 1551 | 					wprintf(L"Package: %s was exported\n", saveto.c_str());
 | 
        
           | 1 | cycrow | 1552 | 				}
 | 
        
           |  |  | 1553 | 				else
 | 
        
           |  |  | 1554 | 					printf("Error! There was a problem exporting the package\n");
 | 
        
           |  |  | 1555 | 			}
 | 
        
           |  |  | 1556 | 		}
 | 
        
           |  |  | 1557 | 	}
 | 
        
           |  |  | 1558 | }
 | 
        
           |  |  | 1559 |   | 
        
           |  |  | 1560 | /*
 | 
        
           |  |  | 1561 | 	Main entry point to program
 | 
        
           |  |  | 1562 | */
 | 
        
           |  |  | 1563 | int main ( int argc, char **argv )
 | 
        
           |  |  | 1564 | {
 | 
        
           |  |  | 1565 | 	// display program header to command prompt
 | 
        
           | 126 | cycrow | 1566 | 	printf ( "\nSPKTool V1.50 (SPK File Version %.2f) 14/02/2021 Created by Cycrow\n\n", (float)FILEVERSION );
 | 
        
           | 1 | cycrow | 1567 |   | 
        
           |  |  | 1568 | 	// parse the cmd name
 | 
        
           | 197 | cycrow | 1569 | 	Utils::WString cmd (argv[0]);
 | 
        
           |  |  | 1570 | 	cmd = cmd.findReplace(L"\\", L"/");
 | 
        
           |  |  | 1571 | 	g_dir = cmd.tokens(L"/", 1, cmd.countToken(L"/") - 1);
 | 
        
           |  |  | 1572 | 	cmd = cmd.token(L"/", cmd.countToken(L"/"));
 | 
        
           | 1 | cycrow | 1573 |   | 
        
           |  |  | 1574 | 	g_read = false;
 | 
        
           |  |  | 1575 |   | 
        
           |  |  | 1576 | 	// not enough arguments, display the syntax and exit
 | 
        
           |  |  | 1577 | 	if ( argc < 2 )
 | 
        
           |  |  | 1578 | 	{
 | 
        
           | 197 | cycrow | 1579 | 		PrintSyntax ( cmd.toString() );
 | 
        
           | 1 | cycrow | 1580 | 		exit ( 1 );
 | 
        
           |  |  | 1581 | 	}
 | 
        
           |  |  | 1582 |   | 
        
           | 197 | cycrow | 1583 | 	Utils::WString fileTypes;
 | 
        
           | 1 | cycrow | 1584 | 	for ( int i = 0; i < FILETYPE_MAX; i++ )
 | 
        
           |  |  | 1585 | 	{
 | 
        
           | 197 | cycrow | 1586 | 		Utils::WString sT = GetFileTypeString(i);
 | 
        
           |  |  | 1587 | 		if ( !sT.empty() )
 | 
        
           | 1 | cycrow | 1588 | 		{
 | 
        
           | 197 | cycrow | 1589 | 			if ( fileTypes.empty() )
 | 
        
           | 1 | cycrow | 1590 | 				fileTypes = sT;
 | 
        
           |  |  | 1591 | 			else
 | 
        
           |  |  | 1592 | 			{
 | 
        
           | 197 | cycrow | 1593 | 				fileTypes += L", ";
 | 
        
           | 1 | cycrow | 1594 | 				fileTypes += sT;
 | 
        
           |  |  | 1595 | 			}
 | 
        
           |  |  | 1596 | 		}
 | 
        
           |  |  | 1597 | 	}
 | 
        
           |  |  | 1598 |   | 
        
           |  |  | 1599 | 	// get the command flag
 | 
        
           | 197 | cycrow | 1600 | 	Utils::WString command(argv[1]);
 | 
        
           | 1 | cycrow | 1601 |   | 
        
           |  |  | 1602 | 	// display the contents of the spk file
 | 
        
           | 197 | cycrow | 1603 | 	if ( command == L"-v" || command == L"--view" || command == L"--version")
 | 
        
           | 1 | cycrow | 1604 | 	{
 | 
        
           |  |  | 1605 | 		if ( argc < 3 )
 | 
        
           | 197 | cycrow | 1606 | 			wprintf(L"Syntax: %s -v <spkfile>\n\tWill open and display the contents of the spkfile\n", cmd.c_str() );
 | 
        
           | 1 | cycrow | 1607 | 		else
 | 
        
           | 134 | cycrow | 1608 | 			DisplayVersion(argv[2]);
 | 
        
           | 1 | cycrow | 1609 | 	}
 | 
        
           |  |  | 1610 |   | 
        
           |  |  | 1611 | 	// creates a new spk file
 | 
        
           | 197 | cycrow | 1612 | 	else if ( command == L"-c" || command == L"--create" )
 | 
        
           | 1 | cycrow | 1613 | 	{
 | 
        
           |  |  | 1614 | 		if ( argc < 3 )
 | 
        
           | 197 | cycrow | 1615 | 			wprintf(L"Syntax:\n\t%s -c <spkfile>\n\t%s --create <spkfile>\n\t\tThis will create a new SPK file and allow you to set some basic settings for the file\n", cmd.c_str(), cmd.c_str() );
 | 
        
           | 1 | cycrow | 1616 | 		else
 | 
        
           |  |  | 1617 | 			CreateFile ( argv[2] );
 | 
        
           |  |  | 1618 | 	}
 | 
        
           |  |  | 1619 |   | 
        
           |  |  | 1620 | 	// appends a file onto the spk archive
 | 
        
           | 197 | cycrow | 1621 | 	else if ( command == L"-a" || command == L"--append" )
 | 
        
           | 1 | cycrow | 1622 | 	{
 | 
        
           |  |  | 1623 | 		if ( argc < 4 )
 | 
        
           | 197 | cycrow | 1624 | 			wprintf(L"Syntax:\n\t%s -a <spkfile> <type> <filename>\n\t%s --append <spkfile> <type> <filename>\n\t\tThis will append the file into the archive and compress it according to the files default compression\n\t<type> = %s\n", cmd.c_str(), cmd.c_str(), fileTypes.c_str() );
 | 
        
           | 1 | cycrow | 1625 | 		else
 | 
        
           |  |  | 1626 | 		{
 | 
        
           |  |  | 1627 | 			CyString arg4;
 | 
        
           |  |  | 1628 | 			if ( argc > 4 )
 | 
        
           |  |  | 1629 | 				arg4 = argv[4];
 | 
        
           |  |  | 1630 | 			AppendFile ( argv[2], argv[3], arg4 );
 | 
        
           |  |  | 1631 | 		}
 | 
        
           |  |  | 1632 | 	}
 | 
        
           |  |  | 1633 |   | 
        
           |  |  | 1634 | 	// removes a file from the spk archive
 | 
        
           | 197 | cycrow | 1635 | 	else if ( command == L"-r" || command == L"--remove" || command == L"--removespk" )
 | 
        
           | 1 | cycrow | 1636 | 	{
 | 
        
           |  |  | 1637 | 		if ( argc < 4 )
 | 
        
           |  |  | 1638 | 		{
 | 
        
           | 197 | cycrow | 1639 | 			wprintf(L"Syntax:\n\t%s -r <spkfile> <type> <filename>\n\t%s --remove <spkfile> <type> <filename\n\t\tThis will remove a file from the archive\n\t<type> = %s\n", cmd.c_str(), cmd.c_str(), fileTypes.c_str() );
 | 
        
           |  |  | 1640 | 			wprintf(L"\t%s -r <multispkfile> <filename>\n\t%s --removespk <multispkfile> <filename>\n\t\tThis will remove a spk file from the Multi-SPK package\n", cmd.c_str(), cmd.c_str() );
 | 
        
           | 1 | cycrow | 1641 | 		}
 | 
        
           |  |  | 1642 | 		else
 | 
        
           |  |  | 1643 | 		{
 | 
        
           |  |  | 1644 | 			CyString arg4;
 | 
        
           |  |  | 1645 | 			if ( argc > 4 )
 | 
        
           |  |  | 1646 | 				arg4 = argv[4];
 | 
        
           |  |  | 1647 | 			RemoveFile ( argv[2], argv[3], arg4 );
 | 
        
           |  |  | 1648 | 		}
 | 
        
           |  |  | 1649 | 	}
 | 
        
           |  |  | 1650 |   | 
        
           |  |  | 1651 | 	// extracts a file from a spk file
 | 
        
           | 197 | cycrow | 1652 | 	else if ( command == L"--extractspk" )
 | 
        
           | 1 | cycrow | 1653 | 	{
 | 
        
           |  |  | 1654 | 		if ( argc < 4 )
 | 
        
           | 197 | cycrow | 1655 | 			wprintf(L"Syntax:\n\t%s --extractspk <multispkfile> <filename> [destination]\n\tThis will extract a spk file from the Multi-Spk package and save it to the destination path\n", cmd.c_str() );
 | 
        
           | 1 | cycrow | 1656 | 		else
 | 
        
           |  |  | 1657 | 		{
 | 
        
           | 134 | cycrow | 1658 | 			Utils::String arg4;
 | 
        
           | 1 | cycrow | 1659 | 			if ( argc > 4 )
 | 
        
           |  |  | 1660 | 				arg4 = argv[3];
 | 
        
           | 134 | cycrow | 1661 | 			ExtractFile(argv[2], argv[3], arg4, Utils::String::Null());
 | 
        
           | 1 | cycrow | 1662 | 		}
 | 
        
           |  |  | 1663 | 	}
 | 
        
           | 197 | cycrow | 1664 | 	else if ( command == L"-x" || command == L"--extract")
 | 
        
           | 1 | cycrow | 1665 | 	{
 | 
        
           |  |  | 1666 | 		if ( argc < 4 )
 | 
        
           |  |  | 1667 | 		{
 | 
        
           | 197 | cycrow | 1668 | 			wprintf(L"Syntax:\n\t%s -x <spkfile> <type> <filename> [destination]\n\tThis will extract a file from the package and save it to the corect path in <directory>\n\t<type> = %s\n", cmd.c_str(), fileTypes.c_str() );
 | 
        
           |  |  | 1669 | 			wprintf(L"\t%s -x <multispkfile> <filename> [destination]\n\tThis will extract a spk file from the Multi-Spk package and save it to the destination path\n", cmd.c_str() );
 | 
        
           | 1 | cycrow | 1670 | 		}
 | 
        
           |  |  | 1671 | 		else
 | 
        
           |  |  | 1672 | 		{
 | 
        
           | 134 | cycrow | 1673 | 			Utils::String arg5, arg4;
 | 
        
           | 1 | cycrow | 1674 | 			if ( argc > 5 )
 | 
        
           |  |  | 1675 | 				arg5 = argv[5];
 | 
        
           |  |  | 1676 | 			if ( argc > 4 )
 | 
        
           |  |  | 1677 | 				arg4 = argv[4];
 | 
        
           | 134 | cycrow | 1678 | 			ExtractFile(argv[2], argv[3], arg4, arg5);
 | 
        
           | 1 | cycrow | 1679 | 		}
 | 
        
           |  |  | 1680 | 	}
 | 
        
           |  |  | 1681 |   | 
        
           |  |  | 1682 | 	// extracts all the files from an archive
 | 
        
           | 197 | cycrow | 1683 | 	else if ( command == L"-e" || command == L"--extractall" )
 | 
        
           | 1 | cycrow | 1684 | 	{
 | 
        
           |  |  | 1685 | 		if ( argc < 3 )
 | 
        
           | 197 | cycrow | 1686 | 			wprintf(L"Syntax:\n\t%s -e <spkfile> [destination]\n\t--extractall <spkfile> <game> [destination]\n\t\tThis will extract all files of a set game into the destination directory\n\n\t\tGame = 0 will extract all files", cmd.c_str() );
 | 
        
           | 1 | cycrow | 1687 | 		else
 | 
        
           |  |  | 1688 | 		{
 | 
        
           | 129 | cycrow | 1689 | 			Utils::String arg4;
 | 
        
           | 1 | cycrow | 1690 | 			if ( argc > 4 )
 | 
        
           |  |  | 1691 | 				arg4 = argv[4];
 | 
        
           | 134 | cycrow | 1692 | 			ExtractFiles(argv[2], arg4, CBaseFile::GetGameFromString(argv[3]));
 | 
        
           | 1 | cycrow | 1693 | 		}
 | 
        
           |  |  | 1694 | 	}
 | 
        
           |  |  | 1695 |   | 
        
           |  |  | 1696 | 	// creates a multispk archive
 | 
        
           | 197 | cycrow | 1697 | 	else if ( command == L"-n" || command == L"--createmulti" )
 | 
        
           | 1 | cycrow | 1698 | 	{
 | 
        
           |  |  | 1699 | 		if ( argc < 3 )
 | 
        
           | 197 | cycrow | 1700 | 			wprintf(L"Syntax:\n\t%s -n <multispkfile>\n\t%s --createmulti <multispkfile>\n\t\tThis will create a multispk file and allow you to add spk files to it\n", cmd.c_str(), cmd.c_str() );
 | 
        
           | 1 | cycrow | 1701 | 		else
 | 
        
           |  |  | 1702 | 			CreateMultiFile ( argv[2] );
 | 
        
           |  |  | 1703 | 	}
 | 
        
           |  |  | 1704 |   | 
        
           |  |  | 1705 | 	// merges 2 multi-spk archives together, or appends a single spk file into a multi-spk file
 | 
        
           | 197 | cycrow | 1706 | 	else if ( command == L"-m" || command == L"--mergemulti" )
 | 
        
           | 1 | cycrow | 1707 | 	{
 | 
        
           |  |  | 1708 | 		if ( argc < 4 )
 | 
        
           | 197 | cycrow | 1709 | 			wprintf(L"Syntax:\n\t%s -m <spkfile1> <spkfile2>\n\t%s --mergemulti <spkfile1> <spkfile2>\n\t\tThis will add spkfile2 into spkfile1, if spkfile1 is a normal SPK file, it will be saved into a Multi-Spk file\nspkfile2 can also be a Multi-Spk file, all files within it will be added\n", cmd.c_str(), cmd.c_str() );
 | 
        
           | 1 | cycrow | 1710 | 		else
 | 
        
           |  |  | 1711 | 			AppendMultiFile ( argv[2], argv[3] );
 | 
        
           |  |  | 1712 | 	}
 | 
        
           |  |  | 1713 |   | 
        
           |  |  | 1714 | 	// splits the multi-spk file, exracts all spk files
 | 
        
           | 197 | cycrow | 1715 | 	else if ( command == L"-s" || command == L"--splitmulti" )
 | 
        
           | 1 | cycrow | 1716 | 	{
 | 
        
           |  |  | 1717 | 		if ( argc < 3 )
 | 
        
           | 197 | cycrow | 1718 | 			wprintf(L"Syntax: %s -s <multispkfile> [destination]\n\tSplits the Multi-SPK file and saves each spk file to the destiantion directory\n", cmd.c_str() );
 | 
        
           | 1 | cycrow | 1719 | 		else
 | 
        
           |  |  | 1720 | 		{
 | 
        
           |  |  | 1721 | 			CyString arg3;
 | 
        
           |  |  | 1722 | 			if ( argc > 3 )
 | 
        
           |  |  | 1723 | 				arg3 = argv[3];
 | 
        
           |  |  | 1724 | 			SplitMulti ( argv[2], arg3 );
 | 
        
           |  |  | 1725 | 		}
 | 
        
           |  |  | 1726 | 	}
 | 
        
           |  |  | 1727 |   | 
        
           | 197 | cycrow | 1728 | 	else if ( command == L"--set" )
 | 
        
           | 1 | cycrow | 1729 | 	{
 | 
        
           |  |  | 1730 | 		if ( argc < 4 )
 | 
        
           | 197 | cycrow | 1731 | 			wprintf(L"Syntax: %s --set <spkfile> <setting> [values]\n\tSets various settings in the package\n", cmd.c_str() );
 | 
        
           | 1 | cycrow | 1732 | 		else
 | 
        
           | 197 | cycrow | 1733 | 			Settings(argv[2], argv[3], argc, argv, CyString(cmd.toString()));
 | 
        
           | 1 | cycrow | 1734 | 	}
 | 
        
           | 197 | cycrow | 1735 | 	else if ( command == L"--setrating" )
 | 
        
           | 1 | cycrow | 1736 | 	{
 | 
        
           |  |  | 1737 | 		if ( argc < 6 )
 | 
        
           | 197 | cycrow | 1738 | 			wprintf(L"Syntax: %s --setrating <spkfile> <easeofuse> <gamechanging> <recommended>\n\tSets the rating of the spk package\n", cmd.c_str() );
 | 
        
           | 1 | cycrow | 1739 | 		else
 | 
        
           |  |  | 1740 | 			SetRating(argv[2], CyString(argv[3]).ToInt(), CyString(argv[4]).ToInt(), CyString(argv[5]).ToInt());
 | 
        
           |  |  | 1741 | 	}
 | 
        
           | 197 | cycrow | 1742 | 	else if ( command == L"--convertxsp" || command == L"--convertxspwizard" )
 | 
        
           | 1 | cycrow | 1743 | 	{
 | 
        
           |  |  | 1744 | 		if ( argc < 3 )
 | 
        
           | 197 | cycrow | 1745 | 			wprintf(L"Syntax: %s %s <xspfile> [newxspfile]\n\tConverts an old format xsp file to work with the new format\n", cmd.c_str(), command.c_str() );
 | 
        
           | 1 | cycrow | 1746 | 		else
 | 
        
           |  |  | 1747 | 		{
 | 
        
           | 185 | cycrow | 1748 | 			Utils::String arg3;
 | 
        
           | 1 | cycrow | 1749 | 			if ( argc > 3 )
 | 
        
           |  |  | 1750 | 				arg3 = argv[3];
 | 
        
           | 197 | cycrow | 1751 | 			ConvertXsp(argv[2], arg3, (command == L"--convertxspwizard") ? true : false);
 | 
        
           | 1 | cycrow | 1752 | 		}
 | 
        
           |  |  | 1753 | 	}
 | 
        
           | 197 | cycrow | 1754 | 	else if ( command == L"--createscript" )
 | 
        
           | 1 | cycrow | 1755 | 	{
 | 
        
           |  |  | 1756 | 		if ( argc < 3 )
 | 
        
           | 197 | cycrow | 1757 | 			wprintf(L"Syntax:\n\t%s --createscript <packagerscript>\n\t\tThis will create a spk/xsp file from a packager script\n", cmd.c_str() );
 | 
        
           | 1 | cycrow | 1758 | 		else
 | 
        
           |  |  | 1759 | 			LoadPackagerScript ( argv[2], false );
 | 
        
           |  |  | 1760 | 	}
 | 
        
           | 197 | cycrow | 1761 | 	else if ( command == L"--generatescript" )
 | 
        
           | 1 | cycrow | 1762 | 	{
 | 
        
           |  |  | 1763 | 		if ( argc < 3 )
 | 
        
           | 197 | cycrow | 1764 | 			wprintf(L"Syntax:\n\t%s --generatescript <package> [packagerscript]\n\t\tThis will generate a packager script file from a spk/xsp file.\n", cmd.c_str() );
 | 
        
           | 1 | cycrow | 1765 | 		else
 | 
        
           |  |  | 1766 | 		{
 | 
        
           |  |  | 1767 | 			if ( argc < 4 )
 | 
        
           | 126 | cycrow | 1768 | 				GeneratePackagerScript ( argv[2], "", 0);
 | 
        
           | 1 | cycrow | 1769 | 			else
 | 
        
           | 126 | cycrow | 1770 | 				GeneratePackagerScript ( argv[2], argv[3], 0);
 | 
        
           | 1 | cycrow | 1771 | 		}
 | 
        
           |  |  | 1772 | 	}
 | 
        
           | 197 | cycrow | 1773 | 	else if ( command == L"--verifyscript" )
 | 
        
           | 1 | cycrow | 1774 | 	{
 | 
        
           |  |  | 1775 | 		if ( argc < 3 )
 | 
        
           | 197 | cycrow | 1776 | 			wprintf(L"Syntax:\n\t%s --verifyscript <packagerscript>\n\t\tThis will read a packager script and check its correct without creating the resulting spk/xsp file\n", cmd.c_str() );
 | 
        
           | 1 | cycrow | 1777 | 		else
 | 
        
           |  |  | 1778 | 			LoadPackagerScript ( argv[2], true );
 | 
        
           |  |  | 1779 | 	}
 | 
        
           | 197 | cycrow | 1780 | 	else if ( command == L"--extractship" )
 | 
        
           | 1 | cycrow | 1781 | 	{
 | 
        
           |  |  | 1782 | 		if ( argc < 4 )
 | 
        
           | 197 | cycrow | 1783 | 			wprintf(L"Syntax:\n\t%s --extractship <modfile> <xspfile> [shipid]\n\t\tThis will create an xsp ship file by extracting from a mod file\n", cmd.c_str() );
 | 
        
           | 1 | cycrow | 1784 | 		else
 | 
        
           |  |  | 1785 | 		{
 | 
        
           |  |  | 1786 | 			if ( argc < 5 )
 | 
        
           | 197 | cycrow | 1787 | 				ExtractShip ( argv[2], argv[3], L"" );
 | 
        
           | 1 | cycrow | 1788 | 			else
 | 
        
           |  |  | 1789 | 				ExtractShip ( argv[2], argv[3], argv[4] );
 | 
        
           |  |  | 1790 | 		}
 | 
        
           |  |  | 1791 | 	}
 | 
        
           | 197 | cycrow | 1792 | 	else if (command == L"--generateupdatefile")
 | 
        
           | 1 | cycrow | 1793 | 	{
 | 
        
           | 197 | cycrow | 1794 | 		if (argc < 3)
 | 
        
           |  |  | 1795 | 			wprintf(L"Syntax:\n\t%s --generateupdatefile <package>\n\t\tThis will generate the update file to allow auto updates for a package\n", cmd.c_str());
 | 
        
           |  |  | 1796 | 		else
 | 
        
           |  |  | 1797 | 			GenerateUpdateFile(argv[2]);
 | 
        
           | 126 | cycrow | 1798 | 	}
 | 
        
           | 197 | cycrow | 1799 | 	else if (command == L"--packagelist")
 | 
        
           | 126 | cycrow | 1800 | 	{
 | 
        
           |  |  | 1801 | 		if (argc < 3)
 | 
        
           | 197 | cycrow | 1802 | 			wprintf(L"Syntax:\n\t%s --packagelist <filenames>\n\t\tThis will generate the update file to allow downloading packages from a server.\n", cmd.c_str());
 | 
        
           | 1 | cycrow | 1803 | 		else
 | 
        
           | 126 | cycrow | 1804 | 			GenerateUpdateList(argc, argv);
 | 
        
           | 1 | cycrow | 1805 | 	}
 | 
        
           |  |  | 1806 |   | 
        
           |  |  | 1807 | 	// not a valid switch, display syntax
 | 
        
           |  |  | 1808 | 	else
 | 
        
           | 197 | cycrow | 1809 | 		PrintSyntax ( CyString(cmd.toString()) );
 | 
        
           | 1 | cycrow | 1810 |   | 
        
           |  |  | 1811 | #ifdef _DEBUG
 | 
        
           |  |  | 1812 | 	char pause;
 | 
        
           |  |  | 1813 | 	scanf ( "%s", &pause );
 | 
        
           |  |  | 1814 | #endif
 | 
        
           |  |  | 1815 |   | 
        
           |  |  | 1816 | 	return 0;
 | 
        
           |  |  | 1817 | }
 |