Skip to content

Commit

Permalink
Merge pull request #4 from EonZeNx/feature/update-03
Browse files Browse the repository at this point in the history
Feature/update 03
  • Loading branch information
EonZeNx authored Aug 13, 2024
2 parents 67e3927 + f336da4 commit b418aa4
Show file tree
Hide file tree
Showing 76 changed files with 2,270 additions and 349 deletions.
7 changes: 6 additions & 1 deletion ATL.CLI/ATL.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ApexChains\ApexChain.AAFSARC\ApexChain.AAFSARC.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.AAF.V01\ApexFormat.AAF.V01.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.ADF.V04\ApexFormat.ADF.V04.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.RTPC.V0104\ApexFormat.RTPC.V0104.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.AVTX.V01\ApexFormat.AVTX.V01.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.IRTPC.V14\ApexFormat.IRTPC.V14.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.RTPC.V01\ApexFormat.RTPC.V01.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.RTPC.V03\ApexFormat.RTPC.V03.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.SARC.V02\ApexFormat.SARC.V02.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.TAB.V02\ApexFormat.TAB.V02.csproj" />
<ProjectReference Include="..\ATL.Console\ATL.Console.csproj" />
<ProjectReference Include="..\ATL.Core\ATL.Core.csproj" />
<ProjectReference Include="..\ATL.Script\ATL.Script.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using CommandLine;

namespace ATL.CLI.Console;
namespace ATL.CLI;

