Skip to content

Commit

Permalink
Reworking handlers to avoid returning errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mindstorm38 committed Jul 12, 2024
1 parent dc95b1d commit c267d46
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
33 changes: 20 additions & 13 deletions rust/src/standard/download.rs → rust/src/download.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Parallel download implementation for standard installer.
//! Parallel download implementation.
//!
//! Partially inspired by: https://patshaughnessy.net/2020/1/20/downloading-100000-files-using-async-rust
Expand All @@ -17,9 +17,12 @@ use tokio::task::JoinSet;
use tokio::sync::mpsc;
use tokio::fs::File;

use crate::http;

use super::{serde, Event, Handler, Installer, Result, Error};
/// A list of pending download that can be all downloaded at once.
#[derive(Debug)]
pub struct DownloadList {
inner: Vec<Download>,
}


/// Bulk download blocking entrypoint.
Expand Down Expand Up @@ -84,7 +87,7 @@ pub async fn download_many(
})?;

// Initialize the HTTP(S) client.
let client = http::builder()
let client = crate::http::builder()
.build()
.unwrap(); // FIXME:

Expand Down Expand Up @@ -253,6 +256,10 @@ async fn download_core(

}

pub trait DownloadWatcher {

}

/// A download entry that can be delayed until a call to [`Handler::flush_download`].
/// This download object borrows the URL and file path.
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -291,17 +298,17 @@ impl DownloadSource {

}

impl<'a> From<&'a serde::Download> for DownloadSource {
// impl<'a> From<&'a serde::Download> for DownloadSource {

fn from(serde: &'a serde::Download) -> Self {
Self {
url: serde.url.clone().into(),
size: serde.size,
sha1: serde.sha1.as_deref().copied(),
}
}
// fn from(serde: &'a serde::Download) -> Self {
// Self {
// url: serde.url.clone().into(),
// size: serde.size,
// sha1: serde.sha1.as_deref().copied(),
// }
// }

}
// }

#[derive(thiserror::Error, Debug)]
pub enum DownloadError {
Expand Down
1 change: 1 addition & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pub mod gav;
pub mod path;
pub mod http;
pub mod download;

pub mod standard;
pub mod mojang;
Expand Down
18 changes: 13 additions & 5 deletions rust/src/mojang/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Optionally cached Mojang manifest.
use std::io::{self, BufReader};
use std::path::PathBuf;
use std::fs::File;

use crate::standard::{Result, Error};
use super::serde;


Expand Down Expand Up @@ -32,21 +32,29 @@ impl MojangManifest {
}
}

pub fn get(&mut self) -> &serde::MojangManifest {
pub fn get(&mut self) -> io::Result<&serde::MojangManifest> {

if let Some(data) = &self.data {
return data;
return Ok(data);
}

if let Some(cache_file) = self.cache_file.as_deref() {

let cache_reader = match File::open(cache_file) {
Ok(reader) => BufReader::new(reader),
Err(e) if e.kind() == io::ErrorKind::NotFound
}

// let file = File::open(cache_file)
// .map_err(|e| )
self.datamatch serde_json::from_reader(BufReader::new(File::open(cache_file)?)) {
Ok(obj) => obj
}

}

todo!()

}

fn

}
3 changes: 0 additions & 3 deletions rust/src/standard/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Standard installation procedure.
pub mod serde;
mod download;

use std::io::{self, BufReader, Seek, SeekFrom};
use std::collections::{HashMap, HashSet};
Expand All @@ -14,8 +13,6 @@ use sha1::{Digest, Sha1};
use crate::path::PathExt;
use crate::gav::Gav;

pub use self::download::{Download, DownloadSource, DownloadError};


/// Base URL for downloading game's assets.
const RESOURCES_URL: &str = "https://resources.download.minecraft.net/";
Expand Down

0 comments on commit c267d46

Please sign in to comment.