Skip to content

Commit

Permalink
Quick downgrade hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbegamerxx954 committed Aug 23, 2024
1 parent a6ad2be commit 4c37d35
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use clap::{
Parser, ValueEnum,
};
use console::style;
use materialbin::{CompiledMaterialDefinition, MinecraftVersion};
use materialbin::{CompiledMaterialDefinition, MinecraftVersion, WriteError};
use scroll::Pread;
use tempfile::tempfile;
use zip::{
Expand Down Expand Up @@ -183,6 +183,7 @@ where
let mut input_zip = ZipArchive::new(input)?;
let mut output_zip = ZipWriter::new(output);
let mut translated_shaders = 0;
let mut warnings = 0;
for index in 0..input_zip.len() {
let mut file = input_zip.by_index(index)?;
if !file.name().ends_with(".material.bin") {
Expand All @@ -201,10 +202,33 @@ where
let file_options = FileOptions::<ExtendedFileOptions>::default()
.compression_level(compression_level.map(|v| v.into()));
output_zip.start_file(file.name(), file_options)?;
material.write(&mut output_zip, version)?;
let result = material.write(&mut output_zip, version);
if let Err(err) = result {
match err {
WriteError::Compat(issue) => {
println!(
"{}:\n{}",
style("Ignoring materialbin because of compatibility error:")
.on_yellow()
.red(),
issue
);
translated_shaders -= 1;
warnings += 1;
}
_ => return Err(err.into()),
}
output_zip.abort_file()?;
}
translated_shaders += 1;
}
output_zip.finish()?;
if warnings != 0 {
println!(
"{}",
style(format!("{warnings} warnings while updating")).yellow()
);
}
println!(
"Ported {} materials in zip to version {}",
style(translated_shaders.to_string()).green(),
Expand Down

0 comments on commit 4c37d35

Please sign in to comment.