use std::path::Path;
use modde_core::manifest::wabbajack::DownloadDirective;
use crate::error::{SourceError, SourceResult};
use crate::traits::{DownloadHandle, DownloadSource, ProgressCallback, VerifiedFile};
pub struct ManualSource;
impl ManualSource {
#[must_use]
pub fn new() -> Self {
Self
}
}
impl Default for ManualSource {
fn default() -> Self {
Self::new()
}
}
impl DownloadSource for ManualSource {
fn can_handle(&self, directive: &DownloadDirective) -> bool {
matches!(directive, DownloadDirective::Manual { .. })
}
async fn resolve(&self, directive: &DownloadDirective) -> SourceResult<DownloadHandle> {
let DownloadDirective::Manual {
url,
prompt,
expected_name,
..
} = directive
else {
return Err(SourceError::other(anyhow::anyhow!(
"not a Manual directive"
)));
};
let prompt = if prompt.is_empty() { "(none)" } else { prompt };
Err(SourceError::other(anyhow::anyhow!(
"manual download required for {expected_name}: visit {url} and place the downloaded \
file in the modde downloads directory. Prompt from list author: {prompt}"
)))
}
async fn download_with_progress(
&self,
_handle: DownloadHandle,
_dest: &Path,
_progress: ProgressCallback,
) -> SourceResult<VerifiedFile> {
Err(SourceError::other(anyhow::anyhow!(
"manual downloads cannot be fetched automatically"
)))
}
}