pub struct ImportFile<R> { /* private fields */ }Expand description
Reads an r2z (r2modman zip) profile export.
Provides access to the manifest and config files stored in the archive.
§Examples
use std::io::Cursor;
use loadsmith_thunderstore::r2z::{ImportFile, ExportFile, ProfileManifest, Mod, Version};
use thunderstore::PackageIdent;
let manifest = ProfileManifest::new(
"Test",
vec![Mod::new(PackageIdent::new("A", "B"), Version::new(1, 0, 0), true)],
(),
);
let data = ExportFile::create(Cursor::new(Vec::new()), &manifest).unwrap().finish().unwrap();
let mut import = ImportFile::open(data).unwrap();
let read = import.read_manifest::<()>().unwrap();
assert_eq!(read.profile_name, "Test");Implementations§
Source§impl<R: Read + Seek> ImportFile<R>
impl<R: Read + Seek> ImportFile<R>
Sourcepub fn open(reader: R) -> Result<Self>
pub fn open(reader: R) -> Result<Self>
Opens an r2z archive for reading.
§Examples
use std::io::Cursor;
use loadsmith_thunderstore::r2z::ImportFile;
let import = ImportFile::open(Cursor::new(Vec::new()));Sourcepub fn read_manifest<T: DeserializeOwned>(
&mut self,
) -> Result<ProfileManifest<T>>
pub fn read_manifest<T: DeserializeOwned>( &mut self, ) -> Result<ProfileManifest<T>>
Reads and deserialises the export.r2x manifest from the archive.
§Examples
use std::io::Cursor;
use loadsmith_thunderstore::r2z::{ImportFile, ExportFile, ProfileManifest};
let manifest = ProfileManifest::new("Test", vec![], ());
let data = ExportFile::create(Cursor::new(Vec::new()), &manifest).unwrap().finish().unwrap();
let mut import = ImportFile::open(data).unwrap();
let read: ProfileManifest<()> = import.read_manifest().unwrap();
assert_eq!(read.profile_name, "Test");Sourcepub fn read_files<F>(&mut self, callback: F) -> Result<()>
pub fn read_files<F>(&mut self, callback: F) -> Result<()>
Iterates over every file in the archive (except export.r2x)
and invokes callback with the file path and a reader.
§Examples
use std::io::Cursor;
use loadsmith_thunderstore::r2z::{ImportFile, ExportFile, ProfileManifest, Mod, Version};
use thunderstore::PackageIdent;
let manifest = ProfileManifest::new(
"Test",
vec![Mod::new(PackageIdent::new("A", "B"), Version::new(1, 0, 0), true)],
(),
);
let mut export = ExportFile::create(Cursor::new(Vec::new()), &manifest).unwrap();
export.write_file("config.cfg", &b"enabled=true"[..]).unwrap();
let data = export.finish().unwrap();
let mut import = ImportFile::open(data).unwrap();
import.read_files(|path, _reader| {
assert_eq!(path, std::path::Path::new("config.cfg"));
Ok(())
}).unwrap();Sourcepub fn import_config_files(
&mut self,
target: impl AsRef<Path>,
filter: bool,
) -> Result<()>
pub fn import_config_files( &mut self, target: impl AsRef<Path>, filter: bool, ) -> Result<()>
Extracts config files from the archive into a target directory.
When filter is true, executable and script file types (.dll,
.exe, .bat, etc.) as well as export.r2x and mods.yml are
skipped. Files under a config/ prefix are mapped to BepInEx/config/.
Files that already exist with identical content are skipped.
§Examples
use std::io::Cursor;
use loadsmith_thunderstore::r2z::{ImportFile, ExportFile, ProfileManifest};
let manifest = ProfileManifest::new("Test", vec![], ());
let data = ExportFile::create(Cursor::new(Vec::new()), &manifest).unwrap().finish().unwrap();
let mut import = ImportFile::open(data).unwrap();
import.import_config_files("./output", true).unwrap();Auto Trait Implementations§
impl<R> Freeze for ImportFile<R>where
R: Freeze,
impl<R> RefUnwindSafe for ImportFile<R>where
R: RefUnwindSafe,
impl<R> Send for ImportFile<R>where
R: Send,
impl<R> Sync for ImportFile<R>where
R: Sync,
impl<R> Unpin for ImportFile<R>where
R: Unpin,
impl<R> UnsafeUnpin for ImportFile<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for ImportFile<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more