made use of walkdir
This commit is contained in:
@@ -3,13 +3,14 @@ use libloot::{
|
||||
error::{GameHandleCreationError, LoadPluginsError, SortPluginsError},
|
||||
};
|
||||
use log::trace;
|
||||
use std::{io, path::Path};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{
|
||||
basic_types::{self, ModdedInstance, RootConfig},
|
||||
utils::walk_files_recursive,
|
||||
use std::{
|
||||
io,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use thiserror::Error;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use crate::basic_types::{self, ModdedInstance, RootConfig};
|
||||
|
||||
pub fn create_loadorder(
|
||||
root_config: &RootConfig,
|
||||
@@ -19,11 +20,23 @@ pub fn create_loadorder(
|
||||
let mut loot_game = Game::new(GameType::SkyrimSE, &game.install_location)?;
|
||||
|
||||
// Add plugins files from the game install
|
||||
let install_plugins: Vec<_> = walk_files_recursive(game.install_location.join("Data"))?
|
||||
.filter(|f| is_plugin_file(f.path()))
|
||||
.map(|f| f.path())
|
||||
.collect();
|
||||
let refs: Vec<_> = install_plugins.iter().map(|e| e.as_path()).collect();
|
||||
let install_plugins: Vec<PathBuf> = WalkDir::new(game.install_location.join("Data"))
|
||||
.into_iter()
|
||||
.map(|entry| {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
|
||||
if is_plugin_file(path) {
|
||||
Ok(Some(path.to_path_buf()))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
})
|
||||
.filter_map(|r| r.transpose())
|
||||
.collect::<Result<_, io::Error>>()?;
|
||||
|
||||
// The loaded_plugins function requires &[&Path]
|
||||
let refs: Vec<&Path> = install_plugins.iter().map(|e| e.as_path()).collect();
|
||||
|
||||
trace!("Loading {} plugins to game", refs.len());
|
||||
loot_game.load_plugins(&refs)?;
|
||||
|
||||
Reference in New Issue
Block a user