Skip to content

Commit

Permalink
Log warning if milo not fully parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
PikminGuts92 committed Feb 7, 2024
1 parent 36a926d commit d7f2bbd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/cli/scene_tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition.workspace = true
[dependencies]
clap = { workspace = true }
grim = { workspace = true, features = [ "midi" ] }
simplelog = { workspace = true }
thiserror = { workspace = true }

[lints]
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/scene_tool/src/apps/dir2milo.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::apps::{SubApp};
use crate::apps::SubApp;
use clap::Parser;

use std::error::Error;

use std::path::{Path};
use std::path::Path;


use grim::{Platform, SystemInfo};
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/scene_tool/src/apps/milo2dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use thiserror::Error;
use grim::{Platform, SystemInfo};
use grim::io::*;
use grim::scene::{Object, ObjectDir, PackedObject, Tex};
use grim::texture::{write_rgba_to_file};
use grim::texture::write_rgba_to_file;

// TODO: Use this error somewhere or refactor
#[derive(Debug, Error)]
Expand Down
19 changes: 19 additions & 0 deletions apps/cli/scene_tool/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
mod apps;
use apps::SceneTool;
use simplelog::*;

#[cfg(debug_assertions)]
const LOG_LEVEL: LevelFilter = LevelFilter::Debug;

#[cfg(not(debug_assertions))]
const LOG_LEVEL: LevelFilter = LevelFilter::Info;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let log_config = ConfigBuilder::new()
.add_filter_allow_str("grim")
.add_filter_allow_str("scene_tool")
.build();

// Setup logging
CombinedLogger::init(
vec![
TermLogger::new(LOG_LEVEL, log_config, TerminalMode::Mixed, ColorChoice::Auto),
]
)?;

let mut scene = SceneTool::new();
scene.run()
}
8 changes: 7 additions & 1 deletion core/grim/src/io/archive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{SystemInfo};
use crate::SystemInfo;
use crate::io::compression::*;
use crate::io::stream::{BinaryStream, IOEndian, MemoryStream, SeekFrom, Stream};
use crate::scene::{Object, ObjectDir, ObjectDirBase, PackedObject};
Expand Down Expand Up @@ -156,6 +156,8 @@ impl MiloArchive {

pub fn unpack_directory(&self, info: &SystemInfo) -> Result<ObjectDir, Box<dyn Error>> {
let mut stream = self.get_stream();
let stream_size = stream.len().unwrap() as u64;

let stream = stream.as_mut();
let mut reader = BinaryStream::from_stream_with_endian(stream, info.endian);

Expand Down Expand Up @@ -258,6 +260,10 @@ impl MiloArchive {
}
}

if stream.pos() < stream_size {
log::warn!("Read less data than length of milo file. Likely not parsed correctly.");
}

Ok(ObjectDir::ObjectDir(ObjectDirBase {
entries: packed_entries
.into_iter()
Expand Down

0 comments on commit d7f2bbd

Please sign in to comment.