List<AssetSource> GatherAssetFiles ( string[] ignorePatterns, IniData iniData, BuildContext context, ref BuildResult result )
{
var assetSources = new List<AssetSource>();
// key contain key path
// value containt full path
var files = new List<LocalFile>();
// gather files from all directories
// and then distinct them by key path.
foreach ( var contentDir in context.ContentDirectories ) {
var localFiles = Directory.EnumerateFiles( contentDir, "*", SearchOption.AllDirectories )
.Where( f1 => Path.GetFileName(f1).ToLowerInvariant() != ".content" );
files.AddRange( localFiles.Select( fullpath => new LocalFile( contentDir, fullpath ) ) );
}
files = files.DistinctBy( file => file.KeyPath ).ToList();
result.Total = files.Count;
// ignore files by ignore pattern
// and count ignored files :
result.Ignored = files.RemoveAll( file => {
foreach ( var pattern in ignorePatterns ) {
if (Wildcard.Match( file.KeyPath, pattern )) {
return true;
}
}
return false;
});
foreach ( var section in iniData.Sections ) {
// 'Ingore' is a special section.
if (section.SectionName=="Ignore") { continue; }
if (section.SectionName=="ContentDirectories") { continue; }
if (section.SectionName=="BinaryDirectories") { continue; }
if (section.SectionName=="Download") { continue; }
// get processor :
if (!processors.ContainsKey(section.SectionName)) {
Log.Warning("Asset processor '{0}' not found. Files will be skipped.", section.SectionName );
Log.Message("");
continue;
}
var procBind = processors[section.SectionName];
// get mask and arguments :
var maskArgs = section.Keys
.Reverse()
.Select( key => new {
Mask = key.KeyName.Split(' ', '\t').FirstOrDefault(),
Args = CommandLineParser.SplitCommandLine( key.KeyName ).Skip(1).ToArray()
})
.ToList();
foreach ( var file in files ) {
if (file.Handled) {
continue;
}
foreach ( var maskArg in maskArgs ) {
if ( Wildcard.Match( file.KeyPath, maskArg.Mask, true ) ) {
file.Handled = true;
assetSources.Add( new AssetSource( file.KeyPath, file.BaseDir, procBind.Type, maskArg.Args, context ) );
break;
}
}
}
// count unhandled files :
result.Skipped = files.Count( f => !f.Handled );
}
return assetSources;
}