Launcher: Horizon's registry as a mod browser source

A browser source for Horizon's own registry (docs/api/mod-index.md): it reads index.json
(HORIZON_MOD_INDEX for a test registry, cached in the game folder for when the registry can't
be reached), searches it by kind and words, lists versions with the SHA-256 the index gives,
and blocks the versions it says were taken down. Downloads accept the registry's release host
and check SHA-256; file:// files only from a local index.

Installing, the takedown check before play and the CLI come next.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-24 22:47:37 +02:00
parent bffb68b0c5
commit 7e513d2d5c
11 changed files with 423 additions and 18 deletions
+32 -8
View File
@@ -8,6 +8,7 @@
pub mod curseforge;
pub mod details;
pub mod download;
pub mod horizon;
pub mod images;
pub mod installed;
pub mod java;
@@ -56,6 +57,8 @@ impl Kind {
pub enum SourceId {
Modrinth,
CurseForge,
/// Horizon's own registry of reviewed mods, modpacks and resource packs ([`horizon`]).
Horizon,
}
impl SourceId {
@@ -63,6 +66,7 @@ impl SourceId {
match self {
SourceId::Modrinth => "Modrinth",
SourceId::CurseForge => "CurseForge",
SourceId::Horizon => "Horizon",
}
}
}
@@ -132,6 +136,8 @@ pub struct FileRef {
pub name: String,
pub size: u64,
pub sha512: Option<String>,
/// What Horizon's registry lists.
pub sha256: Option<String>,
pub sha1: Option<String>,
pub primary: bool,
}
@@ -139,11 +145,13 @@ pub struct FileRef {
impl FileRef {
/// The strongest checksum the source gives: what the download is checked against.
pub fn checksum(&self) -> Option<(&'static str, &str)> {
match (&self.sha512, &self.sha1) {
(Some(h), _) => Some(("SHA-512", h)),
(None, Some(h)) => Some(("SHA-1", h)),
(None, None) => None,
}
[
("SHA-512", &self.sha512),
("SHA-256", &self.sha256),
("SHA-1", &self.sha1),
]
.into_iter()
.find_map(|(algo, h)| Some((algo, h.as_deref()?)))
}
}
@@ -230,10 +238,11 @@ pub trait Source: Send + Sync {
/// What the launcher says wherever CurseForge would be.
pub const CURSEFORGE_SOON: &str = "CurseForge support is coming soon.";
/// The sources this launcher uses: Modrinth. CurseForge support is coming soon: its API needs a
/// paid key, so no search or install goes to it; `curseforge` is kept for then.
/// The sources this launcher uses: Modrinth and Horizon's registry. CurseForge support is coming
/// soon: its API needs a paid key, so no search or install goes to it; `curseforge` is kept for
/// then.
pub fn sources() -> Vec<Box<dyn Source>> {
vec![Box::new(modrinth::Modrinth)]
vec![Box::new(modrinth::Modrinth), Box::new(horizon::Registry)]
}
/// The source of that id, when this launcher can use it.
@@ -243,6 +252,15 @@ pub fn source(id: SourceId) -> Option<Box<dyn Source>> {
/// How well a project of `kind` made for `game_versions` and `loaders` runs in Horizon.
pub fn support(kind: Kind, game_versions: &[String], loaders: &[String]) -> Support {
if loaders.iter().any(|l| l == horizon::LOADER) {
// Made for Horizon and reviewed: it runs when it is for the version Horizon plays.
return match newest_release(game_versions)
.filter(|_| !game_versions.iter().any(|v| v == GAME))
{
Some(other) => Support::No(format!("Made for Horizon on {other}.")),
None => Support::Works,
};
}
match kind {
Kind::ResourcePack => {
if game_versions.iter().any(|v| v == GAME) {
@@ -309,6 +327,12 @@ pub fn pick(kind: Kind, versions: &[Version], everything: bool) -> Option<&Versi
let mut usable = versions
.iter()
.filter(|v| v.blocked.is_none() && v.file().is_some());
if versions
.iter()
.any(|v| v.loaders.iter().any(|l| l == horizon::LOADER))
{
return usable.find(|v| v.game_versions.iter().any(|g| g == GAME));
}
if kind == Kind::Mod {
let java = |v: &&Version| {
v.loaders