Skip to content

Commit

Permalink
use buffered operations
Browse files Browse the repository at this point in the history
  • Loading branch information
bananaturtlesandwich committed Aug 28, 2023
1 parent 73c1ecb commit eae7268
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
name = "blue-fire-rando"
description = "a gamemode for blue fire which shuffles pickups"
repository = "https://github.com/bananaturtlesandwich/blue-fire-rando"
version = "1.1.3"
version = "1.1.4"
authors = ["spuds"]
edition = "2021"

[dependencies]
eframe = { version = "0.22", default-features = false, features = ["glow", "persistence"] }
unreal_asset = { git = "https://github.com/astrotechies/unrealmodding", package = "unreal_asset", rev = "186842c"}
repak = { git = "https://github.com/bananaturtlesandwich/repak", branch = "features-redo", default-features = false }
repak = { git = "https://github.com/trumank/repak", rev = "a749449", default-features = false }
strum = { version = "0.25", features = ["derive"] }
rand = "0.8"
egui-modal = "0.2"
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod logic;
mod map;
mod writing;

type Mod = std::sync::Arc<std::sync::Mutex<repak::PakWriter<std::fs::File>>>;
type Mod = std::sync::Arc<std::sync::Mutex<repak::PakWriter<std::io::BufWriter<std::fs::File>>>>;
type Asset<T> = unreal_asset::Asset<std::io::Cursor<T>>;

pub struct Rando {
Expand Down Expand Up @@ -103,8 +103,9 @@ impl Rando {
ducks: get_bool("ducks"),
}
}
fn pak(&self) -> Result<std::fs::File, std::io::Error> {
fn pak(&self) -> Result<std::io::BufReader<std::fs::File>, std::io::Error> {
std::fs::File::open(self.pak.join("Blue Fire-WindowsNoEditor.pak"))
.map(std::io::BufReader::new)
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/writing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub enum Error {
#[error("locked poisoned writer")]
WriterPoison,
#[error("extracted poisoned writer")]
InnerMutex(#[from] std::sync::PoisonError<repak::PakWriter<std::fs::File>>),
InnerMutex(#[from] std::sync::PoisonError<repak::PakWriter<std::io::BufWriter<std::fs::File>>>),
#[error("some threads are still using writer")]
InnerArc,
#[error("failed to strip prefix when writing file to pak")]
Expand All @@ -51,11 +51,13 @@ macro_rules! stub {
}

stub!(
std::sync::Arc<std::sync::Mutex<repak::PakWriter<std::fs::File>>>,
std::sync::Arc<std::sync::Mutex<repak::PakWriter<std::io::BufWriter<std::fs::File>>>>,
InnerArc
);
stub!(
std::sync::PoisonError<std::sync::MutexGuard<'_, repak::PakWriter<std::fs::File>>>,
std::sync::PoisonError<
std::sync::MutexGuard<'_, repak::PakWriter<std::io::BufWriter<std::fs::File>>>,
>,
WriterPoison
);
stub!(
Expand Down Expand Up @@ -143,7 +145,7 @@ pub fn write(data: Data, app: &crate::Rando) -> Result<(), Error> {
let mut sync = app.pak()?;
let pak = repak::PakReader::new(&mut sync, repak::Version::V9)?;
let mod_pak = std::sync::Arc::new(std::sync::Mutex::new(repak::PakWriter::new(
std::fs::File::create(app.pak.join("rando_p.pak"))?,
std::io::BufWriter::new(std::fs::File::create(app.pak.join("rando_p.pak"))?),
repak::Version::V9,
"../../../".to_string(),
None,
Expand Down

0 comments on commit eae7268

Please sign in to comment.