diff --git a/UnityPackageExporter/Package/Packer.cs b/UnityPackageExporter/Package/Packer.cs index 2926c48..54aeec3 100644 --- a/UnityPackageExporter/Package/Packer.cs +++ b/UnityPackageExporter/Package/Packer.cs @@ -19,6 +19,9 @@ class Packer : IDisposable, IAsyncDisposable /// Output file path. If a stream is given, this is null. public string OutputPath { get; } + /// Sub Folder to write assets too + public string SubFolder { get; set; } = ""; + private Stream _outStream; private GZipOutputStream _gzStream; private TarOutputStream _tarStream; @@ -110,7 +113,7 @@ public async Task AddAssetAsync(string filePath) await _tarStream.WriteFileAsync(file.FullName, $"{guidString}/asset"); await _tarStream.WriteAllTextAsync($"{guidString}/asset.meta", metaContents); - string pathname = relativePath.Replace('\\', '/'); + string pathname = Path.Combine(SubFolder, relativePath).Replace('\\', '/'); if (!pathname.StartsWith("Assets/")) pathname = $"Assets/{pathname}"; await _tarStream.WriteAllTextAsync($"{guidString}/pathname", pathname); } diff --git a/UnityPackageExporter/Program.cs b/UnityPackageExporter/Program.cs index aa7663d..08c0b31 100644 --- a/UnityPackageExporter/Program.cs +++ b/UnityPackageExporter/Program.cs @@ -6,6 +6,7 @@ using System.Collections; using System.Collections.Generic; using System.CommandLine; +using System.CommandLine.Binding; using System.Diagnostics; using System.IO; using System.Linq; @@ -60,25 +61,33 @@ static RootCommand BuildCommands() getDefaultValue: () => "Assets" ); + var subFolderOpt = new Option( + aliases: new[] { "--sub-folder", "-s" }, + description: "Sets the child folder to all included files under.", + getDefaultValue: () => "" + ); + var verboseOpt = new Option( aliases: new[] { "--verbose", "--log-level", "-v" }, description: "Sets the logging level", getDefaultValue: () => NLog.LogLevel.Trace ); + //var command = new Command(name: "pack", description: "Packs the assets in a Unity Project") var command = new RootCommand(description: "Packs the assets in a Unity Project") { sourceArg, outputArg, - assetPatternOpt, + assetPatternOpt, excludePatternOpt, skipDepOpt, assetRootOpt, + subFolderOpt, verboseOpt, }; - command.SetHandler(async (DirectoryInfo source, FileInfo output, IEnumerable assetPattern, IEnumerable excludePattern, bool skipDep, string assetRoot, NLog.LogLevel verbose) => + command.SetHandler(async (DirectoryInfo source, FileInfo output, IEnumerable assetPattern, IEnumerable excludePattern, bool skipDep, string assetRoot, string subFolder, NLog.LogLevel verbose) => { // Setup the logger // TODO: Make logger setup a middleware in command builder @@ -100,7 +109,10 @@ await Logger.Swallow(async () => Stopwatch timer = Stopwatch.StartNew(); using DependencyAnalyser analyser = !skipDep ? await DependencyAnalyser.CreateAsync(Path.Combine(source.FullName, assetRoot), excludePattern) : null; - using Packer packer = new Packer(source.FullName, output.FullName); + using Packer packer = new Packer(source.FullName, output.FullName) + { + SubFolder = subFolder + }; // Match all the assets we need Matcher assetMatcher = new Matcher(); @@ -121,8 +133,17 @@ await Logger.Swallow(async () => //await packer.FlushAsync(); Logger.Info("Finished Packing in {0}ms", timer.ElapsedMilliseconds); }); - }, sourceArg, outputArg, assetPatternOpt, excludePatternOpt, skipDepOpt, assetRootOpt, verboseOpt); + }, sourceArg, + outputArg, + assetPatternOpt, + excludePatternOpt, + skipDepOpt, + assetRootOpt, + subFolderOpt, + verboseOpt); + //This is a good alternative but ordering breaks + // var opts = command.Children.Select(arg => arg as IValueDescriptor).ToArray(); return command; } diff --git a/package.json b/package.json index 19d87fe..5f0d6c7 100644 --- a/package.json +++ b/package.json @@ -1,3 +1,3 @@ { - "version": "1.0.2" + "version": "1.0.3" } \ No newline at end of file