mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-23 08:22:52 +10:00
fix: manifest generation no actually this time
This commit is contained in:
Generated
+1
-1
@@ -219,7 +219,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "droplet-rs"
|
name = "droplet-rs"
|
||||||
version = "0.13.0"
|
version = "0.14.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Drop-OSS"]
|
authors = ["Drop-OSS"]
|
||||||
name = "droplet-rs"
|
name = "droplet-rs"
|
||||||
version = "0.13.0"
|
version = "0.14.0"
|
||||||
license = "AGPL-3.0-only"
|
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"
|
description = "Droplet is a `napi.rs` Rust/Node.js package full of high-performance and low-level utils for Drop"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::path::PathBuf;
|
use std::{os::unix::fs::MetadataExt, path::PathBuf};
|
||||||
|
|
||||||
use droplet_rs::manifest::generate_manifest_rusty;
|
use droplet_rs::manifest::generate_manifest_rusty;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
@@ -6,18 +6,48 @@ use tokio::runtime::Handle;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn main() {
|
pub async fn main() {
|
||||||
|
let target_dir =
|
||||||
|
PathBuf::from("/home/decduck/.local/share/Steam/steamapps/common/BloonsTD6");
|
||||||
let metrics = Handle::current().metrics();
|
let metrics = Handle::current().metrics();
|
||||||
println!("using {} workers", metrics.num_workers());
|
println!("using {} workers", metrics.num_workers());
|
||||||
let manifest = generate_manifest_rusty(
|
let manifest = generate_manifest_rusty(
|
||||||
&PathBuf::from("/home/decduck/.local/share/Steam/steamapps/common/Savage Resurrection"),
|
&target_dir,
|
||||||
|progress| {
|
|progress| println!("PROGRESS: {}", progress),
|
||||||
println!("PROGRESS: {}", progress)
|
|
||||||
},
|
|
||||||
|message| {
|
|message| {
|
||||||
println!("{}", message);
|
println!("{}", message);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 required_single_file = backend.require_whole_files();
|
||||||
|
|
||||||
let mut files = backend.list_files().await?;
|
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
|
// Filepath to chunk data
|
||||||
let mut chunks: Vec<Vec<(VersionFile, u64, u64)>> = Vec::new();
|
let mut chunks: Vec<Vec<(VersionFile, u64, u64)>> = Vec::new();
|
||||||
let mut current_chunk: 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 {
|
for version_file in files {
|
||||||
let current_size = current_chunk.iter().map(|v| v.2).sum::<u64>();
|
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;
|
let size = version_file.size;
|
||||||
current_chunk.push((version_file, 0, 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
|
// Fill up current chunk
|
||||||
let remaining = CHUNK_SIZE - current_size;
|
let remaining = CHUNK_SIZE - current_size;
|
||||||
current_chunk.push((version_file.clone(), 0, remaining));
|
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
|
// This is our offset in our current file
|
||||||
let mut offset = remaining;
|
let mut offset = remaining;
|
||||||
while offset < version_file.size {
|
while offset < version_file.size {
|
||||||
let length = CHUNK_SIZE.min(version_file.size - offset);
|
let length = CHUNK_SIZE.min(version_file.size - offset);
|
||||||
offset += length;
|
|
||||||
if length == CHUNK_SIZE {
|
if length == CHUNK_SIZE {
|
||||||
chunks.push(vec![(version_file.clone(), offset, length)]);
|
chunks.push(vec![(version_file.clone(), offset, length)]);
|
||||||
} else {
|
} else {
|
||||||
current_chunk.push((version_file.clone(), offset, length));
|
current_chunk.push((version_file.clone(), offset, length));
|
||||||
}
|
}
|
||||||
|
offset += length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user