Finish CLI

This commit is contained in:
Chaoscaot
2023-03-06 18:29:03 +01:00
parent d352bfaded
commit 0df001602e
9 changed files with 380 additions and 133 deletions

View File

@ -1,27 +1,29 @@
#![no_mangle]
use std::path::Path;
use jni::JNIEnv;
use jni::objects::{JClass, JString};
use jni::sys::jstring;
use schemsearch_files::Schematic;
use schemsearch_lib::{search, SearchBehavior};
#[no_mangle]
pub extern "system" fn Java_SchemSearch_search<'local>(mut env: JNIEnv<'local>,
class: JClass<'local>,
schematic_path: JString<'local>,
pattern_path: JString<'local>) -> jstring {
let schematic_path: String = env.get_string(&schematic_path).expect("Couldn't get java string!").into();
let pattern_path: String = env.get_string(&pattern_path).expect("Couldn't get java string!").into();
let file = std::fs::File::open(schematic_path).expect("Failed to open file");
let schematic = &std::io::Read::bytes(file).map(|b| b.unwrap()).collect();
let file = std::fs::File::open(pattern_path).expect("Failed to open file");
let pattern = &std::io::Read::bytes(file).map(|b| b.unwrap()).collect();
let schematic = Schematic::load(Path::new(&schematic_path));
let pattern = Schematic::load(Path::new(&pattern_path));
let matches = search(schematic, pattern, SearchBehavior {
let matches = search(&schematic, &pattern, SearchBehavior {
ignore_block_data: true,
ignore_block_entities: true,
ignore_entities: true,
ignore_air: false,
air_as_any: false,
threshold: 0.0,
});
let mut result = String::new();