Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- View, export and replace textures (`.ytd`) from DDS or PNG; preview 3D models; play and replace sounds.

**Install mods**
- Install `.oiv` packages and add-on packs (`dlc.rpf`), with the DLC list updated for you.
- Install `.oiv` and `.oivs` packages and add-on packs (`dlc.rpf`), with the DLC list updated for you.
- On Enhanced, convert models and textures made for Legacy, built in (CodeWalker's converter, no Wine).
- Export your own changes as an `.oiv`, to share them or reinstall them later.

Expand Down
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ libc = "0.2"

[dev-dependencies]
tempfile = "3"
zip = { version = "9", default-features = false, features = ["deflate"] }
67 changes: 57 additions & 10 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,11 @@ enum Command {
Mkdir { path: String },
/// Create a new, empty archive.
New { path: PathBuf },
/// Install an OIV package into the mods folder, or an add-on pack: a
/// dlc.rpf (or a folder holding them) goes to update/x64/dlcpacks/<name>/
/// and into the DLC list. For the Enhanced edition, files made for Legacy
/// are converted first (when paleto-cwconv is installed).
/// Install an OIV package (.oiv, or a super package .oivs) into the mods
/// folder, or an add-on pack: a dlc.rpf (or a folder holding them) goes to
/// update/x64/dlcpacks/<name>/ and into the DLC list. For the Enhanced
/// edition, files made for Legacy are converted first (when paleto-cwconv
/// is installed).
Install {
package: PathBuf,
/// Install files made for Legacy as they are.
Expand All @@ -173,6 +174,14 @@ enum Command {
/// The add-on pack's name (by default its folder's, or the one in its setup2.xml).
#[arg(long)]
name: Option<String>,
/// What to install of a super package, over what it ticks itself:
/// MODULE ticks a module, -MODULE unticks one, GROUP=OPTION or
/// GROUP=none chooses in a group. Example: "visuals,-sfx,alt=both".
#[arg(long, value_name = "CHOICES", allow_hyphen_values = true)]
select: Option<String>,
/// Show what a super package offers and what would be installed; install nothing.
#[arg(long)]
list: bool,
},
/// Convert Legacy models, textures and particles to the Enhanced format
/// (with CodeWalker's converter, paleto-cwconv). Without files: every such
Expand Down Expand Up @@ -823,8 +832,9 @@ fn main() -> Result<()> {
}
}
}
Command::Install { package, no_convert, name } if !package.extension().is_some_and(|e| e.eq_ignore_ascii_case("oiv")) => {
Command::Install { package, no_convert, name, select, list } if !package.extension().is_some_and(|e| e.eq_ignore_ascii_case("oiv") || e.eq_ignore_ascii_case("oivs")) => {
use paleto_core::addon;
anyhow::ensure!(select.is_none() && !list, "--select and --list are for super packages (.oivs)");
let game = find_game(cli.game.as_deref(), None)?;
let keys = game.keys()?;
let packs = addon::find_packs(std::slice::from_ref(&package), Some(&keys));
Expand All @@ -839,12 +849,29 @@ fn main() -> Result<()> {
println!(" {line}");
}
}
Command::Install { package, no_convert, .. } => {
let game = find_game(cli.game.as_deref(), None)?;
let keys = game.keys()?;
Command::Install { package, no_convert, select, list, .. } => {
let mut pkg = Package::open(&package).with_context(|| format!("opening {}", package.display()))?;
let m = &pkg.metadata;
println!("{} {} by {} (OIV {})", m.name, m.version, m.author, m.format_version);
println!("{} {} by {} ({} {})", m.name, m.version, m.author, if pkg.choices.is_some() { "OIVS" } else { "OIV" }, m.format_version);
match pkg.choices.clone() {
Some(choices) => {
let selection = choices.parse_selection(select.as_deref().unwrap_or_default())?;
print_choices(&choices, &selection);
if list {
return Ok(());
}
anyhow::ensure!(choices.installs_anything(&selection), "nothing is chosen: choose with --select (the ids above)");
pkg.select(&selection)?;
}
None => anyhow::ensure!(select.is_none() && !list, "--select and --list are for super packages (.oivs)"),
}
let game = find_game(cli.game.as_deref(), None)?;
let keys = game.keys()?;
if let Some(made) = pkg.metadata.game_version
&& made != game.edition
{
println!("! the package is made for GTA V {made:?}, the game is {:?}: it may crash on it", game.edition);
}
if game.edition == paleto_core::Edition::Enhanced {
let legacy = pkg.legacy_files(Some(&keys))?;
if !legacy.is_empty() {
Expand Down Expand Up @@ -1268,6 +1295,26 @@ fn write_file(path: &Path, data: &[u8]) -> Result<()> {
Ok(())
}

/// What a super package offers, marked as `selection` chooses it, with the ids `--select` takes.
fn print_choices(choices: &paleto_core::oiv::Choices, selection: &paleto_core::oiv::Selection) {
let mark = |on: bool, mark: char| if on { mark } else { ' ' };
if !choices.modules.is_empty() {
println!("modules:");
}
for (m, &on) in choices.modules.iter().zip(&selection.modules) {
println!(" [{}] {:<20} {}{}", mark(on || m.required, 'x'), m.part.id, m.part.label(), if m.required { " (required)" } else { "" });
}
for (g, &choice) in choices.groups.iter().zip(&selection.groups) {
println!("group {} ({}):", g.id, g.label());
if g.allow_none {
println!(" ({}) none", mark(choice.is_none(), '*'));
}
for (i, o) in g.options.iter().enumerate() {
println!(" ({}) {:<20} {}", mark(choice == Some(i), '*'), o.id, o.label());
}
}
}

/// What the writer noted when it finished (a backup it could not remove).
fn show_notes(log: Vec<String>) {
for line in log {
Expand Down Expand Up @@ -1417,7 +1464,7 @@ fn changes_game(command: &Command) -> Option<Option<PathBuf>> {
}
Command::Xml { path, import: Some(_), .. } | Command::Text { path, import: Some(_), .. } => inside(path),
Command::Audio { path, replace, .. } if !replace.is_empty() => inside(path),
Command::Install { .. } | Command::Clean { delete: true } => Some(None),
Command::Install { list: false, .. } | Command::Clean { delete: true } => Some(None),
Command::Hunt { action } if !matches!(action, None | Some(HuntAction::Status)) => Some(None),
Command::Snapshot { action: Some(SnapshotAction::Save { .. } | SnapshotAction::Restore { .. } | SnapshotAction::Delete { .. }) } => Some(None),
Command::Convert { undo: Some(_), .. } => Some(None),
Expand Down
66 changes: 66 additions & 0 deletions crates/cli/tests/install.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//! `paleto install` of a super package (.oivs): what it offers, and choosing from it.

use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};

fn paleto(dir: &Path, args: &[&str]) -> Output {
let mut cmd = Command::new(env!("CARGO_BIN_EXE_paleto"));
// No game or settings of the user's: an empty home.
cmd.env("HOME", dir).env_remove("XDG_CONFIG_HOME").env_remove("XDG_DATA_HOME").current_dir(dir).args(args);
cmd.output().unwrap()
}

fn zip(path: &Path, entries: &[(&str, &str)]) -> PathBuf {
let mut zip = zip::ZipWriter::new(std::fs::File::create(path).unwrap());
for (name, data) in entries {
zip.start_file(*name, zip::write::SimpleFileOptions::default()).unwrap();
zip.write_all(data.as_bytes()).unwrap();
}
zip.finish().unwrap();
path.to_path_buf()
}

const SUPER: &str = r#"<superpackage version="1.0" target="Five"><metadata><name>Pack</name><version><major>1</major><minor>0</minor></version></metadata>
<modules>
<module id="base" required="true" name="Base"><install><content><add source="b.asi">scripts\b.asi</add></content></install></module>
<module id="extra" name="Extra"><install><content><add source="e.asi">scripts\e.asi</add></content></install></module>
</modules>
<groups><group id="alt" title="Alternative" allowNone="true">
<option id="one" name="One"><install><content><add source="o.asi">scripts\o.asi</add></content></install></option>
</group></groups></superpackage>"#;

#[test]
fn lists_and_chooses_what_a_super_package_offers() {
let dir = tempfile::tempdir().unwrap();
let package = zip(&dir.path().join("pack.oivs"), &[("super.xml", SUPER), ("content/b.asi", "b"), ("content/e.asi", "e"), ("content/o.asi", "o")]);
let package = package.to_string_lossy();
let out = paleto(dir.path(), &["install", "--list", "--select", "extra,alt=one", &package]);
let text = String::from_utf8_lossy(&out.stdout);
assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
for line in ["Pack 1.0 by (OIVS 1.0)", "[x] base", "(required)", "[x] extra", "group alt (Alternative):", "( ) none", "(*) one"] {
assert!(text.contains(line), "{line}: {text}");
}
let unknown = paleto(dir.path(), &["install", "--select", "nope", &package]);
assert!(!unknown.status.success() && String::from_utf8_lossy(&unknown.stderr).contains("no module nope"));
// A value that starts with '-' unticks a module.
let out = paleto(dir.path(), &["install", "--list", "--select", "-extra", &package]);
assert!(out.status.success() && String::from_utf8_lossy(&out.stdout).contains("[ ] extra"), "{}", String::from_utf8_lossy(&out.stderr));
// Not for an add-on pack, which would be installed.
std::fs::write(dir.path().join("dlc.rpf"), b"").unwrap();
let out = paleto(dir.path(), &["install", "--list", &dir.path().join("dlc.rpf").to_string_lossy()]);
assert!(!out.status.success() && String::from_utf8_lossy(&out.stderr).contains("are for super packages (.oivs)"));
let plain = zip(&dir.path().join("plain.oiv"), &[("assembly.xml", r#"<package version="2.2"><metadata><name>P</name></metadata><content/></package>"#)]);
let out = paleto(dir.path(), &["install", "--list", &plain.to_string_lossy()]);
assert!(!out.status.success() && String::from_utf8_lossy(&out.stderr).contains("are for super packages (.oivs)"));
}

#[test]
fn a_super_package_with_nothing_chosen_installs_nothing() {
let dir = tempfile::tempdir().unwrap();
let manifest = SUPER.replace(r#"required="true""#, r#"required="false""#);
let package = zip(&dir.path().join("pack.oivs"), &[("super.xml", &manifest), ("content/b.asi", "b"), ("content/e.asi", "e"), ("content/o.asi", "o")]);
let out = paleto(dir.path(), &["install", &package.to_string_lossy()]);
assert!(!out.status.success());
assert!(String::from_utf8_lossy(&out.stderr).contains("nothing is chosen: choose with --select"), "{}", String::from_utf8_lossy(&out.stderr));
}
2 changes: 2 additions & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ mod link_matrix_tests;
#[cfg(test)]
mod oiv_txn_tests;
#[cfg(test)]
mod oivs_tests;
#[cfg(test)]
mod write_safety_tests;

pub use game::{Edition, Game};
Expand Down
Loading
Loading