Game.Modding.Toolchain.IToolchainDependency
Assembly:
Namespace: Game.Modding.Toolchain
Type: interface
Base: (none)
Summary:
Interface describing a single toolchain dependency used by the Toolchain/Modding tooling. Implementations represent items that can be checked, downloaded, installed, updated and removed (for example external tools, runtimes, or SDK pieces). The interface also provides helper types, constants and several static helper methods to assist checking environment variables, reading Windows uninstall registry entries, computing download sizes, ordering install/uninstall operations, and refreshing dependency state.
Fields
-
const string CSII_PATHSET
Text constant name used in environment variable mapping ("CSII_PATHSET"). Useful when implementations need to reference the standardized env var keys. -
const string CSII_INSTALLATIONPATH
Environment variable key constant for the game installation path. -
const string CSII_USERDATAPATH
Environment variable key constant for the user data path. -
const string CSII_TOOLPATH
Environment variable key constant for the user tooling path. -
const string CSII_LOCALMODSPATH
Environment variable key constant for the user's Mods folder. -
const string CSII_UNITYMODPROJECTPATH
Environment variable key constant for the Unity mods project path. -
const string CSII_UNITYVERSION
Environment variable key constant for Unity version used by the toolchain. -
const string CSII_ENTITIESVERSION
Environment variable key constant for entities version; kEntitiesVersion default value referenced elsewhere. -
const string CSII_MODPOSTPROCESSORPATH
Environment variable key constant for the ModPostProcessor path. -
const string CSII_MODPUBLISHERPATH
Environment variable key constant for the ModPublisher path. -
const string CSII_MANAGEDPATH
Environment variable key constant pointing to the Managed assemblies folder. -
const string CSII_PDXCACHEPATH
Environment variable key constant for PDX cache path. -
const string CSII_PDXMODSPATH
Environment variable key constant for PDX Mods cache path. -
const string CSII_ASSEMBLYSEARCHPATH
Environment variable key constant for assembly search path. -
const string CSII_MSCORLIBPATH
Environment variable key constant for mscorlib.dll path. -
const string CSII_MSCORLIBPATH
(duplicate in list above) constant key for mscorlib. -
const string kEntitiesVersion
Default entities version string ("1.3.10") used by the envVars dictionary. -
protected static ILog log
A protected static logger property (backed by ToolchainDependencyManager.log). Implementations and static helpers use this for logging. -
public struct DiskSpaceRequirements
Nested struct representing a disk path and required size (m_Path, m_Size). Use returned Listto show required space before install/uninstall. -
m_Path: string path to check
-
m_Size: long number of bytes required
-
public struct State
Nested struct that encapsulates dependency state, progress and a localized details string. -
m_State: DependencyState (enum)
- m_Progress: int? progress percentage for download/install/remove
- m_Details: LocalizedString giving extra details (constructed from a localized id when provided)
- Provides constructor State(DependencyState state, string details = null, int? progress = null)
- Provides implicit/explicit conversions to/from DependencyState and overrides GetHashCode
- DebuggerDisplay shows "{m_State}: {m_Progress}"
Properties
-
string name { get; }
Unique identifier or programmatic name for the dependency. -
LocalizedString localizedName { get; }
User-facing localized name for UI display. -
string version { get; protected set; }
Current version string for the dependency (may be set by implementations during Refresh/IsInstalled checks). -
State state { get; set; }
Current State struct for the dependency (NotInstalled, Installed, Outdated, Downloading, Installing, Removing, ...). -
bool needDownload { get; protected set; }
True if the dependency needs to be downloaded (set during Refresh). -
List<DiskSpaceRequirements> spaceRequirements { get; protected set; }
List of disk space requirements computed by GetRequiredDiskSpace. -
bool confirmUninstallation { get; }
Whether the UI should request confirmation before uninstalling. -
bool canBeInstalled { get; }
Whether this dependency supports installation via the toolchain. -
bool canBeUninstalled { get; }
Whether this dependency can be uninstalled via the toolchain. -
string installationDirectory { get; set; }
Path where the dependency will be (or is) installed. -
bool canChangeInstallationDirectory { get; }
Whether the installationDirectory is user-changeable. -
string icon { get; }
Path or identifier for an icon representing this dependency in UI. -
DeploymentAction availableActions { get; }
Computed property combining Install/Update/Uninstall based on capability and state. (Computed internally from installAvailable/updateAvailable/uninstallAvailable.) -
bool installAvailable { get; }
True when dependency can be installed and is currently NotInstalled. -
bool uninstallAvailable { get; }
True when dependency can be uninstalled and currently not NotInstalled. -
bool updateAvailable { get; }
True when dependency can be installed (supports updates) and state is Outdated. -
LocalizedString description { get; }
Localized description shown in the UI. -
LocalizedString installDescr { get; }
Localized description for install action. -
LocalizedString uninstallDescr { get; }
Localized description for uninstall action. -
LocalizedString uninstallMessage { get; }
Message to show when confirming uninstall. -
Type[] dependsOnInstallation { get; }
Types of dependencies that this dependency requires to be installed before installing this one. -
Type[] dependsOnUninstallation { get; }
Types of dependencies that must be uninstalled first or affect uninstall ordering. -
IEnumerable<string> envVariables { get; }
List of environment variable keys this dependency expects to be present/set. -
static IReadOnlyDictionary<string, string> envVars
Static dictionary mapping the known CSII_* keys to concrete default paths/values (installation path, user data path, tooling paths, Unity version, Managed path, mscorlib path, etc). Useful for checking expected environment values. -
event ProgressDelegate onNotifyProgress
Event raised by the dependency to notify progress changes; subscribers receive the dependency instance and a State.
Constructors
- (Interfaces do not define constructors)
No public constructors — implementors provide their own constructors and initialization.
Methods
-
static async Task<long> GetDownloadSizeAsync(string url, CancellationToken token, int timeout = 3000)
Sends an HTTP HEAD request to get Content-Length for a download; returns size in bytes or -1 on failure/timeout. Logs errors and timeouts. -
Task<bool> IsInstalled(CancellationToken token)
Check whether the dependency is present/installed. Implementations must check file system, registry or other sources. -
Task<bool> IsUpToDate(CancellationToken token)
Check whether the installed dependency is up-to-date relative to the expected version. -
Task<bool> NeedDownload(CancellationToken token)
Indicates whether the dependency requires a remote download (used to determine space/delivery). -
Task Download(CancellationToken token)
Perform the download step (if applicable). Implement progress notifications via onNotifyProgress and State updates. -
Task Install(CancellationToken token)
Install the dependency (post-download or direct install). Must update state/progress and set version/installationDirectory as appropriate. -
Task Uninstall(CancellationToken token)
Remove the dependency. Implementation should confirm and update state/progress. -
Task<List<DiskSpaceRequirements>> GetRequiredDiskSpace(CancellationToken token)
Return disk space requirements for the operation (list of path/size pairs). -
static bool CheckEnvVariables(IToolchainDependency dependency, bool checkValue = false)
Checks the environment variables listed in dependency.envVariables against user-level environment variables. If checkValue is true, compares against the default values in envVars; otherwise only checks presence. -
Task Refresh(CancellationToken token)
Instance method to refresh the dependency state; implementations should set version, state, needDownload and spaceRequirements appropriately. -
static async Task Refresh(IToolchainDependency dependency, CancellationToken token)
Static helper that performs common refresh logic: - Clears dependency.version
- Uses IsInstalled/IsUpToDate to set state to NotInstalled/Outdated/Installed
- If not Installed, sets needDownload and spaceRequirements via NeedDownload/GetRequiredDiskSpace
-
If Installed, clears needDownload and sets spaceRequirements to empty list
-
static int InstallSorting(IToolchainDependency x, IToolchainDependency y)
Sorter helper for install ordering: if x depends on y, x goes after y (return 1); if y depends on x, x goes before (return -1); otherwise 0. -
static int UninstallSorting(IToolchainDependency x, IToolchainDependency y)
Sorter helper for uninstall ordering: opposite ordering compared to install sort (ensures dependents are uninstalled before dependencies). -
LocalizedString GetLocalizedState(bool includeProgress)
Instance helper to obtain a localized string for the current state; optionally includes progress percentage. -
LocalizedString GetLocalizedVersion()
Returns LocalizedString.Value(version) for use in UI. -
static LocalizedString GetLocalizedState(State state, bool includeProgress)
Static implementation that maps a State to a LocalizedString. If state includes progress (Downloading, Installing, Removing with m_Progress), and includeProgress is true, returns a composite localized string with progress inserted. -
static RegistryKey GetUninstaller(Dictionary<string, string> check, out string keyName)
Searches Windows uninstall registry locations (both 64/32-bit branches) for a product matching the provided key/value checks and returns the RegistryKey and keyName when found. -
static RegistryKey GetUninstaller(string uninstallKeyName, Dictionary<string, string> check, out string keyName)
Helper that inspects a single uninstall registry path for a matching subkey. Returns the first subkey where all provided check key/value pairs match. -
static void UpdateProcessEnvVarPathValue()
Rebuilds the Process-level PATH environment variable by aggregating PATH entries from Process, User and Machine scopes, deduplicating them and setting the Process PATH. This method contains a local helper Add(EnvironmentVariableTarget target) to read and collect entries from each scope.
Usage Example
// Minimal skeleton implementing IToolchainDependency for a hypothetical tool.
public class MyToolDependency : IToolchainDependency
{
public string name => "MyTool";
public LocalizedString localizedName => LocalizedString.Value("My Tool");
public string version { get; protected set; }
public IToolchainDependency.State state { get; set; }
public bool needDownload { get; protected set; }
public List<IToolchainDependency.DiskSpaceRequirements> spaceRequirements { get; protected set; }
public bool confirmUninstallation => true;
public bool canBeInstalled => true;
public bool canBeUninstalled => true;
public string installationDirectory { get; set; }
public bool canChangeInstallationDirectory => true;
public string icon => null;
public LocalizedString description => LocalizedString.Value("Installs My Tool.");
public LocalizedString installDescr => LocalizedString.Value("Download and install My Tool.");
public LocalizedString uninstallDescr => LocalizedString.Value("Remove My Tool.");
public LocalizedString uninstallMessage => LocalizedString.Value("Are you sure you want to remove My Tool?");
public Type[] dependsOnInstallation => new Type[0];
public Type[] dependsOnUninstallation => new Type[0];
public IEnumerable<string> envVariables => new [] { "CSII_TOOLPATH" };
public event IToolchainDependency.ProgressDelegate onNotifyProgress;
public MyToolDependency()
{
state = (IToolchainDependency.State)DependencyState.NotInstalled;
spaceRequirements = new List<IToolchainDependency.DiskSpaceRequirements>();
}
public Task<bool> IsInstalled(CancellationToken token)
{
// check installationDirectory or registry
return Task.FromResult(false);
}
public Task<bool> IsUpToDate(CancellationToken token)
{
// compare installed version with expected
return Task.FromResult(false);
}
public Task<bool> NeedDownload(CancellationToken token)
{
// check remote manifest or assume true
return Task.FromResult(true);
}
public async Task Download(CancellationToken token)
{
// download and report progress:
onNotifyProgress?.Invoke(this, new IToolchainDependency.State(DependencyState.Downloading, progress: 10));
await Task.Delay(100, token);
onNotifyProgress?.Invoke(this, new IToolchainDependency.State(DependencyState.Downloading, progress: 100));
}
public Task Install(CancellationToken token)
{
// perform install steps, update version/state
version = "1.0.0";
state = (IToolchainDependency.State)DependencyState.Installed;
return Task.CompletedTask;
}
public Task Uninstall(CancellationToken token)
{
// remove files and update state
state = (IToolchainDependency.State)DependencyState.NotInstalled;
return Task.CompletedTask;
}
public Task<List<IToolchainDependency.DiskSpaceRequirements>> GetRequiredDiskSpace(CancellationToken token)
{
return Task.FromResult(new List<IToolchainDependency.DiskSpaceRequirements>
{
new IToolchainDependency.DiskSpaceRequirements { m_Path = installationDirectory ?? ".", m_Size = 50L * 1024 * 1024 }
});
}
public Task Refresh(CancellationToken token)
{
// use static helper or implement custom refresh logic
return IToolchainDependency.Refresh(this, token);
}
}
Notes: - Implementations should honor CancellationToken for cancellable operations. - Use the provided static helpers (GetDownloadSizeAsync, GetUninstaller, Refresh, CheckEnvVariables) to avoid duplicating common behavior. - Raise onNotifyProgress with updated State values to keep UI informed about long-running operations.