Skip to content

Game.Modding.Toolchain.Dependencies.BaseIDEDependency

Assembly:
Namespace: Game.Modding.Toolchain.Dependencies

Type: abstract class

Base: BaseDependency

Summary:
BaseIDEDependency is an abstract helper class for modelling an IDE/toolchain dependency used by the modding toolchain. It provides: - an abstract minVersion string that concrete subclasses must supply, - logic to obtain and cache the installed IDE/toolchain version, - helpers to determine whether the installed version satisfies minVersion, - implementations of the dependency state checks and localized state/version strings used by the UI. The class performs asynchronous version probing and exposes synchronous accessors that lazily fetch the version if necessary. It uses System.Version for version comparisons and CancellationToken for cancellable operations. Be careful with the synchronous wait in the version getter (it uses Task.Run(...).Wait()) — this can block the calling thread.


Fields

  • This class declares no private fields of its own.
    {{ YOUR_INFO }} It relies on fields/properties implemented in BaseDependency (for example base.version and base.state) to store the cached version and dependency state.

Properties

  • public abstract string minVersion { get; }
    {{ YOUR_INFO }}
    The minimum required version for the IDE/toolchain. Concrete subclasses must return a version string (for example "17.0.0"). This value is used when checking if an installed IDE meets minimum requirements and when building localized warning messages.

  • public virtual bool isMinVersion { get; }
    {{ YOUR_INFO }}
    Returns true when the currently known version (version property) can be parsed as a System.Version and is greater than or equal to minVersion. If either cannot be parsed, returns false. This is a convenience property for quick checks against the minimum required version.

  • public override string version { get; protected set; }
    {{ YOUR_INFO }}
    Overrides the version property from BaseDependency. The getter will lazily fetch the version if base.version is null by running GetVersion(...) on a background task and waiting for it using Task.Run(...).Wait(), passing GameManager.instance.terminationToken. The setter delegates to base.version. Note: the synchronous wait means callers on certain threads (UI/main) can be blocked if the retrieval takes time — prefer using GetVersion(CancellationToken) to get the version asynchronously.

Constructors

  • public BaseIDEDependency()
    {{ YOUR_INFO }}
    An implicit parameterless constructor is provided by the compiler. Concrete subclasses should call the base constructor when necessary. Because the class is abstract, it cannot be instantiated directly; the constructor is executed by derived classes.

Methods

  • protected abstract Task<string> GetIDEVersion(CancellationToken token)
    {{ YOUR_INFO }}
    Abstract method subclasses must implement to probe the installed IDE/toolchain and return its version string. Should honour the provided CancellationToken. Implementations should return null or empty string if the IDE is not present.

  • public async Task<string> GetVersion(CancellationToken token)
    {{ YOUR_INFO }}
    Asynchronously obtains and caches the IDE version. If base.version is non-null returns it immediately; otherwise calls GetIDEVersion(token) and stores the result in version (which writes to base.version). This method uses ConfigureAwait(false) so it is safe to call from background threads.

  • public override async Task<bool> IsInstalled(CancellationToken token)
    {{ YOUR_INFO }}
    Returns true if GetVersion(token) returns a non-empty string. This method is asynchronous and will probe for the version if not already known.

  • public override async Task<bool> IsUpToDate(CancellationToken token)
    {{ YOUR_INFO }}
    Compares the installed version (obtained via GetVersion) to minVersion using System.Version.TryParse; returns true when the installed version is greater than or equal to minVersion. If parsing fails, returns false.

  • public override LocalizedString GetLocalizedState(bool includeProgress)
    {{ YOUR_INFO }}
    Provides localized state strings for UI display based on base.state.m_State. Returns localized identifiers for Detected, NotDetected, or a DetectedOutdated string that includes the detected version. Falls back to base.GetLocalizedState(includeProgress) for other states.

  • public override LocalizedString GetLocalizedVersion()
    {{ YOUR_INFO }}
    When the dependency is installed, defers to base.GetLocalizedVersion(); otherwise returns a localized warning string including the MIN_VERSION replacement value with the minVersion string.

Usage Example

// Example implementation of a concrete IDE dependency.
// This demonstrates overriding minVersion and providing an async version probe.
public class ExampleIDE : BaseIDEDependency
{
    // Minimum required IDE version
    public override string minVersion => "1.2.0";

    // Probe the system (or registry, or process) and return the installed IDE version string.
    protected override async Task<string> GetIDEVersion(CancellationToken token)
    {
        // Example placeholder: in a real implementation you would query the registry,
        // execute the IDE with a --version argument, or read a known install manifest.
        await Task.Delay(50, token).ConfigureAwait(false);
        // Return null or string.Empty if not installed; otherwise return version string like "1.3.0"
        return "1.3.0";
    }
}

// Example use: check installation and update state from an async context
public async Task CheckDependencyAsync(BaseIDEDependency dep, CancellationToken token)
{
    bool installed = await dep.IsInstalled(token).ConfigureAwait(false);
    bool upToDate = false;
    if (installed)
    {
        upToDate = await dep.IsUpToDate(token).ConfigureAwait(false);
    }

    // Localized messages for UI
    var stateString = dep.GetLocalizedState(includeProgress: false);
    var versionString = dep.GetLocalizedVersion();
}

{{ YOUR_INFO }}
Notes and best practices: - Prefer calling GetVersion, IsInstalled, and IsUpToDate asynchronously with a CancellationToken rather than relying on the synchronous version getter to avoid blocking important threads. - Implementations of GetIDEVersion should be cancellation-aware and return quickly if the token is cancelled. - Ensure returned version strings are parseable by System.Version (semantic-style "major.minor[.build[.revision]]") to enable correct comparisons.