89 lines
3.1 KiB
C#
89 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using ITF_StringID;
|
|
|
|
using Packager.Parameters;
|
|
|
|
using PluginCommon.Bundle;
|
|
|
|
namespace Packager.Tasks
|
|
{
|
|
public class CrcAndFilePaths
|
|
{
|
|
public string Crc { get; set; }
|
|
public string FilePath { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{Crc}\t{FilePath}";
|
|
}
|
|
}
|
|
|
|
class GenerateFilePathStringIdTask : Task
|
|
{
|
|
[Input("Input Directory", IOCardinality.Single, IOType.String)]
|
|
public ReferenceList InputdirectoryPath { get; set; }
|
|
|
|
[Output("File with string ids", IOType.File)]
|
|
public ReferenceList StringIdOutputFolders = new ReferenceList();
|
|
|
|
public GenerateFilePathStringIdTask()
|
|
{
|
|
InputdirectoryPath = new ReferenceList();
|
|
}
|
|
|
|
protected override void StartInternal(BuildConfiguration profile, cookerWrapper cooker)
|
|
{
|
|
try
|
|
{
|
|
foreach (var inputDirectory in InputdirectoryPath)
|
|
{
|
|
var allBundlesPresentInDirectory = Directory.GetFiles(inputDirectory, "*.ipk", SearchOption.AllDirectories);
|
|
foreach (var file in allBundlesPresentInDirectory)
|
|
{
|
|
var crcAndFile = new List<CrcAndFilePaths>();
|
|
|
|
var bundle = new Bundle(file);
|
|
|
|
foreach (var item in bundle.FileList)
|
|
{
|
|
var stringid = StringID.ComputeCRC(item);
|
|
var key = "0X" + $"{stringid:X8}";
|
|
crcAndFile.Add(new CrcAndFilePaths() { Crc = key, FilePath = item });
|
|
}
|
|
|
|
bundle.Dispose();
|
|
|
|
var fileNameWithoutExtention = Path.GetFileNameWithoutExtension(file);
|
|
var parentFolderOfBundle = Directory.GetParent(file).FullName.Replace(":", string.Empty);
|
|
var fileIdentificationName = Path.Combine(parentFolderOfBundle, fileNameWithoutExtention).Replace("\\", "_i_");
|
|
var outputFilePath = string.Format(TaskOutputFolder + "\\({0}).extra", fileIdentificationName);
|
|
WriteOutputFile(outputFilePath, crcAndFile);
|
|
StringIdOutputFolders.Add(outputFilePath);
|
|
|
|
LogMessage(false, Path.GetFileName(file) + @" - Done");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception($"Exception occurred in computing crc thread, while generating string ids from bundle : {ex.Message}");
|
|
}
|
|
}
|
|
|
|
private void WriteOutputFile(string outputFilePath, IEnumerable<CrcAndFilePaths> crcAndFile)
|
|
{
|
|
using (var file = new StreamWriter(outputFilePath, true))
|
|
{
|
|
foreach (var content in crcAndFile)
|
|
{
|
|
file.WriteLine(content);
|
|
}
|
|
LogMessage(false, @"File" + outputFilePath + "Generated !!!");
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|