From 65cf0df3669c723895d8a591e7f4929b44686783 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 26 Feb 2019 23:55:58 -0800 Subject: [PATCH] fixed some bugs in the T4 file --- .../T4Templates/ContentPathGenerator.tt | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/project_name/T4Templates/ContentPathGenerator.tt b/project_name/T4Templates/ContentPathGenerator.tt index 8740c90..9483dc2 100644 --- a/project_name/T4Templates/ContentPathGenerator.tt +++ b/project_name/T4Templates/ContentPathGenerator.tt @@ -20,29 +20,28 @@ namespace Nez // loop through all of our sourceFolders foreach( var sourceFolder in sourceFolders ) { - var directories = Directory.GetDirectories( sourceFolder ); + WriteLine( $"\t\t// folder: {sourceFolder}" ); + + // handle any files in the root sourceFolder + printContentFiles( sourceFolder, 2, sourceFolder ); + // loop through all the directories in our sourceFolder + var directories = Directory.GetDirectories( sourceFolder ); foreach( var dir in directories ) { var dirName = new DirectoryInfo( dir ).Name.ToLower(); if( dirName == "bin" || dirName == "obj" || dirName == "content" ) continue; - // dont delve into directories that don't contan xnb files - var xnbFiles = Directory.GetFiles( dir, "*.xnb", SearchOption.AllDirectories ); - if( xnbFiles.Length == 0 ) + // dont delve into directories that don't contan xnb files if this is the CompiledContent folder + if( !shouldTraverseSubfolders( dir ) ) continue; // start off the recursive directory printing printDirectoryClass( dir, 2, sourceFolder ); } - - // handle any files in the root sourceFolder - printContentFiles( sourceFolder, 2, sourceFolder ); } - #> - } } @@ -62,6 +61,16 @@ namespace Nez "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while" }; + bool shouldTraverseSubfolders( string path ) + { + if( !path.Contains( "/bin/" ) ) + { + return true; + } + + return Directory.GetFiles( path, "*.xnb", SearchOption.AllDirectories ).Length > 0; + } + // recursively creates a class for each directory void printDirectoryClass( string dir, int depth, string sourceFolder ) { @@ -93,7 +102,14 @@ namespace Nez // clear out all of the path up to the sourceFolder so we get just the relative path to the Content folder var finalPath = file.Substring( file.IndexOf( sourceFolder ) + sourceFolder.Length ); var fileInfo = new FileInfo( file ); - var fileName = fileInfo.Name.Replace( ".xnb", string.Empty ); + var fileName = fileInfo.Name; + + // clean the extension + foreach( var extension in fileExtensionsToCopy ) + { + fileName = fileName.Replace( extension, string.Empty ); + } + var className = generateClassName( fileName, false ); if( finalPath[0] == '/' || finalPath[0] == '\\' ) @@ -105,6 +121,11 @@ namespace Nez WriteLine( "{0}public const string {1} = @\"{2}\";", firstIndent, className, finalPath ); } + + if( files.Count() > 0 ) + { + WriteLine( "" ); + } }