Skip to content

Commit

Permalink
Add a button to dump data from all traversed tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cohaereo committed Oct 28, 2024
1 parent fbd9990 commit c11014f
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/gui/tag.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::cell::RefCell;
use std::fs::File;
use std::io::Write as _;
use std::path::PathBuf;
use std::{
collections::HashSet,
fmt::Display,
Expand Down Expand Up @@ -32,7 +35,7 @@ use destiny_pkg::{package::UEntryHeader, GameVersion, TagHash, TagHash64};
use eframe::egui::load::SizedTexture;
use eframe::egui::{collapsing_header::CollapsingState, vec2, RichText, TextureId};
use eframe::egui_wgpu::RenderState;
use eframe::wgpu::naga::{FastHashMap, FastHashSet, FastIndexMap};
use eframe::wgpu::naga::{FastHashSet, FastIndexMap};
use eframe::{
egui::{self, CollapsingHeader},
epaint::Color32,
Expand Down Expand Up @@ -503,6 +506,26 @@ impl TagView {
);
ui.checkbox(&mut self.traversal_interactive, "Interactive");
ui.checkbox(&mut self.hide_already_traversed, "Hide already traversed");

if let Some(traversal) = self.tag_traversal.as_ref() {
if let Some((trav_interactive, _)) = traversal.ready() {
if ui
.button("Dump all tag data")
.on_hover_text("Dumps the tag data for all tags in the traversal tree")
.clicked()
{
let directory = PathBuf::from("dump")
.join(format!("tagdump_{}", trav_interactive.tag));
std::fs::create_dir_all(&directory).ok();
if let Err(e) = Self::dump_traversed_tag_data_recursive(
trav_interactive,
&directory,
) {
error!("Failed to dump tag data: {e:?}");
}
}
}
}
});

if let Some(traversal) = self.tag_traversal.as_ref() {
Expand Down Expand Up @@ -692,6 +715,35 @@ impl TagView {

result
}

pub fn dump_traversed_tag_data_recursive(
tag: &TraversedTag,
directory: &Path,
) -> anyhow::Result<()> {
let tag_postfix = if let Some(entry) = &tag.entry {
format!(
"_{}",
TagType::from_type_subtype(entry.file_type, entry.file_subtype)
)
} else {
"".to_string()
};

let path = directory.join(format!("{}{}.bin", tag.tag, tag_postfix));
match package_manager().read_tag(tag.tag) {
Ok(o) => {
let mut file = File::create(&path)?;
file.write_all(&o)?;
}
Err(e) => error!("Failed to dump data for tag {}: {e:?}", tag.tag),
}

for subtag in &tag.subtags {
Self::dump_traversed_tag_data_recursive(subtag, directory)?;
}

Ok(())
}
}

impl View for TagView {
Expand Down

0 comments on commit c11014f

Please sign in to comment.