Skip to content

Game.Modding.Toolchain.ToolchainDeployment

Assembly:
Namespace: Game.Modding.Toolchain

Type: static class

Base: System.Object

Summary:
ToolchainDeployment is a static helper that orchestrates installing and uninstalling toolchain dependencies for modding (e.g., Unity, .NET, NodeJS, project templates). It owns a ToolchainDependencyManager (dependencyManager) that is pre-populated in the static constructor with the known dependency types. The class provides two public entry points: RunWithUI (which shows a confirmation dialog to the user and invokes a callback with the user's choice) and Run (silent, for programmatic use). The actual work is performed by RunImpl which schedules the install/uninstall work on the game's TaskManager and respects the game's termination token.


Fields

  • None.
    ToolchainDeployment is a static utility and does not declare private fields. It exposes its central manager via a property (see Properties).

Properties

  • public static ToolchainDependencyManager dependencyManager { get; }
    This read-only static property provides the central ToolchainDependencyManager instance used to perform install/uninstall operations and to query state (isInProgress, Install/Uninstall methods, etc.). The manager is instantiated and populated with dependency types in the static constructor.

Constructors

  • static ToolchainDeployment()
    The static constructor initializes dependencyManager and registers the built-in dependency types:
  • UnityDependency
  • UnityLicenseDependency
  • UnityModProjectDependency
  • DotNetDependency
  • ProjectTemplateDependency
  • NodeJSDependency
  • NpxModProjectDependency
  • IDEDependency

This ensures the manager knows how to handle each supported toolchain component for subsequent operations.

Methods

  • public static async void RunWithUI(DeploymentAction action, List<IToolchainDependency> dependencies = null, Action<bool> callback = null)
    Shows a confirmation dialog to the user before performing install/uninstall. Behavior summary:
  • Returns immediately if dependencyManager.isInProgress (prevents concurrent operations).
  • Uses ToolchainDependencyManager.DependencyFilter.Process(action, dependencies) to split accepted and discarded dependencies.
  • If no dependencies are accepted, invokes callback with (dependencies == null) and refreshes dependencyManager state.
  • Sorts accepted dependencies using IToolchainDependency.InstallSorting or UninstallSorting depending on action.
  • Builds a dictionary of localized description elements for the confirmation dialog and creates a ConfirmationDialog with a LocalizedString message (install vs uninstall).
  • Shows the dialog via GameManager.instance.userInterface.appBindings.ShowConfirmationDialog and awaits the user's response using a TaskCompletionSource.
  • If the user confirms, calls RunImpl(action, acceptedDependencies) and awaits its completion.
  • Finally invokes callback with the user's decision (true if confirmed).
  • Notes: This method uses async void because it is driven by UI interactions; callers expecting awaitable behavior should use Run instead. Be mindful that async void exceptions propagate differently — they will be unhandled unless captured by the environment.

  • public static async Task Run(DeploymentAction action, List<IToolchainDependency> dependencies = null)
    Programmatic entry point without UI. Behavior:

  • If dependencyManager.isInProgress, returns immediately.
  • Filters dependencies via ToolchainDependencyManager.DependencyFilter.Process.
  • If there are accepted dependencies, calls RunImpl(action, acceptedDependencies) and awaits completion.
  • Use this when you want to trigger installs/uninstalls from code (tests, automated flows) and you don't need or want a user confirmation dialog.

  • private static async Task RunImpl(DeploymentAction action, List<IToolchainDependency> dependencies)
    Internal implementation that schedules the actual install/uninstall work:

  • If action < DeploymentAction.Uninstall, schedules the install work by calling TaskManager.instance.SharedTask("InstallToolchain", dependencyManager.Install, dependencies, GameManager.instance.terminationToken).
  • Otherwise schedules uninstall via TaskManager.instance.SharedTask("UninstallToolchain", dependencyManager.Uninstall, dependencies, GameManager.instance.terminationToken).
  • The scheduled task runs under the game's TaskManager and honors the game's termination token, enabling cooperative cancellation on shutdown.

Usage Example

// Show a confirmation dialog to the user and run installation if confirmed
ToolchainDeployment.RunWithUI(DeploymentAction.Install, null, confirmed =>
{
    if (confirmed)
    {
        Debug.Log("User confirmed toolchain installation.");
    }
    else
    {
        Debug.Log("User cancelled toolchain installation.");
    }
});

// Trigger installation programmatically (awaitable)
await ToolchainDeployment.Run(DeploymentAction.Install);

// Trigger uninstall programmatically
await ToolchainDeployment.Run(DeploymentAction.Uninstall, new List<IToolchainDependency> { myDependency });

Additional notes: - Dependency filtering (DependencyFilter.Process) is used to determine which dependencies are relevant for the requested action; the UI shows only the accepted items. - The class relies on game systems: GameManager.instance (for UI and terminationToken) and TaskManager.instance (for scheduling long-running tasks). - Because RunWithUI uses async void, it's intended for UI-bound flows; prefer Run in code paths that can await the Task.