// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Enumeration;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using EpicGames.Core;
using EpicGames.UHT.Parsers;
using EpicGames.UHT.Tables;
using EpicGames.UHT.Tokenizer;
using EpicGames.UHT.Types;
using Microsoft.Extensions.Logging;
namespace EpicGames.UHT.Utils
{
///
/// To support the testing framework, source files can be containing in other source files.
/// A source fragment represents this possibility.
///
public struct UhtSourceFragment
{
///
/// When not null, this source comes from another source file
///
public UhtSourceFile? SourceFile { get; set; }
///
/// The file path of the source
///
public string FilePath { get; set; }
///
/// The line number of the fragment in the containing source file.
///
public int LineNumber { get; set; }
///
/// Data of the source file
///
public StringView Data { get; set; }
}
///
/// A structure that represents an engine version.
///
public struct EngineVersion
{
///
/// The major engine version.
///
public int MajorVersion { get; set; } = 0;
///
/// The minor engine version.
///
public int MinorVersion { get; set; } = 0;
///
/// The patch engine version.
///
public int PatchVersion { get; set; } = 0;
///
/// Build a default engine version (0.0.0).
///
public EngineVersion() { }
///
/// Build a new engine version with the given numbers.
///
public EngineVersion(int major, int minor, int patch)
{
MajorVersion = major;
MinorVersion = minor;
PatchVersion = patch;
}
///
/// Compares this engine version to another one.
///
/// The other engine version
/// Returns -1 if this version is less than the other, 1 if it is greater than the other, and 0 if they're equal
public int CompareTo(EngineVersion other)
{
if (MajorVersion != other.MajorVersion)
{
return MajorVersion.CompareTo(other.MajorVersion);
}
if (MinorVersion != other.MinorVersion)
{
return MinorVersion.CompareTo(other.MinorVersion);
}
if (PatchVersion != other.PatchVersion)
{
return PatchVersion.CompareTo(other.PatchVersion);
}
return 0;
}
///
/// Generates a string representation of the engine version.
///
///
public override string ToString()
{
return String.Format("{0}.{1}.{2}", MajorVersion, MinorVersion, PatchVersion);
}
}
///
/// Implementation of the export factory
///
class UhtExportFactory : IUhtExportFactory
{
public struct Output
{
public string FilePath { get; set; }
public string TempFilePath { get; set; }
public bool Saved { get; set; }
}
///
/// UHT session
///
private readonly UhtSession _session;
///
/// Module associated with the plugin
///
private readonly UHTManifest.Module? _pluginModule;
///
/// Limiter for the number of files being saved to the reference directory.
/// The OS can get swamped on high core systems
///
private static readonly Semaphore s_writeRefSemaphore = new(32, 32);
///
/// Requesting exporter
///
public readonly UhtExporter Exporter;
///
/// UHT Session
///
public UhtSession Session => _session;
///
/// Plugin module
///
public UHTManifest.Module? PluginModule => _pluginModule;
///
/// Collection of error from mismatches with the reference files
///
public Dictionary ReferenceErrorMessages { get; } = new Dictionary();
///
/// List of export outputs
///
public List