ages_ice_archive/lib.rs
1//! Operations over SEGA ICE archives, used in _Phantasy Star Online 2_.
2//!
3//! Currently, only ICE versions 3 and 4 are supported for reading and writing.
4//! These are the only kinds of ICE files in the game client and protocol, so it
5//! should be usable for all available ICE files.
6//!
7//! # Examples
8//!
9//! Reading an ICE file:
10//!
11//! ```no_run
12//! use std::fs::File;
13//! use ages_ice_archive::{Group, IceArchive, IceGroupIter};
14//!
15//! let ice_archive = IceArchive::load(
16//! File::open("ice_file.ice").unwrap()
17//! ).unwrap();
18//! let g1_data = ice_archive.decompress_group(Group::Group1).unwrap();
19//! let g2_data = ice_archive.decompress_group(Group::Group2).unwrap();
20//!
21//! println!("Group 1:");
22//! let g1_iter = IceGroupIter::new(&g1_data[..], ice_archive.group_count(Group::Group1)).unwrap();
23//! for f in g1_iter {
24//! println!("\t{}", f.name().unwrap());
25//! }
26//!
27//! println!("Group 2:");
28//! let g2_iter = IceGroupIter::new(&g2_data[..], ice_archive.group_count(Group::Group2)).unwrap();
29//! for f in g2_iter {
30//! println!("\t{}", f.name().unwrap());
31//! }
32//! ```
33//!
34//! Writing an ICE file:
35//!
36//! ```
37//! use std::io::Write;
38//! use ages_ice_archive::{Group, IceWriter};
39//! use ascii::AsciiStr;
40//!
41//! let mut ice_writer = IceWriter::new(4, true, true, false).unwrap();
42//! {
43//! let mut file = ice_writer.begin_file(
44//! AsciiStr::from_ascii("hello.txt").unwrap(),
45//! AsciiStr::from_ascii("txt").unwrap(),
46//! Group::Group1,
47//! );
48//! file.write_all(b"hello world");
49//! file.finish();
50//! }
51//! let mut buf = Vec::new(); // any Write sink is acceptable
52//! ice_writer.finish(&mut buf).unwrap();
53//! ```
54
55pub(crate) mod read;
56pub(crate) mod write;
57
58#[cfg(all(feature = "oodle", any(target_os = "linux", target_os = "windows")))]
59pub(crate) mod ooz_sys;
60
61pub use self::read::{IceArchive, IceGroupIter, IceFile};
62pub use self::write::{IceWriter, IceFileWriter, UnsupportedVersion};
63
64#[derive(Clone, Copy, Debug, PartialEq, Eq)]
65/// One of the two file groups in an ICE archive.
66pub enum Group {
67 Group1,
68 Group2,
69}
70
71impl ::std::fmt::Display for Group {
72 fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
73 let index = match self {
74 Group::Group1 => 1,
75 Group::Group2 => 2,
76 };
77 fmt.write_fmt(format_args!("Group {}", index))
78 }
79}