Skip to content

Commit

Permalink
Unify config stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
trumank committed Jul 22, 2024
1 parent 33aeb2b commit 42bf3a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
5 changes: 5 additions & 0 deletions hook/src/hooks/pak/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ pub struct PlainFileProviderConfig {
path: PathBuf,
globs: Vec<String>,
}
impl PlainFileProviderConfig {
pub fn build(self) -> Result<PlainFileProvider> {
PlainFileProvider::new(self)
}
}

pub struct PlainFileProvider {
path: PathBuf,
Expand Down
20 changes: 14 additions & 6 deletions hook/src/hooks/pak/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::sync::{Mutex, OnceLock};
use crate::globals;
use crate::ue::{FString, TArray};

use self::file::{PlainFileProvider, PlainFileProviderConfig};
use self::network::{EditorNetworkConfig, EditorNetworkFileProvider};
use self::file::PlainFileProviderConfig;
use self::network::EditorNetworkConfig;

#[derive(Debug, Default)]
pub struct FileInfo {
Expand Down Expand Up @@ -55,6 +55,17 @@ enum LayerConfig {
File(PlainFileProviderConfig),
EditorNetwork(EditorNetworkConfig),
}
impl LayerConfig {
fn build(self) -> Result<Box<dyn FileProvider>> {
fn map(p: Result<impl FileProvider + 'static>) -> Result<Box<dyn FileProvider>> {
p.map(|p| Box::new(p) as Box<dyn FileProvider>)
}
match self {
LayerConfig::File(c) => map(c.build()),
LayerConfig::EditorNetwork(c) => map(c.build()),
}
}
}

#[repr(C)]
pub struct IFileHandle<S: Read + Write + Seek> {
Expand Down Expand Up @@ -320,10 +331,7 @@ impl LayeredFileProvider {

for l in config.layers {
if l.enable {
layers.push(match l.config {
LayerConfig::File(c) => Box::new(PlainFileProvider::new(c)?),
LayerConfig::EditorNetwork(c) => Box::new(EditorNetworkFileProvider::new(c)?),
})
layers.push(l.config.build()?);
}
}

Expand Down
5 changes: 5 additions & 0 deletions hook/src/hooks/pak/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ impl Default for EditorNetworkConfig {
}
}
}
impl EditorNetworkConfig {
pub fn build(self) -> Result<EditorNetworkFileProvider> {
EditorNetworkFileProvider::new(self)
}
}

pub struct EditorNetworkFileProvider {
input: BufReader<TcpStream>,
Expand Down

0 comments on commit 42bf3a3

Please sign in to comment.