Compare commits
3 Commits
c34a957a9d
...
1f40e59519
| Author | SHA1 | Date | |
|---|---|---|---|
|
1f40e59519
|
|||
|
58505aeebc
|
|||
|
d4d08570d8
|
@@ -207,6 +207,8 @@ pub struct FileType {
|
||||
pub always_install: Option<String>,
|
||||
#[serde(rename = "@installIfUsable", default = "false_bool")]
|
||||
pub install_if_usable: bool,
|
||||
|
||||
#[serde(rename = "@priority")]
|
||||
pub priority: Option<isize>,
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use crate::fomod::FileTypeEnum;
|
||||
|
||||
pub struct Linker {
|
||||
target: PathBuf,
|
||||
}
|
||||
@@ -21,7 +23,7 @@ impl Linker {
|
||||
}
|
||||
|
||||
fn link_file(&self, from: &Path, to: &Path) -> Result<(), LinkerError> {
|
||||
let target = self.install_path().join(to);
|
||||
let target = self.install_path().join(path_to_lowercase(to));
|
||||
|
||||
if let Some(parent) = target.parent() {
|
||||
fs::create_dir_all(parent)?;
|
||||
@@ -32,7 +34,7 @@ impl Linker {
|
||||
}
|
||||
|
||||
fn remove_link(&self, to: &Path) -> Result<(), LinkerError> {
|
||||
let file = self.install_path().join(to);
|
||||
let file = self.install_path().join(path_to_lowercase(to));
|
||||
let metadata = fs::symlink_metadata(&file)?;
|
||||
|
||||
if !metadata.file_type().is_symlink() {
|
||||
@@ -85,6 +87,35 @@ impl Linker {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn link_plugin_files(
|
||||
&self,
|
||||
entries: &[FileTypeEnum],
|
||||
mod_dir: &Path,
|
||||
) -> Result<(), LinkerError> {
|
||||
let mut sorted_entries = entries.to_owned();
|
||||
sorted_entries.sort_by_cached_key(|e| match e {
|
||||
FileTypeEnum::File(file_type) => file_type.priority.unwrap_or(0),
|
||||
FileTypeEnum::Folder(file_type) => file_type.priority.unwrap_or(0),
|
||||
});
|
||||
|
||||
for entry in sorted_entries {
|
||||
match entry {
|
||||
FileTypeEnum::File(file) => {
|
||||
let from = mod_dir.join(file.source);
|
||||
let to = Path::new("Data").join(file.destination.unwrap_or("".to_owned()));
|
||||
self.link_file(&from, &to)?;
|
||||
}
|
||||
FileTypeEnum::Folder(folder) => {
|
||||
let from = mod_dir.join(folder.source);
|
||||
let to = Path::new("Data").join(folder.destination.unwrap_or("".to_owned()));
|
||||
self.link_recursive(&from, &to)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -109,3 +140,7 @@ impl From<io::Error> for LinkerError {
|
||||
Self::Io(e)
|
||||
}
|
||||
}
|
||||
|
||||
fn path_to_lowercase(path: &Path) -> PathBuf {
|
||||
PathBuf::from(path.to_string_lossy().to_lowercase())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user