Mirror von
https://github.com/Chaoscaot/schemsearch
synchronisiert 2024-11-16 17:00:14 +01:00
Add JNI
Dieser Commit ist enthalten in:
Ursprung
ff03732df5
Commit
d352bfaded
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
/target
|
/target
|
||||||
/Cargo.lock
|
/Cargo.lock
|
||||||
/.idea/
|
/.idea/
|
||||||
|
/SchemSearch.class
|
||||||
|
/SchemSearch.h
|
||||||
|
@ -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
8
SchemSearch.java
Normale Datei
@ -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
15
schemsearch-java/Cargo.toml
Normale Datei
@ -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
34
schemsearch-java/src/lib.rs
Normale Datei
@ -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()
|
||||||
|
}
|
@ -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(
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren