Skip to content

Commit

Permalink
added ability to set subfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
Lachee committed Aug 23, 2023
1 parent 67c1b8c commit 795abe2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
5 changes: 4 additions & 1 deletion UnityPackageExporter/Package/Packer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Packer : IDisposable, IAsyncDisposable
/// <summary>Output file path. If a stream is given, this is null.</summary>
public string OutputPath { get; }

/// <summary>Sub Folder to write assets too</summary>
public string SubFolder { get; set; } = "";

private Stream _outStream;
private GZipOutputStream _gzStream;
private TarOutputStream _tarStream;
Expand Down Expand Up @@ -110,7 +113,7 @@ public async Task<bool> 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);
}
Expand Down
29 changes: 25 additions & 4 deletions UnityPackageExporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,25 +61,33 @@ static RootCommand BuildCommands()
getDefaultValue: () => "Assets"
);

var subFolderOpt = new Option<string>(
aliases: new[] { "--sub-folder", "-s" },
description: "Sets the child folder to all included files under.",
getDefaultValue: () => ""
);

var verboseOpt = new Option<NLog.LogLevel>(
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<string> assetPattern, IEnumerable<string> excludePattern, bool skipDep, string assetRoot, NLog.LogLevel verbose) =>
command.SetHandler(async (DirectoryInfo source, FileInfo output, IEnumerable<string> assetPattern, IEnumerable<string> excludePattern, bool skipDep, string assetRoot, string subFolder, NLog.LogLevel verbose) =>
{
// Setup the logger
// TODO: Make logger setup a middleware in command builder
Expand All @@ -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();
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "1.0.2"
"version": "1.0.3"
}

0 comments on commit 795abe2

Please sign in to comment.