diff options
Diffstat (limited to 'src/launcher')
| -rw-r--r-- | src/launcher/download.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/launcher/download.rs b/src/launcher/download.rs index 8c24cae..ec89a15 100644 --- a/src/launcher/download.rs +++ b/src/launcher/download.rs @@ -8,7 +8,7 @@ use reqwest::{Client, IntoUrl, Method, RequestBuilder}; use sha1_smol::{Digest, Sha1}; use tokio::fs; use tokio::fs::File; -use tokio::io::{AsyncReadExt, AsyncWriteExt}; +use tokio::io::{self, AsyncReadExt, AsyncWriteExt}; use crate::launcher::constants::USER_AGENT; pub trait Download: Debug + Display { @@ -182,13 +182,14 @@ impl Display for VerifiedDownload { } impl VerifiedDownload { - pub fn new(url: &str, path: &Path) -> VerifiedDownload { + pub fn new(url: &str, path: &Path, expect_size: Option<usize>, expect_sha1: Option<Digest>) -> VerifiedDownload { VerifiedDownload { url: url.to_owned(), path: path.to_owned(), - expect_size: None, - expect_sha1: None, + expect_size, + expect_sha1, + file: None, sha1: Sha1::new(), tally: 0 @@ -205,7 +206,11 @@ impl VerifiedDownload { self } - async fn open_output(&mut self) -> Result<(), tokio::io::Error> { + pub async fn make_dirs(&self) -> Result<(), io::Error> { + fs::create_dir_all(self.path.parent().expect("download created with no containing directory (?)")).await + } + + async fn open_output(&mut self) -> Result<(), io::Error> { self.file.replace(File::create(&self.path).await?); Ok(()) } |
