Subversion Repositories spk

Rev

Rev 266 | Rev 277 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 266 Rev 271
Line 1253... Line 1253...
1253
}
1253
}
1254
 
1254
 
1255
CBaseFile *CPackages::openPackage(const Utils::WString &file, int *error, CProgressInfo *progress, int readtype, int flags)
1255
CBaseFile *CPackages::openPackage(const Utils::WString &file, int *error, CProgressInfo *progress, int readtype, int flags)
1256
{
1256
{
1257
	int check = checkOpenPackage(file, error);
1257
	int check = checkOpenPackage(file, error);
1258
	if ( *error == -1 )
1258
	if (*error == -1)
1259
		return NULL;
1259
		return NULL;
1260
 
1260
 
1261
	CBaseFile *installFile = 0;
1261
	CBaseFile *installFile = 0;
1262
 
1262
 
1263
	if ( progress )
1263
	if ( progress )
Line 1278... Line 1278...
1278
					delete installFile;
1278
					delete installFile;
1279
					return NULL;
1279
					return NULL;
1280
				}
1280
				}
1281
				break;
1281
				break;
1282
			}
1282
			}
-
 
1283
			// try and open as archive
-
 
1284
			else if(CFileIO(file).isFileExtension(L"spk"))
-
 
1285
			{
-
 
1286
				if (_check_archive_fromZip(file))
-
 
1287
				{
-
 
1288
					installFile = createFromArchive(file, true);
-
 
1289
					if (installFile)
-
 
1290
						return installFile;
-
 
1291
				}
-
 
1292
			}
1283
			*error = INSTALLERR_INVALID;
1293
			*error = INSTALLERR_INVALID;
1284
			return NULL;
1294
			return NULL;
1285
		case SPKFILE_BASE:
1295
		case SPKFILE_BASE:
1286
			installFile = new CBaseFile();
1296
			installFile = new CBaseFile();
1287
			if ( !installFile->readFile(file, readtype, progress))
1297
			if ( !installFile->readFile(file, readtype, progress))
Line 4432... Line 4442...
4432
		}
4442
		}
4433
	}
4443
	}
4434
 
4444
 
4435
	// now lets shuffle the rest
4445
	// now lets shuffle the rest
4436
	// now find any packages with greater fake patchs and fill the gaps
4446
	// now find any packages with greater fake patchs and fill the gaps
-
 
4447
	std::vector<C_File*> fakepatches;
4437
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4448
	for (CListNode<C_File>* node = m_lFiles.Front(); node; node = node->next())
4438
	{
4449
	{
4439
		C_File *f = node->Data();
4450
		C_File* f = node->Data();
4440
		// already done?
4451
		// already done?
4441
		if ( doneList.FindData(f) ) 
4452
		if (doneList.FindData(f))
4442
			continue;
4453
			continue;
4443
 
4454
 
4444
		// only do files that are enabled
4455
		// only do files that are enabled
4445
		if ( f->IsDisabled() )
4456
		if (f->IsDisabled())
4446
			continue;
4457
			continue;
4447
 
4458
 
4448
		// check if the file is a fake patch
4459
		// check if the file is a fake patch
4449
		if ( !f->IsFakePatch() )
4460
		if (!f->IsFakePatch())
4450
			continue;
4461
			continue;
4451
 
4462
 
4452
		// we only want cat and dat files, all fake patchs should be, but incase theres an error in the package somewhere we can check
4463
		// we only want cat and dat files, all fake patchs should be, but incase theres an error in the package somewhere we can check
4453
		if (!f->checkFileExt(L"cat"))
4464
		if (!f->checkFileExt(L"cat"))
4454
			continue;
4465
			continue;
4455
 
4466
 
-
 
4467
		bool added = false;
-
 
4468
		int num = f->baseName().toInt();
-
 
4469
		for (auto itr = fakepatches.begin(); itr != fakepatches.end(); itr++)
-
 
4470
		{
-
 
4471
			int checkNum = (*itr)->baseName().toInt();
-
 
4472
			if (num < checkNum)
-
 
4473
			{
-
 
4474
				fakepatches.insert(itr, f);
-
 
4475
				added = true;
-
 
4476
				break;
-
 
4477
			}
-
 
4478
		}
-
 
4479
		if (!added)
-
 
4480
			fakepatches.push_back(f);
-
 
4481
	}
-
 
4482
 
-
 
4483
	for(auto itr = fakepatches.begin(); itr != fakepatches.end(); itr++)
-
 
4484
	{
4456
		// now lets check if its greater than our gap
4485
		// now lets check if its greater than our gap
4457
		int check = findNextFakePatch();
4486
		int check = findNextFakePatch();
4458
		int patchNum = f->filename().token(L".", 1).toInt();
4487
		int patchNum = (*itr)->filename().token(L".", 1).toInt();
4459
		if ( patchNum <= check )
4488
		if ( patchNum <= check )
4460
			continue;
4489
			continue;
4461
 
4490
 
4462
		shufflePatchTo(f, check, errors);
4491
		shufflePatchTo(*itr, check, errors);
4463
	}
4492
	}
