diff --git a/Cargo.lock b/Cargo.lock index 4835131..07a064c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -55,6 +55,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + [[package]] name = "byteorder" version = "1.4.3" @@ -260,6 +266,7 @@ dependencies = [ "env_logger", "log", "once_cell", + "whoami", "zip", ] @@ -272,6 +279,15 @@ dependencies = [ "libc", ] +[[package]] +name = "js-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "libc" version = "0.2.148" @@ -509,6 +525,80 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wasm-bindgen" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" + +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "whoami" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22fc3756b8a9133049b26c7f61ab35416c130e8c09b660f5b3958b446f52cc50" +dependencies = [ + "wasm-bindgen", + "web-sys", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 0645efe..ce2189f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,5 @@ anyhow = { version = "1.0", features = ["default"] } once_cell = { version = "1.18.0", features = [] } zip = { version = "0.6", features = ["zstd"] } log = "0.4" -env_logger = "0.10" \ No newline at end of file +env_logger = "0.10" +whoami = "1.4.1" \ No newline at end of file diff --git a/src/native.rs b/src/native.rs index 03981c9..ba40654 100644 --- a/src/native.rs +++ b/src/native.rs @@ -2,6 +2,7 @@ use log::info; use once_cell::sync::Lazy; +use whoami::platform; use crate::class::{unsafe_ref, unsafe_val, UnsafeValue, Value}; use crate::class::Value::Void; @@ -40,50 +41,87 @@ fn cmdProps() -> Value { fn systemProps() -> Value { unsafe { let props: Lazy> = Lazy::new(|| { - let mut vec = Vec::new(); - //TODO set values - vec.push("display_country"); - vec.push("display_language"); - vec.push("display_script"); - vec.push("display_variant"); - vec.push("file_encoding"); - vec.push("file_separator"); - vec.push("format_country"); - vec.push("format_language"); - vec.push("format_script"); - vec.push("format_variant"); - vec.push("ftp_nonProxyHosts"); - vec.push("ftp_proxyHost"); - vec.push("ftp_proxyPort"); - vec.push("http_nonProxyHosts"); - vec.push("http_proxyHost"); - vec.push("http_proxyPort"); - vec.push("https_proxyHost"); - vec.push("https_proxyPort"); - vec.push("java_io_tmpdir"); - vec.push("line_separator"); - vec.push("os_arch"); - vec.push("os_name"); - vec.push("os_version"); - vec.push("path_separator"); - vec.push("socksNonProxyHosts"); - vec.push("socksProxyHost"); - vec.push("socksProxyPort"); - vec.push("stderr_encoding"); - vec.push("stdout_encoding"); - vec.push("sun_arch_abi"); - vec.push("sun_arch_data_model"); - vec.push("sun_cpu_endian"); - vec.push("sun_cpu_isalist"); - vec.push("sun_io_unicode_encoding"); - vec.push("sun_jnu_encoding"); - vec.push("sun_os_patch_level"); - vec.push("user_dir"); - vec.push("user_home"); - vec.push("user_name"); - vec.push("FIXED_LENGTH"); + let mut vec: Vec = Vec::new(); + //TODO set correct values + vec.push("display_country".into()); //null in jdk21 + vec.push("display_language".into()); //null in jdk21 + vec.push("display_script".into()); //null in jdk21 + vec.push("display_variant".into()); //null in jdk21 + vec.push("UTF-8".into()); - vec.into_iter().map(|s| s.to_owned()).collect() + { + #[cfg(target_family = "unix")] + vec.push("/".into()); + #[cfg(target_family = "windows")] + vec.push("\\"); + } + vec.push("format_country".into()); //null in jdk21 + vec.push("format_language".into()); //null in jdk21 + vec.push("format_script".into()); //null in jdk21 + vec.push("format_variant".into()); //null in jdk21 + vec.push("ftp_nonProxyHosts".into()); + if let Ok(ftp_proxy) = std::env::var("ftp_proxy") { + vec.push(ftp_proxy.to_owned());//TODO + vec.push(ftp_proxy); + } else { + vec.push("".to_owned()); + vec.push("".to_owned()); + } + + vec.push("http_nonProxyHosts".into()); + if let Ok(http_proxy) = std::env::var("http_proxy") { + vec.push(http_proxy.to_owned()); + vec.push(http_proxy);//TODO + } else { + vec.push("".to_owned()); + vec.push("".to_owned()); + } + if let Ok(https_proxy) = std::env::var("https_proxy") { + vec.push(https_proxy.to_owned()); + vec.push(https_proxy); + }else { + vec.push("".to_owned()); + vec.push("".to_owned()); + } + vec.push(std::env::temp_dir().display().to_string()); + + { + #[cfg(target_family = "unix")] + vec.push("\n".into()); + #[cfg(target_family = "windows")] + vec.push("\r\n"); + } + vec.push(whoami::platform().to_string()); + vec.push(whoami::devicename()); + vec.push("os_version".into()); + { + #[cfg(target_family = "unix")] + vec.push(":".into()); + #[cfg(target_family = "windows")] + vec.push(";".into()); + } + vec.push("socksNonProxyHosts".into()); + vec.push("socksProxyHost".into()); + vec.push("socksProxyPort".into()); + vec.push("UTF-8".into()); + vec.push("UTF-8".into()); + vec.push("sun_arch_abi".into()); + vec.push("sun_arch_data_model".into()); + vec.push("sun_cpu_endian".into()); //null in jdk21 + vec.push("sun_cpu_isalist".into()); //null in jdk21 + vec.push("sun_io_unicode_encoding".into()); //null in jdk21 + vec.push("sun_jnu_encoding".into()); //null in jdk21 + vec.push("sun_os_patch_level".into()); //null in jdk21 + if let Ok(curdir) = std::env::current_dir() { + vec.push(curdir.display().to_string()); + } + + let home = std::env::home_dir().unwrap(); + vec.push(home.display().to_string()); + vec.push(whoami::username()); + vec.push("FIXED_LENGTH".into()); + + vec }); Value::Ref(unsafe_ref(ObjectRef::StringArray(props.to_vec()))) }