Merge pull request #1640 from ludovic111/feat/launcher-horizon-modpacks
🤖 Agent: merged after verify passed; mod-registry-land-1's combined check (pr_ready --quick on all seven, launcher tests 125, website 25/25, no harness affected) and live end-to-end on horizon-mods.
This commit is contained in:
+8
-1
@@ -159,12 +159,19 @@ into place only after `horizon_mods::index::check_file` passes (size, SHA-256, t
|
||||
has a key, the file's own manifest against the index). A mod becomes `horizon-mods/<id>.hmod`, turned on;
|
||||
`mods disable` and `mods enable` switch it in `horizon-mods.txt`. When the index takes a file down, the launcher turns
|
||||
it off the next time it reads the index or starts the game, says why, and refuses to install it or turn it back on.
|
||||
Horizon modpacks (`.hpack`) and shader packs are listed by the index but not installed by this launcher yet.
|
||||
A Horizon modpack (`.hpack`) installs as its own profile (`browser/horizon/pack.rs`): `horizon-packs/<id>/` holds the
|
||||
checked pack, `pack.json` and `home/`, the profile's game folder, where each of the pack's mods is downloaded and checked
|
||||
like any registry mod and turned on or off as the pack says; its overrides (settings, resource packs, a mod's saved
|
||||
settings) are copied in on the first install only, so the player's changes survive updates. A pack whose mod was taken
|
||||
down installs nothing. It is listed on the Modpacks tab with **Play** and **Remove**, and plays like an imported pack
|
||||
(`modpacks::apply_profile`). Shader packs are listed by the index but not installed by this launcher yet.
|
||||
|
||||
```sh
|
||||
horizon-launcher mods search --source horizon --kind mod coords # with whether it is signed and what it may do
|
||||
horizon-launcher mods install --source horizon coords_hud
|
||||
horizon-launcher mods disable coords_hud
|
||||
horizon-launcher mods install --source horizon cozy # a modpack: its own profile
|
||||
horizon-launcher modpack play cozy
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -111,12 +111,13 @@ fn fetch_index() -> Result<(Index, String), String> {
|
||||
}
|
||||
|
||||
/// The browser's kind for a registry kind; None for one the launcher doesn't install yet
|
||||
/// (Horizon modpacks and shader packs, kinds newer than this launcher).
|
||||
/// (shader packs, kinds newer than this launcher).
|
||||
fn kind_of(kind: &index::Kind) -> Option<Kind> {
|
||||
match kind {
|
||||
index::Kind::Mod => Some(Kind::Mod),
|
||||
index::Kind::ResourcePack => Some(Kind::ResourcePack),
|
||||
index::Kind::Modpack | index::Kind::Shader | index::Kind::Other(_) => None,
|
||||
index::Kind::Modpack => Some(Kind::Modpack),
|
||||
index::Kind::Shader | index::Kind::Other(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,6 +260,23 @@ impl Source for Registry {
|
||||
body.push_str(&format!("- May {}\n", c.describe()));
|
||||
}
|
||||
}
|
||||
if let Some(v) = newest.filter(|v| !v.requires.is_empty()) {
|
||||
body.push_str(
|
||||
"\n\n## Its mods\n\nInstalled with it into its own profile, each checked:\n\n",
|
||||
);
|
||||
for r in &v.requires {
|
||||
let found = index
|
||||
.project(&r.id)
|
||||
.and_then(|m| Some((m, m.versions.iter().find(|w| w.version == r.version)?)));
|
||||
let Some((m, w)) = found else { continue };
|
||||
let may: Vec<&str> = w.capabilities.iter().map(|c| c.describe()).collect();
|
||||
let may = match may.is_empty() {
|
||||
true => String::new(),
|
||||
false => format!(": may {}", may.join(", ")),
|
||||
};
|
||||
body.push_str(&format!("- {} {}{may}\n", m.name, w.version));
|
||||
}
|
||||
}
|
||||
Ok(Details {
|
||||
body,
|
||||
links: vec![
|
||||
@@ -325,9 +343,7 @@ fn relative(kind: Kind, id: &str, file_name: &str) -> Result<String, String> {
|
||||
match kind {
|
||||
Kind::Mod => Ok(format!("{}/{id}.hmod", java::MODS_DIR)),
|
||||
Kind::ResourcePack => Ok(format!("resourcepacks/{file_name}")),
|
||||
Kind::Modpack => {
|
||||
Err("Modpacks from Horizon's registry install from the Modpacks page.".into())
|
||||
}
|
||||
Kind::Modpack => Err("A modpack installs as its own profile (pack::install).".into()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,17 +368,46 @@ fn install_from(
|
||||
let p = index
|
||||
.project(&project.id)
|
||||
.ok_or_else(|| format!("{} isn't in Horizon's registry.", project.title))?;
|
||||
let v = p
|
||||
.versions
|
||||
.iter()
|
||||
.find(|v| v.game == GAME && index.revoked(&p.id, &v.file.sha256).is_none())
|
||||
.ok_or_else(|| format!("{} has no version for {GAME} to install.", project.title))?;
|
||||
let v = newest(index, p)?;
|
||||
install_version(index, local, p, v, home, progress).map(|e| vec![e])
|
||||
}
|
||||
|
||||
/// A project's newest version for this game that wasn't taken down.
|
||||
fn newest<'a>(index: &Index, p: &'a index::Project) -> Result<&'a index::Version, String> {
|
||||
let mut taken_down = None;
|
||||
for v in p.versions.iter().filter(|v| v.game == GAME) {
|
||||
match index.revoked(&p.id, &v.file.sha256) {
|
||||
None => return Ok(v),
|
||||
Some(r) => {
|
||||
taken_down.get_or_insert(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(match taken_down {
|
||||
Some(r) => format!("{} was taken down: {}", p.name, r.reason),
|
||||
None => format!("{} has no version for {GAME} to install.", p.name),
|
||||
})
|
||||
}
|
||||
|
||||
/// Installs version `v` of the registry's mod or resource pack `p` into the game folder `home`.
|
||||
fn install_version(
|
||||
index: &Index,
|
||||
local: bool,
|
||||
p: &index::Project,
|
||||
v: &index::Version,
|
||||
home: &Path,
|
||||
progress: &dyn Fn(&str, f32),
|
||||
) -> Result<installed::Entry, String> {
|
||||
let project = project_of(p).ok_or_else(|| format!("{} can't be installed here.", p.name))?;
|
||||
if let Some(r) = index.revoked(&p.id, &v.file.sha256) {
|
||||
return Err(format!("{} was taken down: {}", p.name, r.reason));
|
||||
}
|
||||
let relative = relative(project.kind, &p.id, &v.file.name)?;
|
||||
let mut list = installed::Installed::load(home);
|
||||
let ours = |e: &installed::Entry| e.source == SourceId::Horizon && e.project == p.id;
|
||||
let old = list.entries.iter().find(|e| ours(e)).cloned();
|
||||
if old.as_ref().is_some_and(|o| o.version == v.version) {
|
||||
return Ok(vec![old.expect("checked")]);
|
||||
return Ok(old.expect("checked"));
|
||||
}
|
||||
let target = home.join(&relative);
|
||||
let taken_by = list.entries.iter().find(|e| !ours(e) && e.file == relative);
|
||||
@@ -416,7 +461,7 @@ fn install_from(
|
||||
list.entries.retain(|e| !ours(e));
|
||||
list.entries.push(entry.clone());
|
||||
list.save(home)?;
|
||||
Ok(vec![entry])
|
||||
Ok(entry)
|
||||
}
|
||||
|
||||
/// The mod id of an installed mod (`horizon-mods/<id>` or `horizon-mods/<id>.hmod`).
|
||||
@@ -465,8 +510,12 @@ pub fn before_play(home: &Path) {
|
||||
if !from_registry {
|
||||
return;
|
||||
}
|
||||
let kept = fs::read_to_string(home.join(CACHE)).ok();
|
||||
if let Some(index) = kept.and_then(|t| Index::parse(&t).ok()) {
|
||||
let kept = fs::read_to_string(crate::backend::game_home().join(CACHE)).ok();
|
||||
let parse = |t: String| match local() {
|
||||
true => Index::parse_local(&t).ok(),
|
||||
false => Index::parse(&t).ok(),
|
||||
};
|
||||
if let Some(index) = kept.and_then(parse) {
|
||||
for line in turn_off_revoked(&index, home) {
|
||||
eprintln!("{line}");
|
||||
}
|
||||
@@ -479,5 +528,6 @@ pub fn before_play(home: &Path) {
|
||||
});
|
||||
}
|
||||
|
||||
pub mod pack;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@@ -0,0 +1,294 @@
|
||||
//! Horizon modpacks from the registry (`.hpack`, docs/api/mod-index.md), each played as its own
|
||||
//! profile: `horizon-packs/<id>/` in the game's home holds the pack's file, `pack.json` (what
|
||||
//! was installed) and `home/`, the profile's game folder: its saves, its options, and the pack's
|
||||
//! mods in `home/horizon-mods/`, each downloaded and checked against the index like any
|
||||
//! registry mod, turned on or off as the pack says. The pack's overrides (settings, resource
|
||||
//! packs, a mod's saved settings) are copied in once, when it is installed.
|
||||
use super::{fetch, index, install_version, local, newest, Index};
|
||||
use crate::browser::{java, FileRef};
|
||||
use horizon_mods::{index as idx, modpack::Modpack};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
const RECORD: &str = "pack.json";
|
||||
|
||||
/// Where registry modpacks live.
|
||||
pub fn packs_dir() -> PathBuf {
|
||||
crate::backend::game_home().join("horizon-packs")
|
||||
}
|
||||
|
||||
/// What `pack.json` keeps of an installed pack.
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Installed {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub sha256: String,
|
||||
/// The pack's mods: `id version`.
|
||||
pub mods: Vec<String>,
|
||||
#[serde(skip)]
|
||||
pub work: PathBuf,
|
||||
}
|
||||
|
||||
/// The installed registry packs, by name.
|
||||
pub fn list() -> Vec<Installed> {
|
||||
list_in(&packs_dir())
|
||||
}
|
||||
|
||||
fn list_in(dir: &Path) -> Vec<Installed> {
|
||||
let mut packs: Vec<Installed> = fs::read_dir(dir)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.flatten()
|
||||
.filter_map(|e| read(&e.path()))
|
||||
.collect();
|
||||
packs.sort_by_key(|p| p.name.to_lowercase());
|
||||
packs
|
||||
}
|
||||
|
||||
fn read(work: &Path) -> Option<Installed> {
|
||||
let text = fs::read_to_string(work.join(RECORD)).ok()?;
|
||||
let mut pack: Installed = serde_json::from_str(&text).ok()?;
|
||||
pack.work = work.to_path_buf();
|
||||
Some(pack)
|
||||
}
|
||||
|
||||
/// Whether `work` is a registry pack's folder.
|
||||
pub fn is_pack(work: &Path) -> bool {
|
||||
work.join(RECORD).is_file()
|
||||
}
|
||||
|
||||
/// The profile's game folder.
|
||||
pub fn home(work: &Path) -> PathBuf {
|
||||
work.join("home")
|
||||
}
|
||||
|
||||
/// Installs the registry modpack `id`: its newest version for this game, then each of its mods.
|
||||
/// Installing it again updates it; its saves and options stay.
|
||||
pub fn install(id: &str, progress: &dyn Fn(&str, f32)) -> Result<Installed, String> {
|
||||
install_in(&*index()?, local(), id, &packs_dir(), progress)
|
||||
}
|
||||
|
||||
fn install_in(
|
||||
index: &Index,
|
||||
local: bool,
|
||||
id: &str,
|
||||
dir: &Path,
|
||||
progress: &dyn Fn(&str, f32),
|
||||
) -> Result<Installed, String> {
|
||||
let p = index
|
||||
.project(id)
|
||||
.ok_or_else(|| format!("{id} isn't in Horizon's registry."))?;
|
||||
if p.kind != idx::Kind::Modpack {
|
||||
return Err(format!("{} is a {}, not a modpack.", p.name, p.kind.name()));
|
||||
}
|
||||
let v = newest(index, p)?;
|
||||
let work = dir.join(&p.id);
|
||||
let fresh = !work.exists();
|
||||
let result = install_version_in(index, local, p, v, &work, progress);
|
||||
if result.is_err() && fresh {
|
||||
let _ = fs::remove_dir_all(&work);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn install_version_in(
|
||||
index: &Index,
|
||||
local: bool,
|
||||
p: &idx::Project,
|
||||
v: &idx::Version,
|
||||
work: &Path,
|
||||
progress: &dyn Fn(&str, f32),
|
||||
) -> Result<Installed, String> {
|
||||
let line = format!("{} {}", p.name, v.version);
|
||||
let file = FileRef {
|
||||
url: v.file.url.clone(),
|
||||
name: v.file.name.clone(),
|
||||
size: v.file.size,
|
||||
sha512: None,
|
||||
sha256: Some(v.file.sha256.clone()),
|
||||
sha1: None,
|
||||
primary: true,
|
||||
};
|
||||
let path = fetch(&file, &work.join("downloads"), local, &|f| {
|
||||
progress(&line, f)
|
||||
})?;
|
||||
idx::check_file(index, p, v, &path).inspect_err(|_| {
|
||||
let _ = fs::remove_file(&path);
|
||||
})?;
|
||||
let pack = Modpack::read(&path)?;
|
||||
let home = home(work);
|
||||
fs::create_dir_all(&home).map_err(|e| format!("{}: {e}", home.display()))?;
|
||||
let mut mods = Vec::new();
|
||||
for m in &pack.manifest.mods {
|
||||
let found = index
|
||||
.project(&m.id)
|
||||
.and_then(|mp| Some((mp, mp.versions.iter().find(|w| w.version == m.version)?)));
|
||||
let Some((mp, mv)) = found.filter(|(_, mv)| mv.file.sha256 == m.sha256) else {
|
||||
return Err(format!(
|
||||
"{} needs {} {}, which isn't in the registry.",
|
||||
p.name, m.id, m.version
|
||||
));
|
||||
};
|
||||
install_version(index, local, mp, mv, &home, progress)?;
|
||||
java::set_enabled(&home, &m.id, m.on)?;
|
||||
mods.push(format!("{} {}", m.id, m.version));
|
||||
}
|
||||
// Settings once: the player's own changes to the profile stay on updates.
|
||||
let first = !work.join(RECORD).exists();
|
||||
if first {
|
||||
Modpack::extract_overrides(&path, &home)?;
|
||||
}
|
||||
let kept = work.join(&v.file.name);
|
||||
fs::rename(&path, &kept).map_err(|e| format!("{}: {e}", kept.display()))?;
|
||||
let record = Installed {
|
||||
id: p.id.clone(),
|
||||
name: p.name.clone(),
|
||||
version: v.version.clone(),
|
||||
sha256: v.file.sha256.clone(),
|
||||
mods,
|
||||
work: work.to_path_buf(),
|
||||
};
|
||||
let text = serde_json::to_string_pretty(&record).map_err(|e| e.to_string())?;
|
||||
fs::write(work.join(RECORD), text).map_err(|e| e.to_string())?;
|
||||
Ok(record)
|
||||
}
|
||||
|
||||
/// Turns the game's command into the pack's profile: its own game folder (the player's
|
||||
/// options.txt copied in when the pack brings none), its taken-down mods turned off first.
|
||||
pub fn apply(cmd: &mut Command, work: &Path) -> Result<(), String> {
|
||||
if !is_pack(work) {
|
||||
return Err(format!("{} is not an installed modpack.", work.display()));
|
||||
}
|
||||
let home = home(work);
|
||||
fs::create_dir_all(&home).map_err(|e| format!("{}: {e}", home.display()))?;
|
||||
let options = home.join("options.txt");
|
||||
let own = crate::backend::game_home().join("options.txt");
|
||||
if !options.exists() && own.is_file() {
|
||||
let _ = fs::copy(own, &options);
|
||||
}
|
||||
super::before_play(&home);
|
||||
cmd.current_dir(&home).env("HORIZON_HOME", &home);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Removes an installed pack: its mods and the profile's saves.
|
||||
pub fn remove(work: &Path) -> Result<(), String> {
|
||||
if work.parent() != Some(packs_dir().as_path()) || !is_pack(work) {
|
||||
return Err(format!("{} is not an installed modpack.", work.display()));
|
||||
}
|
||||
fs::remove_dir_all(work).map_err(|e| format!("{}: {e}", work.display()))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::io::Write;
|
||||
|
||||
/// A local registry: the mod and a pack of it, as `file://` files.
|
||||
fn registry(dir: &Path, on: bool, extra: &str) -> Index {
|
||||
let hmod_src = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../crates/horizon-mods/tests/index/coords_hud-0.1.0.hmod");
|
||||
let hmod = dir.join("coords_hud-0.1.0.hmod");
|
||||
fs::copy(hmod_src, &hmod).unwrap();
|
||||
let hmod_sha = idx::sha256_file(&hmod).unwrap();
|
||||
let hpack = dir.join("cozy-1.0.0.hpack");
|
||||
let mut zip = zip::ZipWriter::new(fs::File::create(&hpack).unwrap());
|
||||
let o = zip::write::SimpleFileOptions::default();
|
||||
zip.start_file("horizon-modpack.toml", o).unwrap();
|
||||
write!(
|
||||
zip,
|
||||
"format = 1\nid = \"cozy\"\nname = \"Cozy\"\nversion = \"1.0.0\"\ngame = \"26.3\"\n\
|
||||
[[mods]]\nid = \"coords_hud\"\nversion = \"0.1.0\"\nsha256 = \"{hmod_sha}\"\non = {on}\n"
|
||||
)
|
||||
.unwrap();
|
||||
zip.start_file("overrides/options.txt", o).unwrap();
|
||||
zip.write_all(b"renderDistance:8\n").unwrap();
|
||||
zip.finish().unwrap();
|
||||
let size = |p: &Path| fs::metadata(p).unwrap().len();
|
||||
let text = format!(
|
||||
r#"{{"schema": 1, "projects": [
|
||||
{{"id": "coords_hud", "kind": "mod", "name": "Coordinates HUD", "summary": "", "license": "MIT",
|
||||
"source": "https://x.test", "versions": [{{"version": "0.1.0", "api": "0.1", "side": "client",
|
||||
"capabilities": ["game-read", "hud", "chat"], "game": "26.3", "file": {{"name": "coords_hud-0.1.0.hmod",
|
||||
"url": "file://{}", "size": {}, "sha256": "{hmod_sha}"}}}}]}},
|
||||
{{"id": "cozy", "kind": "modpack", "name": "Cozy", "summary": "", "license": "MIT",
|
||||
"source": "https://x.test", "versions": [{{"version": "1.0.0", "api": "1", "game": "26.3",
|
||||
"requires": [{{"id": "coords_hud", "version": "0.1.0", "sha256": "{hmod_sha}"}}],
|
||||
"file": {{"name": "cozy-1.0.0.hpack", "url": "file://{}", "size": {}, "sha256": "{}"}}}}]}}
|
||||
]{extra}}}"#,
|
||||
hmod.display(),
|
||||
size(&hmod),
|
||||
hpack.display(),
|
||||
size(&hpack),
|
||||
idx::sha256_file(&hpack).unwrap()
|
||||
);
|
||||
Index::parse_local(&text).unwrap()
|
||||
}
|
||||
|
||||
fn scratch(name: &str) -> PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!(
|
||||
"horizon-launcher-hpack-{name}-{}",
|
||||
std::process::id()
|
||||
));
|
||||
let _ = fs::remove_dir_all(&dir);
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
dir
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pack_installs_as_a_profile_with_its_mods() {
|
||||
let dir = scratch("install");
|
||||
let index = registry(&dir, false, "");
|
||||
let packs = dir.join("horizon-packs");
|
||||
let pack = install_in(&index, true, "cozy", &packs, &|_, _| {}).unwrap();
|
||||
assert_eq!(pack.mods, ["coords_hud 0.1.0"]);
|
||||
let home = home(&packs.join("cozy"));
|
||||
assert!(home.join("horizon-mods/coords_hud.hmod").is_file());
|
||||
assert!(
|
||||
!java::is_enabled(&home, "coords_hud"),
|
||||
"the pack turns it off"
|
||||
);
|
||||
assert_eq!(
|
||||
fs::read_to_string(home.join("options.txt")).unwrap(),
|
||||
"renderDistance:8\n"
|
||||
);
|
||||
assert_eq!(
|
||||
list_in(&packs),
|
||||
[Installed {
|
||||
work: packs.join("cozy"),
|
||||
..pack
|
||||
}]
|
||||
);
|
||||
// Settings the player changed stay on an update.
|
||||
fs::write(home.join("options.txt"), "renderDistance:12\n").unwrap();
|
||||
install_in(&index, true, "cozy", &packs, &|_, _| {}).unwrap();
|
||||
assert_eq!(
|
||||
fs::read_to_string(home.join("options.txt")).unwrap(),
|
||||
"renderDistance:12\n"
|
||||
);
|
||||
// Not a modpack, and not there.
|
||||
assert!(install_in(&index, true, "coords_hud", &packs, &|_, _| {})
|
||||
.unwrap_err()
|
||||
.contains("not a modpack"));
|
||||
assert!(install_in(&index, true, "nope", &packs, &|_, _| {}).is_err());
|
||||
fs::remove_dir_all(&dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pack_with_a_taken_down_mod_installs_nothing() {
|
||||
let dir = scratch("revoked");
|
||||
let index = registry(
|
||||
&dir,
|
||||
true,
|
||||
r#", "revoked": [{"id": "coords_hud", "reason": "Test."}]"#,
|
||||
);
|
||||
let packs = dir.join("horizon-packs");
|
||||
let e = install_in(&index, true, "cozy", &packs, &|_, _| {}).unwrap_err();
|
||||
assert!(e.contains("taken down: Test."), "{e}");
|
||||
assert!(!packs.join("cozy").exists(), "nothing left behind");
|
||||
fs::remove_dir_all(&dir).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -45,8 +45,8 @@ fn searches_by_kind_and_words() {
|
||||
assert_eq!(found("", Kind::Mod), ["coords_hud"]);
|
||||
assert_eq!(found("coordinates HUD", Kind::Mod), ["coords_hud"]);
|
||||
assert!(found("zoom", Kind::Mod).is_empty());
|
||||
// Kinds this launcher can't install yet (modpacks, a world) are never offered.
|
||||
assert!(found("", Kind::Modpack).is_empty());
|
||||
// Modpacks under Modpacks; a kind this launcher can't install yet (a world) never.
|
||||
assert_eq!(found("", Kind::Modpack), ["cozy"]);
|
||||
assert!(found("skyblock", Kind::ResourcePack).is_empty());
|
||||
let p = hud(&index);
|
||||
assert_eq!(p.support(), super::super::Support::Works);
|
||||
@@ -123,7 +123,7 @@ fn refuses_a_changed_file_a_taken_id_and_local_files_from_the_real_registry() {
|
||||
date: String::new(),
|
||||
});
|
||||
let e = install_from(&taken_down, true, &p, &home, &|_, _| {}).unwrap_err();
|
||||
assert!(e.contains("no version"), "{e}");
|
||||
assert_eq!(e, "Coordinates HUD was taken down: Test.");
|
||||
fs::remove_dir_all(&home).unwrap();
|
||||
}
|
||||
|
||||
|
||||
+39
-1
@@ -1214,6 +1214,23 @@ fn mods(action: ModsCmd, as_json: bool) -> Result<(), String> {
|
||||
} => {
|
||||
let source = source.get()?;
|
||||
let p = source.project(&project)?;
|
||||
if p.kind == Kind::Modpack && p.source == SourceId::Horizon {
|
||||
let pack = horizon::pack::install(&p.id, &line)?;
|
||||
if as_json {
|
||||
json(
|
||||
serde_json::json!({"pack": pack.id, "version": pack.version, "mods": pack.mods, "home": horizon::pack::home(&pack.work)}),
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"{} {} is installed as its own profile, with {}.",
|
||||
pack.name,
|
||||
pack.version,
|
||||
pack.mods.join(", ")
|
||||
);
|
||||
println!("Play it: horizon-launcher modpack play {}", pack.id);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
if p.kind == Kind::Modpack {
|
||||
let folder = modpacks::ports_dir().join("downloads");
|
||||
let file =
|
||||
@@ -1306,10 +1323,15 @@ fn mods(action: ModsCmd, as_json: bool) -> Result<(), String> {
|
||||
}
|
||||
|
||||
fn modpack(action: ModpackCmd, as_json: bool) -> Result<(), String> {
|
||||
use horizon_launcher::browser::horizon;
|
||||
use horizon_launcher::modpacks::{self, Imported};
|
||||
use horizon_port_pack::report::Status;
|
||||
let log = &|line: String| eprintln!("{line}");
|
||||
let work = |pack: &str| {
|
||||
let registry = horizon::pack::packs_dir().join(pack);
|
||||
if horizon::pack::is_pack(®istry) {
|
||||
return Ok(registry);
|
||||
}
|
||||
let work = modpacks::ports_dir().join(pack);
|
||||
modpacks::load(&work).map(|_| work)
|
||||
};
|
||||
@@ -1343,10 +1365,26 @@ fn modpack(action: ModpackCmd, as_json: bool) -> Result<(), String> {
|
||||
match action {
|
||||
ModpackCmd::List => {
|
||||
let packs = modpacks::list();
|
||||
if packs.is_empty() && !as_json {
|
||||
let registry = horizon::pack::list();
|
||||
if packs.is_empty() && registry.is_empty() && !as_json {
|
||||
println!("No modpack imported yet: horizon-launcher modpack import <pack>");
|
||||
}
|
||||
packs.iter().for_each(show);
|
||||
for p in ®istry {
|
||||
if as_json {
|
||||
json(
|
||||
serde_json::json!({"pack": p.id, "name": p.name, "version": p.version, "source": "horizon", "mods": p.mods}),
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"{} {} ({}, from Horizon's registry)\n {}",
|
||||
p.name,
|
||||
p.version,
|
||||
p.id,
|
||||
p.mods.join(", ")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ModpackCmd::Import { path } => show(&modpacks::import(&path, log)?),
|
||||
ModpackCmd::Port {
|
||||
|
||||
@@ -205,6 +205,8 @@ struct Launcher {
|
||||
/// The Modpacks page: the imported packs (read when the page first opens), the one shown,
|
||||
/// the report's filter, and the pipeline step running now with its log.
|
||||
packs: Vec<horizon_launcher::modpacks::Imported>,
|
||||
/// Modpacks installed from Horizon's registry, each its own profile.
|
||||
registry_packs: Vec<horizon_launcher::browser::horizon::pack::Installed>,
|
||||
packs_loaded: Option<Instant>,
|
||||
pack_open: Option<String>,
|
||||
pack_filter: Option<horizon_port_pack::report::Status>,
|
||||
@@ -330,6 +332,7 @@ impl Launcher {
|
||||
play_pressed: None,
|
||||
bench: perf::Bench::from_env(),
|
||||
packs: Vec::new(),
|
||||
registry_packs: Vec::new(),
|
||||
packs_loaded: None,
|
||||
pack_open: None,
|
||||
pack_filter: None,
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//! `home/`, the profile's own saves and options. Nothing is uploaded or shared: mod jars are
|
||||
//! often All Rights Reserved, so the ports stay on the player's machine.
|
||||
use crate::backend;
|
||||
use crate::browser::horizon::pack as horizon_pack;
|
||||
use horizon_port_pack::{
|
||||
fetch::{Fetched, How},
|
||||
import::Pack,
|
||||
@@ -232,6 +233,9 @@ pub fn outcome(pack: &Imported) -> String {
|
||||
|
||||
/// Removes an imported pack: its jars, ports and the profile's saves.
|
||||
pub fn remove(work: &Path) -> Result<(), String> {
|
||||
if horizon_pack::is_pack(work) {
|
||||
return horizon_pack::remove(work);
|
||||
}
|
||||
if work.parent() != Some(ports_dir().as_path()) {
|
||||
return Err(format!("{} is not an imported pack", work.display()));
|
||||
}
|
||||
@@ -245,7 +249,11 @@ pub fn profile_home(work: &Path) -> PathBuf {
|
||||
|
||||
/// Turns the game's command into this pack's profile: its own home (the player's options.txt
|
||||
/// copied in the first time, so keys and video settings carry over) and its carried-over mods.
|
||||
/// A modpack from Horizon's registry (`horizon-packs/<id>/`) plays its own profile the same way.
|
||||
pub fn apply_profile(cmd: &mut Command, work: &Path) -> Result<(), String> {
|
||||
if horizon_pack::is_pack(work) {
|
||||
return horizon_pack::apply(cmd, work);
|
||||
}
|
||||
// Only mods that load together: the game would refuse the later of two sharing a namespace.
|
||||
let (mods, _) = pipeline::loadable(&carried(work));
|
||||
if mods.is_empty() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Imported modpacks, on the Mods page's Modpacks tab: import a pack, read its coverage report,
|
||||
//! port what this computer can and play it as its own profile (`horizon_launcher::modpacks`).
|
||||
use super::*;
|
||||
use horizon_launcher::browser::horizon::pack as horizon_pack;
|
||||
use horizon_launcher::modpacks::{self, Imported};
|
||||
use horizon_port_pack::report::Status;
|
||||
use std::path::PathBuf;
|
||||
@@ -130,6 +131,7 @@ impl Launcher {
|
||||
if self.packs_loaded.is_none() {
|
||||
self.mods.report_list.reset();
|
||||
self.packs = modpacks::list();
|
||||
self.registry_packs = horizon_pack::list();
|
||||
if self.pack_open.is_none() {
|
||||
self.pack_open = self.packs.first().map(|p| p.slug.clone());
|
||||
}
|
||||
@@ -177,6 +179,12 @@ impl Launcher {
|
||||
if let Some(e) = &self.pack_error {
|
||||
page = page.child(notice(e.clone(), &t));
|
||||
}
|
||||
if !self.registry_packs.is_empty() {
|
||||
page = page.child(self.registry_pack_rows(cx));
|
||||
}
|
||||
if self.packs.is_empty() && !self.registry_packs.is_empty() {
|
||||
return page;
|
||||
}
|
||||
if self.packs.is_empty() {
|
||||
return page.child(
|
||||
text(theme::CAPTION)
|
||||
@@ -216,6 +224,78 @@ impl Launcher {
|
||||
}
|
||||
}
|
||||
|
||||
/// The modpacks installed from Horizon's registry: each plays its own profile.
|
||||
fn registry_pack_rows(&self, cx: &mut Context<Self>) -> Div {
|
||||
let t = self.theme;
|
||||
let mut list = div().flex().flex_col();
|
||||
for (i, p) in self.registry_packs.iter().enumerate() {
|
||||
let (play, remove) = (p.work.clone(), p.work.clone());
|
||||
let id = p.id.clone();
|
||||
let key = format!("horizon:{id}");
|
||||
let confirming = self.confirm_remove.as_deref() == Some(key.as_str());
|
||||
let right = div()
|
||||
.flex()
|
||||
.gap(px(8.))
|
||||
.child(
|
||||
button(format!("play-pack-{id}"), "Play", Kind::Primary, &t).on_click(
|
||||
cx.listener(move |this, _: &ClickEvent, _, cx| {
|
||||
this.play_pack(play.clone());
|
||||
cx.notify();
|
||||
}),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
button(
|
||||
format!("remove-pack-{id}"),
|
||||
if confirming {
|
||||
"Remove for good"
|
||||
} else {
|
||||
"Remove"
|
||||
},
|
||||
if confirming {
|
||||
Kind::Secondary
|
||||
} else {
|
||||
Kind::Ghost
|
||||
},
|
||||
&t,
|
||||
)
|
||||
.when(confirming, |b| b.text_color(t.danger))
|
||||
.on_click(cx.listener(
|
||||
move |this, _: &ClickEvent, _, cx| {
|
||||
if this.confirm_remove.as_ref() == Some(&key) {
|
||||
match horizon_pack::remove(&remove) {
|
||||
Ok(()) => this.packs_loaded = None,
|
||||
Err(e) => this.pack_error = Some(e),
|
||||
}
|
||||
this.confirm_remove = None;
|
||||
} else {
|
||||
this.confirm_remove = Some(key.clone());
|
||||
}
|
||||
cx.notify();
|
||||
},
|
||||
)),
|
||||
);
|
||||
let detail = format!(
|
||||
"{} from Horizon's registry, its own profile: {}",
|
||||
p.version,
|
||||
p.mods.join(", ")
|
||||
);
|
||||
list = list.child(index_row(
|
||||
i + 1,
|
||||
p.name.clone(),
|
||||
Some(
|
||||
text(theme::CAPTION)
|
||||
.text_color(t.muted)
|
||||
.child(detail)
|
||||
.into_any_element(),
|
||||
),
|
||||
Some(right.into_any_element()),
|
||||
&t,
|
||||
));
|
||||
}
|
||||
list
|
||||
}
|
||||
|
||||
fn pack_log_plate(&self, t: &Theme) -> Div {
|
||||
let start = self.pack_log.len().saturating_sub(LOG_SHOWN);
|
||||
plate(t)
|
||||
|
||||
@@ -468,6 +468,16 @@ impl Launcher {
|
||||
None => source.project(&id)?,
|
||||
};
|
||||
modpack = p.kind == PackKind::Modpack;
|
||||
if modpack && p.source == SourceId::Horizon {
|
||||
let pack = horizon::pack::install(&p.id, &progress)?;
|
||||
return Ok(format!(
|
||||
"Installed {} {} as its own profile with {}, each checked. Play it \
|
||||
from the list above.",
|
||||
pack.name,
|
||||
pack.version,
|
||||
pack.mods.join(", ")
|
||||
));
|
||||
}
|
||||
if modpack {
|
||||
let folder = modpacks::ports_dir().join("downloads");
|
||||
let file = installed::fetch_modpack(&*source, &p, &folder, &|f| {
|
||||
|
||||
Reference in New Issue
Block a user