fix: manifest generation no actually this time

This commit is contained in:
DecDuck
2025-12-20 18:35:24 +11:00
parent 87642befed
commit 3ff2944f77
4 changed files with 42 additions and 12 deletions
+1 -1
View File
@@ -219,7 +219,7 @@ dependencies = [
[[package]]
name = "droplet-rs"
version = "0.13.0"
version = "0.14.0"
dependencies = [
"anyhow",
"async-trait",
+1 -1
View File
@@ -2,7 +2,7 @@
edition = "2021"
authors = ["Drop-OSS"]
name = "droplet-rs"
version = "0.13.0"
version = "0.14.0"
license = "AGPL-3.0-only"
description = "Droplet is a `napi.rs` Rust/Node.js package full of high-performance and low-level utils for Drop"
+36 -6
View File
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{os::unix::fs::MetadataExt, path::PathBuf};
use droplet_rs::manifest::generate_manifest_rusty;
use serde_json::json;
@@ -6,18 +6,48 @@ use tokio::runtime::Handle;
#[tokio::main]
pub async fn main() {
let target_dir =
PathBuf::from("/home/decduck/.local/share/Steam/steamapps/common/BloonsTD6");
let metrics = Handle::current().metrics();
println!("using {} workers", metrics.num_workers());
let manifest = generate_manifest_rusty(
&PathBuf::from("/home/decduck/.local/share/Steam/steamapps/common/Savage Resurrection"),
|progress| {
println!("PROGRESS: {}", progress)
},
&target_dir,
|progress| println!("PROGRESS: {}", progress),
|message| {
println!("{}", message);
},
)
.await
.unwrap();
tokio::fs::write("./manifst.json", json!(manifest).to_string()).await.expect("failed to write manifest");
// Sanity checks
for (_, chunk_data) in manifest.chunks {
for file in chunk_data.files {
let path = target_dir.join(file.filename);
if !path.exists() {
panic!("{} doesn't exist", path.display());
}
let metadata = path.metadata().expect("failed to fetch metadata");
let file_size = metadata.size();
if file.start > file_size as usize {
panic!(
"start for {} doesn't make sense: start: {}, size: {}",
path.display(),
file.start,
file_size
);
}
let end_position = file.start + file.length;
if end_position > file_size as usize {
panic!(
"end for {} doesn't make sense: end: {}, size: {}",
path.display(),
end_position,
file_size
);
}
}
}
}
+4 -4
View File
@@ -56,7 +56,7 @@ pub async fn generate_manifest_rusty<T: Fn(String), V: Fn(f32)>(
let required_single_file = backend.require_whole_files();
let mut files = backend.list_files().await?;
files.sort_by(|a, b| a.size.cmp(&b.size));
files.sort_by(|a, b| b.size.cmp(&a.size));
// Filepath to chunk data
let mut chunks: Vec<Vec<(VersionFile, u64, u64)>> = Vec::new();
let mut current_chunk: Vec<(VersionFile, u64, u64)> = Vec::new();
@@ -91,7 +91,7 @@ pub async fn generate_manifest_rusty<T: Fn(String), V: Fn(f32)>(
for version_file in files {
let current_size = current_chunk.iter().map(|v| v.2).sum::<u64>();
if version_file.size + current_size < CHUNK_SIZE + WIGGLE {
if version_file.size + current_size < CHUNK_SIZE {
let size = version_file.size;
current_chunk.push((version_file, 0, size));
@@ -101,18 +101,18 @@ pub async fn generate_manifest_rusty<T: Fn(String), V: Fn(f32)>(
// Fill up current chunk
let remaining = CHUNK_SIZE - current_size;
current_chunk.push((version_file.clone(), 0, remaining));
chunks.push(std::mem::take(&mut current_chunk));
chunks.push(std::mem::replace(&mut current_chunk, Vec::new()));
// This is our offset in our current file
let mut offset = remaining;
while offset < version_file.size {
let length = CHUNK_SIZE.min(version_file.size - offset);
offset += length;
if length == CHUNK_SIZE {
chunks.push(vec![(version_file.clone(), offset, length)]);
} else {
current_chunk.push((version_file.clone(), offset, length));
}
offset += length;
}
}
}