mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
141 lines
4.2 KiB
C#
141 lines
4.2 KiB
C#
using AssetRipper.Export.UnityProjects;
|
|
using AssetRipper.Export.UnityProjects.Configuration;
|
|
using AssetRipper.Import.Logging;
|
|
using AssetRipper.Processing;
|
|
|
|
namespace AssetRipper.Tools.SystemTester
|
|
{
|
|
static class Program
|
|
{
|
|
private const string TestsDirectory = "../../Tests";
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
Logger.Add(new ConsoleLogger(true));
|
|
Logger.Add(new FileLogger("AssetRipper.Tools.SystemTester.log"));
|
|
Logger.LogSystemInformation("System Tester");
|
|
Logger.BlankLine();
|
|
|
|
if (args.Length == 0)
|
|
{
|
|
RunTests();
|
|
Console.ReadLine();
|
|
}
|
|
else
|
|
{
|
|
Rip(args, Path.Combine(AppContext.BaseDirectory, "Ripped"));
|
|
}
|
|
}
|
|
|
|
static void RunTests()
|
|
{
|
|
if (!Directory.Exists(TestsDirectory))
|
|
{
|
|
Logger.Log(LogType.Warning, LogCategory.General, "Tests folder did not exist. Creating...");
|
|
Directory.CreateDirectory(TestsDirectory);
|
|
Logger.Info(LogCategory.General, "Created. Program will now exit.");
|
|
return;
|
|
}
|
|
|
|
Logger.Info(LogCategory.General, $"Running tests in {Path.GetFullPath(TestsDirectory)}");
|
|
Logger.BlankLine();
|
|
|
|
int numTests = 0;
|
|
int numSuccessful = 0;
|
|
List<(string, string)> successfulTests = new();
|
|
List<(string, string)> unsuccessfulTests = new();
|
|
foreach (string versionPath in Directory.GetDirectories(TestsDirectory))
|
|
{
|
|
string versionName = Path.GetRelativePath(TestsDirectory, versionPath);
|
|
foreach (string testPath in Directory.GetDirectories(versionPath))
|
|
{
|
|
string testName = Path.GetRelativePath(versionPath, testPath);
|
|
Logger.Info(LogCategory.General, $"Found test: '{testName}' for Unity version: '{versionName}'");
|
|
numTests++;
|
|
string inputPath = Path.Combine(testPath, "Input");
|
|
if (!Directory.Exists(inputPath))
|
|
{
|
|
Logger.Log(LogType.Error, LogCategory.General, $"No input folder for '{testName}' on Unity version '{versionName}'");
|
|
unsuccessfulTests.Add((versionName, testName));
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
string[] inputFiles = Directory.GetFiles(inputPath);
|
|
string[] inputDirectories = Directory.GetDirectories(inputPath);
|
|
string[] inputPaths = Combine(inputFiles, inputDirectories);
|
|
string outputPath = Path.Combine(testPath, "Output");
|
|
Rip(inputPaths, outputPath);
|
|
Logger.Info(LogCategory.General, $"Completed test: '{testName}' for Unity version: '{versionName}'");
|
|
Logger.BlankLine(2);
|
|
numSuccessful++;
|
|
successfulTests.Add((versionName, testName));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Log(LogType.Error, LogCategory.General, ex.ToString());
|
|
Logger.BlankLine(2);
|
|
unsuccessfulTests.Add((versionName, testName));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Logger.Info(LogCategory.General, $"{numSuccessful}/{numTests} tests successfully completed");
|
|
if (numSuccessful > 0)
|
|
{
|
|
Logger.Info(LogCategory.General, "Successful:");
|
|
foreach ((string version, string test) in successfulTests)
|
|
{
|
|
Logger.Info(LogCategory.General, $"\t{version,-12} {test}");
|
|
}
|
|
}
|
|
if (numSuccessful < numTests)
|
|
{
|
|
Logger.Info(LogCategory.General, "Unsuccessful:");
|
|
foreach ((string version, string test) in unsuccessfulTests)
|
|
{
|
|
Logger.Info(LogCategory.General, $"\t{version,-12} {test}");
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void Rip(string[] inputPaths, string outputPath)
|
|
{
|
|
LibraryConfiguration settings = new();
|
|
settings.LogConfigurationValues();
|
|
GameData gameData = Ripper.Load(inputPaths, settings);
|
|
Ripper.Process(gameData, Ripper.GetDefaultProcessors(settings));
|
|
PrepareExportDirectory(outputPath);
|
|
Ripper.ExportProject(gameData, settings, outputPath);
|
|
}
|
|
|
|
private static void PrepareExportDirectory(string path)
|
|
{
|
|
if (Directory.Exists(path))
|
|
{
|
|
Logger.Info(LogCategory.Export, "Clearing export directory...");
|
|
Directory.Delete(path, true);
|
|
}
|
|
}
|
|
|
|
private static T[] Combine<T>(T[] array1, T[] array2)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(array1);
|
|
ArgumentNullException.ThrowIfNull(array2);
|
|
|
|
T[] result = new T[array1.Length + array2.Length];
|
|
for (int i = 0; i < array1.Length; i++)
|
|
{
|
|
result[i] = array1[i];
|
|
}
|
|
for (int j = 0; j < array2.Length; j++)
|
|
{
|
|
result[j + array1.Length] = array2[j];
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|