late-java-core 2.2.9

A Rust library for launching Minecraft Java Edition
use crate::error::Result;
use std::path::Path;

/// Descargador de archivos
pub struct Downloader {
    client: reqwest::Client,
}

/// Progreso de descarga
#[derive(Debug, Clone)]
pub struct DownloadProgress {
    pub downloaded: u64,
    pub total: u64,
    pub speed: f64,
    pub element: String,
}

impl Downloader {
    /// Crear un nuevo descargador
    pub fn new() -> Self {
        Self {
            client: reqwest::Client::new(),
        }
    }

    /// Descargar un archivo
    pub async fn download_file(&self, url: &str, path: &Path) -> Result<()> {
        let response = self.client.get(url).send().await?;
        let bytes = response.bytes().await?;
        
        if let Some(parent) = path.parent() {
            std::fs::create_dir_all(parent)?;
        }
        
        std::fs::write(path, bytes)?;
        Ok(())
    }

    /// Descargar mĂșltiples archivos
    pub async fn download_files(&self, files: Vec<(String, String)>) -> Result<()> {
        for (url, path) in files {
            let path = Path::new(&path);
            self.download_file(&url, path).await?;
        }
        Ok(())
    }
}