Example #1
0
void VersionBuilder::buildFromMultilayer()
{
	QLOG_INFO() << "Building version from multilayered sources.";
	// just the builtin stuff for now
	auto minecraftList = MMC->minecraftlist();
	auto mcversion = minecraftList->findVersion(m_instance->intendedVersionId());
	auto minecraftPatch = std::dynamic_pointer_cast<VersionPatch>(mcversion);
	if (!minecraftPatch)
	{
		throw VersionIncomplete("net.minecraft");
	}
	minecraftPatch->setOrder(-2);
	m_version->VersionPatches.append(minecraftPatch);

	// TODO: this is obviously fake.
	QResource LWJGL(":/versions/LWJGL/2.9.1.json");
	auto lwjgl = parseJsonFile(LWJGL.absoluteFilePath(), false, false);
	auto lwjglPatch = std::dynamic_pointer_cast<VersionPatch>(lwjgl);
	if (!lwjglPatch)
	{
		throw VersionIncomplete("org.lwjgl");
	}
	lwjglPatch->setOrder(-1);
	m_version->VersionPatches.append(lwjglPatch);

	// load all patches, put into map for ordering, apply in the right order
	readInstancePatches();

	m_version->finalize();
}
Example #2
0
//////////////////////////////////////////////////////////////////////////
// internalImportResource
BcBool CsCore::internalImportResource( const BcPath& FileName, CsResourceRef<>& Handle, CsDependancyList* pDependancyList, BcBool ForceImport )
{
	BcScopedLock< BcMutex > Lock( ContainerLock_ );

	BcPrintf("CsCore: Importing \"%s\"\n", (*FileName).c_str());

	// Only import if we should. Otherwise just request.
	if( shouldImportResource( FileName, ForceImport ) == BcFalse )
	{
		BcPrintf(" - Does not require import.\n" );
		return internalRequestResource( FileName.getFileNameNoExtension(), FileName.getExtension(), Handle );
	}
	
	// Parse Json file.
	Json::Value Object;
	if( parseJsonFile( (*findImportPath( FileName )).c_str(), Object ) )
	{
		BcBool Success = BcFalse;
		
		if( pDependancyList == NULL )
		{
			CsDependancyList DependancyList;
			Success = internalImportObject( Object, Handle, &DependancyList, ForceImport );
			
			for( CsDependancyListIterator Iter( DependancyList.begin() ); Iter != DependancyList.end(); ++Iter )
			{
				// Add file for monitoring.
				FsCore::pImpl()->addFileMonitor( (*((*Iter).getFileName())).c_str() );
			}
			
			// Store dependancy list in map for reimporting on file modification.
			DependancyMap_[ *FileName ] = DependancyList;
		}
		else
		{
			Success = internalImportObject( Object, Handle, pDependancyList, ForceImport );
		}

		// Add to import map (doesn't matter if reference is bad, it's just for debugging)
		ResourceImportMap_[ *FileName ] = Handle;

		// If we've successfully imported, save dependancies.
		if( Success == BcTrue )
		{
			saveDependancies( FileName );

			BcPrintf(" - SUCCESS!\n" );
		}
		// Return success.
		return Success;
	}

	BcPrintf(" - FAILURE\n" );

	return BcFalse;
}
Example #3
0
void VersionBuilder::buildFromCustomJson()
{
	QLOG_INFO() << "Building version from custom.json within the instance.";
	QLOG_INFO() << "Reading custom.json";
	auto file = parseJsonFile(QFileInfo(instance_root.absoluteFilePath("custom.json")), false);
	file->name = "custom.json";
	file->filename = "custom.json";
	file->fileId = "org.multimc.custom.json";
	file->order = -1;
	file->version = QString();
	m_version->VersionPatches.append(file);
	m_version->finalize();
	return;
}
Example #4
0
void VersionBuilder::buildFromVersionJson()
{
	QLOG_INFO() << "Building version from version.json and patches within the instance.";
	QLOG_INFO() << "Reading version.json";
	auto file = parseJsonFile(QFileInfo(instance_root.absoluteFilePath("version.json")), false);
	file->name = "Minecraft";
	file->fileId = "org.multimc.version.json";
	file->order = -1;
	file->version = m_instance->intendedVersionId();
	file->mcVersion = m_instance->intendedVersionId();
	m_version->VersionPatches.append(file);

	// load all patches, put into map for ordering, apply in the right order
	readInstancePatches();

	// some final touches
	m_version->finalize();
}
Example #5
0
void VersionBuilder::buildFromExternalPatches()
{
	QLOG_INFO() << "Building version from external files.";
	int externalOrder = -1;
	for (auto fileName : external_patches)
	{
		QLOG_INFO() << "Reading" << fileName;
		auto file = parseJsonFile(QFileInfo(fileName), false, fileName.endsWith("pack.json"));
		file->name = QFileInfo(fileName).fileName();
		file->fileId = "org.multimc.external." + file->name;
		file->order = (externalOrder += 1);
		file->version = QString();
		file->mcVersion = QString();
		m_version->VersionPatches.append(file);
	}
	// some final touches
	m_version->finalize();
}
Example #6
0
void VersionBuilder::readInstancePatches()
{
	PatchOrder userOrder;
	readOverrideOrders(m_instance, userOrder);
	QDir patches(instance_root.absoluteFilePath("patches/"));

	// first, load things by sort order.
	for (auto id : userOrder)
	{
		// ignore builtins
		if (id == "net.minecraft")
			continue;
		if (id == "org.lwjgl")
			continue;
		// parse the file
		QString filename = patches.absoluteFilePath(id + ".json");
		QFileInfo finfo(filename);
		if(!finfo.exists())
		{
			QLOG_INFO() << "Patch file " << filename << " was deleted by external means...";
			continue;
		}
		QLOG_INFO() << "Reading" << filename << "by user order";
		auto file = parseJsonFile(finfo, false);
		// sanity check. prevent tampering with files.
		if (file->fileId != id)
		{
			throw VersionBuildError(
				QObject::tr("load id %1 does not match internal id %2").arg(id, file->fileId));
		}
		m_version->VersionPatches.append(file);
	}
	// now load the rest by internal preference.
	QMap<int, QPair<QString, VersionFilePtr>> files;
	for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files))
	{
		// parse the file
		QLOG_INFO() << "Reading" << info.fileName();
		auto file = parseJsonFile(info, true);
		// ignore builtins
		if (file->fileId == "net.minecraft")
			continue;
		if (file->fileId == "org.lwjgl")
			continue;
		// do not load what we already loaded in the first pass
		if (userOrder.contains(file->fileId))
			continue;
		if (files.contains(file->order))
		{
			// FIXME: do not throw?
			throw VersionBuildError(QObject::tr("%1 has the same order as %2")
										.arg(file->fileId, files[file->order].second->fileId));
		}
		files.insert(file->order, qMakePair(info.fileName(), file));
	}
	for (auto order : files.keys())
	{
		auto &filePair = files[order];
		m_version->VersionPatches.append(filePair.second);
	}
}