1
0
Mirror von https://github.com/Chaoscaot/schemsearch synchronisiert 2024-11-16 17:00:14 +01:00
Dieser Commit ist enthalten in:
Chaoscaot 2023-03-05 15:11:51 +01:00
Ursprung ff03732df5
Commit d352bfaded
6 geänderte Dateien mit 64 neuen und 4 gelöschten Zeilen

2
.gitignore vendored
Datei anzeigen

@ -1,3 +1,5 @@
/target /target
/Cargo.lock /Cargo.lock
/.idea/ /.idea/
/SchemSearch.class
/SchemSearch.h

Datei anzeigen

@ -3,5 +3,6 @@ members = [
"schemsearch-cli", "schemsearch-cli",
"schemsearch-lib", "schemsearch-lib",
"schemsearch-files", "schemsearch-files",
"schemsearch-sql" "schemsearch-sql",
"schemsearch-java"
] ]

8
SchemSearch.java Normale Datei
Datei anzeigen

@ -0,0 +1,8 @@
public class SchemSearch {
public static native String search(String schematicFile, String patternFile);
public static void init(String filePath) {
System.loadLibrary(filePath);
}
}

15
schemsearch-java/Cargo.toml Normale Datei
Datei anzeigen

@ -0,0 +1,15 @@
[package]
name = "schemsearch-java"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate_type = ["cdylib"]
[dependencies]
jni = "0.21.0"
schemsearch-lib = { path = "../schemsearch-lib" }
schemsearch-files = { path = "../schemsearch-files" }

34
schemsearch-java/src/lib.rs Normale Datei
Datei anzeigen

@ -0,0 +1,34 @@
#![no_mangle]
use jni::JNIEnv;
use jni::objects::{JClass, JString};
use jni::sys::jstring;
use schemsearch_lib::{search, SearchBehavior};
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 matches = search(schematic, pattern, SearchBehavior {
ignore_block_data: true,
ignore_block_entities: true,
ignore_entities: true,
});
let mut result = String::new();
for (x, y, z) in matches {
result.push_str(&format!("{}, {}, {};", x, y, z));
}
result.remove(result.len() - 1);
let output = env.new_string(result).expect("Couldn't create java string!");
output.into_raw()
}

Datei anzeigen

@ -5,9 +5,9 @@ pub mod pattern_mapper;
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct SearchBehavior { pub struct SearchBehavior {
ignore_block_data: bool, pub ignore_block_data: bool,
ignore_block_entities: bool, pub ignore_block_entities: bool,
ignore_entities: bool, pub ignore_entities: bool,
} }
pub fn search( pub fn search(