public class AtlClOptions : ICloneable
{
Expand Down
99 changes: 30 additions & 69 deletions ATL.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using ApexChain.AAFSARC;
using ApexFormat.AAF.V01;
using ApexFormat.ADF.V04;
using ApexFormat.RTPC.V0104;
using ApexFormat.AVTX.V01;
using ApexFormat.IRTPC.V14;
using ApexFormat.RTPC.V01;
using ApexFormat.RTPC.V03;
using ApexFormat.SARC.V02;
using ApexFormat.TAB.V02;
using ATL.CLI.Console;
using ATL.Console;
using ATL.Core.Class;
using ATL.Core.Config;
using ATL.Core.Hash;
using ATL.Core.Libraries;
using ATL.Script;
using CommandLine;
using CommandLine.Text;

Expand Down Expand Up @@ -62,9 +67,13 @@ public static string[] FilterUnsupportedPaths(IEnumerable<string> inPaths)
if (TabV02Manager.CanProcess(inputPath) ||
SarcV02Manager.CanProcess(inputPath) ||
AafV01Manager.CanProcess(inputPath) ||
AafV01SarcV02Manager.CanProcess(inputPath) ||
AdfV04Manager.CanProcess(inputPath) ||
AvtxV01Manager.CanProcess(inputPath) ||
RtpcV01Manager.CanProcess(inputPath) ||
RtpcV0104Manager.CanProcess(inputPath)
RtpcV03Manager.CanProcess(inputPath) ||
IrtpcV14Manager.CanProcess(inputPath) ||
Path.GetExtension(inputPath) == ".xml"
) {
supportedPaths.Add(inputPath);
continue;
Expand Down Expand Up @@ -117,6 +126,12 @@ public static void MainWithOptions(AtlClOptions inOptions)

var paths = FilterUnsupportedPaths(options.InputPaths);

// if (Path.GetExtension(inPath) == ".xml")
// {
// manager = new ScriptManager();
// message = $"{message} as Script";
// }

#if DEBUG
for (var i = 0; i < paths.Length; i++)
{
Expand All @@ -130,6 +145,19 @@ public static void MainWithOptions(AtlClOptions inOptions)
#endif
}

public static void OperateFile(string inPath, string outDirectory)
{
if (Path.GetExtension(inPath) == ".xml")
{
var manager = new ScriptManager();
manager.ProcessBasic(inPath, outDirectory);

return;
}

AtlOperate.OperateFile(inPath, outDirectory);
}

public static void MainWithErrors(ParserResult<AtlClOptions> result, IEnumerable<Error> errors)
{
CoreConfig.AppConfig.Cli.AutoClose = false;
Expand All @@ -144,73 +172,6 @@ public static void MainWithErrors(ParserResult<AtlClOptions> result, IEnumerable

ConsoleLibrary.Log(helpText, ConsoleColor.White);
}

public static string GetAbsoluteDirectory(string inPath, string outDirectory)
{
var result = Path.GetDirectoryName(inPath) ?? inPath;

if (!string.IsNullOrEmpty(outDirectory))
{ // outDirectory is valid
result = Path.IsPathFullyQualified(outDirectory)
? outDirectory
: Path.GetFullPath(outDirectory, AppDomain.CurrentDomain.BaseDirectory);
}

return result;
}

public static void OperateFile(string inPath, string outDirectory)
{
var pathName = Path.GetFileName(inPath);
if (string.IsNullOrEmpty(pathName))
pathName = Path.GetDirectoryName(inPath);

var message = $"Processing '{pathName}'";

IProcessBasic manager;
if (TabV02Manager.CanProcess(inPath))
{
manager = new TabV02Manager();
message = $"{message} as TABv02";
}
else if (SarcV02Manager.CanProcess(inPath))
{
manager = new SarcV02Manager();
message = $"{message} as SARCv02";
}
else if (AafV01Manager.CanProcess(inPath))
{
manager = new AafV01Manager();
message = $"{message} as AAFv01";
}
else if (AdfV04Manager.CanProcess(inPath))
{
manager = new AdfV04Manager();
message = $"{message} as ADFv04";
}
else if (RtpcV01Manager.CanProcess(inPath))
{
manager = new RtpcV01Manager();
message = $"{message} as RTPCv01";
}
else if (RtpcV0104Manager.CanProcess(inPath))
{ // should be last
manager = new RtpcV0104Manager();
message = $"{message} as RTPCv0104";
}
else
{
ConsoleLibrary.Log($"File not supported '{pathName}'", LogType.Warning);
return;
}

ConsoleLibrary.Log(message, LogType.Info);

var absoluteOutDirectory = GetAbsoluteDirectory(inPath, outDirectory);
manager.ProcessBasic(inPath, absoluteOutDirectory);

ConsoleLibrary.Log($"Finished '{pathName}'", LogType.Info);
}

public static void CurrentDomain_ProcessExit(object? sender, EventArgs e)
{
Expand Down
22 changes: 22 additions & 0 deletions ATL.Console/ATL.Console.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ApexChains\ApexChain.AAFSARC\ApexChain.AAFSARC.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.AAF.V01\ApexFormat.AAF.V01.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.ADF.V04\ApexFormat.ADF.V04.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.AVTX.V01\ApexFormat.AVTX.V01.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.IRTPC.V14\ApexFormat.IRTPC.V14.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.RTPC.V01\ApexFormat.RTPC.V01.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.RTPC.V03\ApexFormat.RTPC.V03.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.SARC.V02\ApexFormat.SARC.V02.csproj" />
<ProjectReference Include="..\ApexFormats\ApexFormat.TAB.V02\ApexFormat.TAB.V02.csproj" />
<ProjectReference Include="..\ATL.Core\ATL.Core.csproj" />
</ItemGroup>

</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
100 changes: 100 additions & 0 deletions ATL.Console/AtlOperate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using ApexChain.AAFSARC;
using ApexFormat.AAF.V01;
using ApexFormat.ADF.V04;
using ApexFormat.AVTX.V01;
using ApexFormat.IRTPC.V14;
using ApexFormat.RTPC.V01;
using ApexFormat.RTPC.V03;
using ApexFormat.SARC.V02;
using ApexFormat.TAB.V02;
using ATL.Core.Class;
using ATL.Core.Libraries;

namespace ATL.Console;

public static class AtlOperate
{
public static void OperateFile(string inPath, string outDirectory)
{
var pathName = Path.GetFileName(inPath);
if (string.IsNullOrEmpty(pathName))
pathName = Path.GetDirectoryName(inPath);

var message = $"Processing '{pathName}'";

IProcessBasic manager;
if (TabV02Manager.CanProcess(inPath))
{
manager = new TabV02Manager();
message = $"{message} as TABv02";
}
else if (AafV01SarcV02Manager.CanProcess(inPath))
{
manager = new AafV01SarcV02Manager();
message = $"{message} as AAFv01-SARCv02 chain";
}
else if (SarcV02Manager.CanProcess(inPath))
{
manager = new SarcV02Manager();
message = $"{message} as SARCv02";
}
else if (AafV01Manager.CanProcess(inPath))
{
manager = new AafV01Manager();
message = $"{message} as AAFv01";
}
else if (AdfV04Manager.CanProcess(inPath))
{
manager = new AdfV04Manager();
message = $"{message} as ADFv04";
}
else if (AvtxV01Manager.CanProcess(inPath))
{
manager = new AvtxV01Manager();
message = $"{message} as AVTXv01";
}
else if (RtpcV01Manager.CanProcess(inPath))
{
manager = new RtpcV01Manager();
message = $"{message} as RTPCv01";
}
else if (RtpcV03Manager.CanProcess(inPath))
{
manager = new RtpcV03Manager();
message = $"{message} as RTPCv03";
}
else if (IrtpcV14Manager.CanProcess(inPath))
{ // should be last
manager = new IrtpcV14Manager();
message = $"{message} as RTPCv0104";
}
// Scripts should not be run from here
// else if (Path.GetExtension(inPath) == ".xml")
else
{
ConsoleLibrary.Log($"File not supported '{pathName}'", LogType.Warning);
return;
}

ConsoleLibrary.Log(message, LogType.Info);

var absoluteOutDirectory = GetAbsoluteDirectory(inPath, outDirectory);
manager.ProcessBasic(inPath, absoluteOutDirectory);

ConsoleLibrary.Log($"Finished '{pathName}'", LogType.Info);
}

public static string GetAbsoluteDirectory(string inPath, string outDirectory)
{
var result = Path.GetDirectoryName(inPath) ?? inPath;

if (!string.IsNullOrEmpty(outDirectory))
{ // outDirectory is valid
result = Path.IsPathFullyQualified(outDirectory)
? outDirectory
: Path.GetFullPath(outDirectory, AppDomain.CurrentDomain.BaseDirectory);
}

return result;
}
}
37 changes: 37 additions & 0 deletions ATL.Core/Extensions/IOLibrary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace ATL.Core.Extensions;

public static class IOLibrary
{
public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive = true)
{
// Get information about the source directory
var dir = new DirectoryInfo(sourceDir);

// Check if the source directory exists
if (!dir.Exists)
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");

// Cache directories before we start copying
var dirs = dir.GetDirectories();

// Create the destination directory
Directory.CreateDirectory(destinationDir);

// Get the files in the source directory and copy to the destination directory
foreach (var file in dir.GetFiles())
{
var targetFilePath = Path.Combine(destinationDir, file.Name);
file.CopyTo(targetFilePath);
}

// If recursive and copying subdirectories, recursively call this method
if (!recursive)
return;

foreach (var subDir in dirs)
{
var newDestinationDir = Path.Combine(destinationDir, subDir.Name);
CopyDirectory(subDir.FullName, newDestinationDir, true);
}
}
}
14 changes: 14 additions & 0 deletions ATL.Core/Extensions/StreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public static string ReadStringZ(this Stream stream)
// Hardcoded sanity check
while (charList.Count < 2048)
{
if (stream.Position == stream.Length)
break;

var newChar = stream.Read<byte>();
if (newChar == '\0')
break;
Expand Down Expand Up @@ -74,6 +77,17 @@ public static T[] ReadArrayLengthPrefix<T>(this Stream stream) where T : unmanag
return stream.ReadArray<T>(stream.Read<int>());
}

public static string[] ReadArrayStringZ(this Stream stream, int count)
{
var values = new string[count];
for (var i = 0; i < count; i++)
{
values[i] = stream.ReadStringZ();
}

return values;
}

public static void CopyToLimit(this Stream stream, Stream destination, int count) => stream.CopyToLimit(destination, count, 81920);
public static void CopyToLimit(this Stream stream, Stream destination, int count, int bufferSize)
{
Expand Down
1 change: 1 addition & 0 deletions ATL.Core/Hash/HashDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public IEnumerable<string> AddToTable(string[] values, EHashType hashType)
command.Transaction = transaction;
command.CommandType = CommandType.Text;
// TODO: Batch in 5 - 10 at a time?
// Ref: https://github.com/morelinq/MoreLINQ/blob/master/MoreLinq/Batch.cs
command.CommandText = $"INSERT OR IGNORE INTO '{hashTable}' (Hash, Value)" +
$"VALUES (@hash, @value)";

Expand Down
2 changes: 1 addition & 1 deletion ATL.Core/Libraries/ConstantsLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class ConstantsLibrary
{
public static string AppFullTitle => "Apex Tools & Launcher";
public static string AppTitle => "ATL";
public static string AppVersion => "v0.11.0";
public static string AppVersion => "v0.12.0";
public static int[] AppWindowSize => [1280, 900];

public static string AppConfigFileName = "atl_config";
Expand Down
14 changes: 14 additions & 0 deletions ATL.Script/ATL.Script.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ATL.Console\ATL.Console.csproj" />
<ProjectReference Include="..\ATL.Core\ATL.Core.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit b418aa4

Please sign in to comment.