diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f975bfd --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "assets"] + path = assets + url = https://git.ethanthesleepy.one/ethanaobrien/sif2-runtime-files diff --git a/Cargo.lock b/Cargo.lock index dda865d..bff9fd6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -642,6 +642,7 @@ dependencies = [ "hex", "hmac", "include-flate-codegen", + "include_dir", "jni", "json", "lazy_static", @@ -1021,6 +1022,25 @@ dependencies = [ "zstd", ] +[[package]] +name = "include_dir" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "923d117408f1e49d914f1a379a309cffe4f18c05cf4e3d12e613a15fc81bd0dd" +dependencies = [ + "include_dir_macros", +] + +[[package]] +name = "include_dir_macros" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cab85a7ed0bd5f0e76d93846e0147172bed2e2d3f859bcc33a8d9699cad1a75" +dependencies = [ + "proc-macro2", + "quote", +] + [[package]] name = "indexmap" version = "2.12.1" diff --git a/Cargo.toml b/Cargo.toml index 5e3daed..968079f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,20 +27,21 @@ cbc = { version = "0.1.2", features = ["alloc"] } aes = "0.8.4" pem = "3.0.6" ureq = "3.1.4" +include_dir = {version = "0.7.4", optional = true } [target.aarch64-linux-android.dependencies] -jni = { version = "0.21.1", features = ["invocation", "default"] } +jni = { version = "0.21.1", features = ["invocation", "default"], optional = true } [target.aarch64-apple-ios.dependencies] -objc2 = "0.6.3" -objc2-foundation = { version = "0.3.2", features = ["NSFileManager"] } +objc2 = { version = "0.6.3", optional = true } +objc2-foundation = { version = "0.3.2", features = ["NSFileManager"], optional = true } [build-dependencies] cc = "1.0" # To enable this library you MUST comment out lib block below and add --features library [features] -library = [] +library = ["jni", "objc2", "objc2-foundation", "include_dir"] #[lib] #crate-type = ["cdylib"] diff --git a/assets b/assets new file mode 160000 index 0000000..dbb068e --- /dev/null +++ b/assets @@ -0,0 +1 @@ +Subproject commit dbb068e72c6c64eb82dfcf54ea97d7d220d8b1be diff --git a/src/static_handlers.rs b/src/static_handlers.rs index d16f2fa..2b5e12e 100644 --- a/src/static_handlers.rs +++ b/src/static_handlers.rs @@ -26,7 +26,29 @@ async fn maintenance(_req: HttpRequest) -> HttpResponse { .body(r#"{"opened_at":"2024-02-05 02:00:00","closed_at":"2024-02-05 04:00:00","message":":(","server":1,"gamelib":0}"#) } +#[cfg(feature = "library")] +use include_dir::{include_dir, Dir}; + +#[cfg(all(feature = "library", target_os = "ios"))] +static SPART_FILES: Dir<'_> = include_dir!("assets/iOS/"); + +#[cfg(all(feature = "library", target_os = "android"))] +static SPART_FILES: Dir<'_> = include_dir!("assets/Android/"); + fn handle_assets(req: HttpRequest) -> HttpResponse { + #[cfg(feature = "library")] + { + let lang: String = req.match_info().get("lang").unwrap_or("JP").parse().unwrap_or(String::from("JP")); + let file_name: String = req.match_info().get("file").unwrap().parse().unwrap(); + let hash: String = req.match_info().get("file").unwrap().parse().unwrap(); + if let Some(file) = SPART_FILES.get_file(format!("{lang}/{hash}/{file_name}")) { + let body = file.contents(); + return HttpResponse::Ok() + .insert_header(ContentType(mime::APPLICATION_OCTET_STREAM)) + .insert_header(("content-length", body.len())) + .body(body); + } + } let file_path = format!("assets{}", req.path()); let exists = fs::exists(&file_path);