Table of Contents

Class InstalledContentIndex

Namespace
McServerLauncher.Services
Assembly
McServerLauncher.dll

What the store says each jar on disk is: one answer per file, asked once a session.

public sealed class InstalledContentIndex
Inheritance
InstalledContentIndex
Inherited Members

Remarks

The same question — "which Modrinth version is this jar?" — was asked in four places with two caches between them and one with none: the replacement of old copies, the "already installed" check, the cleanup panel and the export. Each hashed every jar again and sent the store the hashes the others had just sent, and the cleanup panel asked again on every toggle for the jars the store had already said it did not know.

One cache now, by SHA-1. A jar the store answered without is remembered as unknown; an empty answer is not remembered at all, because it cannot be told apart from being offline.

One instance per server's mods panel, shared by everything in it — the update check, the install, the cleanup panel and the export. That is the point: the answer one of them paid for is the answer the next one reads. It holds no UI and no cancellation of its own; every call takes the token of whoever is asking.

Constructors

InstalledContentIndex(ModrinthService)

public InstalledContentIndex(ModrinthService store)

Parameters

store ModrinthService

Asked about the hashes nobody has asked about yet.

Properties

Hashes

Hashing a jar is the expensive part, so every scan shares these.

public FileHashCache Hashes { get; }

Property Value

FileHashCache

Manifests

What each jar says about itself, for finding the other copies of a mod.

public ContentManifestCache Manifests { get; }

Property Value

ContentManifestCache

Methods

ContentFiles(string)

The content files in folder: jars, switched on or off.

public static IEnumerable<string> ContentFiles(string folder)

Parameters

folder string

Returns

IEnumerable<string>

HashesAsync(IEnumerable<string>, CancellationToken)

The SHA-1 of every jar in paths that can be read, by path.

public Task<Dictionary<string, string>> HashesAsync(IEnumerable<string> paths, CancellationToken ct)

Parameters

paths IEnumerable<string>
ct CancellationToken

Returns

Task<Dictionary<string, string>>

InstalledProjectIdsAsync(string, string?, CancellationToken)

The project id of every installed jar Modrinth recognises, in folder and also in alsoFolder when one is given.

public Task<List<string>> InstalledProjectIdsAsync(string folder, string? alsoFolder, CancellationToken ct)

Parameters

folder string
alsoFolder string
ct CancellationToken

Returns

Task<List<string>>

Remarks

This is what makes "already installed" a real answer rather than a filename comparison. Modrinth's dependencies carry no version range, so a project that is present satisfies them; installing a second copy under a different file name is what produces the loader's "duplicate mod" failure, which is worse than the one being fixed.

IsPrimaryFile(VersionResult, string)

Whether the file with sha1 is the main one of version.

public static bool IsPrimaryFile(VersionResult version, string sha1)

Parameters

version VersionResult
sha1 string

Returns

bool

Remarks

Some projects publish more than one file in a version — a module, a sources jar. The project is what decides that an installed jar is an old copy of a new one, and a module counted as the project would be deleted by installing the core. When the store does not say which file it matched, the version counts as one file.

Known(string)

The version the store said hash is, or null.

public VersionResult? Known(string hash)

Parameters

hash string

Returns

VersionResult

LearnAsync(IEnumerable<string>, CancellationToken)

Asks the store about the hashes it has not been asked about this session.

public Task LearnAsync(IEnumerable<string> hashes, CancellationToken ct)

Parameters

hashes IEnumerable<string>
ct CancellationToken

Returns

Task

ModIdsProvidedIn(string)

Every id the enabled jars in a folder answer to, the ones carried inside them included.

public static HashSet<string> ModIdsProvidedIn(string folder)

Parameters

folder string

Returns

HashSet<string>

Remarks

Whatever is in here is not missing, and asking the store for it either finds nothing — fabric-api's forty-odd modules are not projects — or offers a second copy of a library that is already loaded because it ships inside the mod next to it.

One answer for both places that ask. The scan and the install used to work it out differently, and the scan also counted disabled jars as providing things, which the start check rightly does not: a .jar.disabled loads nothing.

ProjectByPathAsync(string, CancellationToken)

Which Modrinth project each jar in folder is, by path. Jars the store does not know, and files that are not a version's main one, are left out.

public Task<Dictionary<string, string>> ProjectByPathAsync(string folder, CancellationToken ct = default)

Parameters

folder string
ct CancellationToken

Returns

Task<Dictionary<string, string>>

ProjectOf(string)

The project hash is, when it is that version's main file.

public string? ProjectOf(string hash)

Parameters

hash string

Returns

string