using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using Barotrauma.Extensions;
using Barotrauma.LuaCs.Data;
namespace Barotrauma.LuaCs.Services;
public interface IPackageManagementService : IReusableService
{
///
/// Adds packages to the queue of loadable packages without initializing them.
///
///
void QueuePackages(ImmutableArray packages);
///
/// Generates the ModConfigInfo for all queued packages and adds them to the store.
///
/// Use multithreaded loading.
/// Whether duplicate packages should be reported as errors.
/// Failure/Success records for each package.
FluentResults.Result ParseQueuedPackages(bool loadParallel = true, bool reportFailOnDuplicates = false);
///
/// Loads only the localizations, configs, and config profiles for stored packages.
///
///
///
FluentResults.Result LoadPackageConfigsResourcesGroup(bool loadParallel = true);
///
/// Loads all resources for stored packages.
///
/// Use multithreaded loading.
/// Only load safe scripting resources, such as Lua. C# plugins disabled.
///
FluentResults.Result LoadAllPackageResources(bool loadParallel = true, bool safeResourcesOnly = true);
FluentResults.Result UnloadPackages();
bool IsPackageLoaded(ContentPackage package);
bool CheckDependencyLoaded(IPackageDependencyInfo info);
bool CheckDependenciesLoaded([NotNull]IEnumerable infos, out ImmutableArray missingPackages);
bool CheckEnvironmentSupported(IPlatformInfo platform);
///
/// Tries to get the package dependency record to refer to that specific package if it exists, optionally create it.
///
/// ContentPackage reference
/// Register a new IPackageDependencyInfo reference.
///
FluentResults.Result GetPackageDependencyInfoRecord(ContentPackage package,
bool addIfMissing = false);
///
/// Tries to get the package dependency record to refer to that specific package if it exists, optionally create it.
///
/// The Steam Workshop ID, if available, if not enter zero ('0').
/// The name of the package.
/// The folder path, as formatted in [ContentPackage.Path].
/// Register a new IPackageDependencyInfo reference.
///
FluentResults.Result GetPackageDependencyInfoRecord(ulong steamWorkshopId,
string packageName, string folderPath = null, bool addIfMissing = false);
///
/// Tries to get the package dependency record to refer to that specific package if it exists.
/// Note: This overload does not allow the registration of a new dependency.
///
/// The folder path, as formatted in [ContentPackage.Path].
///
FluentResults.Result GetPackageDependencyInfoRecord(string folderPath);
IPackageDependencyInfo CreateOrphanPackageDependencyInfoRecord(string packageName,
string packagePath, ulong steamWorkshopId);
}
public readonly record struct LoadablePackage
{
public ContentPackage Package { get; }
public bool IsEnabled { get; }
public LoadablePackage(ContentPackage package, bool isEnabled)
{
Package = package;
IsEnabled = isEnabled;
}
public static ImmutableArray FromEnumerable(IEnumerable packages, bool isEnabled)
{
var builder = ImmutableArray.CreateBuilder();
packages.ForEach(p => builder.Add(new LoadablePackage(p, isEnabled)));
return builder.ToImmutable();
}
}