Example #1
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 #2
0
//////////////////////////////////////////////////////////////////////////
// findImportPath
BcPath CsCore::findImportPath( const BcPath& InputPath )
{
	for( TOverlayListIterator It( ImportOverlayPaths_.begin() ); It != ImportOverlayPaths_.end(); ++It )
	{
		BcPath AppendedPath = (*It);
		AppendedPath.join( InputPath );

		if( FsCore::pImpl()->fileExists( (*AppendedPath).c_str() ) )
		{
			return AppendedPath;
		}
	}

	// Use path passed in on fail.
	return InputPath;
}
Example #3
0
//////////////////////////////////////////////////////////////////////////
// shouldImportResource
BcBool CsCore::shouldImportResource( const BcPath& FileName, BcBool ForceImport )
{
	BcBool Import = BcFalse;

	// Only attempt import if the resource filename is valid.
	if( isValidResource( FileName ) )
	{
		// Only force import if the resource is actually valid.
		Import = ForceImport;

		// Check if the packed resource exists.
		BcPath PackedPath( "./PackedContent" );
		PackedPath.join( FileName.getFileName() );
		if( FsCore::pImpl()->fileExists( (*PackedPath).c_str() ) == BcFalse )
		{
			Import = BcTrue;
		}

		// Only do a dependancy check if we have a packed file.
		// Dependancies will be regenerated on import.
		if( Import == BcFalse )
		{
			// Load dependancies if we don't have any resident in memory.
			if( DependancyMap_.find( *FileName ) == DependancyMap_.end() )
			{
				loadDependancies( FileName );
			}
	
			// Grab dependancy list for file so we don't do more work than required.
			if( DependancyMap_.find( *FileName ) != DependancyMap_.end() )
			{
				CsDependancyList& DependancyList = DependancyMap_[ *FileName ];
		
				for( CsDependancyListIterator It( DependancyList.begin() ); It != DependancyList.end(); ++It )
				{
					if( (*It).hasChanged() == BcTrue )
					{
						// Update dependancy stats.
						(*It).updateStats();
		
						// Set import to true.
						Import = BcTrue;
					}
				}
			}
			else
			{
				// No dependancy list, do the import.
				Import = BcTrue;
			}
		}
	}

	return Import;	
}
Example #4
0
//////////////////////////////////////////////////////////////////////////
// isValidResource
BcBool CsCore::isValidResource( const BcPath& FileName ) const
{
	BcName ExtensionName = BcName( FileName.getExtension() );
	return ( ResourceFactoryInfoMap_.find( ExtensionName ) != ResourceFactoryInfoMap_.end() );
}
Example #5
0
//////////////////////////////////////////////////////////////////////////
// getPackagePackedPath
BcPath CsCore::getPackagePackedPath( const BcName& Package )
{
	BcPath Path;
	Path.join( "PackedContent", *Package + ".pak" );
	return Path;
}
Example #6
0
//////////////////////////////////////////////////////////////////////////
// getPackageImportPath
BcPath CsCore::getPackageImportPath( const BcName& Package )
{
	BcPath Path;
	Path.join( "Content", *Package + ".pkg" );
	return Path;
}