JD2022-TU1/main/tools/apps/Packager/Tasks/FindBundleTask.cs

64 lines
No EOL
2.1 KiB
C#

using System;
using System.ComponentModel;
using System.Linq;
using JD.LogService;
using Packager.Parameters;
using PluginCommon.Bundle;
using TeaBox;
using Ubisoft.Collections;
using DirectoryInfo = System.IO.DirectoryInfo;
namespace Packager.Tasks
{
[DisplayName("Identify Bundles")]
public class FindBundleTask : Task
{
[Input("File to find in Bundles", IOCardinality.Multi, IOType.String)]
public ReferenceList FilesToFind { get; set; }
[Input("Bundle Directory path where the files are injected", IOCardinality.Multi, IOType.String)]
public SingleReference InjectionBundleDirectory { get; set; }
[Output("Bundle Name", IOType.String)]
public ReferenceList BundlePath = new ReferenceList();
public FindBundleTask()
{
FilesToFind = new ReferenceList();
InjectionBundleDirectory = new SingleReference();
}
protected override void StartInternal(BuildConfiguration profile, cookerWrapper cooker)
{
var injectionBundleDirectoryInfo = new DirectoryInfo(InjectionBundleDirectory.Value);
var bundleToUpdate = injectionBundleDirectoryInfo.GetFiles()
.Where(x => x.Name.EndsWith(@".ipk"))
.ToDictionary(x => x.FullName, x => new Bundle(x.FullName))
.Where(x => IsBundleContainsNeededFiles(x.Value)).ToList();
if (!bundleToUpdate.Any())
{
LogMessage("Mentioned files not found in the any of the .ipk bundle files", LogCategory.Error);
}
CollectionHelper.ForEach(
bundleToUpdate,
x =>
{
BundlePath.Add(x.Key);
x.Value.Dispose();
});
}
private bool IsBundleContainsNeededFiles(Bundle bundle)
{
if (FilesToFind.Any(file => bundle.FileList.Any(value => value.Contains(file))))
return true;
bundle.Dispose();
return false;
}
}
}