From 6d0fb7c0f2fc9bf144b50b6bb00328b3f7057832 Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Mon, 13 Jan 2025 03:05:17 -0600 Subject: more stuff --- src/launcher/download.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/launcher/download.rs') 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, expect_sha1: Option) -> 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(()) } -- cgit v1.2.3-70-g09d2