Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid asset download #326

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,36 +360,39 @@ impl Manager {
let hash_path = format!("{}/{}", &hash[..2], hash);
let location = root_location.join(&hash_path);
if fs::metadata(&location).is_err() {
fs::create_dir_all(location.parent().unwrap()).unwrap();
let res = client
// ignore errors, as either the asset in question may not be available or
// an error might have occoured connecting to the asset server
if let Ok(res) = client
.get(&format!(
"http://resources.download.minecraft.net/{}",
hash_path
))
.send()
.unwrap();
let length = v.get("size").and_then(|v| v.as_u64()).unwrap();
Self::add_task(&progress_info, "Downloading Asset", k, length);
let mut tmp_file = location.to_owned();
tmp_file.set_file_name(format!("{}.tmp", hash));
{
let mut file = fs::File::create(&tmp_file).unwrap();
let mut progress = ProgressRead {
read: res,
progress: &progress_info,
task_name: "Downloading Asset".into(),
task_file: k.to_owned(),
};
io::copy(&mut progress, &mut file).unwrap();
fs::create_dir_all(location.parent().unwrap()).unwrap();
let length = v.get("size").and_then(|v| v.as_u64()).unwrap();
Self::add_task(&progress_info, "Downloading Asset", k, length);
let mut tmp_file = location.to_owned();
tmp_file.set_file_name(format!("{}.tmp", hash));
{
let mut file = fs::File::create(&tmp_file).unwrap();
let mut progress = ProgressRead {
read: res,
progress: &progress_info,
task_name: "Downloading Asset".into(),
task_file: k.to_owned(),
};
io::copy(&mut progress, &mut file).unwrap();
}
fs::rename(&tmp_file, &location).unwrap();
}
fs::rename(&tmp_file, &location).unwrap();
Self::add_task_progress(
&progress_info,
"Downloading Assets",
&root_location.to_string_lossy(),
1,
);
}
Self::add_task_progress(
&progress_info,
"Downloading Assets",
&root_location.to_string_lossy(),
1,
);
}
});
}
Expand Down
Loading