4464
}
4493
}
4465
 
4494
 
4466
void CPackages::shufflePatchTo(C_File *file, int to, Utils::WStringList *errors)
4495
void CPackages::shufflePatchTo(C_File *file, int to, Utils::WStringList *errors)
4467
{
4496
{
Line 9487... Line 9516...
9487
#endif
9516
#endif
9488
 
9517
 
9489
	return archive;
9518
	return archive;
9490
}
9519
}
9491
 
9520
 
-
 
9521
bool CPackages::_check_archive_fromZip(const Utils::WString& filename) const
-
 
9522
{
-
 
9523
	HZIP hz = OpenZip(filename.c_str(), 0);
-
 
9524
	if (!hz)
-
 
9525
		return false;
-
 
9526
 
-
 
9527
	bool found = false;
-
 
9528
 
-
 
9529
	int index;
-
 
9530
	// move the files from the zip to the package
-
 
9531
	ZIPENTRY ze;
-
 
9532
	if (FindZipItem(hz, L"pluginmanager.txt", true, &index, &ze) == Z_OK)
-
 
9533
		found = true;
-
 
9534
	CloseZip(hz);
-
 
9535
 
-
 
9536
	return found;
-
 
9537
}
-
 
9538
 
9492
CBaseFile *CPackages::_archive_fromZip(const Utils::WString &filename, bool toInstall) const
9539
CBaseFile* CPackages::_archive_fromZip(const Utils::WString& filename, bool toInstall) const
9493
{
9540
{
9494
	CBaseFile *archive = NULL;
9541
	CBaseFile *archive = NULL;
9495
 
9542
 
9496
	HZIP hz = OpenZip(filename.c_str(), 0);
9543
	HZIP hz = OpenZip(filename.c_str(), 0);
9497
	if ( !hz ) 
9544
	if ( !hz ) 
Line 9599... Line 9646...
9599
	CBaseFile *archive = NULL;
9646
	CBaseFile *archive = NULL;
9600
	if ( CFileIO(filename).isFileExtension(L"rar") )
9647
	if ( CFileIO(filename).isFileExtension(L"rar") )
9601
		archive = this->_archive_fromRar(filename, toInstall);
9648
		archive = this->_archive_fromRar(filename, toInstall);
9602
	else if ( CFileIO(filename).isFileExtension(L"zip") )
9649
	else if ( CFileIO(filename).isFileExtension(L"zip") )
9603
		archive = this->_archive_fromZip(filename, toInstall);
9650
		archive = this->_archive_fromZip(filename, toInstall);
-
 
9651
	else
-
 
9652
		archive = this->_archive_fromZip(filename, false);
9604
 
9653
 
9605
	if ( archive ) {
9654
	if ( archive ) {
9606
		archive->setFilename(CFileIO(filename).changeFileExtension(L"spk"));
9655
		archive->setFilename(CFileIO(filename).changeFileExtension(L"spk"));
9607
		if ( toInstall )
9656
		if ( toInstall )
9608
			archive->setName(CFileIO(filename).filename());
9657
			archive->setName(CFileIO(filename).filename());