| 6 | cycrow | 1 | // SpkFile.cpp: implementation of the CSpkFile class.
 | 
        
           |  |  | 2 | //
 | 
        
           |  |  | 3 | //////////////////////////////////////////////////////////////////////
 | 
        
           |  |  | 4 |   | 
        
           |  |  | 5 | #include "BaseFile.h"
 | 
        
           |  |  | 6 |   | 
        
           |  |  | 7 | //////////////////////////////////////////////////////////////////////
 | 
        
           |  |  | 8 | // Construction/Destruction
 | 
        
           |  |  | 9 | //////////////////////////////////////////////////////////////////////
 | 
        
           |  |  | 10 |   | 
        
           |  |  | 11 | #include "spk.h"
 | 
        
           |  |  | 12 |   | 
        
           |  |  | 13 | #include "DirIO.h"
 | 
        
           |  |  | 14 | #include "File_IO.h"
 | 
        
           |  |  | 15 | #include "CatFile.h"
 | 
        
           |  |  | 16 | #include "Packages.h"
 | 
        
           | 88 | cycrow | 17 | #include "TextDB.h"
 | 
        
           | 6 | cycrow | 18 |   | 
        
           | 46 | cycrow | 19 | #include <Package/InstallText.h>
 | 
        
           | 6 | cycrow | 20 |   | 
        
           | 46 | cycrow | 21 | // remove these eventually
 | 
        
           |  |  | 22 | using namespace SPK;
 | 
        
           |  |  | 23 | using namespace Package;
 | 
        
           | 6 | cycrow | 24 |   | 
        
           |  |  | 25 | CArchiveFile::~CArchiveFile()
 | 
        
           |  |  | 26 | {
 | 
        
           |  |  | 27 | 	Delete ();
 | 
        
           |  |  | 28 | }
 | 
        
           |  |  | 29 |   | 
        
           |  |  | 30 | CArchiveFile::CArchiveFile() : CBaseFile ()
 | 
        
           |  |  | 31 | {
 | 
        
           |  |  | 32 | 	SetDefaults ();
 | 
        
           |  |  | 33 | }
 | 
        
           |  |  | 34 |   | 
        
           |  |  | 35 | void CBaseFile::SetDefaults ()
 | 
        
           |  |  | 36 | {
 | 
        
           | 46 | cycrow | 37 | 	_setDefaults();
 | 
        
           |  |  | 38 |   | 
        
           | 6 | cycrow | 39 | 	m_pIconFile = NULL;
 | 
        
           |  |  | 40 |   | 
        
           |  |  | 41 | 	m_bAutoGenerateUpdateFile = false;
 | 
        
           |  |  | 42 | 	m_SHeader.iValueCompression = SPKCOMPRESS_ZLIB;
 | 
        
           |  |  | 43 | 	m_SHeader2.iFileCompression = SPKCOMPRESS_ZLIB;
 | 
        
           |  |  | 44 | 	m_SHeader2.iDataCompression = SPKCOMPRESS_LZMA;
 | 
        
           |  |  | 45 | 	m_pParent = NULL;
 | 
        
           | 50 | cycrow | 46 | 	_changed();
 | 
        
           | 6 | cycrow | 47 | 	m_bUpdate = false;
 | 
        
           | 130 | cycrow | 48 | 	_bCombineFiles = false;
 | 
        
           | 6 | cycrow | 49 |   | 
        
           |  |  | 50 | 	ClearError();
 | 
        
           |  |  | 51 |   | 
        
           |  |  | 52 | 	m_iLoadError = 0;
 | 
        
           |  |  | 53 |   | 
        
           |  |  | 54 | 	m_bFullyLoaded = false;
 | 
        
           |  |  | 55 | 	m_bSigned = false;
 | 
        
           |  |  | 56 | 	m_bEnable = m_bGlobal = m_bProfile = m_bModifiedEnabled = true;
 | 
        
           |  |  | 57 | 	m_bOverrideFiles = false;
 | 
        
           |  |  | 58 | }
 | 
        
           |  |  | 59 |   | 
        
           | 88 | cycrow | 60 | CBaseFile::CBaseFile() : _pTextDB(NULL)
 | 
        
           | 6 | cycrow | 61 | {
 | 
        
           |  |  | 62 | 	SetDefaults ();
 | 
        
           |  |  | 63 | }
 | 
        
           |  |  | 64 | CBaseFile::~CBaseFile()
 | 
        
           |  |  | 65 | {
 | 
        
           |  |  | 66 | 	Delete();
 | 
        
           |  |  | 67 | }
 | 
        
           |  |  | 68 |   | 
        
           | 170 | cycrow | 69 |   | 
        
           | 203 | cycrow | 70 | Utils::WString CBaseFile::getFullPackageName(int language, const Utils::WString &byString) const
 | 
        
           | 170 | cycrow | 71 | { 
 | 
        
           |  |  | 72 | 	return getFullPackageName(language, true, byString); 
 | 
        
           |  |  | 73 | }
 | 
        
           | 203 | cycrow | 74 | Utils::WString CBaseFile::getFullPackageName(int language, bool includeVersion, const Utils::WString &byString) const
 | 
        
           | 170 | cycrow | 75 | {
 | 
        
           | 203 | cycrow | 76 | 	Utils::WString p = this->name(language);
 | 
        
           | 170 | cycrow | 77 | 	if (includeVersion)
 | 
        
           |  |  | 78 | 	{
 | 
        
           | 203 | cycrow | 79 | 		p += L" V";
 | 
        
           | 204 | cycrow | 80 | 		p += this->version();
 | 
        
           | 170 | cycrow | 81 | 	}
 | 
        
           | 203 | cycrow | 82 | 	p += L" ";
 | 
        
           |  |  | 83 | 	p += byString + L" " + this->author();
 | 
        
           | 170 | cycrow | 84 | 	return p;
 | 
        
           |  |  | 85 | }
 | 
        
           |  |  | 86 |   | 
        
           | 203 | cycrow | 87 | Utils::WString CBaseFile::getFullPackageName(const Utils::WString &format, int lang) const
 | 
        
           | 170 | cycrow | 88 | {
 | 
        
           |  |  | 89 | 	if (format.empty())
 | 
        
           |  |  | 90 | 		return getFullPackageName(lang);
 | 
        
           |  |  | 91 |   | 
        
           | 204 | cycrow | 92 | 	Utils::WString args[3] = { this->name(lang), this->version(), this->author() };
 | 
        
           | 170 | cycrow | 93 | 	return format.args(args, 3);
 | 
        
           |  |  | 94 | }
 | 
        
           |  |  | 95 |   | 
        
           | 6 | cycrow | 96 | void CBaseFile::Delete ()
 | 
        
           |  |  | 97 | {
 | 
        
           | 170 | cycrow | 98 | 	m_lTempFiles.clear();
 | 
        
           | 6 | cycrow | 99 | 	m_lFiles.clear(true);
 | 
        
           |  |  | 100 |   | 
        
           |  |  | 101 | 	if ( m_pIconFile )
 | 
        
           |  |  | 102 | 	{
 | 
        
           |  |  | 103 | 		delete m_pIconFile;
 | 
        
           |  |  | 104 | 		m_pIconFile = NULL;
 | 
        
           |  |  | 105 | 	}
 | 
        
           |  |  | 106 |   | 
        
           | 88 | cycrow | 107 | 	if ( _pTextDB ) {
 | 
        
           |  |  | 108 | 		delete _pTextDB;
 | 
        
           |  |  | 109 | 		_pTextDB = NULL;
 | 
        
           |  |  | 110 | 	}
 | 
        
           | 6 | cycrow | 111 | }
 | 
        
           |  |  | 112 |   | 
        
           |  |  | 113 |   | 
        
           |  |  | 114 | /*
 | 
        
           |  |  | 115 | ##########################################################################################
 | 
        
           |  |  | 116 | ##################                Base Class Functions                  ##################
 | 
        
           |  |  | 117 | ##########################################################################################
 | 
        
           |  |  | 118 | */
 | 
        
           |  |  | 119 |   | 
        
           | 170 | cycrow | 120 | const CLinkList<C_File> &CBaseFile::fileList() const
 | 
        
           | 131 | cycrow | 121 | {
 | 
        
           | 170 | cycrow | 122 | 	return m_lFiles;
 | 
        
           | 131 | cycrow | 123 | }
 | 
        
           | 170 | cycrow | 124 | CLinkList<C_File> &CBaseFile::fileList(FileType type, CLinkList<C_File>& list) const
 | 
        
           |  |  | 125 | { 
 | 
        
           |  |  | 126 | 	for (CListNode<C_File>* node = m_lFiles.Front(); node; node = node->next())
 | 
        
           | 6 | cycrow | 127 | 	{
 | 
        
           | 170 | cycrow | 128 | 		C_File* f = node->Data();
 | 
        
           |  |  | 129 | 		if (f->GetFileType() == type)
 | 
        
           |  |  | 130 | 			list.push_back(f);
 | 
        
           | 6 | cycrow | 131 | 	}
 | 
        
           |  |  | 132 |   | 
        
           |  |  | 133 | 	return list;
 | 
        
           |  |  | 134 | }
 | 
        
           | 170 | cycrow | 135 | CLinkList<C_File> &CBaseFile::fileList(FileType type)
 | 
        
           |  |  | 136 | {
 | 
        
           |  |  | 137 | 	m_lTempFiles.clear();
 | 
        
           |  |  | 138 | 	return fileList(type, m_lTempFiles);
 | 
        
           |  |  | 139 | }
 | 
        
           | 6 | cycrow | 140 |   | 
        
           | 13 | cycrow | 141 | C_File *CBaseFile::GetNextFile(C_File *prev) const
 | 
        
           | 6 | cycrow | 142 | {
 | 
        
           |  |  | 143 | 	int type = -1;
 | 
        
           |  |  | 144 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 145 | 	{
 | 
        
           |  |  | 146 | 		C_File *f = node->Data();
 | 
        
           |  |  | 147 | 		if ( type == -1 )
 | 
        
           |  |  | 148 | 		{
 | 
        
           |  |  | 149 | 			if ( f == prev )
 | 
        
           |  |  | 150 | 				type = f->GetFileType();
 | 
        
           |  |  | 151 | 		}
 | 
        
           |  |  | 152 | 		else
 | 
        
           |  |  | 153 | 		{
 | 
        
           |  |  | 154 | 			if ( f->GetFileType() == type )
 | 
        
           |  |  | 155 | 				return f;
 | 
        
           |  |  | 156 | 		}
 | 
        
           |  |  | 157 | 	}
 | 
        
           |  |  | 158 |   | 
        
           |  |  | 159 | 	return NULL;
 | 
        
           |  |  | 160 | }
 | 
        
           |  |  | 161 |   | 
        
           | 13 | cycrow | 162 | C_File *CBaseFile::GetPrevFile(C_File *next) const
 | 
        
           | 6 | cycrow | 163 | {
 | 
        
           |  |  | 164 | 	if ( !next )
 | 
        
           |  |  | 165 | 		return NULL;
 | 
        
           |  |  | 166 |   | 
        
           |  |  | 167 | 	int type = -1;
 | 
        
           |  |  | 168 | 	for ( CListNode<C_File> *node = m_lFiles.Back(); node; node = node->prev() )
 | 
        
           |  |  | 169 | 	{
 | 
        
           |  |  | 170 | 		C_File *f = node->Data();
 | 
        
           |  |  | 171 | 		if ( type == -1 )
 | 
        
           |  |  | 172 | 		{
 | 
        
           |  |  | 173 | 			if ( f == next )
 | 
        
           |  |  | 174 | 				type = f->GetFileType();
 | 
        
           |  |  | 175 | 		}
 | 
        
           |  |  | 176 | 		else
 | 
        
           |  |  | 177 | 		{
 | 
        
           |  |  | 178 | 			if ( f->GetFileType() == type )
 | 
        
           |  |  | 179 | 				return f;
 | 
        
           |  |  | 180 | 		}
 | 
        
           |  |  | 181 | 	}
 | 
        
           |  |  | 182 |   | 
        
           |  |  | 183 | 	return NULL;
 | 
        
           |  |  | 184 | }
 | 
        
           |  |  | 185 |   | 
        
           | 13 | cycrow | 186 | C_File *CBaseFile::GetFirstFile(int type) const
 | 
        
           | 6 | cycrow | 187 | {
 | 
        
           |  |  | 188 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 189 | 	{
 | 
        
           |  |  | 190 | 		C_File *f = node->Data();
 | 
        
           |  |  | 191 | 		if ( f->GetFileType() == type )
 | 
        
           |  |  | 192 | 			return f;
 | 
        
           |  |  | 193 | 	}
 | 
        
           |  |  | 194 |   | 
        
           |  |  | 195 | 	return NULL;
 | 
        
           |  |  | 196 | }
 | 
        
           |  |  | 197 |   | 
        
           | 197 | cycrow | 198 | int CBaseFile::CheckFile(const Utils::WString &filename, float *version )
 | 
        
           | 6 | cycrow | 199 | {
 | 
        
           | 91 | cycrow | 200 | 	CFileIO File(filename);
 | 
        
           |  |  | 201 | 	if ( !File.startRead() ) return 0;
 | 
        
           | 210 | cycrow | 202 | 	Utils::WString line = File.readEndOfLine();
 | 
        
           |  |  | 203 | 	Utils::WString type = line.token(L";", 1);
 | 
        
           | 51 | cycrow | 204 | 	File.close();
 | 
        
           | 6 | cycrow | 205 |   | 
        
           |  |  | 206 | 	// check for old version
 | 
        
           | 210 | cycrow | 207 | 	if ( line.left(3) == L"HiP" ) return SPKFILE_OLD;
 | 
        
           | 6 | cycrow | 208 |   | 
        
           |  |  | 209 | 	// check for format
 | 
        
           | 210 | cycrow | 210 | 	if ( version ) *version = line.token(L";", 2);
 | 
        
           | 6 | cycrow | 211 |   | 
        
           | 210 | cycrow | 212 | 	if ( type == L"BaseCycrow" )	return SPKFILE_BASE;
 | 
        
           |  |  | 213 | 	if ( type == L"SPKCycrow" )	return SPKFILE_SINGLE;
 | 
        
           |  |  | 214 | 	if ( type == L"XSPCycrow" )	return SPKFILE_SINGLESHIP;
 | 
        
           |  |  | 215 | 	if ( type == L"MSPKCycrow" )	return SPKFILE_MULTI;
 | 
        
           | 6 | cycrow | 216 | 	return SPKFILE_INVALID;
 | 
        
           |  |  | 217 | }
 | 
        
           |  |  | 218 |   | 
        
           |  |  | 219 | void CBaseFile::ClearFileData()
 | 
        
           |  |  | 220 | {
 | 
        
           | 88 | cycrow | 221 | 	for ( CListNode<C_File> *f = m_lFiles.Front(); f; f = f->next() )
 | 
        
           | 6 | cycrow | 222 | 	{
 | 
        
           | 88 | cycrow | 223 | 		f->Data()->DeleteData();
 | 
        
           | 6 | cycrow | 224 | 	}
 | 
        
           |  |  | 225 | }
 | 
        
           |  |  | 226 |   | 
        
           | 197 | cycrow | 227 | Utils::WString CBaseFile::getNameValidFile() const
 | 
        
           | 6 | cycrow | 228 | {
 | 
        
           | 197 | cycrow | 229 | 	Utils::WString name = this->name();
 | 
        
           | 130 | cycrow | 230 | 	name.removeChar(':');
 | 
        
           |  |  | 231 | 	name.removeChar('/');
 | 
        
           |  |  | 232 | 	name.removeChar('\\');
 | 
        
           |  |  | 233 | 	name.removeChar('*');
 | 
        
           |  |  | 234 | 	name.removeChar('?');
 | 
        
           |  |  | 235 | 	name.removeChar('"');
 | 
        
           |  |  | 236 | 	name.removeChar('<');
 | 
        
           |  |  | 237 | 	name.removeChar('>');
 | 
        
           |  |  | 238 | 	name.removeChar('|');
 | 
        
           |  |  | 239 | 	return name;
 | 
        
           |  |  | 240 | }
 | 
        
           | 6 | cycrow | 241 |   | 
        
           |  |  | 242 | void CBaseFile::SwitchFilePointer(C_File *oldFile, C_File *newFile)
 | 
        
           |  |  | 243 | {
 | 
        
           |  |  | 244 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 245 | 	{
 | 
        
           |  |  | 246 | 		C_File *f = node->Data();
 | 
        
           |  |  | 247 | 		if ( f == oldFile )
 | 
        
           |  |  | 248 | 		{
 | 
        
           |  |  | 249 | 			node->ChangeData(newFile);
 | 
        
           |  |  | 250 | 			break;
 | 
        
           |  |  | 251 | 		}
 | 
        
           |  |  | 252 | 	}
 | 
        
           |  |  | 253 | }
 | 
        
           |  |  | 254 |   | 
        
           |  |  | 255 | bool CBaseFile::AnyFileType ( int type )
 | 
        
           |  |  | 256 | {
 | 
        
           |  |  | 257 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 258 | 	{
 | 
        
           |  |  | 259 | 		C_File *f = node->Data();
 | 
        
           |  |  | 260 | 		if ( f->GetFileType() == type )
 | 
        
           |  |  | 261 | 			return true;
 | 
        
           |  |  | 262 | 	}
 | 
        
           |  |  | 263 |   | 
        
           |  |  | 264 | 	return false;
 | 
        
           |  |  | 265 | }
 | 
        
           |  |  | 266 |   | 
        
           |  |  | 267 | void CBaseFile::AddFile ( C_File *file )
 | 
        
           |  |  | 268 | {
 | 
        
           |  |  | 269 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 270 | 	{
 | 
        
           |  |  | 271 | 		C_File *f = node->Data();
 | 
        
           | 130 | cycrow | 272 | 		if ( f->fileType() != file->fileType() )
 | 
        
           | 6 | cycrow | 273 | 			continue;
 | 
        
           | 130 | cycrow | 274 | 		if ( f->name() != file->name () )
 | 
        
           | 6 | cycrow | 275 | 			continue;
 | 
        
           | 170 | cycrow | 276 | 		if ( f->dir() != file->dir() )
 | 
        
           | 6 | cycrow | 277 | 			continue;
 | 
        
           | 127 | cycrow | 278 | 		if ( f->game() != file->game() )
 | 
        
           | 6 | cycrow | 279 | 			continue;
 | 
        
           |  |  | 280 |   | 
        
           |  |  | 281 | 		m_lFiles.remove(node, true);
 | 
        
           |  |  | 282 | 		break;
 | 
        
           |  |  | 283 | 	}
 | 
        
           |  |  | 284 |   | 
        
           | 88 | cycrow | 285 | 	_addFile(file);
 | 
        
           | 6 | cycrow | 286 | }
 | 
        
           |  |  | 287 |   | 
        
           | 197 | cycrow | 288 | C_File *CBaseFile::addFile(const Utils::WString &file, const Utils::WString &dir, FileType type, int game, bool packed)
 | 
        
           | 127 | cycrow | 289 | {
 | 
        
           |  |  | 290 | 	C_File *newfile = new C_File(file);
 | 
        
           | 178 | cycrow | 291 | 	newfile->setDir(dir);
 | 
        
           | 130 | cycrow | 292 | 	newfile->setFileType(type);
 | 
        
           | 127 | cycrow | 293 | 	newfile->setGame(game);
 | 
        
           | 6 | cycrow | 294 |   | 
        
           | 155 | cycrow | 295 | 	if (packed)
 | 
        
           |  |  | 296 | 	{
 | 
        
           |  |  | 297 | 		if (newfile->PCKFile())
 | 
        
           | 197 | cycrow | 298 | 			newfile->setFilename(CFileIO(newfile->filePointer()).changeFileExtension(L"pck"));
 | 
        
           | 155 | cycrow | 299 | 	}
 | 
        
           |  |  | 300 |   | 
        
           | 6 | cycrow | 301 | 	// first check if the file already exists
 | 
        
           |  |  | 302 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 303 | 	{
 | 
        
           |  |  | 304 | 		C_File *f = node->Data();
 | 
        
           | 130 | cycrow | 305 | 		if ( f->fileType() != newfile->fileType() )
 | 
        
           | 6 | cycrow | 306 | 			continue;
 | 
        
           | 130 | cycrow | 307 | 		if ( f->name() != newfile->name () )
 | 
        
           | 6 | cycrow | 308 | 			continue;
 | 
        
           | 134 | cycrow | 309 | 		if ( f->dir() != newfile->dir() )
 | 
        
           | 6 | cycrow | 310 | 			continue;
 | 
        
           | 130 | cycrow | 311 | 		if (f->game() != newfile->game())
 | 
        
           |  |  | 312 | 		{
 | 
        
           |  |  | 313 | 			//same file, for different game, check if they are the same and combine them
 | 
        
           |  |  | 314 | 			if (_bCombineFiles)
 | 
        
           |  |  | 315 | 			{
 | 
        
           |  |  | 316 | 				char *data = NULL;
 | 
        
           |  |  | 317 | 				char *newData = NULL;
 | 
        
           |  |  | 318 | 				size_t size = 0;
 | 
        
           |  |  | 319 | 				size_t newSize = 0;
 | 
        
           |  |  | 320 |   | 
        
           |  |  | 321 | 				if (f->GetData() && f->GetDataSize())
 | 
        
           | 143 | cycrow | 322 | 					data = (char *)f->UncompressData((long *)&size, NULL);
 | 
        
           | 130 | cycrow | 323 | 				else if(f->isExternalFile())
 | 
        
           |  |  | 324 | 					data = CFileIO(f->filePointer()).ReadToData(&size);
 | 
        
           |  |  | 325 | 				if (newfile->GetData() && newfile->GetDataSize())
 | 
        
           | 143 | cycrow | 326 | 					newData = (char *)f->UncompressData((long *)&newSize, NULL);
 | 
        
           | 130 | cycrow | 327 | 				else
 | 
        
           |  |  | 328 | 					newData = CFileIO(newfile->filePointer()).ReadToData(&newSize);
 | 
        
           |  |  | 329 |   | 
        
           |  |  | 330 | 				// compare bytes
 | 
        
           |  |  | 331 | 				bool matched = false;
 | 
        
           |  |  | 332 | 				if (size == newSize)
 | 
        
           |  |  | 333 | 				{
 | 
        
           |  |  | 334 | 					matched = true;
 | 
        
           |  |  | 335 | 					for (unsigned long i = 0; i < size; ++i)
 | 
        
           |  |  | 336 | 					{
 | 
        
           |  |  | 337 | 						if (data[i] != newData[i])
 | 
        
           |  |  | 338 | 						{
 | 
        
           |  |  | 339 | 							matched = false;
 | 
        
           |  |  | 340 | 							break;
 | 
        
           |  |  | 341 | 						}
 | 
        
           |  |  | 342 | 					}
 | 
        
           |  |  | 343 | 				}
 | 
        
           |  |  | 344 |   | 
        
           | 143 | cycrow | 345 | 				if (data)
 | 
        
           | 130 | cycrow | 346 | 					delete data;
 | 
        
           | 143 | cycrow | 347 | 				if (newData)
 | 
        
           | 130 | cycrow | 348 | 					delete newData;
 | 
        
           |  |  | 349 |   | 
        
           |  |  | 350 | 				if (matched)
 | 
        
           |  |  | 351 | 				{
 | 
        
           |  |  | 352 | 					if(!f->game() || f->game() == GAME_ALLNEW)
 | 
        
           |  |  | 353 | 						newfile->setGame(0);
 | 
        
           |  |  | 354 | 					else
 | 
        
           |  |  | 355 | 						newfile->setGame(newfile->game() | f->game());
 | 
        
           |  |  | 356 | 					m_lFiles.remove(node, true);
 | 
        
           |  |  | 357 | 					break;
 | 
        
           |  |  | 358 | 				}
 | 
        
           |  |  | 359 | 			}
 | 
        
           | 6 | cycrow | 360 | 			continue;
 | 
        
           | 130 | cycrow | 361 | 		}
 | 
        
           | 6 | cycrow | 362 |   | 
        
           |  |  | 363 | 		// must already exist, delete this one
 | 
        
           |  |  | 364 | 		m_lFiles.remove(node, true);
 | 
        
           |  |  | 365 | 		break;
 | 
        
           |  |  | 366 | 	}
 | 
        
           |  |  | 367 |   | 
        
           | 88 | cycrow | 368 | 	_addFile(newfile);
 | 
        
           | 6 | cycrow | 369 |   | 
        
           |  |  | 370 | 	return newfile;
 | 
        
           |  |  | 371 | }
 | 
        
           |  |  | 372 |   | 
        
           | 210 | cycrow | 373 | bool CBaseFile::addFileNow(const Utils::WString &file, const Utils::WString &dir, FileType type, CProgressInfo* progress)
 | 
        
           | 6 | cycrow | 374 | {
 | 
        
           | 170 | cycrow | 375 | 	C_File* f = addFile(file, dir, type);
 | 
        
           |  |  | 376 | 	if (!f->ReadFromFile())
 | 
        
           | 6 | cycrow | 377 | 		return false;
 | 
        
           |  |  | 378 |   | 
        
           |  |  | 379 | 	// compress the file
 | 
        
           | 170 | cycrow | 380 | 	return f->CompressData(m_SHeader2.iDataCompression, progress);
 | 
        
           | 6 | cycrow | 381 | }
 | 
        
           |  |  | 382 |   | 
        
           | 197 | cycrow | 383 | C_File *CBaseFile::appendFile(const Utils::WString &file, int type, int game, bool packed, const Utils::WString &dir, CProgressInfo *progress )
 | 
        
           | 6 | cycrow | 384 | {
 | 
        
           | 155 | cycrow | 385 | 	C_File *newfile = addFile(file, dir, static_cast<FileType>(type), game, packed);
 | 
        
           | 6 | cycrow | 386 | 	if ( !newfile )
 | 
        
           |  |  | 387 | 		return NULL;
 | 
        
           |  |  | 388 |   | 
        
           |  |  | 389 | 	// read the file into memory
 | 
        
           | 155 | cycrow | 390 | 	if (newfile->GetData() && newfile->GetDataSize())
 | 
        
           |  |  | 391 | 	{
 | 
        
           |  |  | 392 | 		// now compress the file
 | 
        
           |  |  | 393 | 		if (newfile->CompressData(m_SHeader2.iDataCompression, progress))
 | 
        
           |  |  | 394 | 			return newfile;
 | 
        
           |  |  | 395 | 	}
 | 
        
           | 6 | cycrow | 396 | 	if ( newfile->ReadFromFile () )
 | 
        
           |  |  | 397 | 	{
 | 
        
           |  |  | 398 | 		// now compress the file
 | 
        
           |  |  | 399 | 		if ( newfile->CompressData ( m_SHeader2.iDataCompression, progress ) )
 | 
        
           |  |  | 400 | 			return newfile;
 | 
        
           |  |  | 401 | 	}
 | 
        
           |  |  | 402 | 	else if ( newfile->GetLastError() == SPKERR_MALLOC )
 | 
        
           |  |  | 403 | 	{
 | 
        
           |  |  | 404 | 		if ( newfile->CompressFile ( progress ) )
 | 
        
           |  |  | 405 | 			return newfile;
 | 
        
           |  |  | 406 | 	}
 | 
        
           |  |  | 407 |   | 
        
           |  |  | 408 | 	m_lFiles.pop_back ();
 | 
        
           |  |  | 409 | 	delete newfile;
 | 
        
           |  |  | 410 |   | 
        
           |  |  | 411 | 	return NULL;
 | 
        
           |  |  | 412 | }
 | 
        
           |  |  | 413 |   | 
        
           | 170 | cycrow | 414 | C_File *CBaseFile::findFileAt(FileType filetype, size_t pos) const
 | 
        
           | 6 | cycrow | 415 | {
 | 
        
           | 170 | cycrow | 416 | 	size_t count = 0;
 | 
        
           | 6 | cycrow | 417 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 418 | 	{
 | 
        
           |  |  | 419 | 		C_File *file = node->Data();
 | 
        
           |  |  | 420 | 		if ( file->GetFileType() != filetype )
 | 
        
           |  |  | 421 | 			continue;
 | 
        
           |  |  | 422 |   | 
        
           |  |  | 423 | 		if ( count == pos )
 | 
        
           |  |  | 424 | 			return file;
 | 
        
           |  |  | 425 |   | 
        
           |  |  | 426 | 		++count;
 | 
        
           |  |  | 427 | 	}
 | 
        
           |  |  | 428 |   | 
        
           |  |  | 429 | 	return NULL;
 | 
        
           |  |  | 430 | }
 | 
        
           |  |  | 431 |   | 
        
           | 197 | cycrow | 432 | C_File* CBaseFile::findFile(const Utils::WString &filename, FileType type, const Utils::WString &dir, int game) const
 | 
        
           | 170 | cycrow | 433 | {	
 | 
        
           | 197 | cycrow | 434 | 	Utils::WString lfile = CFileIO(filename.lower()).filename();
 | 
        
           | 6 | cycrow | 435 |   | 
        
           | 170 | cycrow | 436 | 	CListNode<C_File>* node = m_lFiles.Front();
 | 
        
           |  |  | 437 | 	while (node)
 | 
        
           | 6 | cycrow | 438 | 	{
 | 
        
           | 170 | cycrow | 439 | 		C_File* f = node->Data();
 | 
        
           | 6 | cycrow | 440 | 		node = node->next();
 | 
        
           |  |  | 441 |   | 
        
           | 170 | cycrow | 442 | 		if (type != f->GetFileType())
 | 
        
           | 6 | cycrow | 443 | 			continue;
 | 
        
           | 170 | cycrow | 444 | 		if (dir != f->dir())
 | 
        
           | 6 | cycrow | 445 | 			continue;
 | 
        
           | 232 | cycrow | 446 | 		if (game && (game != f->game()))
 | 
        
           | 6 | cycrow | 447 | 			continue;
 | 
        
           | 170 | cycrow | 448 | 		if (f->name().lower() == lfile)
 | 
        
           | 6 | cycrow | 449 | 			return f;
 | 
        
           |  |  | 450 | 	}
 | 
        
           |  |  | 451 | 	return NULL;
 | 
        
           |  |  | 452 | }
 | 
        
           |  |  | 453 |   | 
        
           | 210 | cycrow | 454 | bool CBaseFile::removeFile(const Utils::WString& file, FileType type, const Utils::WString& dir, int game)
 | 
        
           | 6 | cycrow | 455 | {
 | 
        
           | 170 | cycrow | 456 | 	C_File* f = findFile(file, type, dir, game);
 | 
        
           |  |  | 457 | 	if (!f)
 | 
        
           | 6 | cycrow | 458 | 		return false;
 | 
        
           | 172 | cycrow | 459 | 	return removeFile(f);
 | 
        
           | 6 | cycrow | 460 | }
 | 
        
           |  |  | 461 |   | 
        
           | 172 | cycrow | 462 | bool CBaseFile::removeFile(C_File *file)
 | 
        
           | 6 | cycrow | 463 | {
 | 
        
           | 172 | cycrow | 464 | 	size_t count = 0;
 | 
        
           | 6 | cycrow | 465 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 466 | 	{
 | 
        
           |  |  | 467 | 		C_File *f = node->Data();
 | 
        
           |  |  | 468 | 		if ( f == file )
 | 
        
           | 172 | cycrow | 469 | 			return removeFile(count);
 | 
        
           | 6 | cycrow | 470 | 		++count;
 | 
        
           |  |  | 471 | 	}
 | 
        
           |  |  | 472 | 	return false;
 | 
        
           |  |  | 473 | }
 | 
        
           |  |  | 474 |   | 
        
           | 172 | cycrow | 475 | bool CBaseFile::removeFile(size_t pos)
 | 
        
           | 6 | cycrow | 476 | {
 | 
        
           | 172 | cycrow | 477 | 	if (pos >= static_cast<size_t>(m_lFiles.size()))
 | 
        
           | 6 | cycrow | 478 | 		return false;
 | 
        
           |  |  | 479 |   | 
        
           |  |  | 480 | 	C_File *file = m_lFiles.Get ( pos );
 | 
        
           |  |  | 481 | 	m_lFiles.erase ( pos + 1 );
 | 
        
           |  |  | 482 |   | 
        
           |  |  | 483 | 	if ( file )
 | 
        
           |  |  | 484 | 		delete file;
 | 
        
           |  |  | 485 |   | 
        
           | 50 | cycrow | 486 | 	_changed();
 | 
        
           | 6 | cycrow | 487 |   | 
        
           |  |  | 488 | 	return true;
 | 
        
           |  |  | 489 | }
 | 
        
           |  |  | 490 |   | 
        
           |  |  | 491 |   | 
        
           | 129 | cycrow | 492 | void CBaseFile::removeAllFiles(FileType type, int game)
 | 
        
           | 6 | cycrow | 493 | {
 | 
        
           |  |  | 494 | 	if ( m_lFiles.empty() )
 | 
        
           |  |  | 495 | 		return;
 | 
        
           |  |  | 496 |   | 
        
           |  |  | 497 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 498 | 	{
 | 
        
           | 129 | cycrow | 499 | 		if (game == 0 && node->Data()->game() && node->Data()->game() != GAME_ALLNEW)
 | 
        
           |  |  | 500 | 			continue;
 | 
        
           |  |  | 501 | 		if ( game > -1 )
 | 
        
           |  |  | 502 | 		{
 | 
        
           |  |  | 503 | 			unsigned int fileGame = node->Data()->game() & ~GAME_ALLNEW;
 | 
        
           |  |  | 504 | 			if (fileGame != (1 << game))
 | 
        
           |  |  | 505 | 			{
 | 
        
           |  |  | 506 | 				// just remove the game from file
 | 
        
           |  |  | 507 | 				if (fileGame & (1 << game))
 | 
        
           |  |  | 508 | 					node->Data()->setGame(node->Data()->game() & ~(1 << game));
 | 
        
           | 6 | cycrow | 509 | 				continue;
 | 
        
           | 129 | cycrow | 510 | 			}
 | 
        
           | 6 | cycrow | 511 | 		}
 | 
        
           | 129 | cycrow | 512 | 		if ( type == FILETYPE_UNKNOWN || node->Data()->GetFileType() == type )
 | 
        
           | 6 | cycrow | 513 | 			node->DeleteData();
 | 
        
           |  |  | 514 | 	}
 | 
        
           |  |  | 515 |   | 
        
           |  |  | 516 | 	m_lFiles.RemoveEmpty();
 | 
        
           |  |  | 517 |   | 
        
           | 50 | cycrow | 518 | 	_changed();
 | 
        
           | 6 | cycrow | 519 | }
 | 
        
           |  |  | 520 |   | 
        
           |  |  | 521 | void CBaseFile::RecompressAllFiles ( int type, CProgressInfo *progress )
 | 
        
           |  |  | 522 | {
 | 
        
           |  |  | 523 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 524 | 	{
 | 
        
           |  |  | 525 | 		C_File *file = node->Data();
 | 
        
           |  |  | 526 | 		if ( progress )
 | 
        
           |  |  | 527 | 			progress->UpdateFile(file);
 | 
        
           |  |  | 528 |   | 
        
           |  |  | 529 | 		if ( file->GetCompressionType() == type )
 | 
        
           |  |  | 530 | 			continue;
 | 
        
           |  |  | 531 |   | 
        
           |  |  | 532 | 		if ( !file->GetData() )
 | 
        
           |  |  | 533 | 			file->ReadFromFile();
 | 
        
           |  |  | 534 |   | 
        
           |  |  | 535 | 		file->ChangeCompression ( type, progress );
 | 
        
           |  |  | 536 | 	}
 | 
        
           |  |  | 537 | }
 | 
        
           |  |  | 538 |   | 
        
           | 47 | cycrow | 539 | void CBaseFile::CompressAllFiles ( int type, CProgressInfo *progress, CProgressInfo *overallProgress, int level )
 | 
        
           | 6 | cycrow | 540 | {
 | 
        
           | 47 | cycrow | 541 | 	if ( overallProgress ) overallProgress->SetMax(m_lFiles.size());
 | 
        
           |  |  | 542 |   | 
        
           |  |  | 543 | 	int iCount = 0;
 | 
        
           | 6 | cycrow | 544 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 545 | 	{
 | 
        
           |  |  | 546 | 		C_File *file = node->Data();
 | 
        
           |  |  | 547 | 		if ( progress )
 | 
        
           |  |  | 548 | 			progress->UpdateFile(file);
 | 
        
           |  |  | 549 |   | 
        
           |  |  | 550 | 		if ( !file->GetData() )
 | 
        
           |  |  | 551 | 			file->ReadFromFile();
 | 
        
           |  |  | 552 |   | 
        
           |  |  | 553 | 		file->CompressData ( type, progress, level );
 | 
        
           | 47 | cycrow | 554 |   | 
        
           |  |  | 555 | 		if ( overallProgress ) overallProgress->SetDone(++iCount);
 | 
        
           | 6 | cycrow | 556 | 	}
 | 
        
           |  |  | 557 | }
 | 
        
           |  |  | 558 |   | 
        
           |  |  | 559 | bool CBaseFile::UncompressAllFiles ( CProgressInfo *progress )
 | 
        
           |  |  | 560 | {
 | 
        
           |  |  | 561 | 	int countFile = 0;
 | 
        
           |  |  | 562 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 563 | 	{
 | 
        
           |  |  | 564 | 		C_File *fit = node->Data();
 | 
        
           |  |  | 565 | 		if ( progress )
 | 
        
           |  |  | 566 | 		{
 | 
        
           |  |  | 567 | 			progress->UpdateFile ( fit );
 | 
        
           |  |  | 568 | 			progress->UpdateProgress(countFile++, m_lFiles.size());
 | 
        
           |  |  | 569 | 		}
 | 
        
           |  |  | 570 |   | 
        
           |  |  | 571 | 		bool uncomprToFile = false;
 | 
        
           |  |  | 572 |   | 
        
           |  |  | 573 | 		if ( progress )
 | 
        
           |  |  | 574 | 			progress->SwitchSecond();
 | 
        
           |  |  | 575 |   | 
        
           | 127 | cycrow | 576 | 		if(!fit->isExternalFile())
 | 
        
           | 6 | cycrow | 577 | 		{
 | 
        
           | 127 | cycrow | 578 | 			if (!fit->UncompressData(progress))
 | 
        
           | 6 | cycrow | 579 | 			{
 | 
        
           | 127 | cycrow | 580 | 				if (fit->GetCompressionType() == SPKCOMPRESS_7ZIP)
 | 
        
           | 6 | cycrow | 581 | 				{
 | 
        
           | 213 | cycrow | 582 | 					if (!fit->uncompressToFile(L"temp", this, false, progress))
 | 
        
           | 127 | cycrow | 583 | 						return false;
 | 
        
           |  |  | 584 | 					else
 | 
        
           |  |  | 585 | 					{
 | 
        
           |  |  | 586 | 						uncomprToFile = true;
 | 
        
           | 213 | cycrow | 587 | 						fit->setFullDir(L"temp");
 | 
        
           | 127 | cycrow | 588 | 					}
 | 
        
           | 6 | cycrow | 589 | 				}
 | 
        
           | 127 | cycrow | 590 |   | 
        
           |  |  | 591 | 				if (!uncomprToFile)
 | 
        
           |  |  | 592 | 					return false;
 | 
        
           | 6 | cycrow | 593 | 			}
 | 
        
           |  |  | 594 | 		}
 | 
        
           |  |  | 595 |   | 
        
           |  |  | 596 | 		if ( progress )
 | 
        
           |  |  | 597 | 			progress->SwitchSecond();
 | 
        
           |  |  | 598 | 	}
 | 
        
           |  |  | 599 | 	return true;
 | 
        
           |  |  | 600 | }
 | 
        
           |  |  | 601 |   | 
        
           | 170 | cycrow | 602 | size_t CBaseFile::fileSize() const
 | 
        
           | 6 | cycrow | 603 | {
 | 
        
           | 170 | cycrow | 604 | 	size_t fullsize = 1000;
 | 
        
           | 6 | cycrow | 605 |   | 
        
           | 170 | cycrow | 606 | 	for (CListNode<C_File>* node = m_lFiles.Front(); node; node = node->next())
 | 
        
           | 178 | cycrow | 607 | 		fullsize += node->Data()->uncompressedDataSize();
 | 
        
           | 6 | cycrow | 608 |   | 
        
           | 170 | cycrow | 609 | 	if (m_pIconFile)
 | 
        
           | 178 | cycrow | 610 | 		fullsize += m_pIconFile->uncompressedDataSize();
 | 
        
           | 6 | cycrow | 611 |   | 
        
           |  |  | 612 | 	return fullsize;
 | 
        
           |  |  | 613 | }
 | 
        
           |  |  | 614 |   | 
        
           |  |  | 615 | /*
 | 
        
           |  |  | 616 | 	Func:   GetEndOfLine
 | 
        
           |  |  | 617 | 	Input:  id - The file id for the current file to read from
 | 
        
           |  |  | 618 | 	        line - Pointed to hold the line number thats read
 | 
        
           |  |  | 619 | 			upper - true if it converts to uppercase
 | 
        
           |  |  | 620 | 	Return: String - the string it has read
 | 
        
           |  |  | 621 | 	Desc:   Reads a string from a file, simlar to readLine() classes, reads to the end of the line in a file
 | 
        
           |  |  | 622 | */
 | 
        
           | 175 | cycrow | 623 | Utils::String CBaseFile::GetEndOfLine ( FILE *id, int *line, bool upper )
 | 
        
           | 6 | cycrow | 624 | {
 | 
        
           | 175 | cycrow | 625 | 	Utils::String word;
 | 
        
           | 6 | cycrow | 626 |   | 
        
           |  |  | 627 | 	char c = fgetc ( id );
 | 
        
           |  |  | 628 | 	if ( c == -1 )
 | 
        
           |  |  | 629 | 		return "";
 | 
        
           |  |  | 630 |   | 
        
           |  |  | 631 | 	while ( (c != 13) && (!feof(id)) && (c != '\n') )
 | 
        
           |  |  | 632 | 	{
 | 
        
           |  |  | 633 | 		word += c;
 | 
        
           |  |  | 634 | 		c = fgetc ( id );
 | 
        
           |  |  | 635 | 	}
 | 
        
           |  |  | 636 |   | 
        
           |  |  | 637 | 	if ( line )
 | 
        
           |  |  | 638 | 		++(*line);
 | 
        
           |  |  | 639 |   | 
        
           |  |  | 640 | 	if ( upper )
 | 
        
           | 175 | cycrow | 641 | 		return word.upper();
 | 
        
           | 6 | cycrow | 642 |   | 
        
           |  |  | 643 | 	return word;
 | 
        
           |  |  | 644 | }
 | 
        
           |  |  | 645 |   | 
        
           | 170 | cycrow | 646 | size_t CBaseFile::countFiles(FileType filetype) const
 | 
        
           | 6 | cycrow | 647 | {
 | 
        
           | 170 | cycrow | 648 | 	size_t i = 0;
 | 
        
           | 6 | cycrow | 649 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 650 | 	{
 | 
        
           |  |  | 651 | 		C_File *file = node->Data();
 | 
        
           |  |  | 652 | 		if ( file->GetFileType() != filetype )
 | 
        
           |  |  | 653 | 			continue;
 | 
        
           |  |  | 654 | 		++i;
 | 
        
           |  |  | 655 | 	}
 | 
        
           |  |  | 656 |   | 
        
           |  |  | 657 | 	return i;
 | 
        
           |  |  | 658 | }
 | 
        
           |  |  | 659 |   | 
        
           |  |  | 660 | /*
 | 
        
           |  |  | 661 | 	Func:   CreateFilesLine
 | 
        
           |  |  | 662 | 	Return: String - returns the full string for files list
 | 
        
           |  |  | 663 | 	Desc:   Creates a signle line list of all the files
 | 
        
           |  |  | 664 | */
 | 
        
           | 211 | cycrow | 665 | Utils::WString CBaseFile::createFilesLine(SSPKHeader2 *header, CProgressInfo* progress) const
 | 
        
           | 6 | cycrow | 666 | {
 | 
        
           | 197 | cycrow | 667 | 	Utils::WString line;
 | 
        
           | 6 | cycrow | 668 |   | 
        
           | 170 | cycrow | 669 | 	if (progress)
 | 
        
           | 6 | cycrow | 670 | 	{
 | 
        
           |  |  | 671 | 		progress->SetDone(0);
 | 
        
           |  |  | 672 | 		progress->UpdateStatus(STATUS_COMPRESS);
 | 
        
           |  |  | 673 | 	}
 | 
        
           |  |  | 674 |   | 
        
           | 175 | cycrow | 675 | 	if (header)
 | 
        
           | 6 | cycrow | 676 | 	{
 | 
        
           | 175 | cycrow | 677 | 		header->iDataCompression = m_SHeader2.iDataCompression;
 | 
        
           |  |  | 678 | 		header->iFileCompression = m_SHeader2.iFileCompression;
 | 
        
           |  |  | 679 | 		header->lSize = m_SHeader2.lSize;
 | 
        
           |  |  | 680 | 		header->iNumFiles = 0;
 | 
        
           |  |  | 681 | 		header->lFullSize = 0;
 | 
        
           | 6 | cycrow | 682 | 	}
 | 
        
           |  |  | 683 |   | 
        
           | 170 | cycrow | 684 | 	if (m_pIconFile)
 | 
        
           | 6 | cycrow | 685 | 	{
 | 
        
           |  |  | 686 | 		// no data, read it from file
 | 
        
           | 170 | cycrow | 687 | 		if (!m_pIconFile->GetData())
 | 
        
           |  |  | 688 | 			m_pIconFile->ReadFromFile();
 | 
        
           | 6 | cycrow | 689 |   | 
        
           |  |  | 690 | 		// compress the file
 | 
        
           | 170 | cycrow | 691 | 		if (!m_pIconFile->CompressData(m_SHeader2.iDataCompression, progress))
 | 
        
           | 6 | cycrow | 692 | 			m_pIconFile->SetDataCompression(SPKCOMPRESS_NONE);
 | 
        
           |  |  | 693 |   | 
        
           | 197 | cycrow | 694 | 		line += L"Icon:" + Utils::WString::Number(m_pIconFile->GetDataSize() + (long)4) + L":" + m_pIconFile->uncompressedDataSize() + L":" + (long)m_pIconFile->GetCompressionType() + L":" + _sIconExt + L"\n";
 | 
        
           | 175 | cycrow | 695 | 		if (header)
 | 
        
           | 6 | cycrow | 696 | 		{
 | 
        
           | 175 | cycrow | 697 | 			++header->iNumFiles;
 | 
        
           |  |  | 698 | 			header->lFullSize += (m_pIconFile->GetDataSize() + 4);
 | 
        
           | 6 | cycrow | 699 | 		}
 | 
        
           |  |  | 700 | 	}
 | 
        
           |  |  | 701 |   | 
        
           | 170 | cycrow | 702 | 	for (CListNode<C_File>* node = m_lFiles.Front(); node; node = node->next())
 | 
        
           | 6 | cycrow | 703 | 	{
 | 
        
           | 170 | cycrow | 704 | 		C_File* file = node->Data();
 | 
        
           |  |  | 705 | 		if (progress)
 | 
        
           |  |  | 706 | 			progress->UpdateFile(file);
 | 
        
           | 6 | cycrow | 707 |   | 
        
           |  |  | 708 | 		// no data, read it from file
 | 
        
           | 170 | cycrow | 709 | 		if (!file->GetData())
 | 
        
           | 6 | cycrow | 710 | 		{
 | 
        
           | 170 | cycrow | 711 | 			if (!file->ReadFromFile())
 | 
        
           | 6 | cycrow | 712 | 			{
 | 
        
           | 170 | cycrow | 713 | 				if (file->GetLastError() == SPKERR_MALLOC)
 | 
        
           | 6 | cycrow | 714 | 				{
 | 
        
           | 170 | cycrow | 715 | 					if (!file->CompressFile(progress))
 | 
        
           | 6 | cycrow | 716 | 						continue;
 | 
        
           |  |  | 717 | 				}
 | 
        
           |  |  | 718 | 			}
 | 
        
           |  |  | 719 | 		}
 | 
        
           |  |  | 720 |   | 
        
           | 170 | cycrow | 721 | 		if (!file->GetData())
 | 
        
           | 6 | cycrow | 722 | 			continue;
 | 
        
           |  |  | 723 |   | 
        
           |  |  | 724 | 		// compress the file
 | 
        
           | 170 | cycrow | 725 | 		if (!file->CompressData(m_SHeader2.iDataCompression, progress))
 | 
        
           | 6 | cycrow | 726 | 		{
 | 
        
           |  |  | 727 | 			file->SetDataCompression(SPKCOMPRESS_NONE);
 | 
        
           |  |  | 728 | 			file->SetUncompressedDataSize(file->GetDataSize());
 | 
        
           |  |  | 729 | 		}
 | 
        
           |  |  | 730 |   | 
        
           | 197 | cycrow | 731 | 		Utils::WString command = GetFileTypeString(file->GetFileType());
 | 
        
           | 170 | cycrow | 732 | 		if (command.empty())
 | 
        
           | 6 | cycrow | 733 | 			continue;
 | 
        
           |  |  | 734 |   | 
        
           | 170 | cycrow | 735 | 		if (file->IsShared())
 | 
        
           | 197 | cycrow | 736 | 			command = L"$" + command;
 | 
        
           | 6 | cycrow | 737 |   | 
        
           | 170 | cycrow | 738 | 		if (file->dir().empty())
 | 
        
           | 197 | cycrow | 739 | 			line += command + L":" + (file->GetDataSize() + (long)4) + L":" + file->uncompressedDataSize() + L":" + (long)file->GetCompressionType() + L":" + (long)file->GetCreationTime() + L":" + ((file->IsCompressedToFile()) ? L"1" : L"0") + L":" + file->filename() + L":NULL:" + (long)file->game() + L"\n";
 | 
        
           | 6 | cycrow | 740 | 		else
 | 
        
           | 197 | cycrow | 741 | 			line += command + L":" + (file->GetDataSize() + (long)4) + L":" + file->uncompressedDataSize() + L":" + (long)file->GetCompressionType() + L":" + (long)file->GetCreationTime() + L":" + ((file->IsCompressedToFile()) ? L"1" : L"0") + L":" + file->filename() + L":" + file->dir() + L":" + (long)file->game() + L"\n";
 | 
        
           | 6 | cycrow | 742 |   | 
        
           | 175 | cycrow | 743 | 		if (header)
 | 
        
           | 6 | cycrow | 744 | 		{
 | 
        
           | 175 | cycrow | 745 | 			++header->iNumFiles;
 | 
        
           |  |  | 746 | 			header->lFullSize += (file->GetDataSize() + 4);
 | 
        
           | 6 | cycrow | 747 | 		}
 | 
        
           |  |  | 748 | 	}
 | 
        
           |  |  | 749 |   | 
        
           | 211 | cycrow | 750 | 	return line;
 | 
        
           | 6 | cycrow | 751 | }
 | 
        
           |  |  | 752 |   | 
        
           |  |  | 753 | /*
 | 
        
           |  |  | 754 | ######################################################################################
 | 
        
           |  |  | 755 | ##########							Reading Functions			    		##########
 | 
        
           |  |  | 756 | ######################################################################################
 | 
        
           |  |  | 757 | */
 | 
        
           |  |  | 758 |   | 
        
           |  |  | 759 | void CBaseFile::ReadAllFilesToMemory ()
 | 
        
           |  |  | 760 | {
 | 
        
           |  |  | 761 | 	// no file to read from
 | 
        
           | 50 | cycrow | 762 | 	if ( this->filename().empty() ) return;
 | 
        
           | 6 | cycrow | 763 |   | 
        
           |  |  | 764 | 	// now open the file
 | 
        
           | 58 | cycrow | 765 | 	CFileIO File(this->filename());
 | 
        
           |  |  | 766 | 	if ( !File.startRead() ) return;
 | 
        
           | 6 | cycrow | 767 |   | 
        
           |  |  | 768 | 	// read the header
 | 
        
           | 197 | cycrow | 769 | 	File.readEndOfLineStr();
 | 
        
           | 6 | cycrow | 770 | 	// skip past values
 | 
        
           | 58 | cycrow | 771 | 	File.seek(4 + m_SHeader.lValueCompressSize);
 | 
        
           | 6 | cycrow | 772 |   | 
        
           |  |  | 773 | 	// read the next header
 | 
        
           | 197 | cycrow | 774 | 	File.readEndOfLineStr();
 | 
        
           | 6 | cycrow | 775 | 	// skip past files
 | 
        
           | 58 | cycrow | 776 | 	File.seek(4 + m_SHeader2.lSize);
 | 
        
           | 6 | cycrow | 777 |   | 
        
           |  |  | 778 | 	if ( m_pIconFile )
 | 
        
           |  |  | 779 | 	{
 | 
        
           |  |  | 780 | 		if ( (!m_pIconFile->GetData()) && (!m_pIconFile->Skip()) )
 | 
        
           | 51 | cycrow | 781 | 			m_pIconFile->readFromFile(File, m_pIconFile->GetDataSize());
 | 
        
           | 6 | cycrow | 782 | 		else
 | 
        
           | 58 | cycrow | 783 | 			File.seek(4 + m_pIconFile->GetDataSize());
 | 
        
           | 6 | cycrow | 784 | 	}
 | 
        
           |  |  | 785 |   | 
        
           |  |  | 786 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 787 | 	{
 | 
        
           |  |  | 788 | 		C_File *fit = node->Data();
 | 
        
           |  |  | 789 | 		if ( (!fit->GetData()) && (!fit->Skip()) )
 | 
        
           | 51 | cycrow | 790 | 			fit->readFromFile(File, fit->GetDataSize());
 | 
        
           | 6 | cycrow | 791 | 		else
 | 
        
           | 58 | cycrow | 792 | 			File.seek(4 + fit->GetDataSize());
 | 
        
           | 6 | cycrow | 793 | 	}
 | 
        
           |  |  | 794 |   | 
        
           | 51 | cycrow | 795 | 	File.close();
 | 
        
           | 6 | cycrow | 796 | }
 | 
        
           |  |  | 797 |   | 
        
           |  |  | 798 | bool CBaseFile::ReadFileToMemory(C_File *f)
 | 
        
           |  |  | 799 | {
 | 
        
           | 62 | cycrow | 800 | 	if ( this->filename().empty() || !f ) return false;		// no filename to load from
 | 
        
           | 51 | cycrow | 801 | 	if ( f->GetData() && f->GetDataSize() ) return true;	// already loaded the data
 | 
        
           |  |  | 802 | 	if ( !m_lFiles.FindData(f) ) return false;				// unable to find file entry
 | 
        
           | 6 | cycrow | 803 |   | 
        
           |  |  | 804 | 	// now open the file
 | 
        
           | 58 | cycrow | 805 | 	CFileIO *File = _startRead();
 | 
        
           |  |  | 806 | 	if ( !File ) return false;
 | 
        
           | 6 | cycrow | 807 |   | 
        
           | 58 | cycrow | 808 | 	if ( m_pIconFile ) File->seek(4 + m_pIconFile->GetDataSize());
 | 
        
           | 51 | cycrow | 809 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
 | 
        
           | 6 | cycrow | 810 | 		C_File *fit = node->Data();
 | 
        
           | 51 | cycrow | 811 | 		if (fit == f ) {
 | 
        
           | 58 | cycrow | 812 | 			fit->readFromFile(*File, fit->GetDataSize());
 | 
        
           | 6 | cycrow | 813 | 			break;
 | 
        
           |  |  | 814 | 		}
 | 
        
           | 58 | cycrow | 815 | 		else File->seek(4 + fit->GetDataSize());
 | 
        
           | 6 | cycrow | 816 | 	}
 | 
        
           |  |  | 817 |   | 
        
           | 58 | cycrow | 818 | 	delete File;
 | 
        
           | 6 | cycrow | 819 | 	return true;
 | 
        
           |  |  | 820 | }
 | 
        
           |  |  | 821 |   | 
        
           | 58 | cycrow | 822 | CFileIO *CBaseFile::_startRead()
 | 
        
           | 6 | cycrow | 823 | {
 | 
        
           |  |  | 824 | 	// no file to read from
 | 
        
           | 58 | cycrow | 825 | 	if ( this->filename().empty() ) return NULL;
 | 
        
           | 6 | cycrow | 826 |   | 
        
           |  |  | 827 | 	// now open the file
 | 
        
           | 58 | cycrow | 828 | 	CFileIO *File = new CFileIO(this->filename());
 | 
        
           |  |  | 829 | 	if ( !File->startRead() ) return NULL;
 | 
        
           | 6 | cycrow | 830 |   | 
        
           |  |  | 831 | 	// read the header
 | 
        
           | 197 | cycrow | 832 | 	File->readEndOfLineStr();
 | 
        
           | 6 | cycrow | 833 | 	// skip past values
 | 
        
           | 58 | cycrow | 834 | 	File->seek(4 + m_SHeader.lValueCompressSize);
 | 
        
           | 6 | cycrow | 835 |   | 
        
           |  |  | 836 | 	// read the next header
 | 
        
           | 197 | cycrow | 837 | 	File->readEndOfLineStr();
 | 
        
           | 6 | cycrow | 838 | 	// skip past files
 | 
        
           | 58 | cycrow | 839 | 	File->seek(4 + m_SHeader2.lSize);
 | 
        
           | 6 | cycrow | 840 |   | 
        
           | 58 | cycrow | 841 | 	return File;
 | 
        
           |  |  | 842 | }
 | 
        
           | 6 | cycrow | 843 |   | 
        
           | 88 | cycrow | 844 | void CBaseFile::_addFile(C_File *file, bool dontChange)
 | 
        
           |  |  | 845 | {
 | 
        
           |  |  | 846 | 	if ( !dontChange ) {
 | 
        
           |  |  | 847 | 		file->UpdateSigned();
 | 
        
           |  |  | 848 | 		_changed();
 | 
        
           |  |  | 849 | 	}
 | 
        
           |  |  | 850 | 	m_lFiles.push_back(file);
 | 
        
           |  |  | 851 |   | 
        
           |  |  | 852 | 	_updateTextDB(file);
 | 
        
           |  |  | 853 | }
 | 
        
           |  |  | 854 |   | 
        
           |  |  | 855 | void CBaseFile::_updateTextDB(C_File *file)
 | 
        
           |  |  | 856 | {
 | 
        
           |  |  | 857 | 	if ( !_pTextDB ) _pTextDB = new CTextDB();
 | 
        
           |  |  | 858 |   | 
        
           |  |  | 859 | 	if ( file->GetFileType() == FILETYPE_TEXT ) {
 | 
        
           | 196 | cycrow | 860 | 		Utils::WString baseFile = CFileIO(file->filePointer()).baseName();
 | 
        
           |  |  | 861 | 		int lang = (baseFile.contains(L"-L")) ? baseFile.right(3) : baseFile.truncate(-4);
 | 
        
           | 88 | cycrow | 862 |   | 
        
           |  |  | 863 | 		// read in the text file to the database
 | 
        
           |  |  | 864 | 		_pTextDB->parseTextFile(0, 0, file->filePointer(), lang);
 | 
        
           |  |  | 865 | 	}
 | 
        
           |  |  | 866 | }
 | 
        
           |  |  | 867 |   | 
        
           |  |  | 868 | void CBaseFile::_resetTextDB()
 | 
        
           |  |  | 869 | {
 | 
        
           |  |  | 870 | 	if ( _pTextDB ) delete _pTextDB;
 | 
        
           |  |  | 871 | 	_pTextDB = new CTextDB();
 | 
        
           |  |  | 872 |   | 
        
           |  |  | 873 | 	for(CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next()) {
 | 
        
           |  |  | 874 | 		_updateTextDB(node->Data());
 | 
        
           |  |  | 875 | 	}
 | 
        
           |  |  | 876 | }
 | 
        
           |  |  | 877 |   | 
        
           | 58 | cycrow | 878 | void CBaseFile::ReadIconFileToMemory ()
 | 
        
           |  |  | 879 | {
 | 
        
           |  |  | 880 | 	if ( !m_pIconFile )	return;
 | 
        
           |  |  | 881 | 	CFileIO *File = _startRead();
 | 
        
           |  |  | 882 | 	if ( !File ) return;
 | 
        
           |  |  | 883 |   | 
        
           |  |  | 884 | 	if ( (!m_pIconFile->GetData()) && (!m_pIconFile->Skip()) )
 | 
        
           |  |  | 885 | 		m_pIconFile->readFromFile(*File, m_pIconFile->GetDataSize());
 | 
        
           |  |  | 886 | 	else
 | 
        
           |  |  | 887 | 		File->seek(4 + m_pIconFile->GetDataSize());
 | 
        
           |  |  | 888 |   | 
        
           |  |  | 889 | 	delete File;
 | 
        
           | 6 | cycrow | 890 | }
 | 
        
           |  |  | 891 |   | 
        
           | 14 | cycrow | 892 | void CBaseFile::_install_adjustFakePatches(CPackages *pPackages)
 | 
        
           | 6 | cycrow | 893 | {
 | 
        
           | 197 | cycrow | 894 | 	Utils::WStringList lPatches;
 | 
        
           | 182 | cycrow | 895 | 	int startfake = pPackages->findNextFakePatch();
 | 
        
           | 6 | cycrow | 896 |   | 
        
           | 14 | cycrow | 897 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 898 | 	{
 | 
        
           |  |  | 899 | 		C_File *fit = node->Data();
 | 
        
           |  |  | 900 | 		// only do fake patchs
 | 
        
           |  |  | 901 | 		if ( !fit->IsFakePatch() )
 | 
        
           |  |  | 902 | 			continue;
 | 
        
           |  |  | 903 |   | 
        
           |  |  | 904 | 		// we should only have cat and dat files, but lets check just incase they have been added incorrectly
 | 
        
           | 213 | cycrow | 905 | 		if ( !fit->checkFileExt (L"cat") && !fit->checkFileExt(L"dat") )
 | 
        
           | 14 | cycrow | 906 | 			continue;
 | 
        
           |  |  | 907 |   | 
        
           |  |  | 908 | 		// search for the name on the list
 | 
        
           | 197 | cycrow | 909 | 		Utils::WString newname;
 | 
        
           | 175 | cycrow | 910 | 		bool isOpposite = false;
 | 
        
           |  |  | 911 | 		if (lPatches.contains(fit->baseName()))
 | 
        
           |  |  | 912 | 		{
 | 
        
           |  |  | 913 | 			newname = lPatches.findString(fit->baseName());
 | 
        
           |  |  | 914 | 			isOpposite = true;
 | 
        
           |  |  | 915 | 		}
 | 
        
           | 14 | cycrow | 916 | 		else
 | 
        
           |  |  | 917 | 		{
 | 
        
           | 197 | cycrow | 918 | 			newname = Utils::WString::PadNumber((long)startfake, 2);
 | 
        
           | 175 | cycrow | 919 | 			lPatches.pushBack(fit->baseName(), newname);
 | 
        
           | 14 | cycrow | 920 | 		}
 | 
        
           |  |  | 921 |   | 
        
           |  |  | 922 | 		// rename the file
 | 
        
           |  |  | 923 | 		fit->FixOriginalName();
 | 
        
           | 227 | cycrow | 924 | 		CLog::logf(CLog::Log_Install, 2, L"Adjusting fake patch number, %s => %s", fit->getNameDirectory(this).c_str(), (newname + L"." + fit->fileExt()).c_str());
 | 
        
           | 213 | cycrow | 925 | 		fit->setName(newname + L"." + fit->fileExt());
 | 
        
           | 14 | cycrow | 926 |   | 
        
           |  |  | 927 | 		// find the next gap
 | 
        
           | 175 | cycrow | 928 | 		if ( !isOpposite ) {
 | 
        
           | 182 | cycrow | 929 | 			startfake = pPackages->findNextFakePatch(startfake + 1);
 | 
        
           | 14 | cycrow | 930 | 		}
 | 
        
           |  |  | 931 | 	}
 | 
        
           |  |  | 932 | }
 | 
        
           |  |  | 933 |   | 
        
           | 43 | cycrow | 934 | void CBaseFile::_install_renameText(CPackages *pPackages)
 | 
        
           | 14 | cycrow | 935 | {
 | 
        
           | 130 | cycrow | 936 | 	int starttext = pPackages->findNextTextFile();
 | 
        
           | 43 | cycrow | 937 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
 | 
        
           |  |  | 938 | 		C_File *fit = node->Data();
 | 
        
           | 130 | cycrow | 939 | 		if ( !fit->isAutoTextFile() )
 | 
        
           | 43 | cycrow | 940 | 			continue;
 | 
        
           | 6 | cycrow | 941 |   | 
        
           | 197 | cycrow | 942 | 		Utils::WString newname = SPK::FormatTextName(starttext, pPackages->GetLanguage(), (pPackages->GetCurrentGameFlags() & EXEFLAG_TCTEXT));
 | 
        
           | 43 | cycrow | 943 | 		fit->FixOriginalName();
 | 
        
           | 227 | cycrow | 944 | 		CLog::logf(CLog::Log_Install, 2, L"Adjusting text file, %s => %s", fit->getNameDirectory(this).c_str(), (newname + "." + fit->fileExt()).c_str());
 | 
        
           | 130 | cycrow | 945 | 		fit->setName(newname + "." + fit->fileExt());
 | 
        
           | 6 | cycrow | 946 |   | 
        
           | 43 | cycrow | 947 | 		++starttext;
 | 
        
           |  |  | 948 | 	}
 | 
        
           |  |  | 949 | }
 | 
        
           | 6 | cycrow | 950 |   | 
        
           | 50 | cycrow | 951 | bool CBaseFile::_install_setEnabled(bool bEnable, C_File *fit)
 | 
        
           |  |  | 952 | {
 | 
        
           |  |  | 953 | 	if ( !bEnable )
 | 
        
           |  |  | 954 | 	{
 | 
        
           |  |  | 955 | 		if ( (fit->GetFileType() == FILETYPE_UNINSTALL) || (fit->GetFileType() == FILETYPE_README) || (fit->GetFileType() == FILETYPE_ADVERT) )
 | 
        
           |  |  | 956 | 			bEnable = true;
 | 
        
           | 213 | cycrow | 957 | 		else if ( (fit->GetFileType() == FILETYPE_EXTRA) && (fit->dir().left(7).lower() == L"Extras/") )
 | 
        
           | 50 | cycrow | 958 | 			bEnable = true;
 | 
        
           |  |  | 959 | 		else if ( (IsPatch()) && (fit->GetFileType() == FILETYPE_MOD) && (!fit->IsFakePatch()) )
 | 
        
           |  |  | 960 | 			bEnable = true;
 | 
        
           |  |  | 961 |   | 
        
           | 227 | cycrow | 962 | 		if ( bEnable ) CLog::logf(CLog::Log_Install, 3, L"Filetype(%d) is always enabled, setting enabled flag", fit->GetFileType());
 | 
        
           | 50 | cycrow | 963 | 	}
 | 
        
           |  |  | 964 |   | 
        
           |  |  | 965 | 	return bEnable;
 | 
        
           |  |  | 966 | }
 | 
        
           |  |  | 967 |   | 
        
           | 197 | cycrow | 968 | bool CBaseFile::_install_uncompress(C_File *fit, CProgressInfo *progress, Utils::WStringList *errorStr, bool *uncomprToFile)
 | 
        
           | 50 | cycrow | 969 | {
 | 
        
           |  |  | 970 | 	*uncomprToFile = false;
 | 
        
           | 134 | cycrow | 971 | 	_sLastError = fit->getNameDirectory(this);
 | 
        
           |  |  | 972 | 	_iLastError = SPKERR_UNCOMPRESS;
 | 
        
           | 96 | cycrow | 973 |   | 
        
           | 50 | cycrow | 974 | 	if ( !fit->UncompressData ( progress ) )
 | 
        
           |  |  | 975 | 	{
 | 
        
           | 213 | cycrow | 976 | 		CLog::log(CLog::Log_Install, 2, L"Failed to uncompress data, attempting file decompression");
 | 
        
           | 50 | cycrow | 977 | 		if ( fit->GetCompressionType() == SPKCOMPRESS_7ZIP )
 | 
        
           |  |  | 978 | 		{
 | 
        
           | 197 | cycrow | 979 | 			if ( fit->uncompressToFile(Utils::WString::Null(), this, false, progress ) )
 | 
        
           | 50 | cycrow | 980 | 				*uncomprToFile = true;
 | 
        
           |  |  | 981 | 		}
 | 
        
           |  |  | 982 |   | 
        
           |  |  | 983 | 		if ( !uncomprToFile )
 | 
        
           |  |  | 984 | 		{
 | 
        
           |  |  | 985 | 			if ( errorStr )
 | 
        
           | 175 | cycrow | 986 | 				errorStr->pushBack(_sLastError, ERRORLOG(SPKINSTALL_UNCOMPRESS_FAIL));
 | 
        
           | 213 | cycrow | 987 | 			CLog::log(CLog::Log_Install, 1, L"Unable to decompress file, skipping");
 | 
        
           | 50 | cycrow | 988 | 			return false;
 | 
        
           |  |  | 989 | 		}
 | 
        
           |  |  | 990 | 	}
 | 
        
           |  |  | 991 | 	ClearError ();
 | 
        
           |  |  | 992 |   | 
        
           |  |  | 993 | 	return true;
 | 
        
           |  |  | 994 | }
 | 
        
           |  |  | 995 |   | 
        
           | 197 | cycrow | 996 | bool CBaseFile::_install_checkVersion(C_File *pFile, const Utils::WString &sDestination)
 | 
        
           | 50 | cycrow | 997 | {
 | 
        
           |  |  | 998 | 	// new check if we should install the file
 | 
        
           |  |  | 999 | 	// first get the version
 | 
        
           |  |  | 1000 | 	if ( !m_bOverrideFiles && pFile->ReadScriptVersion() )
 | 
        
           |  |  | 1001 | 	{
 | 
        
           | 213 | cycrow | 1002 | 		CLog::log(CLog::Log_Install, 2, L"Checking for existing file version");
 | 
        
           | 50 | cycrow | 1003 | 		C_File checkfile;
 | 
        
           | 197 | cycrow | 1004 | 		Utils::WString checkfilename = sDestination;
 | 
        
           |  |  | 1005 | 		if ( !checkfilename.empty() ) checkfilename += L"/";
 | 
        
           | 175 | cycrow | 1006 | 		checkfilename += pFile->getNameDirectory(this);
 | 
        
           |  |  | 1007 | 		checkfile.setFilename(checkfilename);
 | 
        
           | 127 | cycrow | 1008 | 		checkfile.setFileType(pFile->fileType());
 | 
        
           | 50 | cycrow | 1009 | 		if ( checkfile.CheckValidFilePointer() ) {
 | 
        
           |  |  | 1010 | 			if ( checkfile.ReadScriptVersion() > pFile->GetVersion() ) {
 | 
        
           | 213 | cycrow | 1011 | 				CLog::log(CLog::Log_Install, 1, L"Newer version of the file found in directory, skipping");
 | 
        
           | 50 | cycrow | 1012 | 				return false;
 | 
        
           |  |  | 1013 | 			}
 | 
        
           |  |  | 1014 | 		}
 | 
        
           |  |  | 1015 | 	}
 | 
        
           |  |  | 1016 |   | 
        
           |  |  | 1017 | 	return true;
 | 
        
           |  |  | 1018 | }
 | 
        
           |  |  | 1019 |   | 
        
           | 210 | cycrow | 1020 | Utils::WString CBaseFile::_install_adjustFilepointer(C_File *pFile, bool bEnabled, const Utils::WString &sDestination)
 | 
        
           | 50 | cycrow | 1021 | {
 | 
        
           | 197 | cycrow | 1022 | 	Utils::WString filename = sDestination;
 | 
        
           |  |  | 1023 | 	if ( !filename.empty() ) filename += L"/";
 | 
        
           | 50 | cycrow | 1024 |   | 
        
           | 130 | cycrow | 1025 | 	if ( (IsPatch()) && (pFile->fileType() == FILETYPE_MOD) )
 | 
        
           | 197 | cycrow | 1026 | 		pFile->setDir(L"Patch");
 | 
        
           | 50 | cycrow | 1027 |   | 
        
           | 160 | cycrow | 1028 | 	if ( pFile->isInMod() )
 | 
        
           | 50 | cycrow | 1029 | 	{
 | 
        
           |  |  | 1030 | 		if ( bEnabled )
 | 
        
           | 197 | cycrow | 1031 | 			pFile->setFilename(filename + pFile->getInMod() + L"::" + pFile->getNameDirectory(this));
 | 
        
           | 50 | cycrow | 1032 | 		else
 | 
        
           | 197 | cycrow | 1033 | 			pFile->setFilename(filename + L"PluginManager/DisabledFiles.cat::" + pFile->getNameDirectory(this));
 | 
        
           | 50 | cycrow | 1034 | 	}
 | 
        
           |  |  | 1035 | 	else
 | 
        
           | 130 | cycrow | 1036 | 		pFile->setFilename ( filename + pFile->getNameDirectory(this) );
 | 
        
           | 50 | cycrow | 1037 |   | 
        
           |  |  | 1038 | 	if ( !bEnabled )
 | 
        
           |  |  | 1039 | 	{
 | 
        
           | 160 | cycrow | 1040 | 		if ( !pFile->isInMod() )
 | 
        
           | 50 | cycrow | 1041 | 		{
 | 
        
           |  |  | 1042 | 			if ( pFile->IsFakePatch() )
 | 
        
           | 203 | cycrow | 1043 | 				pFile->setFilename ( filename + L"PluginManager/Disabled/FakePatches/FakePatch_" + this->getNameValidFile() + L"_" + this->author() + L"_" + pFile->name());
 | 
        
           | 130 | cycrow | 1044 | 			else if ( pFile->isAutoTextFile() )
 | 
        
           | 203 | cycrow | 1045 | 				pFile->setFilename ( filename + L"PluginManager/Disabled/TextFiles/Text_" + this->getNameValidFile() + L"_" + this->author() + L"_" + pFile->name());
 | 
        
           | 50 | cycrow | 1046 | 			else
 | 
        
           | 197 | cycrow | 1047 | 				pFile->setFullDir ( filename + L"PluginManager/Disabled/" + pFile->getDirectory(this) );
 | 
        
           | 50 | cycrow | 1048 | 		}
 | 
        
           |  |  | 1049 | 		pFile->SetDisabled(true);
 | 
        
           |  |  | 1050 | 	}
 | 
        
           |  |  | 1051 |   | 
        
           | 227 | cycrow | 1052 | 	CLog::logf(CLog::Log_Install, 2, L"Adjusting the file pointer to correct install destintation, %s", pFile->filePointer().c_str());
 | 
        
           | 50 | cycrow | 1053 |   | 
        
           | 210 | cycrow | 1054 | 	return filename;
 | 
        
           | 50 | cycrow | 1055 | }
 | 
        
           |  |  | 1056 |   | 
        
           | 197 | cycrow | 1057 | C_File *CBaseFile::_install_checkFile(C_File *pFile, Utils::WStringList *errorStr, bool *bDoFile, CLinkList<C_File> *pFileList)
 | 
        
           | 50 | cycrow | 1058 | {
 | 
        
           |  |  | 1059 | 	if ( !pFile->IsFakePatch() && pFile->GetFileType() != FILETYPE_README )
 | 
        
           |  |  | 1060 | 	{
 | 
        
           |  |  | 1061 | 		C_File *cFile;
 | 
        
           |  |  | 1062 | 		for ( cFile = pFileList->First(); cFile; cFile = pFileList->Next() )
 | 
        
           |  |  | 1063 | 		{
 | 
        
           |  |  | 1064 | 			if ( !cFile->MatchFile(pFile) ) continue;
 | 
        
           |  |  | 1065 | 			if ( !m_bOverrideFiles && !cFile->CompareNew(pFile) ) {
 | 
        
           | 175 | cycrow | 1066 | 				if ( errorStr ) errorStr->pushBack(pFile->getNameDirectory(this), ERRORLOG(SPKINSTALL_SKIPFILE));
 | 
        
           | 213 | cycrow | 1067 | 				CLog::log(CLog::Log_Install, 1, L"Newer version of the file already installed, skipping");
 | 
        
           | 50 | cycrow | 1068 | 				*bDoFile = false;
 | 
        
           |  |  | 1069 | 			}
 | 
        
           |  |  | 1070 | 			break;
 | 
        
           |  |  | 1071 | 		}
 | 
        
           |  |  | 1072 |   | 
        
           |  |  | 1073 | 		return cFile;
 | 
        
           |  |  | 1074 | 	}
 | 
        
           |  |  | 1075 |   | 
        
           |  |  | 1076 | 	return NULL;
 | 
        
           |  |  | 1077 | }
 | 
        
           |  |  | 1078 |   | 
        
           | 197 | cycrow | 1079 | bool CBaseFile::_install_checkFileEnable(C_File *pCheckFile, C_File *fit, const Utils::WString &sDestination, bool bEnabled, Utils::WStringList *errorStr)
 | 
        
           | 50 | cycrow | 1080 | {
 | 
        
           |  |  | 1081 | 	// found a file, check if its in the disabled directory
 | 
        
           | 196 | cycrow | 1082 | 	Utils::WString dir = CFileIO(pCheckFile->filePointer()).dir();
 | 
        
           |  |  | 1083 | 	Utils::WString lastDir = CDirIO(dir).topDir().lower();
 | 
        
           | 50 | cycrow | 1084 |   | 
        
           |  |  | 1085 | 	// if its disabled, rename it so its enabled
 | 
        
           | 196 | cycrow | 1086 | 	if ( ((pCheckFile->IsDisabled()) || (lastDir == L"disabled") || (dir.lower().contains(L"/disabled/"))) && (bEnabled) )
 | 
        
           | 50 | cycrow | 1087 | 	{
 | 
        
           | 227 | cycrow | 1088 | 		CLog::logf(CLog::Log_Install, 2, L"Existing file, %s, is disabled, re-enabling it", pCheckFile->filePointer().c_str());
 | 
        
           | 50 | cycrow | 1089 | 		// first check if the directory exists
 | 
        
           | 160 | cycrow | 1090 | 		if ( pCheckFile->isInMod() ) {
 | 
        
           | 197 | cycrow | 1091 | 			Utils::WString tofile = pCheckFile->filePointer().token(L"::", 2);
 | 
        
           | 50 | cycrow | 1092 |   | 
        
           |  |  | 1093 | 			CCatFile tocat;
 | 
        
           | 197 | cycrow | 1094 | 			int err = tocat.open(fit->filePointer().token(L"::", 1), L"", CATREAD_CATDECRYPT, true);
 | 
        
           | 50 | cycrow | 1095 | 			if ( (err == CATERR_NONE) || (err == CATERR_CREATED) ) {
 | 
        
           | 181 | cycrow | 1096 | 				tocat.appendFile(pCheckFile->filePointer(), tofile);
 | 
        
           | 227 | cycrow | 1097 | 				CLog::logf(CLog::Log_Install, 2, L"Adding existing file into new mod File, %s => %s", fit->filePointer().token(L"::", 1).c_str(), tofile.c_str());
 | 
        
           | 50 | cycrow | 1098 | 			}
 | 
        
           |  |  | 1099 |   | 
        
           |  |  | 1100 | 			CCatFile fromcat;
 | 
        
           | 197 | cycrow | 1101 | 			err = fromcat.open(pCheckFile->filePointer().token(L"::", 1), L"", CATREAD_CATDECRYPT, false);
 | 
        
           | 50 | cycrow | 1102 | 			if ( err == CATERR_NONE ) {
 | 
        
           | 175 | cycrow | 1103 | 				fromcat.removeFile(tofile);
 | 
        
           | 227 | cycrow | 1104 | 				CLog::logf(CLog::Log_Install, 2, L"Removing file from existing mod, %s::%s", pCheckFile->filePointer().token(L"::", 1).c_str(), tofile.c_str());
 | 
        
           | 50 | cycrow | 1105 | 			}
 | 
        
           |  |  | 1106 |   | 
        
           | 227 | cycrow | 1107 | 			CLog::logf(CLog::Log_Install, 1, L"Adjusting existing file name %s => %s", pCheckFile->filePointer().c_str(), fit->filePointer().c_str());
 | 
        
           | 178 | cycrow | 1108 | 			pCheckFile->setFilename(fit->filePointer());
 | 
        
           | 227 | cycrow | 1109 | 			CLog::logf(CLog::Log_Install, 2, L"Adjusting In Mod setting, %s => %s", pCheckFile->getInMod().c_str(), fit->getInMod().c_str());
 | 
        
           | 160 | cycrow | 1110 | 			pCheckFile->setInMod(fit->getInMod());
 | 
        
           | 50 | cycrow | 1111 | 		}
 | 
        
           |  |  | 1112 | 		else {
 | 
        
           | 197 | cycrow | 1113 | 			Utils::WString to = pCheckFile->getDirectory(this);
 | 
        
           | 50 | cycrow | 1114 | 			CDirIO Dir(sDestination);
 | 
        
           | 160 | cycrow | 1115 | 			if ( !Dir.exists(to) ) {
 | 
        
           |  |  | 1116 | 				if ( !Dir.create ( to ) ) {
 | 
        
           | 211 | cycrow | 1117 | 					if ( errorStr )	errorStr->pushBack(to, ERRORLOG(SPKINSTALL_CREATEDIRECTORY_FAIL));
 | 
        
           | 50 | cycrow | 1118 | 					return false;
 | 
        
           |  |  | 1119 | 				}
 | 
        
           | 211 | cycrow | 1120 | 				if ( errorStr )	errorStr->pushBack(to, ERRORLOG(SPKINSTALL_CREATEDIRECTORY));
 | 
        
           | 50 | cycrow | 1121 | 			}
 | 
        
           |  |  | 1122 |   | 
        
           | 197 | cycrow | 1123 | 			Utils::WString destfile = sDestination + L"/" + pCheckFile->getNameDirectory(this);
 | 
        
           |  |  | 1124 | 			if ( CFileIO::Exists(destfile) ) CFileIO::Remove(destfile);
 | 
        
           | 227 | cycrow | 1125 | 			CLog::logf(CLog::Log_Install, 1, L"Adjusting existing filename, %s => %s", pCheckFile->filePointer().c_str(), destfile.c_str());
 | 
        
           | 197 | cycrow | 1126 | 			CFileIO::Rename(pCheckFile->filePointer(), destfile);
 | 
        
           |  |  | 1127 | 			pCheckFile->setFilename (sDestination + L"/" + pCheckFile->getNameDirectory(this) );
 | 
        
           | 50 | cycrow | 1128 | 		}
 | 
        
           |  |  | 1129 | 		pCheckFile->SetDisabled(false);
 | 
        
           |  |  | 1130 |   | 
        
           | 175 | cycrow | 1131 | 		if ( errorStr ) errorStr->pushBack(pCheckFile->getNameDirectory(this), ERRORLOG(SPKINSTALL_ENABLEFILE));
 | 
        
           | 50 | cycrow | 1132 | 	}
 | 
        
           |  |  | 1133 |   | 
        
           |  |  | 1134 | 	return true;
 | 
        
           |  |  | 1135 | }
 | 
        
           | 51 | cycrow | 1136 |   | 
        
           | 197 | cycrow | 1137 | bool CBaseFile::_install_createDirectory(CDirIO &Dir, const Utils::WString &sTo, C_File *pFile, Utils::WStringList *errorStr)
 | 
        
           | 51 | cycrow | 1138 | {
 | 
        
           | 134 | cycrow | 1139 | 	_sLastError = sTo;
 | 
        
           | 197 | cycrow | 1140 | 	if ( !sTo.contains(L"::"))
 | 
        
           | 51 | cycrow | 1141 | 	{
 | 
        
           | 121 | cycrow | 1142 | 		if ( !Dir.exists(sTo) )
 | 
        
           | 51 | cycrow | 1143 | 		{
 | 
        
           | 227 | cycrow | 1144 | 			CLog::logf(CLog::Log_Install, 2, L"Creating directory to install file into, %s", sTo.c_str());
 | 
        
           | 160 | cycrow | 1145 | 			if ( !Dir.create(sTo) )
 | 
        
           | 51 | cycrow | 1146 | 			{
 | 
        
           |  |  | 1147 | 				if ( errorStr )
 | 
        
           | 175 | cycrow | 1148 | 					errorStr->pushBack(sTo, ERRORLOG(SPKINSTALL_CREATEDIRECTORY_FAIL));
 | 
        
           | 51 | cycrow | 1149 | 				return false;
 | 
        
           |  |  | 1150 | 			}
 | 
        
           |  |  | 1151 | 			if ( errorStr )
 | 
        
           | 175 | cycrow | 1152 | 				errorStr->pushBack(sTo, ERRORLOG(SPKINSTALL_CREATEDIRECTORY));
 | 
        
           | 51 | cycrow | 1153 | 		}
 | 
        
           |  |  | 1154 | 	}
 | 
        
           |  |  | 1155 | 	else {
 | 
        
           | 227 | cycrow | 1156 | 		CLog::logf(CLog::Log_Install, 2, L"Adjusting file extension for file in mod, %s => %s", pFile->filePointer().c_str(), CCatFile::PckChangeExtension(pFile->filePointer()).c_str());
 | 
        
           | 134 | cycrow | 1157 | 		pFile->setFilename(CCatFile::PckChangeExtension(pFile->filePointer()));
 | 
        
           | 51 | cycrow | 1158 | 	}
 | 
        
           |  |  | 1159 |   | 
        
           |  |  | 1160 | 	return true;
 | 
        
           |  |  | 1161 | }
 | 
        
           |  |  | 1162 |   | 
        
           | 197 | cycrow | 1163 | void CBaseFile::_install_writeFile(C_File *pFile, const Utils::WString &sDestination, Utils::WStringList *errorStr)
 | 
        
           | 51 | cycrow | 1164 | {
 | 
        
           | 134 | cycrow | 1165 | 	_iLastError = SPKERR_WRITEFILE;
 | 
        
           |  |  | 1166 | 	_sLastError = pFile->filePointer();
 | 
        
           | 197 | cycrow | 1167 | 	Utils::WString sInstalledFile = pFile->getNameDirectory(this);
 | 
        
           | 51 | cycrow | 1168 | 	if ( pFile->IsDisabled() )
 | 
        
           |  |  | 1169 | 	{
 | 
        
           | 134 | cycrow | 1170 | 		sInstalledFile = pFile->filePointer().findRemove(sDestination);
 | 
        
           | 51 | cycrow | 1171 | 		if ( sInstalledFile[0] == '/' || sInstalledFile[0] == '\\' )
 | 
        
           | 134 | cycrow | 1172 | 			sInstalledFile.erase(0, 1);
 | 
        
           | 51 | cycrow | 1173 | 	}
 | 
        
           |  |  | 1174 |   | 
        
           | 129 | cycrow | 1175 | 	if ( !pFile->writeFilePointer() )
 | 
        
           | 51 | cycrow | 1176 | 	{
 | 
        
           | 213 | cycrow | 1177 | 		CLog::log(CLog::Log_Install, 1, L"Failed to write the file");
 | 
        
           | 51 | cycrow | 1178 | 		if ( errorStr )
 | 
        
           | 175 | cycrow | 1179 | 			errorStr->pushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE_FAIL));
 | 
        
           | 51 | cycrow | 1180 | 	}
 | 
        
           |  |  | 1181 | 	else
 | 
        
           |  |  | 1182 | 	{
 | 
        
           | 213 | cycrow | 1183 | 		CLog::log(CLog::Log_Install, 1, L"File written successfully");
 | 
        
           |  |  | 1184 | 		CLog::log(CLog::Log_Install, 2, L"Checking signed status of the file");
 | 
        
           | 51 | cycrow | 1185 | 		pFile->UpdateSigned();
 | 
        
           |  |  | 1186 | 		if ( errorStr )
 | 
        
           | 175 | cycrow | 1187 | 			errorStr->pushBack(sInstalledFile, ERRORLOG(SPKINSTALL_WRITEFILE));
 | 
        
           | 51 | cycrow | 1188 |   | 
        
           |  |  | 1189 | 		switch(pFile->GetFileType())
 | 
        
           |  |  | 1190 | 		{
 | 
        
           |  |  | 1191 | 			case FILETYPE_SCRIPT:
 | 
        
           |  |  | 1192 | 			case FILETYPE_UNINSTALL:
 | 
        
           | 213 | cycrow | 1193 | 				CLog::log(CLog::Log_Install, 2, L"Updating file signature");
 | 
        
           | 160 | cycrow | 1194 | 				pFile->updateSignature();
 | 
        
           | 51 | cycrow | 1195 | 				break;
 | 
        
           |  |  | 1196 | 		}
 | 
        
           |  |  | 1197 | 	}
 | 
        
           |  |  | 1198 | }
 | 
        
           |  |  | 1199 |   | 
        
           | 197 | cycrow | 1200 | bool CBaseFile::installFiles(const Utils::WString &destdir, CProgressInfo *progress, CLinkList<C_File> *filelist, Utils::WStringList *errorStr, bool enabled, CPackages *packages )
 | 
        
           | 43 | cycrow | 1201 | {
 | 
        
           | 50 | cycrow | 1202 | 	//TODO: add errorStr and progress as member variables
 | 
        
           | 43 | cycrow | 1203 | 	if ( enabled ) {
 | 
        
           | 14 | cycrow | 1204 | 		this->_install_adjustFakePatches(packages);
 | 
        
           | 43 | cycrow | 1205 | 		if ( packages ) this->_install_renameText(packages);
 | 
        
           | 6 | cycrow | 1206 | 	}
 | 
        
           |  |  | 1207 |   | 
        
           | 50 | cycrow | 1208 | 	bool bFailed = false;
 | 
        
           |  |  | 1209 |   | 
        
           | 6 | cycrow | 1210 | 	CDirIO Dir(destdir);
 | 
        
           |  |  | 1211 | 	int fileCount = 0;
 | 
        
           |  |  | 1212 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 1213 | 	{
 | 
        
           |  |  | 1214 | 		C_File *fit = node->Data();
 | 
        
           |  |  | 1215 |   | 
        
           | 50 | cycrow | 1216 | 		// start the install process, check if we need to the file enabled or disabled
 | 
        
           | 227 | cycrow | 1217 | 		CLog::logf(CLog::Log_Install, 1, L"Preparing to install file: %s", fit->getNameDirectory(this).c_str());
 | 
        
           | 50 | cycrow | 1218 | 		bool fileEnabled = _install_setEnabled(enabled, fit);
 | 
        
           |  |  | 1219 |   | 
        
           |  |  | 1220 | 		// check if the file is for the correct game version
 | 
        
           | 147 | cycrow | 1221 | 		if (!fit->isForGame(packages->GetGame())) 
 | 
        
           |  |  | 1222 | 		{
 | 
        
           | 227 | cycrow | 1223 | 			CLog::logf(CLog::Log_Install, 1, L"File didn't match game version, skipping, %d != %d", fit->game(), packages->GetGame());
 | 
        
           | 147 | cycrow | 1224 | 			continue;
 | 
        
           | 6 | cycrow | 1225 | 		}
 | 
        
           |  |  | 1226 |   | 
        
           | 50 | cycrow | 1227 | 		// update the progress display to show we are processing this file
 | 
        
           |  |  | 1228 | 		if ( progress ) {
 | 
        
           |  |  | 1229 | 			if ( progress->IsSecond() ) progress->SwitchSecond();
 | 
        
           | 6 | cycrow | 1230 | 			progress->UpdateFile ( fit );
 | 
        
           |  |  | 1231 | 			progress->UpdateProgress(fileCount++, m_lFiles.size());
 | 
        
           |  |  | 1232 | 			progress->SwitchSecond();
 | 
        
           |  |  | 1233 | 		}
 | 
        
           |  |  | 1234 |   | 
        
           |  |  | 1235 | 		// first uncompress the file
 | 
        
           | 50 | cycrow | 1236 | 		//TODO: add this flag to C_File
 | 
        
           |  |  | 1237 | 		bool uncomprToFile;
 | 
        
           |  |  | 1238 | 		if ( !this->_install_uncompress(fit, progress, errorStr, &uncomprToFile) ) {
 | 
        
           |  |  | 1239 | 			bFailed = true;
 | 
        
           |  |  | 1240 | 			continue;
 | 
        
           | 6 | cycrow | 1241 | 		}
 | 
        
           |  |  | 1242 |   | 
        
           | 175 | cycrow | 1243 | 		bool dofile = _install_checkVersion(fit, destdir);
 | 
        
           | 6 | cycrow | 1244 |   | 
        
           |  |  | 1245 | 		// change file pointer
 | 
        
           | 197 | cycrow | 1246 | 		Utils::WString sInstallDir = _install_adjustFilepointer(fit, fileEnabled, destdir);
 | 
        
           | 6 | cycrow | 1247 |   | 
        
           |  |  | 1248 | 		C_File *adjustPointer = NULL;
 | 
        
           |  |  | 1249 |   | 
        
           | 50 | cycrow | 1250 | 		if ( filelist ) {
 | 
        
           | 98 | cycrow | 1251 | 			C_File *cFile = _install_checkFile(fit, errorStr, &dofile, filelist);
 | 
        
           | 6 | cycrow | 1252 |   | 
        
           |  |  | 1253 | 			// no matching file found, adding to main list
 | 
        
           | 50 | cycrow | 1254 | 			if ( !cFile ) filelist->push_back ( fit );
 | 
        
           | 6 | cycrow | 1255 | 			else
 | 
        
           |  |  | 1256 | 			{
 | 
        
           |  |  | 1257 | 				// if the file is not enabled, we need to check for any that might be enabled
 | 
        
           | 51 | cycrow | 1258 | 				if ( !fileEnabled ) //_install_checkDisabled(cFile, destdir, errorStr);
 | 
        
           | 6 | cycrow | 1259 | 				{
 | 
        
           | 50 | cycrow | 1260 | 					//TODO: check what this is actually doing
 | 
        
           | 160 | cycrow | 1261 | 					if ( !cFile->getUsed() )
 | 
        
           | 6 | cycrow | 1262 | 					{
 | 
        
           | 160 | cycrow | 1263 | 						CFileIO rFile(cFile->filePointer());
 | 
        
           | 52 | cycrow | 1264 | 						if ( rFile.exists() )
 | 
        
           | 6 | cycrow | 1265 | 						{
 | 
        
           |  |  | 1266 | 							if ( errorStr )
 | 
        
           |  |  | 1267 | 							{
 | 
        
           | 52 | cycrow | 1268 | 								if ( rFile.remove() )
 | 
        
           | 175 | cycrow | 1269 | 									errorStr->pushBack(cFile->filePointer().findRemove(destdir), ERRORLOG(SPKINSTALL_DELETEFILE));
 | 
        
           | 6 | cycrow | 1270 | 								else
 | 
        
           | 175 | cycrow | 1271 | 									errorStr->pushBack(cFile->filePointer().findRemove(destdir), ERRORLOG(SPKINSTALL_DELETEFILE_FAIL));
 | 
        
           | 6 | cycrow | 1272 | 							}
 | 
        
           |  |  | 1273 | 						}
 | 
        
           | 160 | cycrow | 1274 | 						cFile->setFilename(fit->filePointer());
 | 
        
           | 6 | cycrow | 1275 | 						cFile->SetDisabled(true);
 | 
        
           |  |  | 1276 | 					}
 | 
        
           |  |  | 1277 | 					else
 | 
        
           |  |  | 1278 | 					{
 | 
        
           | 160 | cycrow | 1279 | 						fit->setFullDir(sInstallDir + fit->getDirectory(this));
 | 
        
           | 51 | cycrow | 1280 | 						fit->SetDisabled(false);
 | 
        
           | 6 | cycrow | 1281 | 					}
 | 
        
           |  |  | 1282 | 				}
 | 
        
           |  |  | 1283 | 				// move it to enabled
 | 
        
           | 50 | cycrow | 1284 | 				else {
 | 
        
           | 175 | cycrow | 1285 | 					if ( !this->_install_checkFileEnable(cFile, fit, destdir, fileEnabled, errorStr) ) {
 | 
        
           | 50 | cycrow | 1286 | 						bFailed = true;
 | 
        
           |  |  | 1287 | 						continue;
 | 
        
           | 6 | cycrow | 1288 | 					}
 | 
        
           |  |  | 1289 | 				}
 | 
        
           |  |  | 1290 |   | 
        
           |  |  | 1291 | 				adjustPointer = cFile;
 | 
        
           | 50 | cycrow | 1292 | 				if ( dofile ) adjustPointer->SetCreationTime(fit->GetCreationTime());
 | 
        
           | 6 | cycrow | 1293 | 			}
 | 
        
           |  |  | 1294 | 		}
 | 
        
           |  |  | 1295 |   | 
        
           |  |  | 1296 | 		if ( dofile )
 | 
        
           |  |  | 1297 | 		{
 | 
        
           |  |  | 1298 | 			// uncompressed to file, rename and move
 | 
        
           |  |  | 1299 | 			if ( uncomprToFile )
 | 
        
           |  |  | 1300 | 			{
 | 
        
           | 134 | cycrow | 1301 | 				_iLastError = SPKERR_WRITEFILE;
 | 
        
           | 197 | cycrow | 1302 | 				Utils::WString to = fit->getDirectory(this);
 | 
        
           |  |  | 1303 | 				if ( !fileEnabled )	to = L"PluginManager/Disabled/" + to;
 | 
        
           | 6 | cycrow | 1304 |   | 
        
           | 134 | cycrow | 1305 | 				if ( !_install_createDirectory(Dir, to, fit, errorStr) ) {
 | 
        
           | 51 | cycrow | 1306 | 					bFailed = true;
 | 
        
           |  |  | 1307 | 					continue;
 | 
        
           | 6 | cycrow | 1308 | 				}
 | 
        
           |  |  | 1309 |   | 
        
           | 197 | cycrow | 1310 | 				bool err = true;
 | 
        
           | 134 | cycrow | 1311 | 				_sLastError = to;
 | 
        
           | 197 | cycrow | 1312 | 				if ( !fit->getTempFile().empty())
 | 
        
           |  |  | 1313 | 					err = CFileIO::Rename(fit->getTempFile(), to);
 | 
        
           | 51 | cycrow | 1314 | 				if ( err ) {
 | 
        
           |  |  | 1315 | 					bFailed = true;
 | 
        
           |  |  | 1316 | 					continue;
 | 
        
           |  |  | 1317 | 				}
 | 
        
           | 6 | cycrow | 1318 | 			}
 | 
        
           |  |  | 1319 | 			//otherwise, just extract the file
 | 
        
           |  |  | 1320 | 			else
 | 
        
           |  |  | 1321 | 			{
 | 
        
           |  |  | 1322 | 				// old file is found in list, switch to using new one
 | 
        
           | 50 | cycrow | 1323 | 				if ( (filelist) && (adjustPointer) ) {
 | 
        
           | 6 | cycrow | 1324 | 					adjustPointer->CopyData(fit, false);
 | 
        
           | 213 | cycrow | 1325 | 					CLog::log(CLog::Log_Install, 2, L"Copying data into existing file");
 | 
        
           | 50 | cycrow | 1326 | 				}
 | 
        
           | 6 | cycrow | 1327 |   | 
        
           | 197 | cycrow | 1328 | 				Utils::WString fpointer = fit->filePointer();
 | 
        
           | 134 | cycrow | 1329 | 				_iLastError = SPKERR_CREATEDIRECTORY;
 | 
        
           | 211 | cycrow | 1330 | 				Utils::WString dir = CFileIO(fit->filePointer()).dir();
 | 
        
           | 6 | cycrow | 1331 |   | 
        
           | 175 | cycrow | 1332 | 				dir = dir.findRemove(destdir);
 | 
        
           | 149 | cycrow | 1333 | 				if (!dir.empty() && (dir[0] == '/' || dir[0] == '\\')) 
 | 
        
           |  |  | 1334 | 					dir.erase(0, 1);
 | 
        
           | 6 | cycrow | 1335 |   | 
        
           | 134 | cycrow | 1336 | 				if ( !_install_createDirectory(Dir, dir, fit, errorStr) ) {
 | 
        
           | 51 | cycrow | 1337 | 					bFailed = true;
 | 
        
           |  |  | 1338 | 					continue;
 | 
        
           | 6 | cycrow | 1339 | 				}
 | 
        
           |  |  | 1340 |   | 
        
           | 175 | cycrow | 1341 | 				_install_writeFile(fit, destdir, errorStr);
 | 
        
           | 6 | cycrow | 1342 | 			}
 | 
        
           |  |  | 1343 | 			ClearError ();
 | 
        
           |  |  | 1344 | 		}
 | 
        
           |  |  | 1345 |   | 
        
           |  |  | 1346 | 		if ( adjustPointer )
 | 
        
           |  |  | 1347 | 		{
 | 
        
           | 213 | cycrow | 1348 | 			CLog::log(CLog::Log_Install, 2, L"Adjusting pointers to existing file and deleting new file pointer");
 | 
        
           | 6 | cycrow | 1349 | 			node->ChangeData(adjustPointer);
 | 
        
           |  |  | 1350 | 			delete fit;
 | 
        
           |  |  | 1351 | 		}
 | 
        
           | 50 | cycrow | 1352 |   | 
        
           | 213 | cycrow | 1353 | 		CLog::log(CLog::Log_Install, 1, L"File installation completed");
 | 
        
           | 6 | cycrow | 1354 | 	}
 | 
        
           |  |  | 1355 |   | 
        
           |  |  | 1356 | 	// now clear or data memory
 | 
        
           | 213 | cycrow | 1357 | 	CLog::log(CLog::Log_Install, 2, L"Delting temporary file data from memory");
 | 
        
           | 51 | cycrow | 1358 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) node->Data()->DeleteData();
 | 
        
           | 6 | cycrow | 1359 |   | 
        
           | 50 | cycrow | 1360 | 	return !bFailed;
 | 
        
           | 6 | cycrow | 1361 | }
 | 
        
           |  |  | 1362 |   | 
        
           |  |  | 1363 | /*######################################################################################################*/
 | 
        
           |  |  | 1364 |   | 
        
           |  |  | 1365 |   | 
        
           |  |  | 1366 | /*
 | 
        
           |  |  | 1367 | 	Func:   ParseHeader
 | 
        
           |  |  | 1368 | 	Input:  Header String - string formated directly from the file
 | 
        
           |  |  | 1369 | 	Return: Boolean - If string is a valid header
 | 
        
           |  |  | 1370 | 	Desc:   Splits up the main header string to get all required settings
 | 
        
           |  |  | 1371 | */
 | 
        
           | 210 | cycrow | 1372 | bool CBaseFile::_parseHeader(const Utils::WString &header)
 | 
        
           | 6 | cycrow | 1373 | {
 | 
        
           | 210 | cycrow | 1374 | 	if ( !this->_checkHeader(header.token(L";", 1)))
 | 
        
           | 6 | cycrow | 1375 | 		return false;
 | 
        
           |  |  | 1376 |   | 
        
           | 210 | cycrow | 1377 | 	m_SHeader.fVersion = header.token(L";", 2).toFloat();
 | 
        
           | 6 | cycrow | 1378 | 	if ( m_SHeader.fVersion > FILEVERSION )
 | 
        
           |  |  | 1379 | 		return false;
 | 
        
           |  |  | 1380 |   | 
        
           | 210 | cycrow | 1381 | 	m_SHeader.iValueCompression = header.token(L";", 3).toInt();
 | 
        
           |  |  | 1382 | 	m_SHeader.lValueCompressSize = header.token(L";", 4).toLong();
 | 
        
           | 6 | cycrow | 1383 |   | 
        
           |  |  | 1384 | 	return true;
 | 
        
           |  |  | 1385 | }
 | 
        
           |  |  | 1386 |   | 
        
           | 210 | cycrow | 1387 | bool CBaseFile::_checkHeader(const Utils::WString &header) const
 | 
        
           | 6 | cycrow | 1388 | {
 | 
        
           | 210 | cycrow | 1389 | 	if ( header.Compare(L"BaseCycrow") )
 | 
        
           | 6 | cycrow | 1390 | 		return true;
 | 
        
           |  |  | 1391 | 	return false;
 | 
        
           |  |  | 1392 | }
 | 
        
           |  |  | 1393 |   | 
        
           |  |  | 1394 | /*
 | 
        
           |  |  | 1395 | 	Func:   ParseFileHeader
 | 
        
           |  |  | 1396 | 	Input:  Header String - string formated directly from the file
 | 
        
           |  |  | 1397 | 	Return: Boolean - If string is a valid header
 | 
        
           |  |  | 1398 | 	Desc:   Splits up the file header string to get all required settings
 | 
        
           |  |  | 1399 | */
 | 
        
           | 210 | cycrow | 1400 | bool CBaseFile::_parseFileHeader(const Utils::WString &header)
 | 
        
           | 6 | cycrow | 1401 | {
 | 
        
           | 210 | cycrow | 1402 | 	if (header.token(L";", 1) != L"FileHeader")
 | 
        
           | 6 | cycrow | 1403 | 		return false;
 | 
        
           |  |  | 1404 |   | 
        
           | 210 | cycrow | 1405 | 	m_SHeader2.iNumFiles = header.token(L";", 2).toInt();
 | 
        
           |  |  | 1406 | 	m_SHeader2.lSize = header.token(L";", 3).toInt();
 | 
        
           |  |  | 1407 | 	m_SHeader2.lFullSize = header.token(L";", 4).toInt();
 | 
        
           |  |  | 1408 | 	m_SHeader2.iFileCompression = header.token(L";", 5).toInt();
 | 
        
           |  |  | 1409 | 	m_SHeader2.iDataCompression = header.token(L";", 6).toInt();
 | 
        
           | 6 | cycrow | 1410 |   | 
        
           |  |  | 1411 | 	return true;
 | 
        
           |  |  | 1412 | }
 | 
        
           |  |  | 1413 |   | 
        
           |  |  | 1414 |   | 
        
           |  |  | 1415 | /*
 | 
        
           |  |  | 1416 | 	Func:   ParseValueLine
 | 
        
           |  |  | 1417 | 	Input:  String - single line from a file to set
 | 
        
           |  |  | 1418 | 	Return: Boolean - returns true if value exists
 | 
        
           |  |  | 1419 | 	Desc:   Reads the line and assigns the parameters for the file
 | 
        
           |  |  | 1420 | */
 | 
        
           | 207 | cycrow | 1421 | bool CBaseFile::parseValueLine(const Utils::WString &sLine)
 | 
        
           | 6 | cycrow | 1422 | {
 | 
        
           | 207 | cycrow | 1423 | 	Utils::WString first = sLine.token(L" ", 1);
 | 
        
           |  |  | 1424 | 	Utils::WString rest  = sLine.tokens(L" ", 2);
 | 
        
           | 6 | cycrow | 1425 |   | 
        
           | 207 | cycrow | 1426 | 	if ( first.Compare(L"Name:") )					this->setName(rest);
 | 
        
           |  |  | 1427 | 	else if ( first.Compare(L"Author:") )			this->setAuthor(rest);
 | 
        
           |  |  | 1428 | 	else if ( first.Compare(L"Version:") )			this->setVersion(rest);
 | 
        
           |  |  | 1429 | 	else if ( first.Compare(L"fGameVersion:") ) {
 | 
        
           | 6 | cycrow | 1430 | 		if ( m_lGames.Back() ) {
 | 
        
           | 207 | cycrow | 1431 | 			m_lGames.Back()->Data()->sVersion = rest;
 | 
        
           | 6 | cycrow | 1432 | 		}
 | 
        
           |  |  | 1433 | 	}
 | 
        
           | 207 | cycrow | 1434 | 	else if ( first.Compare(L"GameVersion:") ) {
 | 
        
           | 6 | cycrow | 1435 | 		if ( m_lGames.Back() ) {
 | 
        
           | 197 | cycrow | 1436 | 			m_lGames.Back()->Data()->iVersion = rest.toInt();
 | 
        
           | 6 | cycrow | 1437 | 		}
 | 
        
           |  |  | 1438 | 	}
 | 
        
           | 207 | cycrow | 1439 | 	else if ( first.Compare(L"Game:") )
 | 
        
           |  |  | 1440 | 		this->AddGameCompatability(rest, L"");
 | 
        
           |  |  | 1441 | 	else if ( first.Compare(L"GameCompat:") )
 | 
        
           | 211 | cycrow | 1442 | 		this->AddGameCompatability(rest.token(L" ", 1), rest.tokens(L" ", 2));
 | 
        
           | 207 | cycrow | 1443 | 	else if ( first.Compare(L"GameCompatExact:") )
 | 
        
           | 211 | cycrow | 1444 | 		this->AddGameCompatability(rest.token(L" ", 1), rest.tokens(L" ", 2));
 | 
        
           | 207 | cycrow | 1445 | 	else if ( first.Compare(L"Date:") )				this->setCreationDate(rest);
 | 
        
           |  |  | 1446 | 	else if ( first.Compare(L"WebAddress:") )		this->setWebAddress(rest);
 | 
        
           |  |  | 1447 | 	else if ( first.Compare(L"WebSite:") )			this->setWebSite(rest);
 | 
        
           |  |  | 1448 | 	else if ( first.Compare(L"Email:") )				this->setEmail(rest);
 | 
        
           |  |  | 1449 | 	else if ( first.Compare(L"WebMirror1:") || first.Compare(L"Mirror1:") || first.Compare(L"WebMirror:") )
 | 
        
           | 211 | cycrow | 1450 | 		this->addWebMirror(rest);
 | 
        
           | 207 | cycrow | 1451 | 	else if ( first.Compare(L"WebMirror2:") || first.Compare(L"Mirror2:") )
 | 
        
           | 211 | cycrow | 1452 | 		this->addWebMirror(rest);
 | 
        
           | 207 | cycrow | 1453 | 	else if ( first.Compare(L"PluginType:") )		this->setPluginType(rest);
 | 
        
           |  |  | 1454 | 	else if ( first.Compare(L"Desc:") )				this->setDescription(rest);
 | 
        
           |  |  | 1455 | 	else if ( first.Compare(L"UninstallAfter:") )	this->addUninstallText(parseLanguage(rest.token(L"|", 1)), false, rest.tokens(L"|", 2));
 | 
        
           |  |  | 1456 | 	else if ( first.Compare(L"UninstallBefore:") )	this->addUninstallText(parseLanguage(rest.token(L"|", 1)), true, rest.tokens(L"|", 2));
 | 
        
           |  |  | 1457 | 	else if ( first.Compare(L"InstallAfter:") )		this->addInstallText(parseLanguage(rest.token(L"|", 1)), false, rest.tokens(L"|", 2));
 | 
        
           |  |  | 1458 | 	else if ( first.Compare(L"InstallBefore:") )	this->addInstallText(parseLanguage(rest.token(L"|", 1)), true, rest.tokens(L"|", 2));
 | 
        
           |  |  | 1459 | 	else if ( first.Compare(L"ScriptName:") )		addName(parseLanguage(rest.token(L":", 1)), rest.token(L":", 2));
 | 
        
           |  |  | 1460 | 	else if ( first.Compare(L"GameChanging:") )		this->setGameChanging(rest);
 | 
        
           |  |  | 1461 | 	else if ( first.Compare(L"EaseOfUse:") )		this->setEaseOfUse(rest);
 | 
        
           |  |  | 1462 | 	else if ( first.Compare(L"Recommended:") )		this->setRecommended(rest);
 | 
        
           |  |  | 1463 | 	else if ( first.Compare(L"NeededLibrary:") )
 | 
        
           |  |  | 1464 | 		this->addNeededLibrary(rest.token(L"||", 1), rest.token(L"||", 2), rest.token(L"||", 3));
 | 
        
           |  |  | 1465 | 	else if ( first.Compare(L"FakePatchBefore:") )
 | 
        
           |  |  | 1466 | 		this->addFakePatchOrder(false, rest.token(L"||", 1), rest.token(L"||", 2));
 | 
        
           | 234 | cycrow | 1467 | 	else if (first.Compare(L"FakePatchAfter:"))
 | 
        
           | 207 | cycrow | 1468 | 		this->addFakePatchOrder(true, rest.token(L"||", 1), rest.token(L"||", 2));
 | 
        
           | 234 | cycrow | 1469 | 	else if (first.Compare(L"Globals:"))
 | 
        
           |  |  | 1470 | 		this->addGlobal(rest.token(L";", 1), rest.tokens(L";", 2));
 | 
        
           | 207 | cycrow | 1471 | 	else if ( first.Compare(L"ForumLink:") )			this->setForumLink(rest);
 | 
        
           | 6 | cycrow | 1472 | 	else
 | 
        
           |  |  | 1473 | 		return false;
 | 
        
           |  |  | 1474 |   | 
        
           |  |  | 1475 | 	return true;
 | 
        
           |  |  | 1476 | }
 | 
        
           |  |  | 1477 |   | 
        
           | 207 | cycrow | 1478 | int CBaseFile::parseLanguage(const Utils::WString &lang) const
 | 
        
           | 6 | cycrow | 1479 | {
 | 
        
           | 48 | cycrow | 1480 | 	int langID = lang;
 | 
        
           |  |  | 1481 | 	if ( !langID ) {
 | 
        
           | 207 | cycrow | 1482 | 		if (lang.Compare(L"english"))		return 44;
 | 
        
           |  |  | 1483 | 		else if (lang.Compare(L"default"))	return 0;
 | 
        
           |  |  | 1484 | 		else if (lang.Compare(L"german"))	return 49;
 | 
        
           |  |  | 1485 | 		else if (lang.Compare(L"russian"))	return 7;
 | 
        
           |  |  | 1486 | 		else if (lang.Compare(L"spanish"))	return 34;
 | 
        
           |  |  | 1487 | 		else if (lang.Compare(L"french"))	return 33;
 | 
        
           | 6 | cycrow | 1488 | 	}
 | 
        
           |  |  | 1489 |   | 
        
           |  |  | 1490 | 	return langID;
 | 
        
           |  |  | 1491 | }
 | 
        
           |  |  | 1492 |   | 
        
           |  |  | 1493 | /*
 | 
        
           |  |  | 1494 | 	Func:   ReadValues
 | 
        
           |  |  | 1495 | 	Input:  String - values in one long line
 | 
        
           |  |  | 1496 | 	Desc:   splits the values data into each line to read the data
 | 
        
           |  |  | 1497 | */
 | 
        
           | 207 | cycrow | 1498 | void CBaseFile::_readValues(const Utils::WString &values)
 | 
        
           | 6 | cycrow | 1499 | {
 | 
        
           | 207 | cycrow | 1500 | 	std::vector<Utils::WString> lines;
 | 
        
           |  |  | 1501 | 	values.tokenise(L"\n", lines);
 | 
        
           | 6 | cycrow | 1502 |   | 
        
           | 207 | cycrow | 1503 | 	for (size_t i = 0; i < lines.size(); i++)
 | 
        
           |  |  | 1504 | 		parseValueLine(lines[i]);
 | 
        
           | 6 | cycrow | 1505 | }
 | 
        
           |  |  | 1506 |   | 
        
           |  |  | 1507 | /*
 | 
        
           |  |  | 1508 | 	Func:   ParseFilesLine
 | 
        
           |  |  | 1509 | 	Input:  String - single line from a file to set
 | 
        
           |  |  | 1510 | 	Return: Boolean - returns true if value exists
 | 
        
           |  |  | 1511 | 	Desc:   Reads the line and assigns the parameters for the file
 | 
        
           |  |  | 1512 | */
 | 
        
           | 210 | cycrow | 1513 | bool CBaseFile::_parseFilesLine(const Utils::WString &line)
 | 
        
           | 6 | cycrow | 1514 | {
 | 
        
           | 210 | cycrow | 1515 | 	if ( !line.contains(L":") )
 | 
        
           | 6 | cycrow | 1516 | 		return false;
 | 
        
           |  |  | 1517 |   | 
        
           | 210 | cycrow | 1518 | 	Utils::WString command = line.token(L":", 1);
 | 
        
           | 6 | cycrow | 1519 |   | 
        
           | 210 | cycrow | 1520 | 	long size = line.token(L":", 2).toInt();
 | 
        
           |  |  | 1521 | 	long usize = line.token(L":", 3).toInt ();
 | 
        
           |  |  | 1522 | 	long compression = line.token(L":", 4).toInt ();
 | 
        
           | 6 | cycrow | 1523 |   | 
        
           | 210 | cycrow | 1524 | 	if ( command == L"Icon" )
 | 
        
           | 6 | cycrow | 1525 | 	{
 | 
        
           | 210 | cycrow | 1526 | 		_sIconExt = line.token(L":", 5);
 | 
        
           | 6 | cycrow | 1527 | 		m_pIconFile = new C_File ();
 | 
        
           |  |  | 1528 | 		m_pIconFile->SetDataSize ( size - 4 );
 | 
        
           |  |  | 1529 | 		m_pIconFile->SetDataCompression ( compression );
 | 
        
           |  |  | 1530 | 		m_pIconFile->SetUncompressedDataSize ( usize );
 | 
        
           |  |  | 1531 |   | 
        
           |  |  | 1532 | 		return true;
 | 
        
           |  |  | 1533 | 	}
 | 
        
           |  |  | 1534 |   | 
        
           | 210 | cycrow | 1535 | 	time_t time = line.token(L":", 5).toLong();
 | 
        
           |  |  | 1536 | 	bool compressToFile = (line.token(L":", 6).toInt() == 1) ? true : false;
 | 
        
           |  |  | 1537 | 	Utils::WString name  = line.token(L":", 7);
 | 
        
           |  |  | 1538 | 	Utils::WString dir = line.token(L":", 8);
 | 
        
           | 6 | cycrow | 1539 |   | 
        
           | 127 | cycrow | 1540 | 	if ( name.empty() )
 | 
        
           | 6 | cycrow | 1541 | 		return true;
 | 
        
           |  |  | 1542 |   | 
        
           |  |  | 1543 | 	bool shared = false;
 | 
        
           | 210 | cycrow | 1544 | 	if ( command.left(1) == L"$" )
 | 
        
           | 6 | cycrow | 1545 | 	{
 | 
        
           |  |  | 1546 | 		shared = true;
 | 
        
           | 127 | cycrow | 1547 | 		command.erase(0, 1);
 | 
        
           | 6 | cycrow | 1548 | 	}
 | 
        
           |  |  | 1549 |   | 
        
           | 127 | cycrow | 1550 | 	FileType type = FILETYPE_UNKNOWN;
 | 
        
           | 210 | cycrow | 1551 | 	if ( command == L"Script" )
 | 
        
           | 6 | cycrow | 1552 | 		type = FILETYPE_SCRIPT;
 | 
        
           | 210 | cycrow | 1553 | 	else if ( command == L"Text" )
 | 
        
           | 6 | cycrow | 1554 | 		type = FILETYPE_TEXT;
 | 
        
           | 210 | cycrow | 1555 | 	else if ( command == L"Readme" )
 | 
        
           | 6 | cycrow | 1556 | 		type = FILETYPE_README;
 | 
        
           | 210 | cycrow | 1557 | 	else if ( command == L"Map" )
 | 
        
           | 6 | cycrow | 1558 | 		type = FILETYPE_MAP;
 | 
        
           | 210 | cycrow | 1559 | 	else if ( command == L"Mod" )
 | 
        
           | 6 | cycrow | 1560 | 		type = FILETYPE_MOD;
 | 
        
           | 210 | cycrow | 1561 | 	else if ( command == L"Uninstall" )
 | 
        
           | 6 | cycrow | 1562 | 		type = FILETYPE_UNINSTALL;
 | 
        
           | 210 | cycrow | 1563 | 	else if ( command == L"Sound" )
 | 
        
           | 6 | cycrow | 1564 | 		type = FILETYPE_SOUND;
 | 
        
           | 210 | cycrow | 1565 | 	else if ( command == L"Mission" )
 | 
        
           | 6 | cycrow | 1566 | 		type = FILETYPE_MISSION;
 | 
        
           | 210 | cycrow | 1567 | 	else if ( command == L"Extra" )
 | 
        
           | 6 | cycrow | 1568 | 		type = FILETYPE_EXTRA;
 | 
        
           | 210 | cycrow | 1569 | 	else if ( command == L"Screen" )
 | 
        
           | 6 | cycrow | 1570 | 		type = FILETYPE_SCREEN;
 | 
        
           | 210 | cycrow | 1571 | 	else if ( command == L"Backup" )
 | 
        
           | 6 | cycrow | 1572 | 		type = FILETYPE_BACKUP;
 | 
        
           | 210 | cycrow | 1573 | 	else if ( command == L"Advert" )
 | 
        
           | 6 | cycrow | 1574 | 		type = FILETYPE_ADVERT;
 | 
        
           | 210 | cycrow | 1575 | 	else if ( command == L"ShipScene" )
 | 
        
           | 6 | cycrow | 1576 | 		type = FILETYPE_SHIPSCENE;
 | 
        
           | 210 | cycrow | 1577 | 	else if ( command == L"CockpitScene" )
 | 
        
           | 6 | cycrow | 1578 | 		type = FILETYPE_COCKPITSCENE;
 | 
        
           | 210 | cycrow | 1579 | 	else if ( command == L"ShipOther" )
 | 
        
           | 6 | cycrow | 1580 | 		type = FILETYPE_SHIPOTHER;
 | 
        
           | 210 | cycrow | 1581 | 	else if ( command == L"ShipModel" )
 | 
        
           | 6 | cycrow | 1582 | 		type = FILETYPE_SHIPMODEL;
 | 
        
           |  |  | 1583 |   | 
        
           | 127 | cycrow | 1584 | 	if (type == FILETYPE_UNKNOWN)
 | 
        
           | 6 | cycrow | 1585 | 		return false;
 | 
        
           |  |  | 1586 |   | 
        
           | 127 | cycrow | 1587 | 	C_File *file = new C_File();
 | 
        
           | 6 | cycrow | 1588 |   | 
        
           | 210 | cycrow | 1589 | 	if (dir.left(5).Compare(L"GAME_")) {
 | 
        
           |  |  | 1590 | 		unsigned int iGame = dir.token(L"_", 2).toInt();
 | 
        
           | 130 | cycrow | 1591 | 		if (!iGame)
 | 
        
           |  |  | 1592 | 			file->setGame(0);
 | 
        
           |  |  | 1593 | 		else
 | 
        
           |  |  | 1594 | 			file->setGame(1 << 31 | 1 << iGame);
 | 
        
           | 210 | cycrow | 1595 | 		dir = Utils::WString::Null();
 | 
        
           | 6 | cycrow | 1596 | 	} 
 | 
        
           | 210 | cycrow | 1597 | 	else if ( line.countToken(L":") >= 9 ) 
 | 
        
           | 127 | cycrow | 1598 | 	{
 | 
        
           | 210 | cycrow | 1599 | 		Utils::WString game = line.token(L":", 9);
 | 
        
           |  |  | 1600 | 		if (game.contains(L"_"))
 | 
        
           | 130 | cycrow | 1601 | 		{
 | 
        
           | 210 | cycrow | 1602 | 			unsigned int iGame = game.token(L"_", 2).toInt();
 | 
        
           | 130 | cycrow | 1603 | 			if (iGame)
 | 
        
           |  |  | 1604 | 				file->setGame(1 << 31 | 1 << iGame);
 | 
        
           |  |  | 1605 | 			else
 | 
        
           |  |  | 1606 | 				file->setGame(0);
 | 
        
           |  |  | 1607 | 		}
 | 
        
           | 127 | cycrow | 1608 | 		else
 | 
        
           |  |  | 1609 | 		{
 | 
        
           |  |  | 1610 | 			int iGame = game.toInt();
 | 
        
           |  |  | 1611 | 			if (iGame & (1 << 31))
 | 
        
           |  |  | 1612 | 				file->setGame(iGame);
 | 
        
           | 130 | cycrow | 1613 | 			else if (!iGame)
 | 
        
           |  |  | 1614 | 				file->setGame(0);
 | 
        
           | 127 | cycrow | 1615 | 			else
 | 
        
           |  |  | 1616 | 				file->setGame(1 << 31 | 1 << iGame);
 | 
        
           |  |  | 1617 | 		}
 | 
        
           | 6 | cycrow | 1618 | 	}
 | 
        
           |  |  | 1619 |   | 
        
           | 210 | cycrow | 1620 | 	if (dir.Compare(L"NULL")) {
 | 
        
           |  |  | 1621 | 		dir = Utils::WString::Null();
 | 
        
           | 127 | cycrow | 1622 | 	}
 | 
        
           |  |  | 1623 |   | 
        
           |  |  | 1624 | 	file->setFileType(type);
 | 
        
           | 6 | cycrow | 1625 | 	file->SetCreationTime ( time );
 | 
        
           | 178 | cycrow | 1626 | 	file->setName(name);
 | 
        
           |  |  | 1627 | 	file->setDir(dir);
 | 
        
           | 6 | cycrow | 1628 | 	file->SetDataSize ( size - 4 );
 | 
        
           |  |  | 1629 | 	file->SetDataCompression ( compression );
 | 
        
           |  |  | 1630 | 	file->SetUncompressedDataSize ( usize );
 | 
        
           |  |  | 1631 | 	file->SetShared ( shared );
 | 
        
           |  |  | 1632 | 	file->SetCompressedToFile ( compressToFile );
 | 
        
           |  |  | 1633 |   | 
        
           | 88 | cycrow | 1634 | 	_addFile(file, true);
 | 
        
           | 6 | cycrow | 1635 |   | 
        
           |  |  | 1636 | 	return true;
 | 
        
           |  |  | 1637 | }
 | 
        
           |  |  | 1638 |   | 
        
           |  |  | 1639 |   | 
        
           |  |  | 1640 | /*
 | 
        
           |  |  | 1641 | 	Func:   ParseFiles
 | 
        
           |  |  | 1642 | 	Input:  String - values in one long line
 | 
        
           |  |  | 1643 | 	Desc:   splits the files data into each line to read the data
 | 
        
           |  |  | 1644 | */
 | 
        
           | 211 | cycrow | 1645 | void CBaseFile::_readFiles(const Utils::WString &values)
 | 
        
           | 6 | cycrow | 1646 | {
 | 
        
           | 211 | cycrow | 1647 | 	std::vector<Utils::WString> lines;
 | 
        
           |  |  | 1648 | 	values.tokenise(L"\n", lines);
 | 
        
           | 6 | cycrow | 1649 |   | 
        
           | 211 | cycrow | 1650 | 	for (size_t i = 0; i < lines.size(); i++)
 | 
        
           | 175 | cycrow | 1651 | 		_parseFilesLine(lines[i]);
 | 
        
           | 6 | cycrow | 1652 | }
 | 
        
           |  |  | 1653 |   | 
        
           |  |  | 1654 |   | 
        
           |  |  | 1655 |   | 
        
           |  |  | 1656 | /*
 | 
        
           |  |  | 1657 | 	Func:   ReadFile
 | 
        
           |  |  | 1658 | 	Input:  filename - the name of the file to open and read
 | 
        
           |  |  | 1659 | 			readdata - If falses, dont read the files to memory, just read the headers and values
 | 
        
           |  |  | 1660 | 	Return: boolean - return ture if acceptable format
 | 
        
           |  |  | 1661 | 	Desc:   Opens and reads the spk file and loads all data into class
 | 
        
           |  |  | 1662 | */
 | 
        
           | 210 | cycrow | 1663 | bool CBaseFile::readFile(const Utils::WString &filename, int readtype, CProgressInfo *progress)
 | 
        
           | 130 | cycrow | 1664 | {
 | 
        
           |  |  | 1665 | 	CFileIO File(filename);
 | 
        
           | 58 | cycrow | 1666 | 	if ( !File.startRead() ) return false;
 | 
        
           | 6 | cycrow | 1667 |   | 
        
           | 58 | cycrow | 1668 | 	bool ret = this->readFile(File, readtype, progress);
 | 
        
           | 130 | cycrow | 1669 | 	if ( ret ) this->setFilename(filename);
 | 
        
           | 6 | cycrow | 1670 |   | 
        
           | 58 | cycrow | 1671 | 	File.close();
 | 
        
           | 6 | cycrow | 1672 | 	return ret;
 | 
        
           |  |  | 1673 | }
 | 
        
           | 51 | cycrow | 1674 |   | 
        
           | 109 | cycrow | 1675 | int CBaseFile::_read_Header(CFileIO &File, int iReadType, int iMaxProgress, CProgressInfo *pProgress)
 | 
        
           | 6 | cycrow | 1676 | {
 | 
        
           | 51 | cycrow | 1677 | 	int doneLen = 0;
 | 
        
           | 6 | cycrow | 1678 |   | 
        
           | 51 | cycrow | 1679 | 	// read data to memory
 | 
        
           | 208 | cycrow | 1680 | 	unsigned char *readData = 0;
 | 
        
           | 51 | cycrow | 1681 | 	try {
 | 
        
           |  |  | 1682 | 		readData = new unsigned char[m_SHeader.lValueCompressSize];
 | 
        
           |  |  | 1683 | 	}
 | 
        
           |  |  | 1684 | 	catch (std::exception &e) {
 | 
        
           | 227 | cycrow | 1685 | 		CLog::logf(CLog::Log_IO, 2, L"CBaseFile::_read_Header() unable to malloc [header], %d (%hs)", m_SHeader.lValueCompressSize, e.what());
 | 
        
           | 51 | cycrow | 1686 | 		return -1;
 | 
        
           |  |  | 1687 | 	}
 | 
        
           | 6 | cycrow | 1688 |   | 
        
           | 208 | cycrow | 1689 | 	if (!readData)
 | 
        
           |  |  | 1690 | 		return -1;
 | 
        
           |  |  | 1691 |   | 
        
           | 51 | cycrow | 1692 | 	unsigned char size[4];
 | 
        
           | 109 | cycrow | 1693 | 	File.read(size, 4);
 | 
        
           |  |  | 1694 | 	File.read(readData, m_SHeader.lValueCompressSize);
 | 
        
           | 6 | cycrow | 1695 |   | 
        
           | 51 | cycrow | 1696 | 	unsigned long uncomprLen = (size[0] << 24) + (size[1] << 16) + (size[2] << 8) + size[3];
 | 
        
           | 6 | cycrow | 1697 |   | 
        
           | 51 | cycrow | 1698 | 	// check for zlib compression
 | 
        
           |  |  | 1699 | 	if ( m_SHeader.iValueCompression == SPKCOMPRESS_ZLIB ) {
 | 
        
           |  |  | 1700 | 		// uncomress the data
 | 
        
           |  |  | 1701 | 		try {
 | 
        
           | 6 | cycrow | 1702 | 			unsigned char *uncompr = new unsigned char[uncomprLen];
 | 
        
           |  |  | 1703 | 			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader.lValueCompressSize );
 | 
        
           |  |  | 1704 | 			// update the progress for each section
 | 
        
           | 51 | cycrow | 1705 | 			if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
 | 
        
           | 208 | cycrow | 1706 | 			if (err == Z_OK) 
 | 
        
           |  |  | 1707 | 			{
 | 
        
           | 211 | cycrow | 1708 | 				if (m_SHeader.fVersion < 4.4f)
 | 
        
           | 209 | cycrow | 1709 | 				{
 | 
        
           |  |  | 1710 | 					std::string data((const char*)uncompr);
 | 
        
           |  |  | 1711 | 					_readValues(std::wstring(data.begin(), data.end()));
 | 
        
           |  |  | 1712 | 				}
 | 
        
           |  |  | 1713 | 				else
 | 
        
           |  |  | 1714 | 				{
 | 
        
           |  |  | 1715 | 					const wchar_t* data = (const wchar_t*)uncompr;
 | 
        
           |  |  | 1716 | 					_readValues(Utils::WString(data));
 | 
        
           |  |  | 1717 | 				}
 | 
        
           | 208 | cycrow | 1718 | 			}
 | 
        
           | 6 | cycrow | 1719 | 			doneLen = uncomprLen;
 | 
        
           | 208 | cycrow | 1720 | 			delete []uncompr;
 | 
        
           | 6 | cycrow | 1721 | 		}
 | 
        
           | 51 | cycrow | 1722 | 		catch (std::exception &e) {
 | 
        
           | 227 | cycrow | 1723 | 			CLog::logf(CLog::Log_IO, 2, L"CBaseFile::_read_Header() unable to malloc [uncompr], %d (%hs)", uncomprLen, e.what());
 | 
        
           | 53 | cycrow | 1724 | 			delete []readData;
 | 
        
           | 51 | cycrow | 1725 | 			return -1;
 | 
        
           | 6 | cycrow | 1726 | 		}
 | 
        
           | 51 | cycrow | 1727 | 	}
 | 
        
           |  |  | 1728 | 	else if ( m_SHeader.iValueCompression == SPKCOMPRESS_7ZIP ) {
 | 
        
           |  |  | 1729 | 		long len = uncomprLen;
 | 
        
           |  |  | 1730 | 		unsigned char *compr = LZMADecode_C ( readData, m_SHeader.lValueCompressSize, (size_t*)&len, NULL );
 | 
        
           |  |  | 1731 | 		// update the progress for each section
 | 
        
           |  |  | 1732 | 		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(2, iMaxProgress);
 | 
        
           | 6 | cycrow | 1733 |   | 
        
           | 208 | cycrow | 1734 | 		if (compr) 
 | 
        
           |  |  | 1735 | 		{
 | 
        
           | 211 | cycrow | 1736 | 			if (m_SHeader.fVersion <= 4.4f)
 | 
        
           | 209 | cycrow | 1737 | 			{
 | 
        
           |  |  | 1738 | 				std::string data((const char*)compr);
 | 
        
           |  |  | 1739 | 				_readValues(std::wstring(data.begin(), data.end()));
 | 
        
           |  |  | 1740 | 			}
 | 
        
           |  |  | 1741 | 			else
 | 
        
           |  |  | 1742 | 			{
 | 
        
           |  |  | 1743 | 				const wchar_t* data = (const wchar_t*)compr;
 | 
        
           |  |  | 1744 | 				_readValues(Utils::WString(data));
 | 
        
           |  |  | 1745 | 			}
 | 
        
           | 208 | cycrow | 1746 | 		}
 | 
        
           | 6 | cycrow | 1747 | 	}
 | 
        
           | 51 | cycrow | 1748 | 	// no compression
 | 
        
           |  |  | 1749 | 	else
 | 
        
           | 208 | cycrow | 1750 | 	{
 | 
        
           | 211 | cycrow | 1751 | 		if (m_SHeader.fVersion <= 4.4f)
 | 
        
           | 209 | cycrow | 1752 | 		{
 | 
        
           |  |  | 1753 | 			std::string data((const char*)readData);
 | 
        
           |  |  | 1754 | 			_readValues(std::wstring(data.begin(), data.end()));
 | 
        
           |  |  | 1755 | 		}
 | 
        
           |  |  | 1756 | 		else
 | 
        
           |  |  | 1757 | 		{
 | 
        
           |  |  | 1758 | 			const wchar_t* data = (const wchar_t*)readData;
 | 
        
           |  |  | 1759 | 			_readValues(Utils::WString(data));
 | 
        
           |  |  | 1760 | 		}
 | 
        
           | 208 | cycrow | 1761 | 	}
 | 
        
           | 6 | cycrow | 1762 |   | 
        
           | 53 | cycrow | 1763 | 	delete []readData;
 | 
        
           | 6 | cycrow | 1764 |   | 
        
           | 51 | cycrow | 1765 | 	return doneLen;
 | 
        
           |  |  | 1766 | }
 | 
        
           | 6 | cycrow | 1767 |   | 
        
           | 109 | cycrow | 1768 | int CBaseFile::_read_FileHeader(CFileIO &File, int iReadType, int iMaxProgress, int iDoneLen, CProgressInfo *pProgress)
 | 
        
           | 51 | cycrow | 1769 | {
 | 
        
           |  |  | 1770 | 	unsigned char *readData;
 | 
        
           |  |  | 1771 | 	try {
 | 
        
           |  |  | 1772 | 		readData = new unsigned char[m_SHeader2.lSize];
 | 
        
           |  |  | 1773 | 	}
 | 
        
           |  |  | 1774 | 	catch (std::exception &e) {
 | 
        
           | 227 | cycrow | 1775 | 		CLog::logf(CLog::Log_IO, 2, L"CBaseFile::_read_FileHeader() unable to malloc [header], %d (%hs)", m_SHeader2.lSize, e.what());
 | 
        
           | 51 | cycrow | 1776 | 		return -1;
 | 
        
           |  |  | 1777 | 	}
 | 
        
           | 6 | cycrow | 1778 |   | 
        
           | 51 | cycrow | 1779 | 	unsigned char size[4];
 | 
        
           | 109 | cycrow | 1780 | 	File.read(size, 4);
 | 
        
           |  |  | 1781 | 	File.read(readData, m_SHeader2.lSize);
 | 
        
           | 6 | cycrow | 1782 |   | 
        
           | 51 | cycrow | 1783 | 	unsigned long uncomprLen = (size[0] << 24) + (size[1] << 16) + (size[2] << 8) + size[3];
 | 
        
           | 6 | cycrow | 1784 |   | 
        
           | 51 | cycrow | 1785 | 	// check for zlib compression
 | 
        
           |  |  | 1786 | 	if ( m_SHeader.iValueCompression == SPKCOMPRESS_ZLIB ) {
 | 
        
           |  |  | 1787 | 		if ( uncomprLen < (unsigned long)iDoneLen ) uncomprLen = iDoneLen;
 | 
        
           | 6 | cycrow | 1788 |   | 
        
           | 51 | cycrow | 1789 | 		try {
 | 
        
           | 6 | cycrow | 1790 | 			unsigned char *uncompr = new unsigned char[uncomprLen];
 | 
        
           |  |  | 1791 | 			int err = uncompress ( uncompr, &uncomprLen, readData, m_SHeader2.lSize );
 | 
        
           |  |  | 1792 | 			// update the progress for each section
 | 
        
           | 51 | cycrow | 1793 | 			if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(5, iMaxProgress);
 | 
        
           | 211 | cycrow | 1794 | 			if (err == Z_OK)
 | 
        
           |  |  | 1795 | 			{
 | 
        
           |  |  | 1796 | //#pragma warning(disable:4244)
 | 
        
           |  |  | 1797 | 				if (m_SHeader.fVersion < 4.4f)
 | 
        
           |  |  | 1798 | 				{
 | 
        
           |  |  | 1799 | 					std::string data((char*)uncompr);
 | 
        
           |  |  | 1800 | 					_readFiles(std::wstring(data.begin(), data.end()));
 | 
        
           |  |  | 1801 | 				}
 | 
        
           |  |  | 1802 | 				else
 | 
        
           |  |  | 1803 | 				{
 | 
        
           |  |  | 1804 | 					std::wstring data((wchar_t*)uncompr);
 | 
        
           |  |  | 1805 | 					_readFiles(data);
 | 
        
           |  |  | 1806 | 				}
 | 
        
           |  |  | 1807 | //#pragma warning(enable:4244)
 | 
        
           |  |  | 1808 | 			}
 | 
        
           |  |  | 1809 | 			delete[] uncompr;
 | 
        
           | 6 | cycrow | 1810 | 		}
 | 
        
           | 51 | cycrow | 1811 | 		catch (std::exception &e) {
 | 
        
           | 227 | cycrow | 1812 | 			CLog::logf(CLog::Log_IO, 2, L"CBaseFile::_read_FileHeader() unable to malloc [uncompr], %d (%hs)", uncomprLen, e.what());
 | 
        
           | 53 | cycrow | 1813 | 			delete []readData;
 | 
        
           | 51 | cycrow | 1814 | 			return -1;
 | 
        
           | 6 | cycrow | 1815 | 		}
 | 
        
           |  |  | 1816 |   | 
        
           |  |  | 1817 | 	}
 | 
        
           | 51 | cycrow | 1818 | 	else if ( m_SHeader.iValueCompression == SPKCOMPRESS_7ZIP )
 | 
        
           |  |  | 1819 | 	{
 | 
        
           |  |  | 1820 | 		long len = uncomprLen;
 | 
        
           |  |  | 1821 | 		unsigned char *compr = LZMADecode_C ( readData, m_SHeader2.lSize, (size_t*)&len, NULL );
 | 
        
           |  |  | 1822 | 		// update the progress for each section
 | 
        
           |  |  | 1823 | 		if ( iReadType != SPKREAD_ALL && pProgress ) pProgress->UpdateProgress(5, iMaxProgress);
 | 
        
           | 213 | cycrow | 1824 | 		if (compr) 
 | 
        
           |  |  | 1825 | 		{
 | 
        
           |  |  | 1826 | 			if (m_SHeader.fVersion < 4.4f)
 | 
        
           |  |  | 1827 | 			{
 | 
        
           |  |  | 1828 | 				std::string data((char*)compr);
 | 
        
           |  |  | 1829 | 				_readFiles(std::wstring(data.begin(), data.end()));
 | 
        
           |  |  | 1830 | 			}
 | 
        
           |  |  | 1831 | 			else
 | 
        
           |  |  | 1832 | 			{
 | 
        
           |  |  | 1833 | 				std::wstring data((wchar_t*)compr);
 | 
        
           |  |  | 1834 | 				_readFiles(data);
 | 
        
           |  |  | 1835 | 			}
 | 
        
           |  |  | 1836 | 		}
 | 
        
           | 51 | cycrow | 1837 | 	}
 | 
        
           |  |  | 1838 | 	else
 | 
        
           | 213 | cycrow | 1839 | 	{
 | 
        
           |  |  | 1840 | 		if (m_SHeader.fVersion < 4.4f)
 | 
        
           |  |  | 1841 | 		{
 | 
        
           |  |  | 1842 | 			std::string data((char*)readData);
 | 
        
           |  |  | 1843 | 			_readFiles(std::wstring(data.begin(), data.end()));
 | 
        
           |  |  | 1844 | 		}
 | 
        
           |  |  | 1845 | 		else
 | 
        
           |  |  | 1846 | 		{
 | 
        
           |  |  | 1847 | 			std::wstring data((wchar_t*)readData);
 | 
        
           |  |  | 1848 | 			_readFiles(data);
 | 
        
           |  |  | 1849 | 		}
 | 
        
           |  |  | 1850 | 	}
 | 
        
           | 6 | cycrow | 1851 |   | 
        
           | 53 | cycrow | 1852 | 	delete []readData;
 | 
        
           | 51 | cycrow | 1853 | 	return true;
 | 
        
           |  |  | 1854 | }
 | 
        
           |  |  | 1855 |   | 
        
           | 58 | cycrow | 1856 | bool CBaseFile::readFile(CFileIO &File, int readtype, CProgressInfo *progress)
 | 
        
           | 51 | cycrow | 1857 | {
 | 
        
           |  |  | 1858 | 	ClearError ();
 | 
        
           |  |  | 1859 |   | 
        
           |  |  | 1860 | 	// first read the header
 | 
        
           | 197 | cycrow | 1861 | 	if ( !_parseHeader(File.readEndOfLineStr()) ) return false;
 | 
        
           | 51 | cycrow | 1862 | 	if ( readtype == SPKREAD_HEADER ) return true;
 | 
        
           |  |  | 1863 |   | 
        
           |  |  | 1864 | 	// update the progress for each section
 | 
        
           |  |  | 1865 | 	int maxProgress = (readtype == SPKREAD_VALUES) ? 3 : 6;
 | 
        
           |  |  | 1866 | 	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(1, maxProgress);
 | 
        
           |  |  | 1867 |   | 
        
           |  |  | 1868 | 	long doneLen = 0;
 | 
        
           |  |  | 1869 | 	// next read the data values for the spk files
 | 
        
           | 109 | cycrow | 1870 | 	if ( m_SHeader.lValueCompressSize ) doneLen = this->_read_Header(File, readtype, maxProgress, progress);
 | 
        
           | 51 | cycrow | 1871 |   | 
        
           |  |  | 1872 | 	// update the progress for each section
 | 
        
           |  |  | 1873 | 	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(3, maxProgress);
 | 
        
           |  |  | 1874 | 	if ( readtype == SPKREAD_VALUES ) return true;
 | 
        
           |  |  | 1875 |   | 
        
           |  |  | 1876 | 	// next should be the next header
 | 
        
           | 197 | cycrow | 1877 | 	if ( !_parseFileHeader(File.readEndOfLineStr()) ) return false;
 | 
        
           | 51 | cycrow | 1878 |   | 
        
           |  |  | 1879 | 	// clear the current file list
 | 
        
           |  |  | 1880 | 	m_lFiles.clear(true);
 | 
        
           | 88 | cycrow | 1881 | 	if ( _pTextDB ) {
 | 
        
           |  |  | 1882 | 		delete _pTextDB;
 | 
        
           |  |  | 1883 | 		_pTextDB = NULL;
 | 
        
           |  |  | 1884 | 	}
 | 
        
           | 51 | cycrow | 1885 |   | 
        
           |  |  | 1886 | 	// update the progress for each section
 | 
        
           |  |  | 1887 | 	if ( readtype != SPKREAD_ALL && progress ) progress->UpdateProgress(4, maxProgress);
 | 
        
           |  |  | 1888 |   | 
        
           | 109 | cycrow | 1889 | 	if ( m_SHeader2.lSize ) this->_read_FileHeader(File, readtype, maxProgress, doneLen, progress);
 | 
        
           | 51 | cycrow | 1890 |   | 
        
           | 6 | cycrow | 1891 | 	// file mismatch
 | 
        
           |  |  | 1892 | 	long numfiles = m_lFiles.size();
 | 
        
           | 51 | cycrow | 1893 | 	if ( m_pIconFile ) ++numfiles;
 | 
        
           |  |  | 1894 | 	if ( m_SHeader2.iNumFiles != numfiles ) {
 | 
        
           | 134 | cycrow | 1895 | 		_iLastError = SPKERR_FILEMISMATCH;
 | 
        
           | 6 | cycrow | 1896 | 		return false;
 | 
        
           |  |  | 1897 | 	}
 | 
        
           |  |  | 1898 |   | 
        
           |  |  | 1899 | 	// update the progress for each section
 | 
        
           | 51 | cycrow | 1900 | 	if ( readtype != SPKREAD_ALL && progress )	progress->UpdateProgress(6, maxProgress);
 | 
        
           | 6 | cycrow | 1901 |   | 
        
           | 51 | cycrow | 1902 | 	if ( readtype == SPKREAD_ALL ) {
 | 
        
           | 6 | cycrow | 1903 | 		int fileCount = 2;
 | 
        
           | 58 | cycrow | 1904 | 		if ( m_pIconFile ) m_pIconFile->readFromFile(File, m_pIconFile->GetDataSize());
 | 
        
           | 6 | cycrow | 1905 |   | 
        
           | 51 | cycrow | 1906 | 		// ok finally we need to read all the file
 | 
        
           |  |  | 1907 | 		for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
 | 
        
           | 58 | cycrow | 1908 | 			node->Data()->readFromFile(File, node->Data()->GetDataSize());
 | 
        
           | 51 | cycrow | 1909 | 			if ( progress )	progress->UpdateProgress(fileCount++, m_lFiles.size() + 2);
 | 
        
           | 6 | cycrow | 1910 | 		}
 | 
        
           |  |  | 1911 |   | 
        
           |  |  | 1912 | 		m_bFullyLoaded = true;
 | 
        
           |  |  | 1913 | 	}
 | 
        
           |  |  | 1914 |   | 
        
           |  |  | 1915 | 	return true;
 | 
        
           |  |  | 1916 | }
 | 
        
           |  |  | 1917 |   | 
        
           |  |  | 1918 | bool CBaseFile::IsMod()
 | 
        
           |  |  | 1919 | {
 | 
        
           |  |  | 1920 | 	// check for any mod files that are not fake patchs
 | 
        
           |  |  | 1921 | 	for ( CListNode<C_File> *fNode = m_lFiles.Front(); fNode; fNode = fNode->next() )
 | 
        
           |  |  | 1922 | 	{
 | 
        
           |  |  | 1923 | 		C_File *f = fNode->Data();
 | 
        
           |  |  | 1924 | 		if ( f->GetFileType() != FILETYPE_MOD )
 | 
        
           |  |  | 1925 | 			continue;
 | 
        
           |  |  | 1926 |   | 
        
           |  |  | 1927 | 		if ( !f->IsFakePatch() )
 | 
        
           |  |  | 1928 | 			return true;
 | 
        
           |  |  | 1929 | 	}
 | 
        
           |  |  | 1930 |   | 
        
           |  |  | 1931 | 	return false;
 | 
        
           |  |  | 1932 | }
 | 
        
           |  |  | 1933 |   | 
        
           | 13 | cycrow | 1934 | bool CBaseFile::IsFakePatch() const
 | 
        
           | 6 | cycrow | 1935 | {
 | 
        
           |  |  | 1936 | 	// check for any mod files that are not fake patchs
 | 
        
           |  |  | 1937 | 	for ( CListNode<C_File> *fNode = m_lFiles.Front(); fNode; fNode = fNode->next() )
 | 
        
           |  |  | 1938 | 	{
 | 
        
           |  |  | 1939 | 		C_File *f = fNode->Data();
 | 
        
           |  |  | 1940 | 		if ( f->GetFileType() != FILETYPE_MOD )
 | 
        
           |  |  | 1941 | 			continue;
 | 
        
           |  |  | 1942 |   | 
        
           |  |  | 1943 | 		if ( f->IsFakePatch() )
 | 
        
           |  |  | 1944 | 			return true;
 | 
        
           |  |  | 1945 | 	}
 | 
        
           |  |  | 1946 |   | 
        
           |  |  | 1947 | 	return false;
 | 
        
           |  |  | 1948 | }
 | 
        
           |  |  | 1949 |   | 
        
           | 207 | cycrow | 1950 | Utils::WString CBaseFile::createValuesLine () const
 | 
        
           | 6 | cycrow | 1951 | {
 | 
        
           | 203 | cycrow | 1952 | 	Utils::WString values(L"Name: ");
 | 
        
           |  |  | 1953 | 	values += this->name() + L"\n";
 | 
        
           |  |  | 1954 | 	values += L"Author: " + this->author() + L"\n";
 | 
        
           | 204 | cycrow | 1955 | 	values += L"Version: " + this->version() + L"\n";
 | 
        
           | 206 | cycrow | 1956 | 	if ( !this->creationDate().empty() )values += L"Date: "			+ this->creationDate()	+ L"\n";
 | 
        
           |  |  | 1957 | 	if ( !this->webAddress().empty() )	values += L"WebAddress: "	+ this->webAddress()	+ L"\n";
 | 
        
           |  |  | 1958 | 	if ( !this->webSite().empty() )		values += L"WebSite: "		+ this->webSite()		+ L"\n";
 | 
        
           |  |  | 1959 | 	if ( !this->email().empty() )		values += L"Email: "		+ this->email()			+ L"\n";
 | 
        
           |  |  | 1960 | 	if ( !this->forumLink().empty() )	values += L"ForumLink: "	+ this->forumLink()		+ L"\n";
 | 
        
           | 49 | cycrow | 1961 |   | 
        
           | 208 | cycrow | 1962 | 	for(auto itr = webMirrors().begin(); itr != webMirrors().end(); itr++)
 | 
        
           |  |  | 1963 | 		values += Utils::WString(L"WebMirror: ") + (*itr)->str + L"\n";
 | 
        
           | 48 | cycrow | 1964 | 	if ( !this->description().empty() ) {
 | 
        
           | 206 | cycrow | 1965 | 		Utils::WString desc = this->description();
 | 
        
           | 203 | cycrow | 1966 | 		desc = desc.findReplace(L"<newline>", L"<br>");
 | 
        
           | 213 | cycrow | 1967 | 		desc = desc.findReplace(L"\n", L"<br>");
 | 
        
           | 203 | cycrow | 1968 | 		desc.remove(L'\r');
 | 
        
           |  |  | 1969 | 		values += L"Desc: " + desc + L"\n";
 | 
        
           | 6 | cycrow | 1970 | 	}
 | 
        
           |  |  | 1971 |   | 
        
           |  |  | 1972 | 	for ( CListNode<SGameCompat> *gc = m_lGames.Front(); gc; gc = gc->next() ) {
 | 
        
           | 46 | cycrow | 1973 | 		if ( !gc->Data()->sVersion.empty() )
 | 
        
           | 203 | cycrow | 1974 | 			values += Utils::WString(L"GameCompatExact: ") + (long)gc->Data()->iGame + L" " + gc->Data()->sVersion + L"\n";
 | 
        
           | 6 | cycrow | 1975 | 		else
 | 
        
           | 203 | cycrow | 1976 | 			values += Utils::WString(L"GameCompat: ") + (long)gc->Data()->iGame + L" " + (long)gc->Data()->iVersion + L"\n";
 | 
        
           | 6 | cycrow | 1977 | 	}
 | 
        
           |  |  | 1978 |   | 
        
           | 175 | cycrow | 1979 | 	if (computeSigned(true))
 | 
        
           | 203 | cycrow | 1980 | 		values += L"Signed\n";
 | 
        
           | 6 | cycrow | 1981 |   | 
        
           | 46 | cycrow | 1982 | 	for ( int j = 0; j < 2; j++ ) {
 | 
        
           |  |  | 1983 | 		const CInstallText *text;
 | 
        
           | 203 | cycrow | 1984 | 		Utils::WString textStart;
 | 
        
           | 46 | cycrow | 1985 | 		switch(j) {
 | 
        
           | 203 | cycrow | 1986 | 			case 0:	textStart = L"Uninstall"; text = this->uninstallText(); break;
 | 
        
           |  |  | 1987 | 			case 1: textStart = L"Install"; text = this->installText(); break;
 | 
        
           | 46 | cycrow | 1988 | 		}
 | 
        
           |  |  | 1989 | 		for ( unsigned int i = 0; i < text->count(); i++ ) {
 | 
        
           |  |  | 1990 | 			int iLang = text->language(i);
 | 
        
           | 206 | cycrow | 1991 | 			if ( !text->getBefore(iLang).empty() ) values += textStart + L"Before: " + (long)iLang + L"|" + text->getBefore(iLang) + L"\n";
 | 
        
           |  |  | 1992 | 			if ( !text->getAfter(iLang).empty() ) values += textStart + L"After: " + (long)iLang + L"|" + text->getAfter(iLang) + L"\n";
 | 
        
           | 46 | cycrow | 1993 | 		}
 | 
        
           | 6 | cycrow | 1994 | 	}
 | 
        
           |  |  | 1995 |   | 
        
           | 203 | cycrow | 1996 | 	values += Utils::WString(L"GameChanging: ") + (long)gameChanging() + L"\n";
 | 
        
           |  |  | 1997 | 	values += Utils::WString(L"EaseOfUse: ") + (long)easeOfUse() + L"\n";
 | 
        
           |  |  | 1998 | 	values += Utils::WString(L"Recommended: ") + (long)recommended() + L"\n";
 | 
        
           | 6 | cycrow | 1999 |   | 
        
           | 170 | cycrow | 2000 | 	for(auto itr = namesList()->begin(); itr != namesList()->end(); itr++)
 | 
        
           | 204 | cycrow | 2001 | 		values += Utils::WString(L"ScriptName: ") + (long)(*itr)->iLanguage + L":" + (*itr)->sName + L"\n";
 | 
        
           | 6 | cycrow | 2002 |   | 
        
           | 14 | cycrow | 2003 | 	for ( CListNode<SNeededLibrary> *libNode = m_lNeededLibrarys.Front(); libNode; libNode = libNode->next() ) {
 | 
        
           | 6 | cycrow | 2004 | 		SNeededLibrary *l = libNode->Data();
 | 
        
           | 204 | cycrow | 2005 | 		values += L"NeededLibrary: " + l->sName + L"||" + l->sAuthor + L"||" + l->sMinVersion + L"\n";
 | 
        
           | 6 | cycrow | 2006 | 	}
 | 
        
           |  |  | 2007 |   | 
        
           | 160 | cycrow | 2008 | 	for (auto itr = _lFakePatchBefore.begin(); itr != _lFakePatchBefore.end(); itr++)
 | 
        
           | 207 | cycrow | 2009 | 		values += L"FakePatchBefore: " + (*itr)->str + L"||" + (*itr)->data + L"\n";
 | 
        
           | 160 | cycrow | 2010 | 	for (auto itr = _lFakePatchAfter.begin(); itr != _lFakePatchAfter.end(); itr++)
 | 
        
           | 207 | cycrow | 2011 | 		values += L"FakePatchAfter: " + (*itr)->str + L"||" + (*itr)->data + L"\n";
 | 
        
           | 6 | cycrow | 2012 |   | 
        
           | 203 | cycrow | 2013 | 	values += Utils::WString(L"PluginType: ") + (long)this->pluginType() + L"\n";
 | 
        
           | 6 | cycrow | 2014 |   | 
        
           | 234 | cycrow | 2015 | 	for (auto itr = _lGlobals.begin(); itr != _lGlobals.end(); itr++)
 | 
        
           |  |  | 2016 | 		values += L"Globals: " + (*itr)->str + L";" + (*itr)->data + L"\n";
 | 
        
           |  |  | 2017 |   | 
        
           | 207 | cycrow | 2018 | 	return values;
 | 
        
           | 6 | cycrow | 2019 | }
 | 
        
           |  |  | 2020 |   | 
        
           |  |  | 2021 |   | 
        
           |  |  | 2022 | /*
 | 
        
           |  |  | 2023 | 	Func:   WriteFile
 | 
        
           |  |  | 2024 | 	Input:  filename - The filename of the spk file to write to
 | 
        
           |  |  | 2025 | 	Desc:   Writes the data to an spk file
 | 
        
           |  |  | 2026 | */
 | 
        
           | 210 | cycrow | 2027 | bool CBaseFile::writeFile(const Utils::WString &filename, CProgressInfo *progress) const
 | 
        
           | 6 | cycrow | 2028 | {
 | 
        
           | 52 | cycrow | 2029 | 	CFileIO File(filename);
 | 
        
           | 175 | cycrow | 2030 | 	if ( File.startWrite() ) return writeData(File, progress);
 | 
        
           | 52 | cycrow | 2031 | 	return false;
 | 
        
           | 6 | cycrow | 2032 | }
 | 
        
           |  |  | 2033 |   | 
        
           | 175 | cycrow | 2034 | bool CBaseFile::writeHeader(CFileIO &file, int valueheader, int valueComprLen) const
 | 
        
           | 6 | cycrow | 2035 | {
 | 
        
           | 52 | cycrow | 2036 | 	return file.write("BaseCycrow;%.2f;%d;%d\n", FILEVERSION, valueheader, valueComprLen);
 | 
        
           | 6 | cycrow | 2037 | }
 | 
        
           |  |  | 2038 |   | 
        
           | 175 | cycrow | 2039 | bool CBaseFile::writeData(CFileIO &file, CProgressInfo *progress ) const
 | 
        
           | 6 | cycrow | 2040 | {
 | 
        
           |  |  | 2041 | 	int valueheader = m_SHeader.iValueCompression, fileheader = m_SHeader.iValueCompression;
 | 
        
           |  |  | 2042 | 	if ( valueheader == SPKCOMPRESS_7ZIP )
 | 
        
           |  |  | 2043 | 		valueheader = SPKCOMPRESS_ZLIB;
 | 
        
           |  |  | 2044 | 	if ( fileheader == SPKCOMPRESS_7ZIP )
 | 
        
           |  |  | 2045 | 		fileheader = SPKCOMPRESS_ZLIB;
 | 
        
           |  |  | 2046 |   | 
        
           |  |  | 2047 | 	// get the script values
 | 
        
           | 207 | cycrow | 2048 | 	Utils::WString values = this->createValuesLine();
 | 
        
           | 209 | cycrow | 2049 | 	const char* data = (const char*)values.c_str();
 | 
        
           | 6 | cycrow | 2050 |   | 
        
           |  |  | 2051 | 	// compress the values
 | 
        
           | 209 | cycrow | 2052 | 	int valueUncomprLen = (int)(wcslen(values.c_str()) * sizeof(wchar_t)) / sizeof(char);
 | 
        
           | 6 | cycrow | 2053 | 	unsigned long valueComprLen = 0;
 | 
        
           |  |  | 2054 | 	unsigned char *valueCompr = NULL;
 | 
        
           |  |  | 2055 | 	bool compressed = false;
 | 
        
           | 208 | cycrow | 2056 |   | 
        
           | 6 | cycrow | 2057 | 	if ( valueheader == SPKCOMPRESS_ZLIB )
 | 
        
           |  |  | 2058 | 	{
 | 
        
           |  |  | 2059 | 		valueComprLen = valueUncomprLen;
 | 
        
           |  |  | 2060 | 		if ( valueComprLen < 100 )
 | 
        
           |  |  | 2061 | 			valueComprLen = 200;
 | 
        
           |  |  | 2062 | 		else if ( valueComprLen < 1000 )
 | 
        
           |  |  | 2063 | 			valueComprLen *= 2;
 | 
        
           |  |  | 2064 |   | 
        
           |  |  | 2065 | 		valueCompr = (unsigned char *)calloc((unsigned int)valueComprLen, 1);
 | 
        
           | 209 | cycrow | 2066 | 		int err = compress ( (unsigned char *)valueCompr, &valueComprLen, (const unsigned char *)data, (unsigned long)valueUncomprLen, 0 );
 | 
        
           | 6 | cycrow | 2067 | 		if ( err == Z_OK )
 | 
        
           |  |  | 2068 | 			compressed = true;
 | 
        
           |  |  | 2069 | 	}
 | 
        
           |  |  | 2070 |   | 
        
           |  |  | 2071 | 	if ( !compressed )
 | 
        
           |  |  | 2072 | 	{
 | 
        
           |  |  | 2073 | 		valueComprLen = valueUncomprLen;
 | 
        
           |  |  | 2074 | 		valueCompr = (unsigned char *)calloc((unsigned int)valueComprLen, 1);
 | 
        
           | 209 | cycrow | 2075 | 		memcpy ( valueCompr, (const unsigned char *)data, valueComprLen );
 | 
        
           | 6 | cycrow | 2076 | 		valueheader = SPKCOMPRESS_NONE;
 | 
        
           |  |  | 2077 | 	}
 | 
        
           |  |  | 2078 |   | 
        
           |  |  | 2079 | 	// write the main header to the file
 | 
        
           | 175 | cycrow | 2080 | 	if ( !this->writeHeader(file, valueheader, valueComprLen) )	return false;
 | 
        
           | 6 | cycrow | 2081 |   | 
        
           |  |  | 2082 | 	// write the compressed data to file
 | 
        
           | 52 | cycrow | 2083 | 	file.put(static_cast<unsigned char>(valueUncomprLen >> 24));
 | 
        
           |  |  | 2084 | 	file.put(static_cast<unsigned char>(valueUncomprLen >> 16));
 | 
        
           |  |  | 2085 | 	file.put(static_cast<unsigned char>(valueUncomprLen >> 8));
 | 
        
           |  |  | 2086 | 	file.put(static_cast<unsigned char>(valueUncomprLen));
 | 
        
           |  |  | 2087 | 	file.write(valueCompr, valueComprLen);
 | 
        
           | 6 | cycrow | 2088 | 	free ( valueCompr );
 | 
        
           |  |  | 2089 |   | 
        
           |  |  | 2090 | 	// now compress the files header
 | 
        
           |  |  | 2091 | 	// create the files values
 | 
        
           | 175 | cycrow | 2092 | 	SSPKHeader2 header;
 | 
        
           | 211 | cycrow | 2093 | 	Utils::WString files = createFilesLine(&header, progress);
 | 
        
           | 175 | cycrow | 2094 |   | 
        
           | 6 | cycrow | 2095 | 	// compress the files values
 | 
        
           | 211 | cycrow | 2096 | 	long fileUncomprLen = (long)((wcslen(files.c_str()) * sizeof(wchar_t)) / sizeof(char)), fileComprLen = fileUncomprLen;
 | 
        
           | 6 | cycrow | 2097 | 	unsigned char *fileCompr = NULL;
 | 
        
           |  |  | 2098 |   | 
        
           |  |  | 2099 | 	compressed = false;
 | 
        
           |  |  | 2100 | 	if ( fileUncomprLen )
 | 
        
           |  |  | 2101 | 	{
 | 
        
           |  |  | 2102 | 		if ( fileheader == SPKCOMPRESS_ZLIB )
 | 
        
           |  |  | 2103 | 		{
 | 
        
           |  |  | 2104 | 			if ( fileComprLen < 100 )
 | 
        
           |  |  | 2105 | 				fileComprLen = 200;
 | 
        
           |  |  | 2106 | 			else if ( fileComprLen < 1000 )
 | 
        
           |  |  | 2107 | 				fileComprLen *= 2;
 | 
        
           |  |  | 2108 | 			fileCompr = (unsigned char *)calloc((unsigned int)fileComprLen, 1);
 | 
        
           | 211 | cycrow | 2109 | 			int err = compress ( (unsigned char *)fileCompr, (unsigned long *)&fileComprLen, (const unsigned char *)files.c_str(), (unsigned long)fileUncomprLen, 0 );
 | 
        
           | 6 | cycrow | 2110 | 			if ( err == Z_OK )
 | 
        
           |  |  | 2111 | 				compressed = true;
 | 
        
           |  |  | 2112 | 		}
 | 
        
           |  |  | 2113 | 	}
 | 
        
           |  |  | 2114 |   | 
        
           |  |  | 2115 | 	// if unable to compress, store it as plain text
 | 
        
           |  |  | 2116 | 	if ( !compressed )
 | 
        
           |  |  | 2117 | 	{
 | 
        
           |  |  | 2118 | 		fileComprLen = fileUncomprLen;
 | 
        
           |  |  | 2119 | 		fileCompr = (unsigned char *)calloc((unsigned int)fileComprLen, 1);
 | 
        
           | 211 | cycrow | 2120 | 		memcpy ( fileCompr, (const unsigned char *)files.c_str(), fileComprLen );
 | 
        
           | 6 | cycrow | 2121 | 		fileheader = SPKCOMPRESS_NONE;
 | 
        
           |  |  | 2122 | 	}
 | 
        
           |  |  | 2123 |   | 
        
           |  |  | 2124 | 	// now write the file header
 | 
        
           | 175 | cycrow | 2125 | 	header.lSize = fileComprLen;
 | 
        
           |  |  | 2126 | 	file.write("FileHeader;%d;%ld;%ld;%d;%d\n", header.iNumFiles, header.lSize, header.lFullSize, fileheader, header.iDataCompression);
 | 
        
           | 6 | cycrow | 2127 |   | 
        
           | 52 | cycrow | 2128 | 	file.put(static_cast<unsigned char>(fileUncomprLen >> 24));
 | 
        
           |  |  | 2129 | 	file.put(static_cast<unsigned char>(fileUncomprLen >> 16));
 | 
        
           |  |  | 2130 | 	file.put(static_cast<unsigned char>(fileUncomprLen >> 8));
 | 
        
           |  |  | 2131 | 	file.put(static_cast<unsigned char>(fileUncomprLen));
 | 
        
           |  |  | 2132 | 	file.write(fileCompr, fileComprLen);
 | 
        
           | 6 | cycrow | 2133 | 	free ( fileCompr );
 | 
        
           |  |  | 2134 |   | 
        
           |  |  | 2135 | 	if ( progress )
 | 
        
           |  |  | 2136 | 	{
 | 
        
           |  |  | 2137 | 		progress->UpdateStatus(STATUS_WRITE);
 | 
        
           |  |  | 2138 | 		progress->SetDone(0);
 | 
        
           |  |  | 2139 | 		long max = 0;
 | 
        
           | 88 | cycrow | 2140 | 		for ( CListNode<C_File> *file = m_lFiles.Front(); file; file = file->next() )
 | 
        
           |  |  | 2141 | 			max += file->Data()->GetDataSize();
 | 
        
           | 6 | cycrow | 2142 | 		if ( m_pIconFile )
 | 
        
           |  |  | 2143 | 			max += m_pIconFile->GetDataSize();
 | 
        
           |  |  | 2144 | 		progress->SetMax(max);
 | 
        
           |  |  | 2145 | 	}
 | 
        
           |  |  | 2146 |   | 
        
           |  |  | 2147 | 	// now finally, write all the file data
 | 
        
           | 52 | cycrow | 2148 | 	if ( m_pIconFile ) {
 | 
        
           |  |  | 2149 | 		if ( progress )	progress->UpdateFile(m_pIconFile);
 | 
        
           | 178 | cycrow | 2150 | 		file.writeSize(m_pIconFile->uncompressedDataSize());
 | 
        
           | 52 | cycrow | 2151 | 		file.write(m_pIconFile->GetData(), m_pIconFile->GetDataSize());
 | 
        
           |  |  | 2152 | 		if ( progress )	progress->IncDone(m_pIconFile->GetDataSize());
 | 
        
           | 6 | cycrow | 2153 | 	}
 | 
        
           |  |  | 2154 |   | 
        
           |  |  | 2155 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 2156 | 	{
 | 
        
           | 52 | cycrow | 2157 | 		C_File *f = node->Data();
 | 
        
           |  |  | 2158 | 		if ( progress )	progress->UpdateFile(f);
 | 
        
           | 178 | cycrow | 2159 | 		file.writeSize(f->uncompressedDataSize());
 | 
        
           | 52 | cycrow | 2160 | 		unsigned char *data = f->GetData();
 | 
        
           |  |  | 2161 | 		size_t remaining = f->GetDataSize();
 | 
        
           |  |  | 2162 | 		while ( remaining )	{
 | 
        
           | 6 | cycrow | 2163 | 			size_t writeSize = WRITECHUNK;
 | 
        
           | 52 | cycrow | 2164 | 			if ( writeSize > remaining ) writeSize = remaining;
 | 
        
           | 6 | cycrow | 2165 |   | 
        
           | 52 | cycrow | 2166 | 			if ( file.write(data, writeSize) ) {
 | 
        
           |  |  | 2167 | 				data += writeSize;
 | 
        
           |  |  | 2168 | 				remaining -= writeSize;
 | 
        
           |  |  | 2169 | 			}
 | 
        
           | 6 | cycrow | 2170 |   | 
        
           | 52 | cycrow | 2171 | 			if ( progress ) progress->IncDone((int)writeSize);
 | 
        
           | 6 | cycrow | 2172 | 		}
 | 
        
           |  |  | 2173 | 	}
 | 
        
           |  |  | 2174 |   | 
        
           |  |  | 2175 | 	return true;
 | 
        
           |  |  | 2176 | }
 | 
        
           |  |  | 2177 |   | 
        
           | 210 | cycrow | 2178 | bool CBaseFile::extractFile(C_File *file, const Utils::WString &dir, bool includedir, CProgressInfo *progress)
 | 
        
           | 131 | cycrow | 2179 | {
 | 
        
           |  |  | 2180 | 	if (ReadFileToMemory(file))
 | 
        
           | 6 | cycrow | 2181 | 	{
 | 
        
           |  |  | 2182 | 		// now finally, uncompress the file
 | 
        
           |  |  | 2183 | 		long len = 0;
 | 
        
           | 131 | cycrow | 2184 | 		unsigned char *data = file->UncompressData(&len, progress);
 | 
        
           |  |  | 2185 | 		if (!data)
 | 
        
           | 6 | cycrow | 2186 | 		{
 | 
        
           |  |  | 2187 | 			// attempt a file decompress
 | 
        
           | 131 | cycrow | 2188 | 			if (file->GetCompressionType() == SPKCOMPRESS_7ZIP)
 | 
        
           | 6 | cycrow | 2189 | 			{
 | 
        
           | 178 | cycrow | 2190 | 				if (file->uncompressToFile(dir, this, includedir, progress))
 | 
        
           | 6 | cycrow | 2191 | 					return true;
 | 
        
           |  |  | 2192 | 			}
 | 
        
           |  |  | 2193 | 			return false;
 | 
        
           |  |  | 2194 | 		}
 | 
        
           |  |  | 2195 |   | 
        
           | 210 | cycrow | 2196 | 		if (!file->writeToDir(dir, this, includedir, Utils::WString::Null(), data, len))
 | 
        
           | 6 | cycrow | 2197 | 			return false;
 | 
        
           |  |  | 2198 |   | 
        
           |  |  | 2199 | 		return true;
 | 
        
           |  |  | 2200 |   | 
        
           |  |  | 2201 | 	}
 | 
        
           |  |  | 2202 | 	else
 | 
        
           |  |  | 2203 | 		return false;
 | 
        
           |  |  | 2204 | }
 | 
        
           | 210 | cycrow | 2205 | bool CBaseFile::extractFile(C_File *file, const Utils::WString &dir, unsigned int game, const Utils::WStringList &gameAddons, bool includedir, CProgressInfo *progress)
 | 
        
           | 131 | cycrow | 2206 | {
 | 
        
           |  |  | 2207 | 	if (ReadFileToMemory(file))
 | 
        
           |  |  | 2208 | 	{
 | 
        
           |  |  | 2209 | 		CDirIO Dir(dir);
 | 
        
           | 197 | cycrow | 2210 | 		Utils::WString addonDir;
 | 
        
           | 131 | cycrow | 2211 | 		if (file->isFileInAddon())
 | 
        
           |  |  | 2212 | 		{
 | 
        
           |  |  | 2213 | 			int addonGame = file->getForSingleGame();
 | 
        
           |  |  | 2214 | 			if (!addonGame) addonGame = game;
 | 
        
           | 6 | cycrow | 2215 |   | 
        
           | 131 | cycrow | 2216 | 			if (addonGame > 0)
 | 
        
           | 197 | cycrow | 2217 | 				addonDir = gameAddons.findString(Utils::WString::Number(addonGame));
 | 
        
           | 131 | cycrow | 2218 | 		}
 | 
        
           |  |  | 2219 |   | 
        
           |  |  | 2220 | 		if (!addonDir.empty())
 | 
        
           |  |  | 2221 | 			Dir.cd(addonDir);
 | 
        
           |  |  | 2222 |   | 
        
           |  |  | 2223 | 		// create directory first
 | 
        
           |  |  | 2224 | 		Dir.create(file->getDirectory(this));
 | 
        
           |  |  | 2225 |   | 
        
           |  |  | 2226 | 		// now finally, uncompress the file
 | 
        
           |  |  | 2227 | 		long len = 0;
 | 
        
           |  |  | 2228 | 		unsigned char *data = file->UncompressData(&len, progress);
 | 
        
           |  |  | 2229 | 		if (!data)
 | 
        
           |  |  | 2230 | 		{
 | 
        
           |  |  | 2231 | 			// attempt a file decompress
 | 
        
           |  |  | 2232 | 			if (file->GetCompressionType() == SPKCOMPRESS_7ZIP)
 | 
        
           |  |  | 2233 | 			{
 | 
        
           | 210 | cycrow | 2234 | 				if (file->uncompressToFile(Dir.dir(), this, includedir, progress))
 | 
        
           | 131 | cycrow | 2235 | 					return true;
 | 
        
           |  |  | 2236 | 			}
 | 
        
           |  |  | 2237 | 			return false;
 | 
        
           |  |  | 2238 | 		}
 | 
        
           |  |  | 2239 |   | 
        
           | 210 | cycrow | 2240 | 		if (!file->writeToDir(Dir.dir(), this, includedir, Utils::WString::Null(), data, len))
 | 
        
           | 131 | cycrow | 2241 | 			return false;
 | 
        
           |  |  | 2242 |   | 
        
           |  |  | 2243 | 		return true;
 | 
        
           |  |  | 2244 |   | 
        
           |  |  | 2245 | 	}
 | 
        
           |  |  | 2246 | 	else
 | 
        
           |  |  | 2247 | 		return false;
 | 
        
           |  |  | 2248 | }
 | 
        
           |  |  | 2249 |   | 
        
           | 210 | cycrow | 2250 | bool CBaseFile::extractFile(int filenum, const Utils::WString &dir, unsigned int game, const Utils::WStringList &gameAddons, bool includedir, CProgressInfo *progress)
 | 
        
           | 131 | cycrow | 2251 | {
 | 
        
           |  |  | 2252 | 	// invalid valus
 | 
        
           |  |  | 2253 | 	if (filenum < 0)
 | 
        
           |  |  | 2254 | 		return false;
 | 
        
           |  |  | 2255 | 	// out of range
 | 
        
           |  |  | 2256 | 	if (filenum > m_lFiles.size())
 | 
        
           |  |  | 2257 | 		return false;
 | 
        
           |  |  | 2258 |   | 
        
           |  |  | 2259 | 	// get the file pointer
 | 
        
           |  |  | 2260 | 	C_File *file = m_lFiles.Get(filenum);
 | 
        
           |  |  | 2261 | 	return extractFile(file, dir, game, gameAddons, includedir, progress);
 | 
        
           |  |  | 2262 | }
 | 
        
           |  |  | 2263 |   | 
        
           | 210 | cycrow | 2264 | bool CBaseFile::extractFile(int filenum, const Utils::WString &dir, bool includedir, CProgressInfo *progress)
 | 
        
           | 131 | cycrow | 2265 | {
 | 
        
           |  |  | 2266 | 	// invalid valus
 | 
        
           |  |  | 2267 | 	if (filenum < 0)
 | 
        
           |  |  | 2268 | 		return false;
 | 
        
           |  |  | 2269 | 	// out of range
 | 
        
           |  |  | 2270 | 	if (filenum > m_lFiles.size())
 | 
        
           |  |  | 2271 | 		return false;
 | 
        
           |  |  | 2272 |   | 
        
           |  |  | 2273 | 	// get the file pointer
 | 
        
           |  |  | 2274 | 	C_File *file = m_lFiles.Get(filenum);
 | 
        
           | 175 | cycrow | 2275 | 	return extractFile(file, dir, includedir, progress);
 | 
        
           | 131 | cycrow | 2276 | }
 | 
        
           |  |  | 2277 |   | 
        
           | 210 | cycrow | 2278 | bool CBaseFile::extractAll(const Utils::WString &dir, int game, const Utils::WStringList &gameAddons, bool includedir, CProgressInfo *progress)
 | 
        
           | 6 | cycrow | 2279 | {
 | 
        
           |  |  | 2280 | 	// no file to read from
 | 
        
           | 129 | cycrow | 2281 | 	if (this->filename().empty())
 | 
        
           | 6 | cycrow | 2282 | 		return false;
 | 
        
           |  |  | 2283 |   | 
        
           |  |  | 2284 | 	// now open the file
 | 
        
           | 58 | cycrow | 2285 | 	CFileIO *File = _startRead();
 | 
        
           | 129 | cycrow | 2286 | 	if (!File) return false;
 | 
        
           | 6 | cycrow | 2287 |   | 
        
           |  |  | 2288 | 	// now were in the file section
 | 
        
           |  |  | 2289 | 	// skip past each one
 | 
        
           | 129 | cycrow | 2290 | 	if (m_pIconFile) File->seek(4 + m_pIconFile->GetDataSize());
 | 
        
           | 6 | cycrow | 2291 |   | 
        
           | 134 | cycrow | 2292 | 	for (CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next()) 
 | 
        
           |  |  | 2293 | 	{
 | 
        
           | 6 | cycrow | 2294 | 		C_File *fit = node->Data();
 | 
        
           |  |  | 2295 |   | 
        
           | 134 | cycrow | 2296 | 		if ((!fit->GetDataSize()) || (!fit->GetData())) 
 | 
        
           |  |  | 2297 | 		{
 | 
        
           |  |  | 2298 | 			if (!fit->readFromFile(*File, fit->GetDataSize())) 
 | 
        
           |  |  | 2299 | 				return false;
 | 
        
           | 6 | cycrow | 2300 | 		}
 | 
        
           |  |  | 2301 | 		else
 | 
        
           | 58 | cycrow | 2302 | 			File->seek(fit->GetDataSize());
 | 
        
           | 6 | cycrow | 2303 |   | 
        
           | 129 | cycrow | 2304 | 		if (game && !fit->isForGame(game))
 | 
        
           |  |  | 2305 | 			continue;
 | 
        
           |  |  | 2306 |   | 
        
           | 134 | cycrow | 2307 | 		if (progress)	
 | 
        
           |  |  | 2308 | 			progress->UpdateFile(fit);
 | 
        
           |  |  | 2309 |   | 
        
           | 129 | cycrow | 2310 | 		CDirIO Dir(dir);
 | 
        
           | 210 | cycrow | 2311 | 		Utils::WString addonDir;
 | 
        
           | 129 | cycrow | 2312 | 		if (fit->isFileInAddon())
 | 
        
           |  |  | 2313 | 		{
 | 
        
           |  |  | 2314 | 			int addonGame = fit->getForSingleGame();
 | 
        
           |  |  | 2315 | 			if (!addonGame) addonGame = game;
 | 
        
           |  |  | 2316 |   | 
        
           |  |  | 2317 | 			if (addonGame > 0)
 | 
        
           | 210 | cycrow | 2318 | 				addonDir = gameAddons.findString(Utils::WString::Number(addonGame));
 | 
        
           | 6 | cycrow | 2319 | 		}
 | 
        
           |  |  | 2320 |   | 
        
           | 129 | cycrow | 2321 | 		if (!addonDir.empty())
 | 
        
           |  |  | 2322 | 			Dir.cd(addonDir);
 | 
        
           |  |  | 2323 |   | 
        
           | 6 | cycrow | 2324 | 		// create directory first
 | 
        
           | 129 | cycrow | 2325 | 		Dir.create(fit->getDirectory(this));
 | 
        
           | 6 | cycrow | 2326 |   | 
        
           |  |  | 2327 | 		long size = 0;
 | 
        
           | 129 | cycrow | 2328 | 		unsigned char *data = fit->UncompressData(&size, progress);
 | 
        
           |  |  | 2329 | 		if ((!data) && (fit->GetCompressionType() == SPKCOMPRESS_7ZIP)) {
 | 
        
           | 210 | cycrow | 2330 | 			if (!fit->uncompressToFile(Dir.dir(), this, includedir, progress)) return false;
 | 
        
           | 6 | cycrow | 2331 | 		}
 | 
        
           | 210 | cycrow | 2332 | 		else if ((!data) || (!fit->writeToDir(Dir.dir(), this, includedir, Utils::WString::Null(), data, size))) return false;
 | 
        
           | 6 | cycrow | 2333 | 	}
 | 
        
           |  |  | 2334 |   | 
        
           | 58 | cycrow | 2335 | 	delete File;
 | 
        
           | 6 | cycrow | 2336 | 	return true;
 | 
        
           |  |  | 2337 | }
 | 
        
           |  |  | 2338 |   | 
        
           |  |  | 2339 |   | 
        
           | 175 | cycrow | 2340 | bool CBaseFile::computeSigned(bool updateFiles) const
 | 
        
           | 6 | cycrow | 2341 | {
 | 
        
           | 252 | cycrow | 2342 | 	// any globals?
 | 
        
           |  |  | 2343 | 	if (!_lGlobals.empty())
 | 
        
           |  |  | 2344 | 		return false;
 | 
        
           |  |  | 2345 |   | 
        
           | 175 | cycrow | 2346 | 	for (CListNode<C_File>* node = m_lFiles.Front(); node; node = node->next())
 | 
        
           | 6 | cycrow | 2347 | 	{
 | 
        
           | 175 | cycrow | 2348 | 		C_File* file = node->Data();
 | 
        
           |  |  | 2349 | 		if (updateFiles)
 | 
        
           | 6 | cycrow | 2350 | 			file->UpdateSigned();
 | 
        
           |  |  | 2351 | 		// extra, text, soundtrack, readmes and screen files do not require a modified game directly
 | 
        
           | 175 | cycrow | 2352 | 		if ((file->GetFileType() == FILETYPE_EXTRA) || (file->GetFileType() == FILETYPE_TEXT) || (file->GetFileType() == FILETYPE_SOUND) || (file->GetFileType() == FILETYPE_SCREEN) || (file->GetFileType() == FILETYPE_README))
 | 
        
           | 6 | cycrow | 2353 | 			continue;
 | 
        
           |  |  | 2354 | 		// mods and maps always need modified game
 | 
        
           | 175 | cycrow | 2355 | 		else if ((file->GetFileType() == FILETYPE_MOD) || (file->GetFileType() == FILETYPE_MAP))
 | 
        
           |  |  | 2356 | 			return false;
 | 
        
           | 6 | cycrow | 2357 |   | 
        
           |  |  | 2358 | 		// else should be a script file, script or uninstall type
 | 
        
           |  |  | 2359 | 		// all scripts must be signed, if any are not, then no signed status
 | 
        
           | 175 | cycrow | 2360 | 		if (!file->IsSigned())
 | 
        
           |  |  | 2361 | 			return false;
 | 
        
           | 6 | cycrow | 2362 | 	}
 | 
        
           |  |  | 2363 |   | 
        
           | 175 | cycrow | 2364 | 	return true;
 | 
        
           |  |  | 2365 | }
 | 
        
           |  |  | 2366 |   | 
        
           |  |  | 2367 | bool CBaseFile::updateSigned(bool updateFiles)
 | 
        
           |  |  | 2368 | {
 | 
        
           |  |  | 2369 | 	m_bSigned = computeSigned(updateFiles);
 | 
        
           | 6 | cycrow | 2370 | 	return m_bSigned;
 | 
        
           |  |  | 2371 | }
 | 
        
           |  |  | 2372 |   | 
        
           | 203 | cycrow | 2373 | bool CBaseFile::isPackageNeeded(const Utils::WString &scriptName, const Utils::WString &author)
 | 
        
           | 6 | cycrow | 2374 | {
 | 
        
           |  |  | 2375 | 	for ( CListNode<SNeededLibrary> *node = m_lNeededLibrarys.Front(); node; node = node->next() )
 | 
        
           |  |  | 2376 | 	{
 | 
        
           |  |  | 2377 | 		SNeededLibrary *l = node->Data();
 | 
        
           |  |  | 2378 | 		if ( l->sName.Compare(scriptName) && l->sAuthor.Compare(author) )
 | 
        
           |  |  | 2379 | 			return true;
 | 
        
           |  |  | 2380 | 	}
 | 
        
           |  |  | 2381 |   | 
        
           |  |  | 2382 | 	return false;
 | 
        
           |  |  | 2383 | }
 | 
        
           |  |  | 2384 |   | 
        
           | 203 | cycrow | 2385 | SNeededLibrary *CBaseFile::findPackageNeeded(const Utils::WString &scriptName, const Utils::WString &author)
 | 
        
           | 6 | cycrow | 2386 | {
 | 
        
           |  |  | 2387 | 	for ( CListNode<SNeededLibrary> *node = m_lNeededLibrarys.Front(); node; node = node->next() )
 | 
        
           |  |  | 2388 | 	{
 | 
        
           |  |  | 2389 | 		SNeededLibrary *l = node->Data();
 | 
        
           |  |  | 2390 | 		if ( l->sName.Compare(scriptName) && l->sAuthor.Compare(author) )
 | 
        
           |  |  | 2391 | 			return l;
 | 
        
           |  |  | 2392 | 	}
 | 
        
           |  |  | 2393 |   | 
        
           |  |  | 2394 | 	return NULL;
 | 
        
           |  |  | 2395 | }
 | 
        
           |  |  | 2396 |   | 
        
           | 207 | cycrow | 2397 | void CBaseFile::removeFakePatchOrder(const Utils::WString &scriptName, const Utils::WString &author)
 | 
        
           | 6 | cycrow | 2398 | {
 | 
        
           | 160 | cycrow | 2399 | 	removeFakePatchOrder(true, scriptName, author);
 | 
        
           |  |  | 2400 | 	removeFakePatchOrder(false, scriptName, author);
 | 
        
           | 6 | cycrow | 2401 | }
 | 
        
           | 207 | cycrow | 2402 | void CBaseFile::removeFakePatchOrder(bool after, const Utils::WString &scriptName, const Utils::WString &author)
 | 
        
           | 6 | cycrow | 2403 | {
 | 
        
           | 207 | cycrow | 2404 | 	Utils::WStringList *list;
 | 
        
           | 6 | cycrow | 2405 | 	if ( after )
 | 
        
           | 160 | cycrow | 2406 | 		list = &_lFakePatchAfter;
 | 
        
           | 6 | cycrow | 2407 | 	else
 | 
        
           | 160 | cycrow | 2408 | 		list = &_lFakePatchBefore;
 | 
        
           | 6 | cycrow | 2409 |   | 
        
           | 160 | cycrow | 2410 | 	int found = list->findStringAndData(scriptName, author);
 | 
        
           |  |  | 2411 | 	while (found != -1)
 | 
        
           | 6 | cycrow | 2412 | 	{
 | 
        
           | 160 | cycrow | 2413 | 		list->removeAt(found);
 | 
        
           |  |  | 2414 | 		found = list->findStringAndData(scriptName, author);
 | 
        
           | 6 | cycrow | 2415 | 	}
 | 
        
           |  |  | 2416 | }
 | 
        
           |  |  | 2417 |   | 
        
           | 207 | cycrow | 2418 | void CBaseFile::addFakePatchOrder(bool after, const Utils::WString &scriptName, const Utils::WString &author)
 | 
        
           | 6 | cycrow | 2419 | {
 | 
        
           | 207 | cycrow | 2420 | 	Utils::WStringList *list;
 | 
        
           | 6 | cycrow | 2421 | 	if ( after )
 | 
        
           | 160 | cycrow | 2422 | 		list = &_lFakePatchAfter;
 | 
        
           | 6 | cycrow | 2423 | 	else
 | 
        
           | 160 | cycrow | 2424 | 		list = &_lFakePatchBefore;
 | 
        
           | 6 | cycrow | 2425 |   | 
        
           |  |  | 2426 | 	// check if the package already exists
 | 
        
           | 160 | cycrow | 2427 | 	if (!list->containsStringAndData(scriptName, author))
 | 
        
           | 6 | cycrow | 2428 | 	{
 | 
        
           | 160 | cycrow | 2429 | 		// cant have it on both list
 | 
        
           |  |  | 2430 | 		removeFakePatchOrder(!after, scriptName, author);
 | 
        
           |  |  | 2431 |   | 
        
           |  |  | 2432 | 		list->pushBack(scriptName, author);
 | 
        
           | 6 | cycrow | 2433 | 	}
 | 
        
           |  |  | 2434 | }
 | 
        
           | 204 | cycrow | 2435 | void CBaseFile::addNeededLibrary(const Utils::WString &scriptName, const Utils::WString &author, const Utils::WString &minVersion)
 | 
        
           | 6 | cycrow | 2436 | {
 | 
        
           | 203 | cycrow | 2437 | 	SNeededLibrary *l = this->findPackageNeeded(scriptName, author);
 | 
        
           | 6 | cycrow | 2438 | 	if ( !l )
 | 
        
           |  |  | 2439 | 	{
 | 
        
           |  |  | 2440 | 		l = new SNeededLibrary;
 | 
        
           |  |  | 2441 | 		l->sName = scriptName;
 | 
        
           |  |  | 2442 | 		l->sAuthor = author;
 | 
        
           |  |  | 2443 | 		m_lNeededLibrarys.push_back(l);
 | 
        
           |  |  | 2444 | 	}
 | 
        
           |  |  | 2445 | 	l->sMinVersion = minVersion;
 | 
        
           |  |  | 2446 | }
 | 
        
           |  |  | 2447 |   | 
        
           | 203 | cycrow | 2448 | void CBaseFile::removePackageNeeded(const Utils::WString &scriptName, const Utils::WString &author)
 | 
        
           | 6 | cycrow | 2449 | {
 | 
        
           | 203 | cycrow | 2450 | 	SNeededLibrary *l = this->findPackageNeeded(scriptName, author);
 | 
        
           | 6 | cycrow | 2451 | 	if ( l )
 | 
        
           |  |  | 2452 | 	{
 | 
        
           |  |  | 2453 | 		m_lNeededLibrarys.remove(l);
 | 
        
           |  |  | 2454 | 		delete l;
 | 
        
           |  |  | 2455 | 	}
 | 
        
           |  |  | 2456 | }
 | 
        
           |  |  | 2457 |   | 
        
           |  |  | 2458 | void CBaseFile::ClearNeededPackages()
 | 
        
           |  |  | 2459 | {
 | 
        
           | 203 | cycrow | 2460 | 	SNeededLibrary *ns = this->findPackageNeeded(L"<package>", L"<author>");
 | 
        
           | 204 | cycrow | 2461 | 	Utils::WString version;
 | 
        
           | 46 | cycrow | 2462 | 	if ( ns ) version = ns->sMinVersion;
 | 
        
           |  |  | 2463 |   | 
        
           | 6 | cycrow | 2464 | 	for ( CListNode<SNeededLibrary> *node = m_lNeededLibrarys.Front(); node; node = node->next() )
 | 
        
           |  |  | 2465 | 		node->DeleteData();
 | 
        
           |  |  | 2466 | 	m_lNeededLibrarys.clear();
 | 
        
           |  |  | 2467 |   | 
        
           | 203 | cycrow | 2468 | 	if ( !version.empty() )	this->addNeededLibrary(L"<package>", L"<author>", version);
 | 
        
           | 6 | cycrow | 2469 | }
 | 
        
           |  |  | 2470 |   | 
        
           |  |  | 2471 |   | 
        
           | 210 | cycrow | 2472 | bool CBaseFile::GeneratePackagerScript(bool wildcard, Utils::WStringList *list, int game, const Utils::WStringList &gameAddons, bool datafile)
 | 
        
           | 6 | cycrow | 2473 | {
 | 
        
           | 210 | cycrow | 2474 | 	list->pushBack(L"#");
 | 
        
           |  |  | 2475 | 	list->pushBack(L"# Packager Script");
 | 
        
           |  |  | 2476 | 	list->pushBack(L"# -- Generated by SPK Libraries V" + Utils::WString::FromFloat(GetLibraryVersion(), 2) + L" --");
 | 
        
           |  |  | 2477 | 	list->pushBack(L"#");
 | 
        
           |  |  | 2478 | 	list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2479 | 	if ( !datafile )
 | 
        
           |  |  | 2480 | 	{
 | 
        
           | 210 | cycrow | 2481 | 		list->pushBack(L"# Variable for your game directory, where to get files from");
 | 
        
           |  |  | 2482 | 		list->pushBack(L"# $PATH variable is used to get the current path");
 | 
        
           |  |  | 2483 | 		list->pushBack(L"Variable: $GAMEDIR $PATH");
 | 
        
           |  |  | 2484 | 		list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2485 | 	}
 | 
        
           | 210 | cycrow | 2486 | 	list->pushBack(L"# The name of the script");
 | 
        
           |  |  | 2487 | 	list->pushBack(L"Name: " + this->name());
 | 
        
           |  |  | 2488 | 	list->pushBack(L"");
 | 
        
           |  |  | 2489 | 	list->pushBack(L"# The author of the script, ie, you");
 | 
        
           |  |  | 2490 | 	list->pushBack(L"Author: " + this->author());
 | 
        
           |  |  | 2491 | 	list->pushBack(L"");
 | 
        
           |  |  | 2492 | 	list->pushBack(L"# The creation data, when it was created");
 | 
        
           | 6 | cycrow | 2493 | 	if ( datafile )
 | 
        
           | 210 | cycrow | 2494 | 		list->pushBack(L"Date: " + this->creationDate());
 | 
        
           | 50 | cycrow | 2495 | 	else {
 | 
        
           | 210 | cycrow | 2496 | 		list->pushBack(L"# $DATE variable is used to get the current date");
 | 
        
           |  |  | 2497 | 		list->pushBack(L"Date: $DATE");
 | 
        
           | 6 | cycrow | 2498 | 	}
 | 
        
           | 210 | cycrow | 2499 | 	list->pushBack(L"");
 | 
        
           |  |  | 2500 | 	list->pushBack(L"# The version of script");
 | 
        
           | 6 | cycrow | 2501 | 	if ( datafile )
 | 
        
           | 210 | cycrow | 2502 | 		list->pushBack(L"Version: " + this->version());
 | 
        
           | 6 | cycrow | 2503 | 	else
 | 
        
           |  |  | 2504 | 	{
 | 
        
           | 210 | cycrow | 2505 | 		list->pushBack(L"# $ASK variable is used to get an input when creating");
 | 
        
           |  |  | 2506 | 		list->pushBack(L"Version: $ASK");
 | 
        
           | 6 | cycrow | 2507 | 	}
 | 
        
           | 210 | cycrow | 2508 | 	list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2509 |   | 
        
           |  |  | 2510 | 	if ( !m_lGames.empty() ) {
 | 
        
           | 210 | cycrow | 2511 | 		list->pushBack(L"# The game version the script is for <game> <version> (can have multiple games)");
 | 
        
           | 6 | cycrow | 2512 | 		for ( SGameCompat *g = m_lGames.First(); g; g = m_lGames.Next() ) {
 | 
        
           | 126 | cycrow | 2513 | 			if (game > 0 && g->iGame != game)
 | 
        
           |  |  | 2514 | 				continue;
 | 
        
           |  |  | 2515 |   | 
        
           | 197 | cycrow | 2516 | 			Utils::WString game = CBaseFile::ConvertGameToString(g->iGame);
 | 
        
           | 6 | cycrow | 2517 |   | 
        
           | 46 | cycrow | 2518 | 			if ( !g->sVersion.empty() )
 | 
        
           | 6 | cycrow | 2519 | 			{
 | 
        
           | 197 | cycrow | 2520 | 				game += L" ";
 | 
        
           | 46 | cycrow | 2521 | 				game += g->sVersion;
 | 
        
           | 6 | cycrow | 2522 | 			}
 | 
        
           |  |  | 2523 | 			else
 | 
        
           |  |  | 2524 | 			{
 | 
        
           | 197 | cycrow | 2525 | 				game += L" ";
 | 
        
           | 6 | cycrow | 2526 | 				game += (long)g->iVersion;
 | 
        
           |  |  | 2527 | 			}
 | 
        
           |  |  | 2528 |   | 
        
           | 210 | cycrow | 2529 | 			list->pushBack(L"Game: " + game);
 | 
        
           | 6 | cycrow | 2530 | 		}
 | 
        
           |  |  | 2531 |   | 
        
           | 210 | cycrow | 2532 | 		list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2533 | 	}
 | 
        
           |  |  | 2534 |   | 
        
           | 48 | cycrow | 2535 | 	if ( !this->description().empty() ) {
 | 
        
           | 210 | cycrow | 2536 | 		list->pushBack(L"# The description of the script, displays when installing");
 | 
        
           |  |  | 2537 | 		list->pushBack(L"Description: " + this->description());
 | 
        
           |  |  | 2538 | 		list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2539 | 	}
 | 
        
           |  |  | 2540 |   | 
        
           | 49 | cycrow | 2541 | 	if ( !this->webSite().empty() ) {
 | 
        
           | 210 | cycrow | 2542 | 		list->pushBack(L"# A link to the website for the script, ie for an online help page");
 | 
        
           |  |  | 2543 | 		list->pushBack(L"WebSite: " + this->webSite());
 | 
        
           |  |  | 2544 | 		list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2545 | 	}
 | 
        
           |  |  | 2546 |   | 
        
           | 49 | cycrow | 2547 | 	if ( !this->forumLink().empty() ) {
 | 
        
           | 210 | cycrow | 2548 | 		list->pushBack(L"# A direct link to the thread in the egosoft forum");
 | 
        
           |  |  | 2549 | 		list->pushBack(L"ForumLink: " + this->forumLink());
 | 
        
           |  |  | 2550 | 		list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2551 | 	}
 | 
        
           |  |  | 2552 |   | 
        
           | 49 | cycrow | 2553 | 	if ( !this->webAddress().empty() ) {
 | 
        
           | 210 | cycrow | 2554 | 		list->pushBack(L"# A link to the address for the update file");
 | 
        
           |  |  | 2555 | 		list->pushBack(L"WebAddress: " + this->webAddress());
 | 
        
           |  |  | 2556 | 		list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2557 | 	}
 | 
        
           |  |  | 2558 |   | 
        
           | 49 | cycrow | 2559 | 	if ( !this->email().empty() ) {
 | 
        
           | 210 | cycrow | 2560 | 		list->pushBack(L"# The email address of the author, to allow users to contract if needed");
 | 
        
           |  |  | 2561 | 		list->pushBack(L"Email: " + this->email());
 | 
        
           |  |  | 2562 | 		list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2563 | 	}
 | 
        
           |  |  | 2564 |   | 
        
           | 208 | cycrow | 2565 | 	if (webMirrors().size())
 | 
        
           | 6 | cycrow | 2566 | 	{
 | 
        
           | 210 | cycrow | 2567 | 		list->pushBack(L"# A link to the mirror address for the update file, can have many of these");
 | 
        
           | 208 | cycrow | 2568 | 		for(auto itr = webMirrors().begin(); itr != webMirrors().end(); itr++)
 | 
        
           | 210 | cycrow | 2569 | 			list->pushBack(Utils::WString(L"WebMirror: ") + (*itr)->str);
 | 
        
           |  |  | 2570 | 		list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2571 | 	}
 | 
        
           |  |  | 2572 |   | 
        
           |  |  | 2573 | 	if ( m_bAutoGenerateUpdateFile )
 | 
        
           |  |  | 2574 | 	{
 | 
        
           | 210 | cycrow | 2575 | 		list->pushBack(L"# Auto generate the package update file when created");
 | 
        
           |  |  | 2576 | 		list->pushBack(L"GenerateUpdateFile");
 | 
        
           | 6 | cycrow | 2577 | 	}
 | 
        
           |  |  | 2578 |   | 
        
           |  |  | 2579 | 	if ( m_lNeededLibrarys.size() )
 | 
        
           |  |  | 2580 | 	{
 | 
        
           | 210 | cycrow | 2581 | 		list->pushBack(L"# Needed Library dependacies, require these to be installed");
 | 
        
           | 6 | cycrow | 2582 | 		for ( CListNode<SNeededLibrary> *node = m_lNeededLibrarys.Front(); node; node = node->next() )
 | 
        
           | 210 | cycrow | 2583 | 			list->pushBack(L"Depend: " + node->Data()->sName + L"|" + node->Data()->sMinVersion + L"|" + node->Data()->sAuthor);
 | 
        
           | 6 | cycrow | 2584 |   | 
        
           | 210 | cycrow | 2585 | 		list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2586 | 	}
 | 
        
           |  |  | 2587 |   | 
        
           | 46 | cycrow | 2588 | 	if ( !_noRatings() )
 | 
        
           | 6 | cycrow | 2589 | 	{
 | 
        
           | 210 | cycrow | 2590 | 		list->pushBack(L"# Ratings Values, 0 to 5, <ease> <changing> <recommended>");
 | 
        
           |  |  | 2591 | 		list->pushBack(Utils::WString(L"Ratings: ") + (long)easeOfUse() + L" " + (long)gameChanging() + L" " + (long)recommended());
 | 
        
           |  |  | 2592 | 		list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2593 | 	}
 | 
        
           |  |  | 2594 |   | 
        
           | 170 | cycrow | 2595 | 	if (namesList()->size())
 | 
        
           | 6 | cycrow | 2596 | 	{
 | 
        
           | 210 | cycrow | 2597 | 		list->pushBack(L"# Package names, uses different names for different languages");
 | 
        
           | 170 | cycrow | 2598 | 		for(auto itr = namesList()->begin(); itr != namesList()->end(); itr++)
 | 
        
           | 210 | cycrow | 2599 | 			list->pushBack(Utils::WString("ScriptName: ") + (long)(*itr)->iLanguage + L" " + (*itr)->sName);
 | 
        
           |  |  | 2600 | 		list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2601 | 	}
 | 
        
           |  |  | 2602 |   | 
        
           | 46 | cycrow | 2603 | 	for ( int j = 0; j < 2; j++ ) {
 | 
        
           | 206 | cycrow | 2604 | 		Utils::WString installText = (j == 0) ? L"Install" : L"Uninstall";
 | 
        
           | 46 | cycrow | 2605 | 		const CInstallText *pText = (j == 0) ? this->installText() : this->uninstallText();
 | 
        
           |  |  | 2606 | 		if ( pText->any() )
 | 
        
           | 6 | cycrow | 2607 | 		{
 | 
        
           | 210 | cycrow | 2608 | 			list->pushBack(L"# " + installText + L" Texts, display text before and/or after " + installText + L"ing to inform the use of special conditions");
 | 
        
           | 46 | cycrow | 2609 | 			for ( unsigned int i = 0; i < pText->count(); i++ ) {
 | 
        
           |  |  | 2610 | 				long iLang = pText->language(i);
 | 
        
           | 210 | cycrow | 2611 | 				if ( !pText->getBefore(iLang).empty() )	list->pushBack(installText + "Before: " + iLang + L" " + pText->getBefore(iLang));
 | 
        
           |  |  | 2612 | 				if ( !pText->getAfter(iLang).empty()  )	list->pushBack(installText + "After: " + iLang + L" " + pText->getAfter(iLang));
 | 
        
           | 46 | cycrow | 2613 | 			}
 | 
        
           | 210 | cycrow | 2614 | 			list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2615 | 		}
 | 
        
           |  |  | 2616 | 	}
 | 
        
           |  |  | 2617 |   | 
        
           | 210 | cycrow | 2618 | 	list->pushBack(L"# Plugin Type, the type the plugin is, mainly used to show users the type, types include: Normal, Stable, Experimental, Cheat, Mod");
 | 
        
           | 48 | cycrow | 2619 | 	switch ( this->pluginType() )
 | 
        
           | 6 | cycrow | 2620 | 	{
 | 
        
           |  |  | 2621 | 		case PLUGIN_NORMAL:
 | 
        
           | 210 | cycrow | 2622 | 			list->pushBack(L"PluginType: Normal");
 | 
        
           | 6 | cycrow | 2623 | 			break;
 | 
        
           |  |  | 2624 | 		case PLUGIN_STABLE:
 | 
        
           | 210 | cycrow | 2625 | 			list->pushBack(L"PluginType: Stable");
 | 
        
           | 6 | cycrow | 2626 | 			break;
 | 
        
           |  |  | 2627 | 		case PLUGIN_EXPERIMENTAL:
 | 
        
           | 210 | cycrow | 2628 | 			list->pushBack(L"PluginType: Experimental");
 | 
        
           | 6 | cycrow | 2629 | 			break;
 | 
        
           |  |  | 2630 | 		case PLUGIN_CHEAT:
 | 
        
           | 210 | cycrow | 2631 | 			list->pushBack(L"PluginType: Cheat");
 | 
        
           | 6 | cycrow | 2632 | 			break;
 | 
        
           |  |  | 2633 | 		case PLUGIN_MOD:
 | 
        
           | 210 | cycrow | 2634 | 			list->pushBack(L"PluginType: Mod");
 | 
        
           | 6 | cycrow | 2635 | 			break;
 | 
        
           |  |  | 2636 | 	}
 | 
        
           | 210 | cycrow | 2637 | 	list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2638 |   | 
        
           | 239 | cycrow | 2639 | 	if (!_lGlobals.empty())
 | 
        
           |  |  | 2640 | 	{
 | 
        
           |  |  | 2641 | 		list->pushBack(L"# Globals, add global overrides to a package when generating the globals file, to override game settings");
 | 
        
           |  |  | 2642 | 		for (auto itr = _lGlobals.begin(); itr != _lGlobals.end(); itr++)
 | 
        
           |  |  | 2643 | 			list->pushBack(L"Global: " + (*itr)->str + L";" + (*itr)->data);
 | 
        
           |  |  | 2644 | 		list->pushBack(L"");
 | 
        
           |  |  | 2645 | 	}
 | 
        
           |  |  | 2646 |   | 
        
           | 6 | cycrow | 2647 | 	return true;
 | 
        
           |  |  | 2648 | }
 | 
        
           |  |  | 2649 |   | 
        
           | 210 | cycrow | 2650 | bool CBaseFile::GeneratePackagerScriptFile(bool wildcard, Utils::WStringList *list, int game, const Utils::WStringList &gameAddons)
 | 
        
           | 6 | cycrow | 2651 | {
 | 
        
           |  |  | 2652 | 	// now do files and wildcards
 | 
        
           | 197 | cycrow | 2653 | 	Utils::WStringList files;
 | 
        
           | 6 | cycrow | 2654 | 	for ( CListNode<C_File> *f = m_lFiles.Front(); f; f = f->next() )
 | 
        
           |  |  | 2655 | 	{
 | 
        
           | 127 | cycrow | 2656 | 		if (game && !(f->Data()->game() & 1 << game))
 | 
        
           | 126 | cycrow | 2657 | 			continue;
 | 
        
           | 6 | cycrow | 2658 |   | 
        
           | 197 | cycrow | 2659 | 		Utils::WString name = L"$GAMEDIR/";
 | 
        
           | 126 | cycrow | 2660 |   | 
        
           | 127 | cycrow | 2661 | 		// addon directory?
 | 
        
           |  |  | 2662 | 		unsigned int checkGame = f->Data()->game() & ~(1 << 31);
 | 
        
           |  |  | 2663 | 		unsigned int foundGame = 0;
 | 
        
           |  |  | 2664 | 		for (int i = 0; i < 31; ++i)
 | 
        
           |  |  | 2665 | 		{
 | 
        
           |  |  | 2666 | 			if (checkGame == 1 << i)
 | 
        
           |  |  | 2667 | 			{
 | 
        
           |  |  | 2668 | 				foundGame = i;
 | 
        
           |  |  | 2669 | 				break;
 | 
        
           |  |  | 2670 | 			}
 | 
        
           |  |  | 2671 | 		}
 | 
        
           |  |  | 2672 |   | 
        
           |  |  | 2673 | 		if (foundGame)
 | 
        
           |  |  | 2674 | 		{
 | 
        
           | 210 | cycrow | 2675 | 			Utils::WString str = gameAddons.findString(Utils::WString::Number(foundGame));
 | 
        
           | 127 | cycrow | 2676 | 			if(!str.empty())
 | 
        
           | 197 | cycrow | 2677 | 				name += str + L"/";
 | 
        
           | 127 | cycrow | 2678 | 		}
 | 
        
           |  |  | 2679 |   | 
        
           | 6 | cycrow | 2680 | 		bool done = false;
 | 
        
           |  |  | 2681 | 		if ( wildcard )
 | 
        
           |  |  | 2682 | 		{
 | 
        
           | 197 | cycrow | 2683 | 			Utils::WString base = f->Data()->baseName();
 | 
        
           | 131 | cycrow | 2684 | 			if ( f->Data()->fileType() == FILETYPE_SCRIPT )
 | 
        
           | 6 | cycrow | 2685 | 			{
 | 
        
           | 197 | cycrow | 2686 | 				if ( base.token(L".", 1).Compare(L"plugin") || base.token(L".", 1).Compare(L"lib") )
 | 
        
           | 6 | cycrow | 2687 | 				{
 | 
        
           | 197 | cycrow | 2688 | 					name += f->Data()->getDirectory(this) + "/" + base.tokens(L".", 1, 2) + L".*";
 | 
        
           | 6 | cycrow | 2689 | 					done = true;
 | 
        
           |  |  | 2690 | 				}
 | 
        
           | 197 | cycrow | 2691 | 				else if ( base.token(L".", 1).Compare(L"al") && !base.token(L".", 2).Compare(L"plugin") )
 | 
        
           | 6 | cycrow | 2692 | 				{
 | 
        
           | 197 | cycrow | 2693 | 					name += f->Data()->getDirectory(this) + L"/" + base.tokens(L".", 1, 2) + L".*";
 | 
        
           | 6 | cycrow | 2694 | 					done = true;
 | 
        
           |  |  | 2695 | 				}
 | 
        
           |  |  | 2696 | 			}
 | 
        
           | 131 | cycrow | 2697 | 			else if ( f->Data()->fileType() == FILETYPE_TEXT )
 | 
        
           | 6 | cycrow | 2698 | 			{
 | 
        
           | 197 | cycrow | 2699 | 				if ( base.contains(L"-L") )
 | 
        
           | 6 | cycrow | 2700 | 				{
 | 
        
           | 197 | cycrow | 2701 | 					name += f->Data()->getDirectory(this) + L"/" + base.token(L"-L", 1) + L"-L*";
 | 
        
           | 6 | cycrow | 2702 | 					done = true;
 | 
        
           |  |  | 2703 | 				}
 | 
        
           |  |  | 2704 | 				else
 | 
        
           |  |  | 2705 | 				{
 | 
        
           | 197 | cycrow | 2706 | 					name += f->Data()->getDirectory(this) + L"/*" + base.right(4) + L".*";
 | 
        
           | 6 | cycrow | 2707 | 					done = true;
 | 
        
           |  |  | 2708 | 				}
 | 
        
           |  |  | 2709 | 			}
 | 
        
           |  |  | 2710 | 		}
 | 
        
           |  |  | 2711 |   | 
        
           |  |  | 2712 | 		if ( !done )
 | 
        
           | 131 | cycrow | 2713 | 			name += f->Data()->getNameDirectory(this);
 | 
        
           | 6 | cycrow | 2714 |   | 
        
           | 131 | cycrow | 2715 | 		if ( !f->Data()->dir().empty() )
 | 
        
           | 6 | cycrow | 2716 | 		{
 | 
        
           | 197 | cycrow | 2717 | 			name += L"|";
 | 
        
           | 131 | cycrow | 2718 | 			name += f->Data()->dir();
 | 
        
           | 6 | cycrow | 2719 | 		}
 | 
        
           | 197 | cycrow | 2720 | 		Utils::WString s = L"GAME ";
 | 
        
           | 127 | cycrow | 2721 | 		if (!f->Data()->game() || f->Data()->game() == GAME_ALLNEW)
 | 
        
           |  |  | 2722 | 			s += CBaseFile::ConvertGameToString(f->Data()->game());
 | 
        
           |  |  | 2723 | 		else
 | 
        
           |  |  | 2724 | 		{
 | 
        
           |  |  | 2725 | 			bool first = true;
 | 
        
           |  |  | 2726 | 			for (int i = 0; i < 31; ++i) 
 | 
        
           |  |  | 2727 | 			{
 | 
        
           |  |  | 2728 | 				if (f->Data()->game() & 1 << i)
 | 
        
           |  |  | 2729 | 				{
 | 
        
           |  |  | 2730 | 					if (first)
 | 
        
           |  |  | 2731 | 						first = false;
 | 
        
           |  |  | 2732 | 					else
 | 
        
           | 210 | cycrow | 2733 | 						s += L"|";
 | 
        
           | 127 | cycrow | 2734 | 					s += CBaseFile::ConvertGameToString(i);
 | 
        
           |  |  | 2735 | 				}
 | 
        
           |  |  | 2736 | 			}
 | 
        
           |  |  | 2737 | 		}
 | 
        
           |  |  | 2738 |   | 
        
           | 197 | cycrow | 2739 | 		s += L" " + name;
 | 
        
           | 126 | cycrow | 2740 | 		if(!files.contains(s))
 | 
        
           | 178 | cycrow | 2741 | 			files.pushBack(s, f->Data()->fileTypeString());
 | 
        
           | 6 | cycrow | 2742 | 	}
 | 
        
           |  |  | 2743 |   | 
        
           |  |  | 2744 |   | 
        
           | 126 | cycrow | 2745 | 	if ( !files.empty() )
 | 
        
           | 6 | cycrow | 2746 | 	{
 | 
        
           | 210 | cycrow | 2747 | 		list->pushBack(L"# Files List, all the files to add, can include wild cards");
 | 
        
           | 126 | cycrow | 2748 | 		for(auto itr = files.begin(); itr != files.end(); itr++)
 | 
        
           | 210 | cycrow | 2749 | 			list->pushBack((*itr)->data + L": " + (*itr)->str);
 | 
        
           |  |  | 2750 | 		list->pushBack(L"");
 | 
        
           | 6 | cycrow | 2751 | 	}
 | 
        
           |  |  | 2752 |   | 
        
           |  |  | 2753 | 	return true;
 | 
        
           |  |  | 2754 | }
 | 
        
           |  |  | 2755 |   | 
        
           | 203 | cycrow | 2756 | Utils::WString CBaseFile::getAutosaveName() const
 | 
        
           | 6 | cycrow | 2757 | {
 | 
        
           | 210 | cycrow | 2758 | 	return this->name() + L"-V" + this->version() + L"-" + this->creationDate().findReplace(L"/", L".");
 | 
        
           | 6 | cycrow | 2759 | }
 | 
        
           |  |  | 2760 |   | 
        
           | 233 | cycrow | 2761 | void CBaseFile::addGlobal(const Utils::WString& global, const Utils::WString& setting)
 | 
        
           |  |  | 2762 | {
 | 
        
           |  |  | 2763 | 	if (!_lGlobals.changeData(global, setting))
 | 
        
           |  |  | 2764 | 		_lGlobals.pushBack(global, setting);
 | 
        
           |  |  | 2765 | }
 | 
        
           |  |  | 2766 |   | 
        
           |  |  | 2767 | void CBaseFile::removeGlobal(const Utils::WString& global)
 | 
        
           |  |  | 2768 | {
 | 
        
           |  |  | 2769 | 	_lGlobals.remove(global);
 | 
        
           |  |  | 2770 | }
 | 
        
           |  |  | 2771 |   | 
        
           | 237 | cycrow | 2772 | void CBaseFile::clearGlobals()
 | 
        
           |  |  | 2773 | {
 | 
        
           |  |  | 2774 | 	_lGlobals.clear();
 | 
        
           |  |  | 2775 | }
 | 
        
           | 233 | cycrow | 2776 |   | 
        
           | 6 | cycrow | 2777 | bool CBaseFile::CheckGameCompatability(int game)
 | 
        
           |  |  | 2778 | {
 | 
        
           |  |  | 2779 | 	if ( m_lGames.empty() )
 | 
        
           |  |  | 2780 | 		return true; // no game compatability added, assume its ok for all
 | 
        
           |  |  | 2781 |   | 
        
           |  |  | 2782 | 	for ( CListNode<SGameCompat> *node = m_lGames.Front(); node; node = node->next() ) {
 | 
        
           |  |  | 2783 | 		if ( node->Data()->iGame == 0 || node->Data()->iGame == game )
 | 
        
           |  |  | 2784 | 			return true;
 | 
        
           |  |  | 2785 | 	}
 | 
        
           |  |  | 2786 | 	return false;
 | 
        
           |  |  | 2787 | }
 | 
        
           |  |  | 2788 |   | 
        
           | 197 | cycrow | 2789 | bool CBaseFile::checkGameVersionCompatability(int game, const Utils::WString &sVersion, int iVersion) const
 | 
        
           | 6 | cycrow | 2790 | {
 | 
        
           | 170 | cycrow | 2791 | 	if (m_lGames.empty())
 | 
        
           | 6 | cycrow | 2792 | 		return true; // no game compatability added, assume its ok for all
 | 
        
           |  |  | 2793 |   | 
        
           |  |  | 2794 | 	bool foundAll = false;
 | 
        
           |  |  | 2795 | 	for ( CListNode<SGameCompat> *node = m_lGames.Front(); node; node = node->next() ) {
 | 
        
           |  |  | 2796 | 		if ( node->Data()->iGame == 0 )
 | 
        
           |  |  | 2797 | 			foundAll = true;
 | 
        
           |  |  | 2798 | 		else if ( node->Data()->iGame == game ) { // now check the version
 | 
        
           | 46 | cycrow | 2799 | 			if ( node->Data()->sVersion.empty() ) {
 | 
        
           | 170 | cycrow | 2800 | 				if (node->Data()->sVersion.compareVersion(sVersion) == COMPARE_OLDER)
 | 
        
           | 6 | cycrow | 2801 | 					return false;
 | 
        
           |  |  | 2802 | 				return true;
 | 
        
           |  |  | 2803 | 			}
 | 
        
           |  |  | 2804 | 			else {
 | 
        
           |  |  | 2805 | 				if ( node->Data()->iVersion > iVersion )
 | 
        
           |  |  | 2806 | 					return false;
 | 
        
           |  |  | 2807 | 				return true;
 | 
        
           |  |  | 2808 | 			}
 | 
        
           |  |  | 2809 | 		}
 | 
        
           |  |  | 2810 | 	}
 | 
        
           |  |  | 2811 | 	return foundAll;
 | 
        
           |  |  | 2812 | }
 | 
        
           |  |  | 2813 |   | 
        
           |  |  | 2814 | bool CBaseFile::RemoveGameCompatability(int game)
 | 
        
           |  |  | 2815 | {
 | 
        
           |  |  | 2816 | 	for ( CListNode<SGameCompat> *node = m_lGames.Front(); node; node = node->next() ) {
 | 
        
           |  |  | 2817 | 		if ( node->Data()->iGame == game ) {
 | 
        
           |  |  | 2818 | 			m_lGames.remove(node);
 | 
        
           | 50 | cycrow | 2819 | 			_changed();
 | 
        
           | 6 | cycrow | 2820 | 			return true;
 | 
        
           |  |  | 2821 | 		}
 | 
        
           |  |  | 2822 | 	}
 | 
        
           |  |  | 2823 |   | 
        
           |  |  | 2824 | 	return false;
 | 
        
           |  |  | 2825 | }
 | 
        
           |  |  | 2826 |   | 
        
           |  |  | 2827 | SGameCompat *CBaseFile::GetGameCompatability(int game)
 | 
        
           |  |  | 2828 | {
 | 
        
           |  |  | 2829 | 	for ( CListNode<SGameCompat> *node = m_lGames.Front(); node; node = node->next() ) {
 | 
        
           |  |  | 2830 | 		if ( node->Data()->iGame == game ) {
 | 
        
           |  |  | 2831 | 			return node->Data();
 | 
        
           |  |  | 2832 | 		}
 | 
        
           |  |  | 2833 | 	}
 | 
        
           |  |  | 2834 |   | 
        
           |  |  | 2835 | 	return NULL;
 | 
        
           |  |  | 2836 | }
 | 
        
           |  |  | 2837 |   | 
        
           | 210 | cycrow | 2838 | void CBaseFile::AddGameCompatability(int game, const Utils::WString &version)
 | 
        
           | 6 | cycrow | 2839 | {
 | 
        
           |  |  | 2840 | 	// first check if we already have it on the list
 | 
        
           |  |  | 2841 | 	SGameCompat *Found = this->GetGameCompatability(game);
 | 
        
           |  |  | 2842 | 	if ( !Found ) {
 | 
        
           |  |  | 2843 | 		Found = new SGameCompat;
 | 
        
           |  |  | 2844 | 		m_lGames.push_back(Found);
 | 
        
           |  |  | 2845 | 	}
 | 
        
           |  |  | 2846 |   | 
        
           |  |  | 2847 | 	Found->iGame = game;
 | 
        
           |  |  | 2848 | 	Found->iVersion = -1;
 | 
        
           | 210 | cycrow | 2849 | 	Found->sVersion = L"";
 | 
        
           | 6 | cycrow | 2850 |   | 
        
           | 210 | cycrow | 2851 | 	if ( version.contains(L".") || !version.isNumber() )
 | 
        
           |  |  | 2852 | 		Found->sVersion = version;
 | 
        
           | 6 | cycrow | 2853 | 	else
 | 
        
           | 210 | cycrow | 2854 | 		Found->iVersion = version;
 | 
        
           | 50 | cycrow | 2855 | 	_changed();
 | 
        
           | 6 | cycrow | 2856 | }
 | 
        
           |  |  | 2857 |   | 
        
           | 196 | cycrow | 2858 | Utils::WString CBaseFile::_replaceFilename(const Utils::WString &fname)
 | 
        
           | 131 | cycrow | 2859 | {
 | 
        
           | 196 | cycrow | 2860 | 	Utils::WString filename = fname;
 | 
        
           | 213 | cycrow | 2861 | 	Utils::WString cdate = this->creationDate().findReplace(L"/", L".").remove(' ');
 | 
        
           | 196 | cycrow | 2862 | 	if (filename.contains(L"$AUTOSAVE"))
 | 
        
           | 131 | cycrow | 2863 | 	{
 | 
        
           |  |  | 2864 | 		if (this->GetType() == TYPE_XSP)
 | 
        
           | 196 | cycrow | 2865 | 			filename = filename.findReplace(L"$AUTOSAVE", L"$NAME-V$VERSION-$CDATE.xsp");
 | 
        
           | 131 | cycrow | 2866 | 		else
 | 
        
           | 196 | cycrow | 2867 | 			filename = filename.findReplace(L"$AUTOSAVE", L"$NAME-V$VERSION-$CDATE.spk");
 | 
        
           | 131 | cycrow | 2868 | 	}
 | 
        
           | 203 | cycrow | 2869 | 	filename = filename.findReplace(L"$NAME", this->name().remove(L' '));
 | 
        
           |  |  | 2870 | 	filename = filename.findReplace(L"$AUTHOR", this->author().remove(L' '));
 | 
        
           | 199 | cycrow | 2871 | 	filename = filename.findReplace(L"$DATE", cdate);
 | 
        
           |  |  | 2872 | 	filename = filename.findReplace(L"$CDATE", cdate);
 | 
        
           |  |  | 2873 | 	filename = filename.findReplace(L"$VERSION", this->version());
 | 
        
           | 131 | cycrow | 2874 |   | 
        
           |  |  | 2875 | 	return filename;
 | 
        
           |  |  | 2876 | }
 | 
        
           | 197 | cycrow | 2877 | bool CBaseFile::loadPackageData(const Utils::WString &sFirst, const Utils::WString &sRest, const Utils::WString &sMainGame, Utils::WStringList &otherGames, Utils::WStringList &gameAddons, CProgressInfo *progress)
 | 
        
           | 6 | cycrow | 2878 | {
 | 
        
           | 207 | cycrow | 2879 | 	if (sFirst.Compare(L"Name"))					this->setName(sRest);
 | 
        
           |  |  | 2880 | 	else if (sFirst.Compare(L"Author"))				this->setAuthor(sRest);
 | 
        
           |  |  | 2881 | 	else if (sFirst.Compare(L"ScriptName"))			addName(parseLanguage(sRest.token(L" ", 1)), sRest.tokens(L" ", 2));
 | 
        
           |  |  | 2882 | 	else if (sFirst.Compare(L"UninstallBefore"))	this->addUninstallText(parseLanguage(sRest.token(L" ", 1)), true, sRest.tokens(L" ", 2));
 | 
        
           |  |  | 2883 | 	else if (sFirst.Compare(L"UninstallAfter"))		this->addUninstallText(parseLanguage(sRest.token(L" ", 1)), false, sRest.tokens(L" ", 2));
 | 
        
           |  |  | 2884 | 	else if (sFirst.Compare(L"InstallBefore"))		this->addInstallText(parseLanguage(sRest.token(L" ", 1)), true, sRest.tokens(L" ", 2));
 | 
        
           |  |  | 2885 | 	else if (sFirst.Compare(L"InstallAfter"))		this->addInstallText(parseLanguage(sRest.token(L" ", 1)), false, sRest.tokens(L" ", 2));
 | 
        
           | 211 | cycrow | 2886 | 	else if (sFirst.Compare(L"Date"))				this->setCreationDate(sRest);
 | 
        
           |  |  | 2887 | 	else if (sFirst.Compare(L"Version"))			this->setVersion(sRest);
 | 
        
           | 197 | cycrow | 2888 | 	else if (sFirst.Compare(L"GameVersion"))
 | 
        
           | 211 | cycrow | 2889 | 		this->AddGameCompatability(-1, sRest);
 | 
        
           | 197 | cycrow | 2890 | 	else if (sFirst.Compare(L"PluginType")) {
 | 
        
           | 134 | cycrow | 2891 | 		if (sRest.isNumber())						this->setPluginType(sRest);
 | 
        
           | 197 | cycrow | 2892 | 		else if (sRest.Compare(L"Normal"))			this->setPluginType(PLUGIN_NORMAL);
 | 
        
           |  |  | 2893 | 		else if (sRest.Compare(L"Stable"))			this->setPluginType(PLUGIN_STABLE);
 | 
        
           |  |  | 2894 | 		else if (sRest.Compare(L"Experimental"))	this->setPluginType(PLUGIN_EXPERIMENTAL);
 | 
        
           |  |  | 2895 | 		else if (sRest.Compare(L"Cheat"))			this->setPluginType(PLUGIN_CHEAT);
 | 
        
           |  |  | 2896 | 		else if (sRest.Compare(L"Mod"))				this->setPluginType(PLUGIN_MOD);
 | 
        
           | 6 | cycrow | 2897 | 	}
 | 
        
           |  |  | 2898 | 	// new version
 | 
        
           | 197 | cycrow | 2899 | 	else if (sFirst.Compare(L"GenerateUpdateFile"))
 | 
        
           | 6 | cycrow | 2900 | 		m_bAutoGenerateUpdateFile = true;
 | 
        
           | 197 | cycrow | 2901 | 	else if (sFirst.Compare(L"Game"))
 | 
        
           | 6 | cycrow | 2902 | 	{
 | 
        
           | 197 | cycrow | 2903 | 		Utils::WString sGame = sRest.token(L" ", 1);
 | 
        
           | 211 | cycrow | 2904 | 		this->AddGameCompatability(CBaseFile::GetGameFromString(sGame), sRest.token(L" ", 2));
 | 
        
           | 6 | cycrow | 2905 | 	}
 | 
        
           | 211 | cycrow | 2906 | 	else if (sFirst.Compare(L"Description"))		this->setDescription(sRest);
 | 
        
           | 197 | cycrow | 2907 | 	else if (sFirst.Compare(L"AutoSave") || sFirst.Compare(L"AutoExport") || sFirst.Compare(L"AutoRarExport") || sFirst.Compare(L"AutoZipExport"))
 | 
        
           | 6 | cycrow | 2908 | 	{
 | 
        
           | 196 | cycrow | 2909 | 		Utils::WString filename = _replaceFilename(sRest);
 | 
        
           | 6 | cycrow | 2910 |   | 
        
           | 197 | cycrow | 2911 | 		if (sFirst.Compare(L"AutoZipExport") || sFirst.Compare(L"AutoExport"))
 | 
        
           | 211 | cycrow | 2912 | 			this->setExportFilename(CFileIO(filename).changeFileExtension(L"zip"));
 | 
        
           | 197 | cycrow | 2913 | 		else if (sFirst.Compare(L"AutoRarExport"))
 | 
        
           | 211 | cycrow | 2914 | 			this->setExportFilename(CFileIO(filename).changeFileExtension(L"rar"));
 | 
        
           | 6 | cycrow | 2915 | 		else
 | 
        
           | 197 | cycrow | 2916 | 			this->setFilename(filename);
 | 
        
           | 6 | cycrow | 2917 | 	}
 | 
        
           | 211 | cycrow | 2918 | 	else if (sFirst.Compare(L"WebSite"))		this->setWebSite(sRest);
 | 
        
           | 213 | cycrow | 2919 | 	else if (sFirst.Compare(L"ForumLink") || sFirst.Compare(L"Forum")) this->setForumLink(sRest);
 | 
        
           | 211 | cycrow | 2920 | 	else if (sFirst.Compare(L"Email"))			this->setEmail(sRest);
 | 
        
           |  |  | 2921 | 	else if (sFirst.Compare(L"WebAddress"))		this->setWebAddress(sRest);
 | 
        
           | 197 | cycrow | 2922 | 	else if (sFirst.Compare(L"WebMirror"))
 | 
        
           | 211 | cycrow | 2923 | 		this->addWebMirror(sRest);
 | 
        
           | 197 | cycrow | 2924 | 	else if (sFirst.Compare(L"WebMirror1"))
 | 
        
           | 211 | cycrow | 2925 | 		this->addWebMirror(sRest);
 | 
        
           | 197 | cycrow | 2926 | 	else if (sFirst.Compare(L"WebMirror2"))
 | 
        
           | 211 | cycrow | 2927 | 		this->addWebMirror(sRest);
 | 
        
           | 197 | cycrow | 2928 | 	else if (sFirst.Compare(L"Ftp"))
 | 
        
           | 210 | cycrow | 2929 | 		_sFtpAddr = sRest;
 | 
        
           | 197 | cycrow | 2930 | 	else if (sFirst.Compare(L"Ratings"))		_setRatings(sRest.token(L" ", 1), sRest.token(L" ", 2), sRest.token(L" ", 3));
 | 
        
           |  |  | 2931 | 	else if (sFirst.Compare(L"EaseOfUse"))		setEaseOfUse(sRest);
 | 
        
           |  |  | 2932 | 	else if (sFirst.Compare(L"GameChanging"))	setGameChanging(sRest);
 | 
        
           |  |  | 2933 | 	else if (sFirst.Compare(L"Recommended"))	setRecommended(sRest);
 | 
        
           |  |  | 2934 | 	else if (sFirst.Compare(L"Depend"))
 | 
        
           | 6 | cycrow | 2935 | 	{
 | 
        
           | 197 | cycrow | 2936 | 		Utils::WString version = sRest.token(L"|", 2);
 | 
        
           |  |  | 2937 | 		Utils::WString name = sRest.token(L"|", 1);
 | 
        
           |  |  | 2938 | 		Utils::WString author = sRest.tokens(L"|", 3);
 | 
        
           | 6 | cycrow | 2939 |   | 
        
           | 211 | cycrow | 2940 | 		this->addNeededLibrary(name, author, version);
 | 
        
           | 6 | cycrow | 2941 | 	}
 | 
        
           | 197 | cycrow | 2942 | 	else if (sFirst.Compare(L"DependPackage"))
 | 
        
           | 6 | cycrow | 2943 | 	{
 | 
        
           |  |  | 2944 | 		CPackages p;
 | 
        
           | 182 | cycrow | 2945 | 		CBaseFile *spk = p.openPackage(sRest, 0, 0, SPKREAD_VALUES);
 | 
        
           | 134 | cycrow | 2946 | 		if (spk)
 | 
        
           | 6 | cycrow | 2947 | 		{
 | 
        
           | 203 | cycrow | 2948 | 			this->addNeededLibrary(spk->name(), spk->author(), spk->version());
 | 
        
           | 6 | cycrow | 2949 | 			delete spk;
 | 
        
           |  |  | 2950 | 		}
 | 
        
           |  |  | 2951 | 	}
 | 
        
           | 197 | cycrow | 2952 | 	else if (sFirst.Compare(L"Icon"))
 | 
        
           | 6 | cycrow | 2953 | 	{
 | 
        
           | 197 | cycrow | 2954 | 		C_File *icon = new C_File(sRest);
 | 
        
           | 134 | cycrow | 2955 | 		if (icon->ReadFromFile())
 | 
        
           | 211 | cycrow | 2956 | 			this->setIcon(icon, CFileIO(sRest).extension());
 | 
        
           | 6 | cycrow | 2957 | 	}
 | 
        
           | 197 | cycrow | 2958 | 	else if (sFirst.Compare(L"CombineGameFiles"))
 | 
        
           |  |  | 2959 | 		_bCombineFiles = sRest.Compare(L"true") || sRest.Compare(L"yes") || sRest.toInt();
 | 
        
           |  |  | 2960 | 	else if (sFirst.Compare(L"UpdateFile"))
 | 
        
           | 134 | cycrow | 2961 | 		this->createUpdateFile(sRest);
 | 
        
           | 197 | cycrow | 2962 | 	else if (sFirst.Compare(L"ExportZip"))
 | 
        
           | 131 | cycrow | 2963 | 	{
 | 
        
           | 196 | cycrow | 2964 | 		Utils::WString ext = L"zip";
 | 
        
           | 197 | cycrow | 2965 | 		Utils::WString game = sRest.word(1);
 | 
        
           | 196 | cycrow | 2966 | 		Utils::WString file = _replaceFilename(CFileIO(sRest.words(2)).fullFilename());
 | 
        
           | 197 | cycrow | 2967 | 		if (game.contains(L"|"))
 | 
        
           | 131 | cycrow | 2968 | 		{
 | 
        
           | 197 | cycrow | 2969 | 			std::vector<Utils::WString> games;
 | 
        
           |  |  | 2970 | 			if(game.tokenise(L"|", games))
 | 
        
           | 131 | cycrow | 2971 | 			{
 | 
        
           | 197 | cycrow | 2972 | 				for (size_t i = 0; i < games.size(); ++i)
 | 
        
           | 131 | cycrow | 2973 | 				{
 | 
        
           | 211 | cycrow | 2974 | 					unsigned int g = CBaseFile::GetGameFromString(games[i]);
 | 
        
           | 197 | cycrow | 2975 | 					Utils::WString filename = CFileIO(file).dir() + L"/" + CFileIO(file).baseName() + L"_" + CBaseFile::ConvertGameToString(g) + L"." + ext;
 | 
        
           | 211 | cycrow | 2976 | 					this->addAutoExport(g, filename);
 | 
        
           | 131 | cycrow | 2977 | 				}
 | 
        
           |  |  | 2978 | 			}
 | 
        
           |  |  | 2979 | 		}
 | 
        
           |  |  | 2980 | 		else
 | 
        
           |  |  | 2981 | 		{
 | 
        
           | 211 | cycrow | 2982 | 			unsigned int g = CBaseFile::GetGameFromString(game);
 | 
        
           | 197 | cycrow | 2983 | 			Utils::WString filename = CFileIO(file).dir() + L"/" + CFileIO(file).baseName() + L"_" + CBaseFile::ConvertGameToString(g) + L"." + ext;
 | 
        
           | 211 | cycrow | 2984 | 			this->addAutoExport(g, filename);
 | 
        
           | 131 | cycrow | 2985 | 		}
 | 
        
           |  |  | 2986 | 	}
 | 
        
           | 197 | cycrow | 2987 | 	else if (sFirst.Compare(L"Extract"))
 | 
        
           | 131 | cycrow | 2988 | 	{
 | 
        
           | 197 | cycrow | 2989 | 		Utils::WString game = sRest.word(1);
 | 
        
           | 196 | cycrow | 2990 | 		Utils::WString dir = CDirIO(sRest.words(2)).dir();
 | 
        
           | 197 | cycrow | 2991 | 		if (game.contains(L"|"))
 | 
        
           | 131 | cycrow | 2992 | 		{
 | 
        
           | 197 | cycrow | 2993 | 			std::vector<Utils::WString> games;
 | 
        
           |  |  | 2994 | 			if (game.tokenise(L"|", games))
 | 
        
           | 131 | cycrow | 2995 | 			{
 | 
        
           | 197 | cycrow | 2996 | 				for(size_t i = 0; i < games.size(); ++i)
 | 
        
           | 211 | cycrow | 2997 | 					this->addAutoExtract(CBaseFile::GetGameFromString(games[i]), dir);
 | 
        
           | 131 | cycrow | 2998 | 			}
 | 
        
           |  |  | 2999 | 		}
 | 
        
           |  |  | 3000 | 		else
 | 
        
           | 211 | cycrow | 3001 | 			this->addAutoExtract(CBaseFile::GetGameFromString(game), dir);
 | 
        
           | 131 | cycrow | 3002 | 	}
 | 
        
           | 239 | cycrow | 3003 | 	else if (sFirst.Compare(L"Global"))
 | 
        
           |  |  | 3004 | 		this->addGlobal(sRest.token(L";", 1), sRest.token(L";", 2));
 | 
        
           | 6 | cycrow | 3005 | 	else
 | 
        
           |  |  | 3006 | 	{
 | 
        
           | 197 | cycrow | 3007 | 		Utils::WString checkType = sFirst;
 | 
        
           | 6 | cycrow | 3008 | 		bool shared = false;
 | 
        
           | 197 | cycrow | 3009 | 		if (checkType.left(6).Compare(L"Shared"))
 | 
        
           | 6 | cycrow | 3010 | 		{
 | 
        
           | 14 | cycrow | 3011 | 			checkType = sFirst.right(-6);
 | 
        
           | 6 | cycrow | 3012 | 			shared = true;
 | 
        
           |  |  | 3013 | 		}
 | 
        
           | 155 | cycrow | 3014 | 		bool packed = false;
 | 
        
           | 197 | cycrow | 3015 | 		if (checkType.right(3).Compare(L"PCK"))
 | 
        
           | 155 | cycrow | 3016 | 		{
 | 
        
           |  |  | 3017 | 			checkType = sFirst.left(-3);
 | 
        
           |  |  | 3018 | 			packed = true;
 | 
        
           |  |  | 3019 | 		}
 | 
        
           | 6 | cycrow | 3020 |   | 
        
           |  |  | 3021 | 		// now check type name
 | 
        
           | 127 | cycrow | 3022 | 		FileType filetype = GetFileTypeFromString(checkType);
 | 
        
           |  |  | 3023 | 		if (filetype != FILETYPE_UNKNOWN)
 | 
        
           | 197 | cycrow | 3024 | 			this->addFileScript(filetype, shared, packed, sRest, sMainGame, otherGames, gameAddons, progress);
 | 
        
           | 213 | cycrow | 3025 | 		else if ( !checkType.Compare(L"changelog") )
 | 
        
           | 6 | cycrow | 3026 | 			return false;
 | 
        
           |  |  | 3027 | 	}
 | 
        
           |  |  | 3028 |   | 
        
           |  |  | 3029 | 	return true;
 | 
        
           |  |  | 3030 | }
 | 
        
           |  |  | 3031 |   | 
        
           | 197 | cycrow | 3032 | void CBaseFile::addFileScript(FileType filetype, bool shared, bool packed, const Utils::WString &sRest, const Utils::WString &sMainGame, Utils::WStringList &otherGames, Utils::WStringList &gameAddons, CProgressInfo *progress)
 | 
        
           | 6 | cycrow | 3033 | {
 | 
        
           | 197 | cycrow | 3034 | 	Utils::WString dir;
 | 
        
           |  |  | 3035 | 	Utils::WString rest = sRest;
 | 
        
           | 127 | cycrow | 3036 |   | 
        
           | 211 | cycrow | 3037 | 	unsigned int mainGame = CBaseFile::GetGameFromString(sMainGame);
 | 
        
           | 127 | cycrow | 3038 | 	unsigned int game = 0;
 | 
        
           | 197 | cycrow | 3039 | 	if ( rest.token(L" ", 1).left(4).Compare(L"GAME") ) {
 | 
        
           |  |  | 3040 | 		Utils::WString gameStr = rest.token(L" ", 2);
 | 
        
           |  |  | 3041 | 		if (gameStr.contains(L"|"))
 | 
        
           | 127 | cycrow | 3042 | 		{
 | 
        
           | 197 | cycrow | 3043 | 			std::vector<Utils::WString> games;
 | 
        
           |  |  | 3044 | 			gameStr.tokenise(L"|", games);
 | 
        
           |  |  | 3045 | 			for (size_t i = 0; i < games.size(); ++i)
 | 
        
           | 127 | cycrow | 3046 | 			{
 | 
        
           | 211 | cycrow | 3047 | 				unsigned int g = CBaseFile::GetGameFromString(games[i]);
 | 
        
           | 127 | cycrow | 3048 | 				if (g)
 | 
        
           |  |  | 3049 | 					game |= 1 << g;
 | 
        
           |  |  | 3050 | 			}
 | 
        
           |  |  | 3051 | 		}
 | 
        
           |  |  | 3052 | 		else
 | 
        
           | 131 | cycrow | 3053 | 		{
 | 
        
           | 211 | cycrow | 3054 | 			unsigned int g = CBaseFile::GetGameFromString(gameStr);
 | 
        
           | 131 | cycrow | 3055 | 			if (g)
 | 
        
           |  |  | 3056 | 				game = 1 << g;
 | 
        
           |  |  | 3057 | 		}
 | 
        
           | 197 | cycrow | 3058 | 		rest = rest.tokens(L" ", 3);
 | 
        
           | 6 | cycrow | 3059 | 	}
 | 
        
           | 127 | cycrow | 3060 | 	if (game)
 | 
        
           |  |  | 3061 | 		game |= 1 << 31;
 | 
        
           | 6 | cycrow | 3062 |   | 
        
           | 197 | cycrow | 3063 | 	if (rest.contains(L"|"))
 | 
        
           | 127 | cycrow | 3064 | 	{
 | 
        
           | 197 | cycrow | 3065 | 		dir = rest.tokens(L"|", 2);
 | 
        
           |  |  | 3066 | 		rest = rest.token(L"|", 1);
 | 
        
           | 6 | cycrow | 3067 | 	}
 | 
        
           |  |  | 3068 |   | 
        
           | 197 | cycrow | 3069 | 	rest = rest.findReplace(L"\\", L"/");
 | 
        
           | 6 | cycrow | 3070 |   | 
        
           |  |  | 3071 | 	// wild cards
 | 
        
           | 197 | cycrow | 3072 | 	if ( rest.containsAny(L"*?") )
 | 
        
           | 6 | cycrow | 3073 | 	{
 | 
        
           | 102 | cycrow | 3074 | 		CDirIO Dir(CFileIO(rest).dir());
 | 
        
           | 197 | cycrow | 3075 | 		Utils::WStringList dirList;
 | 
        
           | 160 | cycrow | 3076 | 		if(Dir.dirList(dirList))
 | 
        
           | 6 | cycrow | 3077 | 		{
 | 
        
           | 160 | cycrow | 3078 | 			for(auto itr = dirList.begin(); itr != dirList.end(); itr++)
 | 
        
           | 6 | cycrow | 3079 | 			{
 | 
        
           | 196 | cycrow | 3080 | 				Utils::WString file = Dir.file((*itr)->str);
 | 
        
           | 127 | cycrow | 3081 | 				if (file.match(rest))
 | 
        
           | 6 | cycrow | 3082 | 				{
 | 
        
           | 98 | cycrow | 3083 | 					int addGame = game;
 | 
        
           |  |  | 3084 | 					// check if the file exists in the subdirectory too, if it does, add for each game
 | 
        
           |  |  | 3085 | 					if ( game == GAME_ALL && !sMainGame.empty() && !otherGames.empty() ) {
 | 
        
           |  |  | 3086 | 						CFileIO F(file);
 | 
        
           | 197 | cycrow | 3087 | 						for(Utils::WString g = otherGames.firstString(); !g.empty(); g = otherGames.nextString()) {
 | 
        
           |  |  | 3088 | 							Utils::WString checkDir = F.dir() + L"/" + g;
 | 
        
           | 121 | cycrow | 3089 | 							if ( CDirIO(checkDir).exists(F.filename()) ) {
 | 
        
           | 98 | cycrow | 3090 | 								addGame = mainGame;
 | 
        
           | 211 | cycrow | 3091 | 								C_File *newfile = this->appendFile(CDirIO(checkDir).file(F.filename()), filetype, CBaseFile::GetGameFromString(g), packed, dir);
 | 
        
           | 134 | cycrow | 3092 | 								if (newfile && progress)
 | 
        
           |  |  | 3093 | 									progress->UpdateFile(newfile);
 | 
        
           | 98 | cycrow | 3094 | 								if ( newfile ) newfile->SetShared(shared);
 | 
        
           |  |  | 3095 | 							}
 | 
        
           |  |  | 3096 | 						}
 | 
        
           |  |  | 3097 | 					}
 | 
        
           |  |  | 3098 |   | 
        
           | 197 | cycrow | 3099 | 					C_File *newfile = this->appendFile(file, filetype, addGame, packed, dir);
 | 
        
           | 134 | cycrow | 3100 | 					if (newfile && progress)
 | 
        
           |  |  | 3101 | 						progress->UpdateFile(newfile);
 | 
        
           | 6 | cycrow | 3102 | 					if ( newfile )
 | 
        
           |  |  | 3103 | 						newfile->SetShared(shared);
 | 
        
           |  |  | 3104 | 				}
 | 
        
           |  |  | 3105 | 			}
 | 
        
           |  |  | 3106 | 		}
 | 
        
           |  |  | 3107 | 	}
 | 
        
           |  |  | 3108 | 	else
 | 
        
           |  |  | 3109 | 	{
 | 
        
           | 127 | cycrow | 3110 | 		unsigned int addGame = game;
 | 
        
           | 98 | cycrow | 3111 | 		// check if the file exists in the subdirectory too, if it does, add for each game
 | 
        
           |  |  | 3112 | 		if ( game == GAME_ALL && !sMainGame.empty() && !otherGames.empty() ) {
 | 
        
           |  |  | 3113 | 			CFileIO F(rest);
 | 
        
           | 197 | cycrow | 3114 | 			for(Utils::WString g = otherGames.firstString(); !g.empty(); g = otherGames.nextString()) {
 | 
        
           |  |  | 3115 | 				Utils::WString checkDir = F.dir() + L"/" + g;
 | 
        
           | 121 | cycrow | 3116 | 				if ( CDirIO(checkDir).exists(F.filename()) ) {
 | 
        
           | 98 | cycrow | 3117 | 					addGame = mainGame;
 | 
        
           | 211 | cycrow | 3118 | 					C_File *newfile = this->appendFile(CDirIO(checkDir).file(F.filename()), filetype, CBaseFile::GetGameFromString(g), packed, dir);
 | 
        
           | 134 | cycrow | 3119 | 					if (newfile && progress)
 | 
        
           |  |  | 3120 | 						progress->UpdateFile(newfile);
 | 
        
           | 98 | cycrow | 3121 | 					if ( newfile ) newfile->SetShared(shared);
 | 
        
           |  |  | 3122 | 				}
 | 
        
           |  |  | 3123 | 			}
 | 
        
           |  |  | 3124 | 		}
 | 
        
           |  |  | 3125 |   | 
        
           | 127 | cycrow | 3126 | 		unsigned int checkGame = addGame & ~(1 << 31);
 | 
        
           |  |  | 3127 | 		unsigned int foundGame = 0;
 | 
        
           |  |  | 3128 | 		for (int i = 0; i < 31; ++i)
 | 
        
           |  |  | 3129 | 		{
 | 
        
           |  |  | 3130 | 			if (1 << i == checkGame)
 | 
        
           |  |  | 3131 | 			{
 | 
        
           |  |  | 3132 | 				foundGame = i;
 | 
        
           |  |  | 3133 | 				break;
 | 
        
           |  |  | 3134 | 			}
 | 
        
           |  |  | 3135 | 		}
 | 
        
           |  |  | 3136 |   | 
        
           |  |  | 3137 | 		C_File *file = NULL;
 | 
        
           |  |  | 3138 | 		if (foundGame)
 | 
        
           |  |  | 3139 | 		{
 | 
        
           | 197 | cycrow | 3140 | 			Utils::WString addon = gameAddons.findString(Utils::WString::Number(foundGame));
 | 
        
           | 127 | cycrow | 3141 | 			if (!addon.empty())
 | 
        
           |  |  | 3142 | 			{
 | 
        
           | 197 | cycrow | 3143 | 				Utils::WString dir = C_File::GetDirectory(filetype, rest, this);
 | 
        
           |  |  | 3144 | 				Utils::WString filename = rest;
 | 
        
           | 130 | cycrow | 3145 | 				if (CCatFile::IsAddonDir(dir) && !filename.contains(addon))
 | 
        
           |  |  | 3146 | 				{
 | 
        
           | 197 | cycrow | 3147 | 					filename = filename.findReplace(dir + L"/", addon + L"/" + dir + L"/");
 | 
        
           | 155 | cycrow | 3148 | 					file = this->appendFile(filename, filetype, addGame, packed, dir);
 | 
        
           | 130 | cycrow | 3149 | 				}
 | 
        
           | 127 | cycrow | 3150 | 			}
 | 
        
           |  |  | 3151 | 		}
 | 
        
           |  |  | 3152 |   | 
        
           |  |  | 3153 | 		if(!file)
 | 
        
           | 155 | cycrow | 3154 | 			file = this->appendFile(rest, filetype, addGame, packed, dir);
 | 
        
           | 127 | cycrow | 3155 |   | 
        
           | 134 | cycrow | 3156 | 		if (file && progress)
 | 
        
           |  |  | 3157 | 			progress->UpdateFile(file);
 | 
        
           | 127 | cycrow | 3158 | 		if (file)
 | 
        
           | 6 | cycrow | 3159 | 			file->SetShared(shared);
 | 
        
           |  |  | 3160 | 	}
 | 
        
           |  |  | 3161 | }
 | 
        
           |  |  | 3162 |   | 
        
           |  |  | 3163 |   | 
        
           | 197 | cycrow | 3164 | Utils::WString CBaseFile::fileSizeString() const { return SPK::GetSizeString ( this->fileSize() ); }
 | 
        
           | 6 | cycrow | 3165 |   | 
        
           | 52 | cycrow | 3166 | // used for a multiple spk file
 | 
        
           | 197 | cycrow | 3167 | unsigned char *CBaseFile::createData(size_t *size, CProgressInfo *progress)
 | 
        
           | 6 | cycrow | 3168 | {
 | 
        
           | 213 | cycrow | 3169 | 	if ( this->writeFile(L"temp.dat", progress) ) {
 | 
        
           | 197 | cycrow | 3170 | 		CFileIO File(L"temp.dat");
 | 
        
           | 52 | cycrow | 3171 | 		File.setAutoDelete(true);
 | 
        
           |  |  | 3172 | 		return File.readAll(size);
 | 
        
           | 6 | cycrow | 3173 | 	}
 | 
        
           |  |  | 3174 | 	return NULL;
 | 
        
           |  |  | 3175 | }
 | 
        
           |  |  | 3176 |   | 
        
           |  |  | 3177 |   | 
        
           | 210 | cycrow | 3178 | void CBaseFile::convertNormalMod(C_File *f, const Utils::WString &to) const
 | 
        
           | 6 | cycrow | 3179 | {
 | 
        
           | 170 | cycrow | 3180 | 	C_File *match = this->findMatchingMod(f);
 | 
        
           | 6 | cycrow | 3181 | 	if ( match )
 | 
        
           |  |  | 3182 | 	{
 | 
        
           |  |  | 3183 | 		// file link
 | 
        
           |  |  | 3184 | 		if ( !match->GetData() )
 | 
        
           |  |  | 3185 | 			match->ReadFromFile();
 | 
        
           | 178 | cycrow | 3186 | 		match->changeBaseName(to);
 | 
        
           | 6 | cycrow | 3187 | 	}
 | 
        
           |  |  | 3188 |   | 
        
           |  |  | 3189 | 	// file link
 | 
        
           |  |  | 3190 | 	if ( !f->GetData() )
 | 
        
           |  |  | 3191 | 		f->ReadFromFile();
 | 
        
           |  |  | 3192 |   | 
        
           | 178 | cycrow | 3193 | 	f->changeBaseName(to);
 | 
        
           | 6 | cycrow | 3194 | }
 | 
        
           |  |  | 3195 |   | 
        
           | 170 | cycrow | 3196 | void CBaseFile::convertAutoText(C_File *f) const
 | 
        
           | 6 | cycrow | 3197 | {
 | 
        
           | 197 | cycrow | 3198 | 	Utils::WString to;
 | 
        
           |  |  | 3199 | 	if ( f->baseName().contains(L"-L") )
 | 
        
           |  |  | 3200 | 		to = L"0000-L" + f->baseName().token(L"-L", 2);
 | 
        
           | 213 | cycrow | 3201 | 	else if ( f->baseName().contains(L"-l") )
 | 
        
           | 197 | cycrow | 3202 | 		to = L"0000-L" + f->baseName().token(L"-l", 2);
 | 
        
           | 6 | cycrow | 3203 | 	else
 | 
        
           | 197 | cycrow | 3204 | 		to = f->baseName().left(-4) + L"0000";
 | 
        
           | 6 | cycrow | 3205 |   | 
        
           |  |  | 3206 | 	// file link
 | 
        
           |  |  | 3207 | 	if ( !f->GetData() )
 | 
        
           |  |  | 3208 | 		f->ReadFromFile();
 | 
        
           |  |  | 3209 |   | 
        
           | 178 | cycrow | 3210 | 	f->changeBaseName(to);
 | 
        
           | 6 | cycrow | 3211 | }
 | 
        
           |  |  | 3212 |   | 
        
           | 170 | cycrow | 3213 | void CBaseFile::convertFakePatch(C_File *f) const
 | 
        
           | 6 | cycrow | 3214 | {
 | 
        
           |  |  | 3215 | 	// find next available fake patch
 | 
        
           |  |  | 3216 | 	int num = 0;
 | 
        
           |  |  | 3217 |   | 
        
           |  |  | 3218 | 	bool found = true;
 | 
        
           |  |  | 3219 | 	while ( found )
 | 
        
           |  |  | 3220 | 	{
 | 
        
           |  |  | 3221 | 		++num;
 | 
        
           |  |  | 3222 | 		found = false;
 | 
        
           | 211 | cycrow | 3223 | 		Utils::WString find = Utils::WString::PadNumber(num, 2);
 | 
        
           | 6 | cycrow | 3224 | 		for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 3225 | 		{
 | 
        
           |  |  | 3226 | 			if ( node->Data()->GetFileType() != FILETYPE_MOD )
 | 
        
           |  |  | 3227 | 				continue;
 | 
        
           |  |  | 3228 | 			if ( !node->Data()->IsFakePatch() )
 | 
        
           |  |  | 3229 | 				continue;
 | 
        
           | 170 | cycrow | 3230 | 			if ( node->Data()->baseName().Compare(find) )
 | 
        
           | 6 | cycrow | 3231 | 			{
 | 
        
           |  |  | 3232 | 				found = true;
 | 
        
           |  |  | 3233 | 				break;
 | 
        
           |  |  | 3234 | 			}
 | 
        
           |  |  | 3235 | 		}
 | 
        
           |  |  | 3236 | 	}
 | 
        
           |  |  | 3237 |   | 
        
           | 211 | cycrow | 3238 | 	Utils::WString to = Utils::WString::PadNumber(num, 2);
 | 
        
           | 170 | cycrow | 3239 | 	C_File *match = this->findMatchingMod(f);
 | 
        
           | 6 | cycrow | 3240 |   | 
        
           |  |  | 3241 | 	// file link
 | 
        
           |  |  | 3242 | 	if ( !f->GetData() )
 | 
        
           |  |  | 3243 | 		f->ReadFromFile();
 | 
        
           |  |  | 3244 |   | 
        
           | 178 | cycrow | 3245 | 	f->changeBaseName(to);
 | 
        
           | 6 | cycrow | 3246 | 	if ( match )
 | 
        
           |  |  | 3247 | 	{
 | 
        
           |  |  | 3248 | 		// file link
 | 
        
           |  |  | 3249 | 		if ( !match->GetData() )
 | 
        
           |  |  | 3250 | 			match->ReadFromFile();
 | 
        
           | 178 | cycrow | 3251 | 		match->changeBaseName(to);
 | 
        
           | 6 | cycrow | 3252 | 	}
 | 
        
           |  |  | 3253 | }
 | 
        
           |  |  | 3254 |   | 
        
           | 170 | cycrow | 3255 | C_File *CBaseFile::findMatchingMod(C_File *f) const
 | 
        
           | 6 | cycrow | 3256 | {
 | 
        
           |  |  | 3257 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
 | 
        
           |  |  | 3258 | 	{
 | 
        
           |  |  | 3259 | 		if ( node->Data()->GetFileType() != FILETYPE_MOD )
 | 
        
           |  |  | 3260 | 			continue;
 | 
        
           |  |  | 3261 |   | 
        
           | 178 | cycrow | 3262 | 		if ( f->fileExt().Compare(node->Data()->fileExt()) )
 | 
        
           | 6 | cycrow | 3263 | 			continue;
 | 
        
           |  |  | 3264 |   | 
        
           | 178 | cycrow | 3265 | 		if ( f->baseName().Compare(node->Data()->baseName()) )
 | 
        
           | 6 | cycrow | 3266 | 			return node->Data();
 | 
        
           |  |  | 3267 | 	}
 | 
        
           |  |  | 3268 |   | 
        
           |  |  | 3269 | 	return NULL;
 | 
        
           |  |  | 3270 | }
 | 
        
           |  |  | 3271 |   | 
        
           | 210 | cycrow | 3272 | void CBaseFile::renameFile(C_File *f, const Utils::WString &baseName) const
 | 
        
           | 6 | cycrow | 3273 | {
 | 
        
           |  |  | 3274 | 	if ( f->GetFileType() == FILETYPE_MOD )
 | 
        
           |  |  | 3275 | 	{
 | 
        
           | 170 | cycrow | 3276 | 		C_File *match = this->findMatchingMod(f);
 | 
        
           | 6 | cycrow | 3277 | 		if ( match )
 | 
        
           | 178 | cycrow | 3278 | 			match->changeBaseName(baseName);
 | 
        
           | 6 | cycrow | 3279 | 	}
 | 
        
           |  |  | 3280 |   | 
        
           |  |  | 3281 | 	// need to edit the file
 | 
        
           | 134 | cycrow | 3282 | 	if (f->GetFileType() == FILETYPE_SCRIPT || f->GetFileType() == FILETYPE_UNINSTALL)
 | 
        
           | 178 | cycrow | 3283 | 		f->renameScript(baseName);
 | 
        
           | 6 | cycrow | 3284 |   | 
        
           | 178 | cycrow | 3285 | 	f->changeBaseName(baseName);
 | 
        
           | 6 | cycrow | 3286 | }
 | 
        
           |  |  | 3287 |   | 
        
           | 196 | cycrow | 3288 | Utils::WString CBaseFile::createUpdateFile(const Utils::WString &dir) const
 | 
        
           | 6 | cycrow | 3289 | {
 | 
        
           | 203 | cycrow | 3290 | 	Utils::WString file = this->getNameValidFile() + L"_" + this->author() + L".dat";
 | 
        
           | 134 | cycrow | 3291 | 	file.removeChar(' ');
 | 
        
           | 6 | cycrow | 3292 |   | 
        
           | 203 | cycrow | 3293 | 	Utils::WStringList write;
 | 
        
           |  |  | 3294 | 	write.pushBack(L"Package: " + this->name());
 | 
        
           |  |  | 3295 | 	write.pushBack(L"Author: " + this->author());
 | 
        
           | 204 | cycrow | 3296 | 	write.pushBack(L"Version: " + this->version());
 | 
        
           | 203 | cycrow | 3297 | 	write.pushBack(L"File: " + CFileIO(this->filename()).filename());
 | 
        
           | 6 | cycrow | 3298 |   | 
        
           | 197 | cycrow | 3299 | 	CFileIO File(dir + L"/" + file);
 | 
        
           | 134 | cycrow | 3300 | 	if (File.writeFile(&write))
 | 
        
           | 102 | cycrow | 3301 | 		return File.fullFilename();
 | 
        
           | 196 | cycrow | 3302 | 	return Utils::WString::Null();
 | 
        
           | 6 | cycrow | 3303 | }
 | 
        
           |  |  | 3304 |   | 
        
           | 197 | cycrow | 3305 | Utils::WString CBaseFile::ErrorString(int error, const Utils::WString &errorStr)
 | 
        
           | 6 | cycrow | 3306 | {
 | 
        
           | 197 | cycrow | 3307 | 	if (error == SPKERR_NONE) return Utils::WString::Null();
 | 
        
           | 6 | cycrow | 3308 |   | 
        
           | 197 | cycrow | 3309 | 	Utils::WString err;
 | 
        
           | 6 | cycrow | 3310 |   | 
        
           | 126 | cycrow | 3311 | 	switch (error)
 | 
        
           | 6 | cycrow | 3312 | 	{
 | 
        
           | 126 | cycrow | 3313 | 	case SPKERR_MALLOC:
 | 
        
           | 197 | cycrow | 3314 | 		err = L"Memory Failed";
 | 
        
           | 126 | cycrow | 3315 | 		break;
 | 
        
           |  |  | 3316 | 	case SPKERR_FILEOPEN:
 | 
        
           | 197 | cycrow | 3317 | 		err = L"Failed to open file";
 | 
        
           | 126 | cycrow | 3318 | 		break;
 | 
        
           |  |  | 3319 | 	case SPKERR_FILEREAD:
 | 
        
           | 197 | cycrow | 3320 | 		err = L"Failed to read file";
 | 
        
           | 126 | cycrow | 3321 | 		break;
 | 
        
           |  |  | 3322 | 	case SPKERR_UNCOMPRESS:
 | 
        
           | 197 | cycrow | 3323 | 		err = L"Failed to Uncompress";
 | 
        
           | 126 | cycrow | 3324 | 		break;
 | 
        
           |  |  | 3325 | 	case SPKERR_WRITEFILE:
 | 
        
           | 197 | cycrow | 3326 | 		err = L"Failed to write file";
 | 
        
           | 126 | cycrow | 3327 | 		break;
 | 
        
           |  |  | 3328 | 	case SPKERR_CREATEDIRECTORY:
 | 
        
           | 197 | cycrow | 3329 | 		err = L"Failed to create directory";
 | 
        
           | 126 | cycrow | 3330 | 		break;
 | 
        
           |  |  | 3331 | 	case SPKERR_FILEMISMATCH:
 | 
        
           | 197 | cycrow | 3332 | 		err = L"File count mismatch";
 | 
        
           | 126 | cycrow | 3333 | 		break;
 | 
        
           | 6 | cycrow | 3334 | 	}
 | 
        
           |  |  | 3335 |   | 
        
           | 134 | cycrow | 3336 | 	if (!err.empty())
 | 
        
           | 6 | cycrow | 3337 | 	{
 | 
        
           | 134 | cycrow | 3338 | 		if (!errorStr.empty())
 | 
        
           | 6 | cycrow | 3339 | 		{
 | 
        
           | 197 | cycrow | 3340 | 			err += L" (";
 | 
        
           |  |  | 3341 | 			err += errorStr + L")";
 | 
        
           | 6 | cycrow | 3342 | 		}
 | 
        
           |  |  | 3343 | 		return err;
 | 
        
           |  |  | 3344 | 	}
 | 
        
           |  |  | 3345 |   | 
        
           | 197 | cycrow | 3346 | 	return Utils::WString::Number((long)error);
 | 
        
           | 6 | cycrow | 3347 | }
 | 
        
           |  |  | 3348 |   | 
        
           | 210 | cycrow | 3349 | bool CBaseFile::saveToArchive(const Utils::WString &filename, int game, const CGameExe *exes, CProgressInfo *progress)
 | 
        
           | 131 | cycrow | 3350 | {
 | 
        
           |  |  | 3351 | 	CDirIO Dir(CFileIO(filename).dir());
 | 
        
           |  |  | 3352 | 	if (!Dir.exists())
 | 
        
           |  |  | 3353 | 		Dir.create();
 | 
        
           |  |  | 3354 |   | 
        
           | 210 | cycrow | 3355 | 	HZIP hz = CreateZip(filename.c_str(), 0);
 | 
        
           | 126 | cycrow | 3356 | 	if (!hz) return false;
 | 
        
           | 6 | cycrow | 3357 |   | 
        
           |  |  | 3358 | 	// read files and compress
 | 
        
           |  |  | 3359 | 	ReadAllFilesToMemory();
 | 
        
           | 126 | cycrow | 3360 | 	if (!UncompressAllFiles(progress))
 | 
        
           | 6 | cycrow | 3361 | 	{
 | 
        
           |  |  | 3362 | 		CloseZip(hz);
 | 
        
           |  |  | 3363 | 		return false;
 | 
        
           |  |  | 3364 | 	}
 | 
        
           |  |  | 3365 |   | 
        
           | 126 | cycrow | 3366 | 	for (CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next())
 | 
        
           | 6 | cycrow | 3367 | 	{
 | 
        
           | 126 | cycrow | 3368 | 		if (game != -1) {
 | 
        
           | 127 | cycrow | 3369 | 			if (game && !(node->Data()->game() & (1 << game)))
 | 
        
           | 6 | cycrow | 3370 | 				continue;
 | 
        
           | 127 | cycrow | 3371 | 			// extracting for all games, so ignore files that have a game set
 | 
        
           |  |  | 3372 | 			if (!game && node->Data()->game() && node->Data()->game() != GAME_ALLNEW)
 | 
        
           | 6 | cycrow | 3373 | 				continue;
 | 
        
           |  |  | 3374 | 		}
 | 
        
           | 197 | cycrow | 3375 | 		Utils::WString fname = node->Data()->getNameDirectory(this);
 | 
        
           | 126 | cycrow | 3376 |   | 
        
           |  |  | 3377 | 		// use the addon directory
 | 
        
           |  |  | 3378 | 		if (node->Data()->isFileInAddon() && exes)
 | 
        
           |  |  | 3379 | 		{
 | 
        
           | 127 | cycrow | 3380 | 			unsigned int whatGame = game;
 | 
        
           | 126 | cycrow | 3381 | 			if (game == -1)
 | 
        
           | 127 | cycrow | 3382 | 			{
 | 
        
           |  |  | 3383 | 				unsigned int checkGame = node->Data()->game() & ~GAME_ALLNEW;
 | 
        
           |  |  | 3384 | 				whatGame = 0;
 | 
        
           |  |  | 3385 | 				for (int i = 0; i < 31; ++i)
 | 
        
           |  |  | 3386 | 				{
 | 
        
           |  |  | 3387 | 					if (1 << i == checkGame)
 | 
        
           |  |  | 3388 | 					{
 | 
        
           |  |  | 3389 | 						whatGame = i;
 | 
        
           |  |  | 3390 | 						break;
 | 
        
           |  |  | 3391 | 					}
 | 
        
           |  |  | 3392 | 				}
 | 
        
           |  |  | 3393 | 			}
 | 
        
           | 126 | cycrow | 3394 |   | 
        
           | 127 | cycrow | 3395 | 			if (whatGame > 0)
 | 
        
           | 126 | cycrow | 3396 | 			{
 | 
        
           | 197 | cycrow | 3397 | 				SGameExe *e = exes->game(whatGame - 1);
 | 
        
           | 127 | cycrow | 3398 | 				if (e)
 | 
        
           |  |  | 3399 | 				{
 | 
        
           |  |  | 3400 | 					if (e->iFlags & EXEFLAG_ADDON)
 | 
        
           | 197 | cycrow | 3401 | 						fname = e->sAddon + L"/" + fname;
 | 
        
           | 127 | cycrow | 3402 | 				}
 | 
        
           | 126 | cycrow | 3403 | 			}
 | 
        
           |  |  | 3404 | 		}
 | 
        
           |  |  | 3405 |   | 
        
           | 6 | cycrow | 3406 | 		// create the directory
 | 
        
           | 197 | cycrow | 3407 | 		//wsprintf(buf, L"%hs", fname.c_str());
 | 
        
           | 127 | cycrow | 3408 | 		if (node->Data()->isExternalFile())
 | 
        
           |  |  | 3409 | 		{
 | 
        
           |  |  | 3410 | 			CFileIO file(node->Data()->filePointer());
 | 
        
           |  |  | 3411 | 			size_t size = 0;
 | 
        
           |  |  | 3412 | 			unsigned char *data = file.readAll(&size);
 | 
        
           | 197 | cycrow | 3413 | 			ZipAdd(hz, fname.c_str(), data, size);
 | 
        
           | 127 | cycrow | 3414 | 			delete data;
 | 
        
           |  |  | 3415 | 		}
 | 
        
           |  |  | 3416 | 		else
 | 
        
           | 197 | cycrow | 3417 | 			ZipAdd(hz, fname.c_str(), node->Data()->GetData(), node->Data()->GetDataSize());
 | 
        
           | 6 | cycrow | 3418 | 	}
 | 
        
           |  |  | 3419 |   | 
        
           | 109 | cycrow | 3420 | 	// if its a ship, then add any generated files
 | 
        
           |  |  | 3421 | 	this->addGeneratedFiles(hz);
 | 
        
           |  |  | 3422 |   | 
        
           | 6 | cycrow | 3423 | 	// add the data file
 | 
        
           | 210 | cycrow | 3424 | 	Utils::WStringList list;
 | 
        
           |  |  | 3425 | 	Utils::WStringList addons;
 | 
        
           | 127 | cycrow | 3426 | 	if ( this->GeneratePackagerScript(false, &list, game, addons, true) )
 | 
        
           | 6 | cycrow | 3427 | 	{
 | 
        
           | 210 | cycrow | 3428 | 		if ( CFileIO(L"test.tmp").writeFile(&list) )
 | 
        
           | 6 | cycrow | 3429 | 		{
 | 
        
           |  |  | 3430 | 			ZipAdd(hz, L"pluginmanager.txt", L"test.tmp");
 | 
        
           | 210 | cycrow | 3431 | 			CFileIO::Remove(L"test.tmp");
 | 
        
           | 6 | cycrow | 3432 | 		}
 | 
        
           |  |  | 3433 | 	}
 | 
        
           |  |  | 3434 |   | 
        
           |  |  | 3435 | 	CloseZip(hz);
 | 
        
           |  |  | 3436 |   | 
        
           |  |  | 3437 | 	return true;
 | 
        
           |  |  | 3438 | }
 | 
        
           |  |  | 3439 |   | 
        
           | 210 | cycrow | 3440 | int CBaseFile::GetGameFromString(const Utils::WString &sGame)
 | 
        
           | 6 | cycrow | 3441 | {
 | 
        
           |  |  | 3442 | 	int iGame = GAME_ALL;
 | 
        
           | 210 | cycrow | 3443 | 	if ( sGame.Compare(L"ALL") )
 | 
        
           | 6 | cycrow | 3444 | 		iGame = GAME_ALL;
 | 
        
           | 210 | cycrow | 3445 | 	else if ( sGame.Compare(L"X3") )
 | 
        
           | 6 | cycrow | 3446 | 		iGame = GAME_X3;
 | 
        
           | 210 | cycrow | 3447 | 	else if ( sGame.Compare(L"X2") )
 | 
        
           | 6 | cycrow | 3448 | 		iGame = GAME_X2;
 | 
        
           | 210 | cycrow | 3449 | 	else if ( sGame.Compare(L"X3TC") )
 | 
        
           | 6 | cycrow | 3450 | 		iGame = GAME_X3TC;
 | 
        
           | 210 | cycrow | 3451 | 	else if (sGame.Compare(L"X3AP"))
 | 
        
           | 6 | cycrow | 3452 | 		iGame = GAME_X3AP;
 | 
        
           | 210 | cycrow | 3453 | 	else if (sGame.Compare(L"X3FL"))
 | 
        
           | 126 | cycrow | 3454 | 		iGame = GAME_X3FL;
 | 
        
           | 13 | cycrow | 3455 | 	else if ( sGame.isNumber() )
 | 
        
           |  |  | 3456 | 		iGame = sGame;
 | 
        
           | 6 | cycrow | 3457 |   | 
        
           |  |  | 3458 | 	return iGame;
 | 
        
           |  |  | 3459 | }
 | 
        
           |  |  | 3460 |   | 
        
           | 197 | cycrow | 3461 | Utils::WString CBaseFile::ConvertGameToString(int iGame)
 | 
        
           | 6 | cycrow | 3462 | {
 | 
        
           | 197 | cycrow | 3463 | 	Utils::WString game = L"ALL";
 | 
        
           | 6 | cycrow | 3464 |   | 
        
           |  |  | 3465 | 	switch(iGame) {
 | 
        
           |  |  | 3466 | 		case GAME_ALL:
 | 
        
           | 127 | cycrow | 3467 | 		case GAME_ALLNEW:
 | 
        
           | 197 | cycrow | 3468 | 			game = L"ALL";
 | 
        
           | 6 | cycrow | 3469 | 			break;
 | 
        
           |  |  | 3470 | 		case GAME_X2:
 | 
        
           | 197 | cycrow | 3471 | 			game = L"X2";
 | 
        
           | 6 | cycrow | 3472 | 			break;
 | 
        
           |  |  | 3473 | 		case GAME_X3:
 | 
        
           | 197 | cycrow | 3474 | 			game = L"X3";
 | 
        
           | 6 | cycrow | 3475 | 			break;
 | 
        
           |  |  | 3476 | 		case GAME_X3TC:
 | 
        
           | 197 | cycrow | 3477 | 			game = L"X3TC";
 | 
        
           | 6 | cycrow | 3478 | 			break;
 | 
        
           |  |  | 3479 | 		case GAME_X3AP:
 | 
        
           | 197 | cycrow | 3480 | 			game = L"X3AP";
 | 
        
           | 6 | cycrow | 3481 | 			break;
 | 
        
           | 126 | cycrow | 3482 | 		case GAME_X3FL:
 | 
        
           | 197 | cycrow | 3483 | 			game = L"X3FL";
 | 
        
           | 126 | cycrow | 3484 | 			break;
 | 
        
           | 6 | cycrow | 3485 | 		default:
 | 
        
           |  |  | 3486 | 			game = (long)iGame;
 | 
        
           |  |  | 3487 | 	}
 | 
        
           |  |  | 3488 |   | 
        
           |  |  | 3489 | 	return game;
 | 
        
           |  |  | 3490 | }
 | 
        
           |  |  | 3491 |   | 
        
           |  |  | 3492 | bool CBaseFile::IsGameInPackage(int game)
 | 
        
           |  |  | 3493 | {
 | 
        
           |  |  | 3494 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
 | 
        
           |  |  | 3495 | 		if ( node->Data()->GetGame() == game )
 | 
        
           |  |  | 3496 | 			return true;
 | 
        
           |  |  | 3497 | 	}
 | 
        
           |  |  | 3498 |   | 
        
           |  |  | 3499 | 	return false;
 | 
        
           |  |  | 3500 | }
 | 
        
           |  |  | 3501 |   | 
        
           |  |  | 3502 | bool CBaseFile::IsAnyGameInPackage()
 | 
        
           |  |  | 3503 | {
 | 
        
           |  |  | 3504 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
 | 
        
           |  |  | 3505 | 		if ( node->Data()->GetGame() )
 | 
        
           |  |  | 3506 | 			return true;
 | 
        
           |  |  | 3507 | 	}
 | 
        
           |  |  | 3508 |   | 
        
           |  |  | 3509 | 	return false;
 | 
        
           |  |  | 3510 | }
 | 
        
           |  |  | 3511 |   | 
        
           | 211 | cycrow | 3512 | Utils::WString builtInWares()
 | 
        
           | 88 | cycrow | 3513 | {
 | 
        
           | 211 | cycrow | 3514 | 	Utils::WString str;
 | 
        
           |  |  | 3515 | 	str += L"28;0;0;0;0;59;5753;0;35714;1;1;0;35714;-100000;0;0;SS_WARE_SW_NEW1;\n";
 | 
        
           |  |  | 3516 | 	str += L"28;0;0;0;0;60;5763;0;33232;1;1;0;33232;0;1043;0;SS_WARE_SW_NEW2;\n";
 | 
        
           |  |  | 3517 | 	str += L"28;0;0;0;0;61;5773;0;21428;1;1;0;21428;0;1043;0;SS_WARE_SW_NEW3;\n";
 | 
        
           |  |  | 3518 | 	str += L"28;0;0;0;0;62;5783;0;56;1;1;0;56;-100000;0;0;SS_WARE_SW_NEW4;\n";
 | 
        
           |  |  | 3519 | 	str += L"28;0;0;0;0;63;5793;0;88;1;1;0;88;-100000;0;0;SS_WARE_SW_NEW5;\n";
 | 
        
           |  |  | 3520 | 	str += L"28;0;0;0;0;64;5803;0;283;1;1;0;283;-100000;0;0;SS_WARE_SW_NEW6;\n";
 | 
        
           |  |  | 3521 | 	str += L"28;0;0;0;0;65;5813;0;383;1;1;0;383;-100000;0;0;SS_WARE_SW_NEW7;\n";
 | 
        
           |  |  | 3522 | 	str += L"28;0;0;0;0;66;5823;0;1389;1;1;0;1389;-100000;1043;0;SS_WARE_SW_NEW8;\n";
 | 
        
           |  |  | 3523 | 	str += L"28;0;0;0;0;67;5833;0;3396;1;1;0;3396;-100000;0;0;SS_WARE_SW_NEW9;\n";
 | 
        
           |  |  | 3524 | 	str += L"28;0;0;0;0;68;5843;0;4215;1;1;0;4215;-100000;0;0;SS_WARE_SW_NEW10;\n";
 | 
        
           |  |  | 3525 | 	str += L"28;0;0;0;0;69;5853;0;5635;1;1;0;5635;-100000;0;0;SS_WARE_SW_NEW11;\n";
 | 
        
           |  |  | 3526 | 	str += L"28;0;0;0;0;70;5863;0;65735;1;1;0;65735;-100000;0;0;SS_WARE_SW_NEW12;\n";
 | 
        
           |  |  | 3527 | 	str += L"28;0;0;0;0;71;5873;0;17857;1;1;0;17857;333;1043;0;SS_WARE_SW_NEW13;\n";
 | 
        
           |  |  | 3528 | 	str += L"28;0;0;0;0;72;5883;0;21428;1;1;0;21428;0;1043;0;SS_WARE_SW_NEW14;\n";
 | 
        
           |  |  | 3529 | 	str += L"28;0;0;0;0;73;5893;0;324515;1;1;0;324515;-100000;0;0;SS_WARE_SW_NEW15;\n";
 | 
        
           |  |  | 3530 | 	str += L"28;0;0;0;0;74;5903;0;638508;1;1;0;638508;-100000;0;0;SS_WARE_SW_NEW16;\n";
 | 
        
           |  |  | 3531 | 	str += L"28;0;0;0;0;75;5913;0;225755;1;1;0;225755;-100000;0;0;SS_WARE_SW_NEW17;\n";
 | 
        
           |  |  | 3532 | 	str += L"28;0;0;0;0;76;5923;0;1931535;1;1;0;1931535;1000;0;0;SS_WARE_SW_NEW18;\n";
 | 
        
           |  |  | 3533 | 	str += L"28;0;0;0;0;77;5933;0;2209150;1;1;0;2209150;-100000;0;0;SS_WARE_SW_NEW19;\n";
 | 
        
           |  |  | 3534 | 	str += L"28;0;0;0;0;78;5943;0;6727565;1;1;0;6727565;-100000;0;0;SS_WARE_SW_NEW20;\n";
 | 
        
           |  |  | 3535 | 	str += L"28;0;0;0;0;85;9999;0;105;1;5;0;105;0;1043;0;SS_WARE_SW_X3TC_1;\n";
 | 
        
           |  |  | 3536 | 	str += L"28;0;0;0;0;86;15053;0;105;1;5;0;105;0;1043;0;SS_WARE_SW_X3TC_2;\n";
 | 
        
           |  |  | 3537 | 	str += L"28;0;0;0;0;87;15063;0;105;1;5;0;105;0;1043;0;SS_WARE_SW_X3TC_3;\n";
 | 
        
           |  |  | 3538 | 	str += L"28;0;0;0;0;88;15073;0;105;1;5;0;105;0;1043;0;SS_WARE_SW_X3TC_4;\n";
 | 
        
           |  |  | 3539 | 	str += L"28;0;0;0;0;89;15083;0;105;1;5;0;105;0;1043;0;SS_WARE_SW_X3TC_5;\n";
 | 
        
           |  |  | 3540 | 	str += L"28;0;0;0;0;90;15093;0;105;1;5;0;105;0;1043;0;SS_WARE_SW_X3TC_6;\n";
 | 
        
           | 88 | cycrow | 3541 |   | 
        
           |  |  | 3542 | 	return str;
 | 
        
           |  |  | 3543 | }
 | 
        
           |  |  | 3544 |   | 
        
           | 197 | cycrow | 3545 | void CBaseFile::_addWaresToList(int iLang, CLinkList<SWareEntry> &list, const Utils::WString &wares, enum WareTypes eType)
 | 
        
           | 88 | cycrow | 3546 | {
 | 
        
           | 197 | cycrow | 3547 | 	std::vector<Utils::WString> w;
 | 
        
           |  |  | 3548 | 	wares.tokenise(L"\n", w);
 | 
        
           | 88 | cycrow | 3549 |   | 
        
           | 197 | cycrow | 3550 | 	for(size_t i = 0; i < w.size(); i++) {
 | 
        
           |  |  | 3551 | 		int textId = w[i].token(L";", 7).toLong();
 | 
        
           | 88 | cycrow | 3552 | 		int useLang = iLang;
 | 
        
           |  |  | 3553 | 		if ( !_pTextDB->exists(useLang, 17, textId) )
 | 
        
           |  |  | 3554 | 			useLang = 44;
 | 
        
           |  |  | 3555 | 		if ( !_pTextDB->exists(useLang, 17, textId) )
 | 
        
           |  |  | 3556 | 			useLang = 49;
 | 
        
           |  |  | 3557 | 		if ( _pTextDB->exists(useLang, 17, textId) ) {	
 | 
        
           |  |  | 3558 | 			SWareEntry *ware = new SWareEntry;
 | 
        
           |  |  | 3559 | 			ware->name = _pTextDB->get(useLang, 17, textId);
 | 
        
           |  |  | 3560 | 			ware->description = _pTextDB->get(useLang, 17, textId + 1);
 | 
        
           | 197 | cycrow | 3561 | 			ware->id = w[i].token(L";", -2);
 | 
        
           |  |  | 3562 | 			ware->relval = w[i].token(L";", 9).toLong();
 | 
        
           |  |  | 3563 | 			ware->notority = w[i].token(L";", 14).toLong();
 | 
        
           | 88 | cycrow | 3564 | 			ware->type = eType;
 | 
        
           |  |  | 3565 | 			ware->position = i;
 | 
        
           | 89 | cycrow | 3566 | 			ware->package = this;
 | 
        
           | 88 | cycrow | 3567 | 			list.push_back(ware);
 | 
        
           |  |  | 3568 | 		}
 | 
        
           |  |  | 3569 | 	}
 | 
        
           |  |  | 3570 | }
 | 
        
           |  |  | 3571 |   | 
        
           | 197 | cycrow | 3572 | bool CBaseFile::readWares(int iLang, CLinkList<SWareEntry> &list, const Utils::WString &empWares)
 | 
        
           | 88 | cycrow | 3573 | {
 | 
        
           |  |  | 3574 | 	_pTextDB->setLanguage(iLang);
 | 
        
           |  |  | 3575 |   | 
        
           |  |  | 3576 | 	// now go through all emp wares and get the ones we have text for
 | 
        
           |  |  | 3577 | 	_addWaresToList(iLang, list, empWares, Ware_EMP);
 | 
        
           |  |  | 3578 | 	_addWaresToList(iLang, list, builtInWares(), Ware_BuiltIn);
 | 
        
           |  |  | 3579 |   | 
        
           | 89 | cycrow | 3580 | 	return true;
 | 
        
           |  |  | 3581 | }
 | 
        
           | 88 | cycrow | 3582 |   | 
        
           | 89 | cycrow | 3583 | bool CBaseFile::_readCommands(int iLang, int iStartID, CLinkList<SCommandSlot> &list)
 | 
        
           |  |  | 3584 | {
 | 
        
           |  |  | 3585 | 	_pTextDB->setLanguage(iLang);
 | 
        
           |  |  | 3586 |   | 
        
           |  |  | 3587 | 	for(int i = 2; i <= 13; i++) {
 | 
        
           |  |  | 3588 | 		for(int j = 0; j < 64; j++) {
 | 
        
           |  |  | 3589 | 			int id = (i * 100) + j;
 | 
        
           |  |  | 3590 | 			if ( _pTextDB->exists(iLang, iStartID + 2, id) ) {
 | 
        
           |  |  | 3591 | 				SCommandSlot *slot = new SCommandSlot;
 | 
        
           |  |  | 3592 | 				list.push_back(slot);
 | 
        
           |  |  | 3593 |   | 
        
           |  |  | 3594 | 				slot->id = _pTextDB->get(iLang, iStartID, id);
 | 
        
           |  |  | 3595 | 				slot->name = _pTextDB->get(iLang, iStartID + 2, id);
 | 
        
           |  |  | 3596 | 				slot->shortName = _pTextDB->get(iLang, iStartID + 3, id);
 | 
        
           |  |  | 3597 | 				slot->info = _pTextDB->get(iLang, iStartID + 14, id);
 | 
        
           |  |  | 3598 | 				slot->slot = id;
 | 
        
           |  |  | 3599 | 				slot->package = this;
 | 
        
           |  |  | 3600 |  			}
 | 
        
           |  |  | 3601 | 		}
 | 
        
           |  |  | 3602 | 	}
 | 
        
           |  |  | 3603 |   | 
        
           |  |  | 3604 | 	for(int i = 1400; i <= 2000; i++) {
 | 
        
           |  |  | 3605 | 		if ( _pTextDB->exists(iLang, iStartID + 2, i) ) {
 | 
        
           |  |  | 3606 | 			SCommandSlot *slot = new SCommandSlot;
 | 
        
           |  |  | 3607 | 			list.push_back(slot);
 | 
        
           |  |  | 3608 |   | 
        
           |  |  | 3609 | 			slot->id = _pTextDB->get(iLang, iStartID, i);
 | 
        
           |  |  | 3610 | 			slot->name = _pTextDB->get(iLang, iStartID + 2, i);
 | 
        
           |  |  | 3611 | 			slot->shortName = _pTextDB->get(iLang, iStartID + 3, i);
 | 
        
           |  |  | 3612 | 			slot->info = _pTextDB->get(iLang, iStartID + 14, i);
 | 
        
           |  |  | 3613 | 			slot->slot = i;
 | 
        
           |  |  | 3614 | 			slot->package = this;
 | 
        
           |  |  | 3615 | 		}
 | 
        
           |  |  | 3616 | 	}
 | 
        
           |  |  | 3617 |   | 
        
           |  |  | 3618 | 	for(int i = 6000; i <= 9999; i++) {
 | 
        
           |  |  | 3619 | 		if ( _pTextDB->exists(iLang, iStartID + 2, i) ) {
 | 
        
           |  |  | 3620 | 			SCommandSlot *slot = new SCommandSlot;
 | 
        
           |  |  | 3621 | 			list.push_back(slot);
 | 
        
           |  |  | 3622 |   | 
        
           |  |  | 3623 | 			slot->id = _pTextDB->get(iLang, iStartID, i);
 | 
        
           |  |  | 3624 | 			slot->name = _pTextDB->get(iLang, iStartID + 2, i);
 | 
        
           |  |  | 3625 | 			slot->shortName = _pTextDB->get(iLang, iStartID + 3, i);
 | 
        
           |  |  | 3626 | 			slot->info = _pTextDB->get(iLang, iStartID + 14, i);
 | 
        
           |  |  | 3627 | 			slot->slot = i;
 | 
        
           |  |  | 3628 | 			slot->package = this;
 | 
        
           |  |  | 3629 | 		}
 | 
        
           |  |  | 3630 | 	}
 | 
        
           |  |  | 3631 |   | 
        
           | 88 | cycrow | 3632 | 	return true;
 | 
        
           |  |  | 3633 | }
 | 
        
           |  |  | 3634 |   | 
        
           | 89 | cycrow | 3635 | bool CBaseFile::readWingCommands(int iLang, CLinkList<SCommandSlot> &list)
 | 
        
           |  |  | 3636 | {
 | 
        
           |  |  | 3637 | 	return _readCommands(iLang, 2028, list);
 | 
        
           |  |  | 3638 | }
 | 
        
           |  |  | 3639 |   | 
        
           |  |  | 3640 | bool CBaseFile::readCommands(int iLang, CLinkList<SCommandSlot> &list)
 | 
        
           |  |  | 3641 | {
 | 
        
           |  |  | 3642 | 	return _readCommands(iLang, 2008, list);
 | 
        
           |  |  | 3643 | }
 | 
        
           |  |  | 3644 |   | 
        
           | 6 | cycrow | 3645 | int CBaseFile::FindFirstGameInPackage()
 | 
        
           |  |  | 3646 | {
 | 
        
           |  |  | 3647 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
 | 
        
           |  |  | 3648 | 		if ( node->Data()->GetGame() )
 | 
        
           |  |  | 3649 | 			return node->Data()->GetGame();
 | 
        
           |  |  | 3650 | 	}
 | 
        
           |  |  | 3651 |   | 
        
           |  |  | 3652 | 	return 0;
 | 
        
           |  |  | 3653 | }
 | 
        
           |  |  | 3654 | bool CBaseFile::IsMultipleGamesInPackage()
 | 
        
           |  |  | 3655 | {
 | 
        
           |  |  | 3656 | 	int game = 0;
 | 
        
           |  |  | 3657 | 	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
 | 
        
           |  |  | 3658 | 		if ( node->Data()->GetGame() ) {
 | 
        
           |  |  | 3659 | 			if ( game != node->Data()->GetGame() )
 | 
        
           |  |  | 3660 | 				return true;
 | 
        
           |  |  | 3661 | 			game = node->Data()->GetGame();
 | 
        
           |  |  | 3662 | 		}
 | 
        
           |  |  | 3663 | 	}
 | 
        
           |  |  | 3664 |   | 
        
           |  |  | 3665 | 	return false;
 | 
        
           |  |  | 3666 | }
 |