use std::path::{Path, PathBuf};
use crate::file::{FileEntry, FileIcon, FileVersionInfo, Priority, Result};
use crate::win::resolve_shortcut;
#[derive(Debug)]
pub struct Shortcut {
link_path: PathBuf,
target_path: PathBuf,
}
impl Shortcut {
#[must_use]
pub fn new(link_path: PathBuf) -> Option<Self> {
let target_path = resolve_shortcut(&link_path)?;
Some(Self {
link_path,
target_path,
})
}
}
impl FileEntry for Shortcut {
fn path(&self) -> &Path {
&self.target_path
}
fn link_path(&self) -> Option<&Path> {
Some(&self.link_path)
}
fn icon(&self) -> Result<FileIcon> {
Ok(FileIcon::from_paths(
self.link_path.clone(),
Some(self.target_path.clone()),
))
}
fn version_info(&self) -> Result<FileVersionInfo> {
Ok(FileVersionInfo::load(&self.target_path)?)
}
fn priority(&self) -> Priority {
Priority(1.0)
}
fn display_name(&self) -> String {
self.link_path
.file_stem()
.map(|s| s.to_string_lossy().into_owned())
.unwrap_or_default()
}
}