Files
rojo/src/snapshot_middleware/rbxlx.rs
Lucien Greathouse a48c238ed7 Add InstanceMetadata builder (#269)
* Add InstanceMetadata builder, with context field for globbing

* Revert snapshot changes

* Port snapshot functions to InstanceMetadata builder-ish pattern

* Remove IgnoreGlob struct

* Elide lifetime
2019-12-03 14:49:40 -08:00

48 lines
1.3 KiB
Rust

use crate::{
snapshot::{InstanceMetadata, InstanceSnapshot},
vfs::{Vfs, VfsEntry, VfsFetcher},
};
use super::{
context::InstanceSnapshotContext,
middleware::{SnapshotInstanceResult, SnapshotMiddleware},
util::match_file_name,
};
pub struct SnapshotRbxlx;
impl SnapshotMiddleware for SnapshotRbxlx {
fn from_vfs<F: VfsFetcher>(
_context: &mut InstanceSnapshotContext,
vfs: &Vfs<F>,
entry: &VfsEntry,
) -> SnapshotInstanceResult {
if entry.is_directory() {
return Ok(None);
}
let instance_name = match match_file_name(entry.path(), ".rbxlx") {
Some(name) => name,
None => return Ok(None),
};
let options = rbx_xml::DecodeOptions::new()
.property_behavior(rbx_xml::DecodePropertyBehavior::ReadUnknown);
let temp_tree = rbx_xml::from_reader(entry.contents(vfs)?.as_slice(), options)
.expect("TODO: Handle rbx_xml errors");
let root_id = temp_tree.get_root_id();
let snapshot = InstanceSnapshot::from_tree(&temp_tree, root_id)
.name(instance_name)
.metadata(
InstanceMetadata::new()
.instigating_source(entry.path())
.relevant_paths(vec![entry.path().to_path_buf()]),
);
Ok(Some(snapshot))
}
}