Skip to main content

modde_sources/manual/
mod.rs

1//! Source for manual-download directives, which cannot be fetched
2//! automatically and instead fail fast with a pointer to the upstream URL.
3
4use std::path::Path;
5
6use modde_core::manifest::wabbajack::DownloadDirective;
7
8use crate::error::{SourceError, SourceResult};
9use crate::traits::{DownloadHandle, DownloadSource, ProgressCallback, VerifiedFile};
10
11/// Source for `ManualDownloader` archives. The Wabbajack tool prompts the user
12/// to download these by hand and drop the file into the downloads directory;
13/// modde mirrors that behaviour by failing fast at resolve time with a clear
14/// pointer to the upstream URL.
15pub struct ManualSource;
16
17impl ManualSource {
18    /// Create a new manual source.
19    #[must_use]
20    pub fn new() -> Self {
21        Self
22    }
23}
24
25impl Default for ManualSource {
26    fn default() -> Self {
27        Self::new()
28    }
29}
30
31impl DownloadSource for ManualSource {
32    fn can_handle(&self, directive: &DownloadDirective) -> bool {
33        matches!(directive, DownloadDirective::Manual { .. })
34    }
35
36    async fn resolve(&self, directive: &DownloadDirective) -> SourceResult<DownloadHandle> {
37        let DownloadDirective::Manual {
38            url,
39            prompt,
40            expected_name,
41            ..
42        } = directive
43        else {
44            return Err(SourceError::other(anyhow::anyhow!(
45                "not a Manual directive"
46            )));
47        };
48
49        let prompt = if prompt.is_empty() { "(none)" } else { prompt };
50        Err(SourceError::other(anyhow::anyhow!(
51            "manual download required for {expected_name}: visit {url} and place the downloaded \
52             file in the modde downloads directory. Prompt from list author: {prompt}"
53        )))
54    }
55
56    async fn download_with_progress(
57        &self,
58        _handle: DownloadHandle,
59        _dest: &Path,
60        _progress: ProgressCallback,
61    ) -> SourceResult<VerifiedFile> {
62        Err(SourceError::other(anyhow::anyhow!(
63            "manual downloads cannot be fetched automatically"
64        )))
65    }
66}