From 26e8355528d91e186a6d48de8dfbcbb1a947b2af Mon Sep 17 00:00:00 2001 From: fufesou Date: Fri, 18 Nov 2022 13:33:54 +0800 Subject: [PATCH 1/5] dynamic library - win virtual display Signed-off-by: fufesou --- Cargo.lock | 2 +- Cargo.toml | 2 +- build.py | 6 ++++ libs/clipboard/build.rs | 2 +- libs/virtual_display/Cargo.toml | 4 +++ libs/virtual_display/build.rs | 4 +-- libs/virtual_display/src/lib.rs | 9 +++++ src/server.rs | 2 ++ src/server/video_service.rs | 2 +- src/server/virtual_display.rs | 64 +++++++++++++++++++++++++++++++++ 10 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 src/server/virtual_display.rs diff --git a/Cargo.lock b/Cargo.lock index 49fcc3dce..0e892aa31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4391,6 +4391,7 @@ dependencies = [ "lazy_static", "libappindicator", "libc", + "libloading", "libpulse-binding", "libpulse-simple-binding", "mac_address", @@ -4424,7 +4425,6 @@ dependencies = [ "trayicon", "url", "uuid", - "virtual_display", "whoami", "winapi 0.3.9", "windows-service", diff --git a/Cargo.toml b/Cargo.toml index 836bd07d4..a3758c861 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,7 @@ flutter_rust_bridge = { git = "https://github.com/SoLongAndThanksForAllThePizza/ errno = "0.2.8" rdev = { git = "https://github.com/asur4s/rdev" } url = { version = "2.1", features = ["serde"] } +libloading = "0.7" reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls"], default-features=false } chrono = "0.4.23" @@ -91,7 +92,6 @@ winit = "0.26" winapi = { version = "0.3", features = ["winuser"] } winreg = "0.10" windows-service = "0.4" -virtual_display = { path = "libs/virtual_display" } impersonate_system = { git = "https://github.com/21pages/impersonate-system" } shared_memory = "0.12.4" shutdown_hooks = "0.1.0" diff --git a/build.py b/build.py index c907334ce..48eaf1bc0 100755 --- a/build.py +++ b/build.py @@ -280,6 +280,7 @@ def build_flutter_windows(version, features): exit(-1) os.chdir('flutter') os.system('flutter build windows --release') + shutil.copy2('target/release/deps/virtual_display.dll', flutter_win_target_dir) os.chdir('..') os.chdir('libs/portable') os.system('pip3 install -r requirements.txt') @@ -316,6 +317,11 @@ def main(): os.system('python3 res/inline-sciter.py') portable = args.portable if windows: + # build virtual display dynamic library + os.chdir('libs/virtual_display') + os.system('cargo build --release') + os.chdir('../..') + if flutter: build_flutter_windows(version, features) return diff --git a/libs/clipboard/build.rs b/libs/clipboard/build.rs index b5c547637..7eb52c75b 100644 --- a/libs/clipboard/build.rs +++ b/libs/clipboard/build.rs @@ -18,7 +18,7 @@ fn build_c_impl() { if build.get_compiler().is_like_msvc() { build.define("WIN32", ""); // build.define("_AMD64_", ""); - build.flag("-Zi"); + build.flag("-Z7"); build.flag("-GR-"); // build.flag("-std:c++11"); } else { diff --git a/libs/virtual_display/Cargo.toml b/libs/virtual_display/Cargo.toml index 8d0b65171..d0b63b454 100644 --- a/libs/virtual_display/Cargo.toml +++ b/libs/virtual_display/Cargo.toml @@ -3,6 +3,10 @@ name = "virtual_display" version = "0.1.0" edition = "2021" +[lib] +name = "virtual_display" +crate-type = ["cdylib", "staticlib", "rlib"] + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [build-dependencies] diff --git a/libs/virtual_display/build.rs b/libs/virtual_display/build.rs index 177d92371..29c3dd5d4 100644 --- a/libs/virtual_display/build.rs +++ b/libs/virtual_display/build.rs @@ -13,7 +13,7 @@ fn build_c_impl() { if build.get_compiler().is_like_msvc() { build.define("WIN32", ""); - build.flag("-Zi"); + build.flag("-Z7"); build.flag("-GR-"); // build.flag("-std:c++11"); } else { @@ -24,7 +24,7 @@ fn build_c_impl() { } #[cfg(target_os = "windows")] - build.compile("xxx"); + build.compile("win_virtual_display"); #[cfg(target_os = "windows")] println!("cargo:rerun-if-changed=src/win10/IddController.c"); diff --git a/libs/virtual_display/src/lib.rs b/libs/virtual_display/src/lib.rs index 9f71fd6da..7ffcc679f 100644 --- a/libs/virtual_display/src/lib.rs +++ b/libs/virtual_display/src/lib.rs @@ -11,6 +11,7 @@ lazy_static::lazy_static! { static ref MONITOR_PLUGIN: Mutex> = Mutex::new(Vec::new()); } +#[no_mangle] pub fn download_driver() -> ResultType<()> { #[cfg(windows)] let _download_url = win10::DRIVER_DOWNLOAD_URL; @@ -22,6 +23,7 @@ pub fn download_driver() -> ResultType<()> { Ok(()) } +#[no_mangle] pub fn install_update_driver(_reboot_required: &mut bool) -> ResultType<()> { #[cfg(windows)] let install_path = win10::DRIVER_INSTALL_PATH; @@ -62,6 +64,7 @@ pub fn install_update_driver(_reboot_required: &mut bool) -> ResultType<()> { Ok(()) } +#[no_mangle] pub fn uninstall_driver(_reboot_required: &mut bool) -> ResultType<()> { #[cfg(windows)] let install_path = win10::DRIVER_INSTALL_PATH; @@ -96,6 +99,7 @@ pub fn uninstall_driver(_reboot_required: &mut bool) -> ResultType<()> { Ok(()) } +#[no_mangle] pub fn is_device_created() -> bool { #[cfg(windows)] return *H_SW_DEVICE.lock().unwrap() != 0; @@ -103,6 +107,7 @@ pub fn is_device_created() -> bool { return false; } +#[no_mangle] pub fn create_device() -> ResultType<()> { if is_device_created() { return Ok(()); @@ -120,6 +125,7 @@ pub fn create_device() -> ResultType<()> { Ok(()) } +#[no_mangle] pub fn close_device() { #[cfg(windows)] unsafe { @@ -129,6 +135,7 @@ pub fn close_device() { } } +#[no_mangle] pub fn plug_in_monitor() -> ResultType<()> { #[cfg(windows)] unsafe { @@ -149,6 +156,7 @@ pub fn plug_in_monitor() -> ResultType<()> { Ok(()) } +#[no_mangle] pub fn plug_out_monitor() -> ResultType<()> { #[cfg(windows)] unsafe { @@ -169,6 +177,7 @@ pub fn plug_out_monitor() -> ResultType<()> { Ok(()) } +#[no_mangle] pub fn update_monitor_modes() -> ResultType<()> { #[cfg(windows)] unsafe { diff --git a/src/server.rs b/src/server.rs index 7e00532fe..bf81468ce 100644 --- a/src/server.rs +++ b/src/server.rs @@ -53,6 +53,8 @@ mod connection; pub mod portable_service; mod service; mod video_qos; +#[cfg(windows)] +mod virtual_display; pub mod video_service; use hbb_common::tcp::new_listener; diff --git a/src/server/video_service.rs b/src/server/video_service.rs index 3ccc3af39..0597ac956 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -42,7 +42,7 @@ use std::{ time::{self, Duration, Instant}, }; #[cfg(windows)] -use virtual_display; +use super::virtual_display; pub const SCRAP_UBUNTU_HIGHER_REQUIRED: &str = "Wayland requires Ubuntu 21.04 or higher version."; pub const SCRAP_OTHER_VERSION_OR_X11_REQUIRED: &str = diff --git a/src/server/virtual_display.rs b/src/server/virtual_display.rs new file mode 100644 index 000000000..23071326b --- /dev/null +++ b/src/server/virtual_display.rs @@ -0,0 +1,64 @@ +#![allow(dead_code)] + +use hbb_common::{bail, ResultType}; +use std::sync::{Arc, Mutex}; + +const LIB_NAME_VIRTUAL_DISPLAY: &str = "virtual_display"; + +lazy_static::lazy_static! { + static ref LIB_VIRTUAL_DISPLAY: Arc>> = { + #[cfg(target_os = "windows")] + let libname = format!("{}.dll", LIB_NAME_VIRTUAL_DISPLAY); + #[cfg(target_os = "linux")] + let libname = format!("lib{}.so", LIB_NAME_VIRTUAL_DISPLAY); + #[cfg(target_os = "macos")] + let libname = format!("lib{}.dylib", LIB_NAME_VIRTUAL_DISPLAY); + Arc::new(Mutex::new(unsafe { libloading::Library::new(libname) })) + }; +} + +pub(super) fn is_device_created() -> bool { + match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { + Ok(lib) => unsafe { + match lib.get:: bool>>(b"is_device_created") { + Ok(func) => func(), + Err(..) => false, + } + }, + Err(..) => false, + } +} + +macro_rules! def_func_result { + ($func:ident, $name: tt) => { + pub(super) fn $func() -> ResultType<()> { + match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { + Ok(lib) => unsafe { + match lib.get:: ResultType<()>>>($name.as_bytes()) { + Ok(func) => func(), + Err(..) => bail!("Failed to load func {}", $name), + } + }, + Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e), + } + } + }; +} + +def_func_result!(create_device, "create_device"); + +pub(super) fn close_device() { + match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { + Ok(lib) => unsafe { + match lib.get::>(b"close_device") { + Ok(func) => func(), + Err(..) => {}, + } + }, + Err(..) => {}, + } +} + +def_func_result!(plug_in_monitor, "plug_in_monitor"); +def_func_result!(plug_out_monitor, "plug_out_monitor"); +def_func_result!(update_monitor_modes, "update_monitor_modes"); From 27e7b5722255ab297077d9f3252f2099b00ef2ff Mon Sep 17 00:00:00 2001 From: fufesou Date: Fri, 18 Nov 2022 14:52:01 +0800 Subject: [PATCH 2/5] move virtual display to lib workspace Signed-off-by: fufesou --- Cargo.lock | 20 +- Cargo.toml | 4 +- build.py | 6 +- libs/virtual_display/Cargo.lock | 1358 +++++++++++++++++ libs/virtual_display/Cargo.toml | 12 +- libs/virtual_display/README.md | 31 +- libs/virtual_display/dylib/Cargo.toml | 19 + libs/virtual_display/dylib/README.md | 32 + libs/virtual_display/{ => dylib}/build.rs | 0 libs/virtual_display/dylib/src/lib.rs | 201 +++ .../{ => dylib}/src/win10/IddController.c | 0 .../{ => dylib}/src/win10/IddController.h | 0 .../{ => dylib}/src/win10/Public.h | 0 .../{ => dylib}/src/win10/idd.rs | 0 .../{ => dylib}/src/win10/mod.rs | 0 libs/virtual_display/src/lib.rs | 248 +-- src/server.rs | 2 - src/server/video_service.rs | 2 +- src/server/virtual_display.rs | 64 - 19 files changed, 1702 insertions(+), 297 deletions(-) create mode 100644 libs/virtual_display/Cargo.lock create mode 100644 libs/virtual_display/dylib/Cargo.toml create mode 100644 libs/virtual_display/dylib/README.md rename libs/virtual_display/{ => dylib}/build.rs (100%) create mode 100644 libs/virtual_display/dylib/src/lib.rs rename libs/virtual_display/{ => dylib}/src/win10/IddController.c (100%) rename libs/virtual_display/{ => dylib}/src/win10/IddController.h (100%) rename libs/virtual_display/{ => dylib}/src/win10/Public.h (100%) rename libs/virtual_display/{ => dylib}/src/win10/idd.rs (100%) rename libs/virtual_display/{ => dylib}/src/win10/mod.rs (100%) delete mode 100644 src/server/virtual_display.rs diff --git a/Cargo.lock b/Cargo.lock index 0e892aa31..07cb346b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1392,6 +1392,18 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0" +[[package]] +name = "dylib_virtual_display" +version = "0.1.0" +dependencies = [ + "cc", + "hbb_common", + "lazy_static", + "serde 1.0.144", + "serde_derive", + "thiserror", +] + [[package]] name = "ed25519" version = "1.5.2" @@ -4391,7 +4403,6 @@ dependencies = [ "lazy_static", "libappindicator", "libc", - "libloading", "libpulse-binding", "libpulse-simple-binding", "mac_address", @@ -4425,6 +4436,7 @@ dependencies = [ "trayicon", "url", "uuid", + "virtual_display", "whoami", "winapi 0.3.9", "windows-service", @@ -5555,12 +5567,10 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" name = "virtual_display" version = "0.1.0" dependencies = [ - "cc", + "dylib_virtual_display", "hbb_common", "lazy_static", - "serde 1.0.144", - "serde_derive", - "thiserror", + "libloading", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a3758c861..6375bce26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,7 +65,6 @@ flutter_rust_bridge = { git = "https://github.com/SoLongAndThanksForAllThePizza/ errno = "0.2.8" rdev = { git = "https://github.com/asur4s/rdev" } url = { version = "2.1", features = ["serde"] } -libloading = "0.7" reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls"], default-features=false } chrono = "0.4.23" @@ -92,6 +91,7 @@ winit = "0.26" winapi = { version = "0.3", features = ["winuser"] } winreg = "0.10" windows-service = "0.4" +virtual_display = { path = "libs/virtual_display" } impersonate_system = { git = "https://github.com/21pages/impersonate-system" } shared_memory = "0.12.4" shutdown_hooks = "0.1.0" @@ -126,7 +126,7 @@ jni = "0.19" flutter_rust_bridge = { git = "https://github.com/SoLongAndThanksForAllThePizza/flutter_rust_bridge" } [workspace] -members = ["libs/scrap", "libs/hbb_common", "libs/enigo", "libs/clipboard", "libs/virtual_display", "libs/simple_rc", "libs/portable"] +members = ["libs/scrap", "libs/hbb_common", "libs/enigo", "libs/clipboard", "libs/virtual_display", "libs/virtual_display/dylib", "libs/simple_rc", "libs/portable"] [package.metadata.winres] LegalCopyright = "Copyright © 2022 Purslane, Inc." diff --git a/build.py b/build.py index 48eaf1bc0..a95c64dc1 100755 --- a/build.py +++ b/build.py @@ -280,8 +280,8 @@ def build_flutter_windows(version, features): exit(-1) os.chdir('flutter') os.system('flutter build windows --release') - shutil.copy2('target/release/deps/virtual_display.dll', flutter_win_target_dir) os.chdir('..') + shutil.copy2('target/release/deps/dylib_virtual_display.dll', flutter_win_target_dir) os.chdir('libs/portable') os.system('pip3 install -r requirements.txt') os.system( @@ -318,9 +318,9 @@ def main(): portable = args.portable if windows: # build virtual display dynamic library - os.chdir('libs/virtual_display') + os.chdir('libs/virtual_display/dylib') os.system('cargo build --release') - os.chdir('../..') + os.chdir('../../..') if flutter: build_flutter_windows(version, features) diff --git a/libs/virtual_display/Cargo.lock b/libs/virtual_display/Cargo.lock new file mode 100644 index 000000000..22fa681b2 --- /dev/null +++ b/libs/virtual_display/Cargo.lock @@ -0,0 +1,1358 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "aho-corasick" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +dependencies = [ + "memchr", +] + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bumpalo" +version = "3.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" + +[[package]] +name = "bytes" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" +dependencies = [ + "serde", +] + +[[package]] +name = "cc" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" +dependencies = [ + "jobserver", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-integer", + "num-traits", + "time", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "confy" +version = "0.4.0" +source = "git+https://github.com/open-trade/confy#630cc28a396cb7d01eefdd9f3824486fe4d8554b" +dependencies = [ + "directories-next", + "serde", + "thiserror", + "toml", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "cxx" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97abf9f0eca9e52b7f81b945524e76710e6cb2366aead23b7d4fbf72e281f888" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cc32cc5fea1d894b77d269ddb9f192110069a8a9c1f1d441195fba90553dea3" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ca220e4794c934dc6b1207c3b42856ad4c302f2df1712e9f8d2eec5afaacf1f" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "directories-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "dylib_virtual_display" +version = "0.1.0" +dependencies = [ + "cc", + "hbb_common", + "lazy_static", + "serde", + "serde_derive", + "thiserror", +] + +[[package]] +name = "ed25519" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" +dependencies = [ + "signature", +] + +[[package]] +name = "either" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" + +[[package]] +name = "env_logger" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "fastrand" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +dependencies = [ + "instant", +] + +[[package]] +name = "filetime" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b9663d381d07ae25dc88dbdf27df458faa83a9b25336bcac83d5e452b5fc9d3" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "windows-sys", +] + +[[package]] +name = "futures" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" + +[[package]] +name = "futures-executor" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" + +[[package]] +name = "futures-macro" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" + +[[package]] +name = "futures-task" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" + +[[package]] +name = "futures-util" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "hbb_common" +version = "0.1.0" +dependencies = [ + "anyhow", + "bytes", + "chrono", + "confy", + "directories-next", + "dirs-next", + "env_logger", + "filetime", + "futures", + "futures-util", + "lazy_static", + "log", + "mac_address", + "machine-uid", + "protobuf", + "protobuf-codegen", + "rand", + "regex", + "serde", + "serde_derive", + "socket2 0.3.19", + "sodiumoxide", + "tokio", + "tokio-socks", + "tokio-util", + "winapi", + "zstd", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "iana-time-zone" +version = "0.1.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + +[[package]] +name = "indexmap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "jobserver" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" +dependencies = [ + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" + +[[package]] +name = "libloading" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "libsodium-sys" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b779387cd56adfbc02ea4a668e704f729be8d6a6abd2c27ca5ee537849a92fd" +dependencies = [ + "cc", + "libc", + "pkg-config", + "walkdir", +] + +[[package]] +name = "link-cplusplus" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +dependencies = [ + "cc", +] + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "mac_address" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b238e3235c8382b7653c6408ed1b08dd379bdb9fdf990fb0bbae3db2cc0ae963" +dependencies = [ + "nix", + "winapi", +] + +[[package]] +name = "machine-uid" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f1595709b0a7386bcd56ba34d250d626e5503917d05d32cdccddcd68603e212" +dependencies = [ + "winreg", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "mio" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" +dependencies = [ + "libc", + "log", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys", +] + +[[package]] +name = "nix" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "memoffset", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-sys", +] + +[[package]] +name = "pin-project" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "protobuf" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e" +dependencies = [ + "bytes", + "once_cell", + "protobuf-support", + "thiserror", +] + +[[package]] +name = "protobuf-codegen" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd418ac3c91caa4032d37cb80ff0d44e2ebe637b2fb243b6234bf89cdac4901" +dependencies = [ + "anyhow", + "once_cell", + "protobuf", + "protobuf-parse", + "regex", + "tempfile", + "thiserror", +] + +[[package]] +name = "protobuf-parse" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d39b14605eaa1f6a340aec7f320b34064feb26c93aec35d6a9a2272a8ddfa49" +dependencies = [ + "anyhow", + "indexmap", + "log", + "protobuf", + "protobuf-support", + "tempfile", + "thiserror", + "which", +] + +[[package]] +name = "protobuf-support" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d4d7b8601c814cfb36bcebb79f0e61e45e1e93640cf778837833bbed05c372" +dependencies = [ + "thiserror", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall", + "thiserror", +] + +[[package]] +name = "regex" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "scratch" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" + +[[package]] +name = "serde" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" + +[[package]] +name = "serde_derive" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" + +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[package]] +name = "socket2" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +dependencies = [ + "cfg-if", + "libc", + "winapi", +] + +[[package]] +name = "socket2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "sodiumoxide" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e26be3acb6c2d9a7aac28482586a7856436af4cfe7100031d219de2d2ecb0028" +dependencies = [ + "ed25519", + "libc", + "libsodium-sys", + "serde", +] + +[[package]] +name = "syn" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + +[[package]] +name = "tokio" +version = "1.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.4.7", + "tokio-macros", + "winapi", +] + +[[package]] +name = "tokio-macros" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-socks" +version = "0.5.1-1" +source = "git+https://github.com/open-trade/tokio-socks#7034e79263ce25c348be072808d7601d82cd892d" +dependencies = [ + "bytes", + "either", + "futures-core", + "futures-sink", + "futures-util", + "pin-project", + "thiserror", + "tokio", + "tokio-util", +] + +[[package]] +name = "tokio-util" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" +dependencies = [ + "bytes", + "futures-core", + "futures-io", + "futures-sink", + "futures-util", + "hashbrown", + "pin-project-lite", + "slab", + "tokio", + "tracing", +] + +[[package]] +name = "toml" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +dependencies = [ + "serde", +] + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" + +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "virtual_display" +version = "0.1.0" +dependencies = [ + "dylib_virtual_display", + "hbb_common", + "lazy_static", + "libloading", +] + +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" + +[[package]] +name = "which" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" +dependencies = [ + "either", + "libc", + "once_cell", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + +[[package]] +name = "winreg" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" +dependencies = [ + "winapi", +] + +[[package]] +name = "zstd" +version = "0.9.2+zstd.1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2390ea1bf6c038c39674f22d95f0564725fc06034a47129179810b2fc58caa54" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "4.1.3+zstd.1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e99d81b99fb3c2c2c794e3fe56c305c63d5173a16a46b5850b07c935ffc7db79" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "1.6.2+zstd.1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2daf2f248d9ea44454bfcb2516534e8b8ad2fc91bf818a1885495fc42bc8ac9f" +dependencies = [ + "cc", + "libc", +] diff --git a/libs/virtual_display/Cargo.toml b/libs/virtual_display/Cargo.toml index d0b63b454..88e065206 100644 --- a/libs/virtual_display/Cargo.toml +++ b/libs/virtual_display/Cargo.toml @@ -3,18 +3,10 @@ name = "virtual_display" version = "0.1.0" edition = "2021" -[lib] -name = "virtual_display" -crate-type = ["cdylib", "staticlib", "rlib"] - # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[build-dependencies] -cc = "1.0" - [dependencies] -thiserror = "1.0.30" lazy_static = "1.4" -serde = "1.0" -serde_derive = "1.0" +libloading = "0.7" hbb_common = { path = "../hbb_common" } +dylib_virtual_display = { path = "./dylib" } diff --git a/libs/virtual_display/README.md b/libs/virtual_display/README.md index d5a1a0862..86b7b2ea2 100644 --- a/libs/virtual_display/README.md +++ b/libs/virtual_display/README.md @@ -1,32 +1,3 @@ # virtual display -Virtual display may be used on computers that do not have a monitor. - -[Development reference](https://github.com/pavlobu/deskreen/discussions/86) - -## windows - -### win10 - -Win10 provides [Indirect Display Driver Model](https://msdn.microsoft.com/en-us/library/windows/hardware/mt761968(v=vs.85).aspx). - -This lib uses [this project](https://github.com/fufesou/RustDeskIddDriver) as the driver. - - -**NOTE**: Versions before Win10 1607. Try follow [this method](https://github.com/fanxiushu/xdisp_virt/tree/master/indirect_display). - - -#### tested platforms - -- [x] 19041 -- [x] 19043 - -### win7 - -TODO - -[WDDM](https://docs.microsoft.com/en-us/windows-hardware/drivers/display/windows-vista-display-driver-model-design-guide). - -## X11 - -## OSX +[doc](./dylib/README.md) diff --git a/libs/virtual_display/dylib/Cargo.toml b/libs/virtual_display/dylib/Cargo.toml new file mode 100644 index 000000000..fee4e3e4f --- /dev/null +++ b/libs/virtual_display/dylib/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "dylib_virtual_display" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib", "staticlib", "rlib"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[build-dependencies] +cc = "1.0" + +[dependencies] +thiserror = "1.0.30" +lazy_static = "1.4" +serde = "1.0" +serde_derive = "1.0" +hbb_common = { path = "../../hbb_common" } diff --git a/libs/virtual_display/dylib/README.md b/libs/virtual_display/dylib/README.md new file mode 100644 index 000000000..d5a1a0862 --- /dev/null +++ b/libs/virtual_display/dylib/README.md @@ -0,0 +1,32 @@ +# virtual display + +Virtual display may be used on computers that do not have a monitor. + +[Development reference](https://github.com/pavlobu/deskreen/discussions/86) + +## windows + +### win10 + +Win10 provides [Indirect Display Driver Model](https://msdn.microsoft.com/en-us/library/windows/hardware/mt761968(v=vs.85).aspx). + +This lib uses [this project](https://github.com/fufesou/RustDeskIddDriver) as the driver. + + +**NOTE**: Versions before Win10 1607. Try follow [this method](https://github.com/fanxiushu/xdisp_virt/tree/master/indirect_display). + + +#### tested platforms + +- [x] 19041 +- [x] 19043 + +### win7 + +TODO + +[WDDM](https://docs.microsoft.com/en-us/windows-hardware/drivers/display/windows-vista-display-driver-model-design-guide). + +## X11 + +## OSX diff --git a/libs/virtual_display/build.rs b/libs/virtual_display/dylib/build.rs similarity index 100% rename from libs/virtual_display/build.rs rename to libs/virtual_display/dylib/build.rs diff --git a/libs/virtual_display/dylib/src/lib.rs b/libs/virtual_display/dylib/src/lib.rs new file mode 100644 index 000000000..7ffcc679f --- /dev/null +++ b/libs/virtual_display/dylib/src/lib.rs @@ -0,0 +1,201 @@ +#[cfg(windows)] +pub mod win10; + +use hbb_common::{bail, lazy_static, ResultType}; +use std::{path::Path, sync::Mutex}; + +lazy_static::lazy_static! { + // If device is uninstalled though "Device Manager" Window. + // Rustdesk is unable to handle device any more... + static ref H_SW_DEVICE: Mutex = Mutex::new(0); + static ref MONITOR_PLUGIN: Mutex> = Mutex::new(Vec::new()); +} + +#[no_mangle] +pub fn download_driver() -> ResultType<()> { + #[cfg(windows)] + let _download_url = win10::DRIVER_DOWNLOAD_URL; + #[cfg(target_os = "linux")] + let _download_url = ""; + + // process download and report progress + + Ok(()) +} + +#[no_mangle] +pub fn install_update_driver(_reboot_required: &mut bool) -> ResultType<()> { + #[cfg(windows)] + let install_path = win10::DRIVER_INSTALL_PATH; + #[cfg(not(windows))] + let install_path = ""; + + let abs_path = Path::new(install_path).canonicalize()?; + if !abs_path.exists() { + bail!("{} not exists", install_path) + } + + #[cfg(windows)] + unsafe { + { + // Device must be created before install driver. + // https://github.com/fufesou/RustDeskIddDriver/issues/1 + if let Err(e) = create_device() { + bail!("{}", e); + } + + let full_install_path: Vec = abs_path + .to_string_lossy() + .as_ref() + .encode_utf16() + .chain(Some(0).into_iter()) + .collect(); + + let mut reboot_required_tmp = win10::idd::FALSE; + if win10::idd::InstallUpdate(full_install_path.as_ptr() as _, &mut reboot_required_tmp) + == win10::idd::FALSE + { + bail!("{}", win10::get_last_msg()?); + } + *_reboot_required = reboot_required_tmp == win10::idd::TRUE; + } + } + + Ok(()) +} + +#[no_mangle] +pub fn uninstall_driver(_reboot_required: &mut bool) -> ResultType<()> { + #[cfg(windows)] + let install_path = win10::DRIVER_INSTALL_PATH; + #[cfg(not(windows))] + let install_path = ""; + + let abs_path = Path::new(install_path).canonicalize()?; + if !abs_path.exists() { + bail!("{} not exists", install_path) + } + + #[cfg(windows)] + unsafe { + { + let full_install_path: Vec = abs_path + .to_string_lossy() + .as_ref() + .encode_utf16() + .chain(Some(0).into_iter()) + .collect(); + + let mut reboot_required_tmp = win10::idd::FALSE; + if win10::idd::Uninstall(full_install_path.as_ptr() as _, &mut reboot_required_tmp) + == win10::idd::FALSE + { + bail!("{}", win10::get_last_msg()?); + } + *_reboot_required = reboot_required_tmp == win10::idd::TRUE; + } + } + + Ok(()) +} + +#[no_mangle] +pub fn is_device_created() -> bool { + #[cfg(windows)] + return *H_SW_DEVICE.lock().unwrap() != 0; + #[cfg(not(windows))] + return false; +} + +#[no_mangle] +pub fn create_device() -> ResultType<()> { + if is_device_created() { + return Ok(()); + } + #[cfg(windows)] + unsafe { + let mut lock_device = H_SW_DEVICE.lock().unwrap(); + let mut h_sw_device = *lock_device as win10::idd::HSWDEVICE; + if win10::idd::DeviceCreate(&mut h_sw_device) == win10::idd::FALSE { + bail!("{}", win10::get_last_msg()?); + } else { + *lock_device = h_sw_device as u64; + } + } + Ok(()) +} + +#[no_mangle] +pub fn close_device() { + #[cfg(windows)] + unsafe { + win10::idd::DeviceClose(*H_SW_DEVICE.lock().unwrap() as win10::idd::HSWDEVICE); + *H_SW_DEVICE.lock().unwrap() = 0; + MONITOR_PLUGIN.lock().unwrap().clear(); + } +} + +#[no_mangle] +pub fn plug_in_monitor() -> ResultType<()> { + #[cfg(windows)] + unsafe { + let monitor_index = 0 as u32; + let mut plug_in_monitors = MONITOR_PLUGIN.lock().unwrap(); + for i in 0..plug_in_monitors.len() { + if let Some(d) = plug_in_monitors.get(i) { + if *d == monitor_index { + return Ok(()); + } + }; + } + if win10::idd::MonitorPlugIn(monitor_index, 0, 30) == win10::idd::FALSE { + bail!("{}", win10::get_last_msg()?); + } + (*plug_in_monitors).push(monitor_index); + } + Ok(()) +} + +#[no_mangle] +pub fn plug_out_monitor() -> ResultType<()> { + #[cfg(windows)] + unsafe { + let monitor_index = 0 as u32; + if win10::idd::MonitorPlugOut(monitor_index) == win10::idd::FALSE { + bail!("{}", win10::get_last_msg()?); + } + let mut plug_in_monitors = MONITOR_PLUGIN.lock().unwrap(); + for i in 0..plug_in_monitors.len() { + if let Some(d) = plug_in_monitors.get(i) { + if *d == monitor_index { + plug_in_monitors.remove(i); + break; + } + }; + } + } + Ok(()) +} + +#[no_mangle] +pub fn update_monitor_modes() -> ResultType<()> { + #[cfg(windows)] + unsafe { + let monitor_index = 0 as u32; + let mut modes = vec![win10::idd::MonitorMode { + width: 1920, + height: 1080, + sync: 60, + }]; + if win10::idd::FALSE + == win10::idd::MonitorModesUpdate( + monitor_index as win10::idd::UINT, + modes.len() as win10::idd::UINT, + modes.as_mut_ptr(), + ) + { + bail!("{}", win10::get_last_msg()?); + } + } + Ok(()) +} diff --git a/libs/virtual_display/src/win10/IddController.c b/libs/virtual_display/dylib/src/win10/IddController.c similarity index 100% rename from libs/virtual_display/src/win10/IddController.c rename to libs/virtual_display/dylib/src/win10/IddController.c diff --git a/libs/virtual_display/src/win10/IddController.h b/libs/virtual_display/dylib/src/win10/IddController.h similarity index 100% rename from libs/virtual_display/src/win10/IddController.h rename to libs/virtual_display/dylib/src/win10/IddController.h diff --git a/libs/virtual_display/src/win10/Public.h b/libs/virtual_display/dylib/src/win10/Public.h similarity index 100% rename from libs/virtual_display/src/win10/Public.h rename to libs/virtual_display/dylib/src/win10/Public.h diff --git a/libs/virtual_display/src/win10/idd.rs b/libs/virtual_display/dylib/src/win10/idd.rs similarity index 100% rename from libs/virtual_display/src/win10/idd.rs rename to libs/virtual_display/dylib/src/win10/idd.rs diff --git a/libs/virtual_display/src/win10/mod.rs b/libs/virtual_display/dylib/src/win10/mod.rs similarity index 100% rename from libs/virtual_display/src/win10/mod.rs rename to libs/virtual_display/dylib/src/win10/mod.rs diff --git a/libs/virtual_display/src/lib.rs b/libs/virtual_display/src/lib.rs index 7ffcc679f..47b11d74a 100644 --- a/libs/virtual_display/src/lib.rs +++ b/libs/virtual_display/src/lib.rs @@ -1,201 +1,89 @@ #[cfg(windows)] -pub mod win10; +pub use dylib_virtual_display::win10; -use hbb_common::{bail, lazy_static, ResultType}; -use std::{path::Path, sync::Mutex}; +use hbb_common::{bail, ResultType}; +use std::sync::{Arc, Mutex}; + +const LIB_NAME_VIRTUAL_DISPLAY: &str = "virtual_display"; lazy_static::lazy_static! { - // If device is uninstalled though "Device Manager" Window. - // Rustdesk is unable to handle device any more... - static ref H_SW_DEVICE: Mutex = Mutex::new(0); - static ref MONITOR_PLUGIN: Mutex> = Mutex::new(Vec::new()); + static ref LIB_VIRTUAL_DISPLAY: Arc>> = { + #[cfg(target_os = "windows")] + let libname = format!("{}.dll", LIB_NAME_VIRTUAL_DISPLAY); + #[cfg(target_os = "linux")] + let libname = format!("lib{}.so", LIB_NAME_VIRTUAL_DISPLAY); + #[cfg(target_os = "macos")] + let libname = format!("lib{}.dylib", LIB_NAME_VIRTUAL_DISPLAY); + Arc::new(Mutex::new(unsafe { libloading::Library::new(libname) })) + }; } -#[no_mangle] -pub fn download_driver() -> ResultType<()> { - #[cfg(windows)] - let _download_url = win10::DRIVER_DOWNLOAD_URL; - #[cfg(target_os = "linux")] - let _download_url = ""; - - // process download and report progress - - Ok(()) -} - -#[no_mangle] -pub fn install_update_driver(_reboot_required: &mut bool) -> ResultType<()> { - #[cfg(windows)] - let install_path = win10::DRIVER_INSTALL_PATH; - #[cfg(not(windows))] - let install_path = ""; - - let abs_path = Path::new(install_path).canonicalize()?; - if !abs_path.exists() { - bail!("{} not exists", install_path) - } - - #[cfg(windows)] - unsafe { - { - // Device must be created before install driver. - // https://github.com/fufesou/RustDeskIddDriver/issues/1 - if let Err(e) = create_device() { - bail!("{}", e); - } - - let full_install_path: Vec = abs_path - .to_string_lossy() - .as_ref() - .encode_utf16() - .chain(Some(0).into_iter()) - .collect(); - - let mut reboot_required_tmp = win10::idd::FALSE; - if win10::idd::InstallUpdate(full_install_path.as_ptr() as _, &mut reboot_required_tmp) - == win10::idd::FALSE - { - bail!("{}", win10::get_last_msg()?); - } - *_reboot_required = reboot_required_tmp == win10::idd::TRUE; - } - } - - Ok(()) -} - -#[no_mangle] -pub fn uninstall_driver(_reboot_required: &mut bool) -> ResultType<()> { - #[cfg(windows)] - let install_path = win10::DRIVER_INSTALL_PATH; - #[cfg(not(windows))] - let install_path = ""; - - let abs_path = Path::new(install_path).canonicalize()?; - if !abs_path.exists() { - bail!("{} not exists", install_path) - } - - #[cfg(windows)] - unsafe { - { - let full_install_path: Vec = abs_path - .to_string_lossy() - .as_ref() - .encode_utf16() - .chain(Some(0).into_iter()) - .collect(); - - let mut reboot_required_tmp = win10::idd::FALSE; - if win10::idd::Uninstall(full_install_path.as_ptr() as _, &mut reboot_required_tmp) - == win10::idd::FALSE - { - bail!("{}", win10::get_last_msg()?); - } - *_reboot_required = reboot_required_tmp == win10::idd::TRUE; - } - } - - Ok(()) -} - -#[no_mangle] pub fn is_device_created() -> bool { - #[cfg(windows)] - return *H_SW_DEVICE.lock().unwrap() != 0; - #[cfg(not(windows))] - return false; + match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { + Ok(lib) => unsafe { + match lib.get:: bool>>(b"is_device_created") { + Ok(func) => func(), + Err(..) => false, + } + }, + Err(..) => false, + } } -#[no_mangle] -pub fn create_device() -> ResultType<()> { - if is_device_created() { - return Ok(()); - } - #[cfg(windows)] - unsafe { - let mut lock_device = H_SW_DEVICE.lock().unwrap(); - let mut h_sw_device = *lock_device as win10::idd::HSWDEVICE; - if win10::idd::DeviceCreate(&mut h_sw_device) == win10::idd::FALSE { - bail!("{}", win10::get_last_msg()?); - } else { - *lock_device = h_sw_device as u64; - } - } - Ok(()) -} - -#[no_mangle] pub fn close_device() { - #[cfg(windows)] - unsafe { - win10::idd::DeviceClose(*H_SW_DEVICE.lock().unwrap() as win10::idd::HSWDEVICE); - *H_SW_DEVICE.lock().unwrap() = 0; - MONITOR_PLUGIN.lock().unwrap().clear(); + match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { + Ok(lib) => unsafe { + match lib.get::>(b"close_device") { + Ok(func) => func(), + Err(..) => {} + } + }, + Err(..) => {} } } -#[no_mangle] -pub fn plug_in_monitor() -> ResultType<()> { - #[cfg(windows)] - unsafe { - let monitor_index = 0 as u32; - let mut plug_in_monitors = MONITOR_PLUGIN.lock().unwrap(); - for i in 0..plug_in_monitors.len() { - if let Some(d) = plug_in_monitors.get(i) { - if *d == monitor_index { - return Ok(()); - } - }; +macro_rules! def_func_result { + ($func:ident, $name: tt) => { + pub fn $func() -> ResultType<()> { + match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { + Ok(lib) => unsafe { + match lib.get:: ResultType<()>>>($name.as_bytes()) { + Ok(func) => func(), + Err(..) => bail!("Failed to load func {}", $name), + } + }, + Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e), + } } - if win10::idd::MonitorPlugIn(monitor_index, 0, 30) == win10::idd::FALSE { - bail!("{}", win10::get_last_msg()?); - } - (*plug_in_monitors).push(monitor_index); - } - Ok(()) + }; } -#[no_mangle] -pub fn plug_out_monitor() -> ResultType<()> { - #[cfg(windows)] - unsafe { - let monitor_index = 0 as u32; - if win10::idd::MonitorPlugOut(monitor_index) == win10::idd::FALSE { - bail!("{}", win10::get_last_msg()?); - } - let mut plug_in_monitors = MONITOR_PLUGIN.lock().unwrap(); - for i in 0..plug_in_monitors.len() { - if let Some(d) = plug_in_monitors.get(i) { - if *d == monitor_index { - plug_in_monitors.remove(i); - break; - } - }; - } +pub fn install_update_driver(reboot_required: &mut bool) -> ResultType<()> { + match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { + Ok(lib) => unsafe { + match lib.get:: ResultType<()>>>(b"install_update_driver") { + Ok(func) => func(reboot_required), + Err(..) => bail!("Failed to load func install_update_driver"), + } + }, + Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e), } - Ok(()) } -#[no_mangle] -pub fn update_monitor_modes() -> ResultType<()> { - #[cfg(windows)] - unsafe { - let monitor_index = 0 as u32; - let mut modes = vec![win10::idd::MonitorMode { - width: 1920, - height: 1080, - sync: 60, - }]; - if win10::idd::FALSE - == win10::idd::MonitorModesUpdate( - monitor_index as win10::idd::UINT, - modes.len() as win10::idd::UINT, - modes.as_mut_ptr(), - ) - { - bail!("{}", win10::get_last_msg()?); - } +pub fn uninstall_driver(reboot_required: &mut bool) -> ResultType<()> { + match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { + Ok(lib) => unsafe { + match lib.get:: ResultType<()>>>(b"uninstall_driver") { + Ok(func) => func(reboot_required), + Err(..) => bail!("Failed to load func uninstall_driver"), + } + }, + Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e), } - Ok(()) } + +def_func_result!(download_driver, "download_driver"); +def_func_result!(create_device, "create_device"); +def_func_result!(plug_in_monitor, "plug_in_monitor"); +def_func_result!(plug_out_monitor, "plug_out_monitor"); +def_func_result!(update_monitor_modes, "update_monitor_modes"); diff --git a/src/server.rs b/src/server.rs index bf81468ce..7e00532fe 100644 --- a/src/server.rs +++ b/src/server.rs @@ -53,8 +53,6 @@ mod connection; pub mod portable_service; mod service; mod video_qos; -#[cfg(windows)] -mod virtual_display; pub mod video_service; use hbb_common::tcp::new_listener; diff --git a/src/server/video_service.rs b/src/server/video_service.rs index 0597ac956..3ccc3af39 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -42,7 +42,7 @@ use std::{ time::{self, Duration, Instant}, }; #[cfg(windows)] -use super::virtual_display; +use virtual_display; pub const SCRAP_UBUNTU_HIGHER_REQUIRED: &str = "Wayland requires Ubuntu 21.04 or higher version."; pub const SCRAP_OTHER_VERSION_OR_X11_REQUIRED: &str = diff --git a/src/server/virtual_display.rs b/src/server/virtual_display.rs deleted file mode 100644 index 23071326b..000000000 --- a/src/server/virtual_display.rs +++ /dev/null @@ -1,64 +0,0 @@ -#![allow(dead_code)] - -use hbb_common::{bail, ResultType}; -use std::sync::{Arc, Mutex}; - -const LIB_NAME_VIRTUAL_DISPLAY: &str = "virtual_display"; - -lazy_static::lazy_static! { - static ref LIB_VIRTUAL_DISPLAY: Arc>> = { - #[cfg(target_os = "windows")] - let libname = format!("{}.dll", LIB_NAME_VIRTUAL_DISPLAY); - #[cfg(target_os = "linux")] - let libname = format!("lib{}.so", LIB_NAME_VIRTUAL_DISPLAY); - #[cfg(target_os = "macos")] - let libname = format!("lib{}.dylib", LIB_NAME_VIRTUAL_DISPLAY); - Arc::new(Mutex::new(unsafe { libloading::Library::new(libname) })) - }; -} - -pub(super) fn is_device_created() -> bool { - match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { - Ok(lib) => unsafe { - match lib.get:: bool>>(b"is_device_created") { - Ok(func) => func(), - Err(..) => false, - } - }, - Err(..) => false, - } -} - -macro_rules! def_func_result { - ($func:ident, $name: tt) => { - pub(super) fn $func() -> ResultType<()> { - match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { - Ok(lib) => unsafe { - match lib.get:: ResultType<()>>>($name.as_bytes()) { - Ok(func) => func(), - Err(..) => bail!("Failed to load func {}", $name), - } - }, - Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e), - } - } - }; -} - -def_func_result!(create_device, "create_device"); - -pub(super) fn close_device() { - match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { - Ok(lib) => unsafe { - match lib.get::>(b"close_device") { - Ok(func) => func(), - Err(..) => {}, - } - }, - Err(..) => {}, - } -} - -def_func_result!(plug_in_monitor, "plug_in_monitor"); -def_func_result!(plug_out_monitor, "plug_out_monitor"); -def_func_result!(update_monitor_modes, "update_monitor_modes"); From aa3b8ca084babcb451ea73dc18843a49ff1d88eb Mon Sep 17 00:00:00 2001 From: fufesou Date: Fri, 18 Nov 2022 15:51:33 +0800 Subject: [PATCH 3/5] virtual display remove static links Signed-off-by: fufesou --- Cargo.lock | 1 - build.py | 5 -- libs/virtual_display/Cargo.toml | 1 - .../{ => dylib}/examples/idd_controller.rs | 2 +- libs/virtual_display/dylib/src/lib.rs | 6 ++ libs/virtual_display/src/lib.rs | 68 ++++++++++++++----- 6 files changed, 59 insertions(+), 24 deletions(-) rename libs/virtual_display/{ => dylib}/examples/idd_controller.rs (98%) diff --git a/Cargo.lock b/Cargo.lock index 07cb346b8..9eb270683 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5567,7 +5567,6 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" name = "virtual_display" version = "0.1.0" dependencies = [ - "dylib_virtual_display", "hbb_common", "lazy_static", "libloading", diff --git a/build.py b/build.py index a95c64dc1..07c571b11 100755 --- a/build.py +++ b/build.py @@ -317,11 +317,6 @@ def main(): os.system('python3 res/inline-sciter.py') portable = args.portable if windows: - # build virtual display dynamic library - os.chdir('libs/virtual_display/dylib') - os.system('cargo build --release') - os.chdir('../../..') - if flutter: build_flutter_windows(version, features) return diff --git a/libs/virtual_display/Cargo.toml b/libs/virtual_display/Cargo.toml index 88e065206..c700bd12a 100644 --- a/libs/virtual_display/Cargo.toml +++ b/libs/virtual_display/Cargo.toml @@ -9,4 +9,3 @@ edition = "2021" lazy_static = "1.4" libloading = "0.7" hbb_common = { path = "../hbb_common" } -dylib_virtual_display = { path = "./dylib" } diff --git a/libs/virtual_display/examples/idd_controller.rs b/libs/virtual_display/dylib/examples/idd_controller.rs similarity index 98% rename from libs/virtual_display/examples/idd_controller.rs rename to libs/virtual_display/dylib/examples/idd_controller.rs index 7d5677724..c9a3fbbab 100644 --- a/libs/virtual_display/examples/idd_controller.rs +++ b/libs/virtual_display/dylib/examples/idd_controller.rs @@ -1,5 +1,5 @@ #[cfg(windows)] -use virtual_display::win10::{idd, DRIVER_INSTALL_PATH}; +use dylib_virtual_display::win10::{idd, DRIVER_INSTALL_PATH}; #[cfg(windows)] use std::{ diff --git a/libs/virtual_display/dylib/src/lib.rs b/libs/virtual_display/dylib/src/lib.rs index 7ffcc679f..4a95e3461 100644 --- a/libs/virtual_display/dylib/src/lib.rs +++ b/libs/virtual_display/dylib/src/lib.rs @@ -11,6 +11,12 @@ lazy_static::lazy_static! { static ref MONITOR_PLUGIN: Mutex> = Mutex::new(Vec::new()); } +#[no_mangle] +#[cfg(windows)] +pub fn get_dirver_install_path() -> &'static str { + win10::DRIVER_INSTALL_PATH +} + #[no_mangle] pub fn download_driver() -> ResultType<()> { #[cfg(windows)] diff --git a/libs/virtual_display/src/lib.rs b/libs/virtual_display/src/lib.rs index 47b11d74a..cd9402c69 100644 --- a/libs/virtual_display/src/lib.rs +++ b/libs/virtual_display/src/lib.rs @@ -1,24 +1,52 @@ -#[cfg(windows)] -pub use dylib_virtual_display::win10; - use hbb_common::{bail, ResultType}; use std::sync::{Arc, Mutex}; -const LIB_NAME_VIRTUAL_DISPLAY: &str = "virtual_display"; +const LIB_NAME_VIRTUAL_DISPLAY: &str = "dylib_virtual_display"; lazy_static::lazy_static! { static ref LIB_VIRTUAL_DISPLAY: Arc>> = { - #[cfg(target_os = "windows")] - let libname = format!("{}.dll", LIB_NAME_VIRTUAL_DISPLAY); - #[cfg(target_os = "linux")] - let libname = format!("lib{}.so", LIB_NAME_VIRTUAL_DISPLAY); - #[cfg(target_os = "macos")] - let libname = format!("lib{}.dylib", LIB_NAME_VIRTUAL_DISPLAY); - Arc::new(Mutex::new(unsafe { libloading::Library::new(libname) })) + Arc::new(Mutex::new(unsafe { libloading::Library::new(get_lib_name()) })) }; } +#[cfg(target_os = "windows")] +fn get_lib_name() -> String { + format!("{}.dll", LIB_NAME_VIRTUAL_DISPLAY) +} + +#[cfg(target_os = "linux")] +fn get_lib_name() -> String { + format!("lib{}.so", LIB_NAME_VIRTUAL_DISPLAY) +} + +#[cfg(target_os = "macos")] +fn get_lib_name() -> String { + format!("lib{}.dylib", LIB_NAME_VIRTUAL_DISPLAY) +} + +fn try_reload_lib() { + let mut lock = LIB_VIRTUAL_DISPLAY.lock().unwrap(); + if lock.is_err() { + *lock = unsafe { libloading::Library::new(get_lib_name()) }; + } +} + +#[cfg(windows)] +pub fn get_dirver_install_path() -> ResultType<&'static str> { + try_reload_lib(); + match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { + Ok(lib) => unsafe { + match lib.get:: &'static str>>(b"get_dirver_install_path") { + Ok(func) => Ok(func()), + Err(e) => bail!("Failed to load func get_dirver_install_path, {}", e), + } + }, + Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e), + } +} + pub fn is_device_created() -> bool { + try_reload_lib(); match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { Ok(lib) => unsafe { match lib.get:: bool>>(b"is_device_created") { @@ -31,6 +59,7 @@ pub fn is_device_created() -> bool { } pub fn close_device() { + try_reload_lib(); match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { Ok(lib) => unsafe { match lib.get::>(b"close_device") { @@ -45,11 +74,12 @@ pub fn close_device() { macro_rules! def_func_result { ($func:ident, $name: tt) => { pub fn $func() -> ResultType<()> { + try_reload_lib(); match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { Ok(lib) => unsafe { match lib.get:: ResultType<()>>>($name.as_bytes()) { Ok(func) => func(), - Err(..) => bail!("Failed to load func {}", $name), + Err(e) => bail!("Failed to load func {}, {}", $name, e), } }, Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e), @@ -59,11 +89,14 @@ macro_rules! def_func_result { } pub fn install_update_driver(reboot_required: &mut bool) -> ResultType<()> { + try_reload_lib(); match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { Ok(lib) => unsafe { - match lib.get:: ResultType<()>>>(b"install_update_driver") { + match lib.get:: ResultType<()>>>( + b"install_update_driver", + ) { Ok(func) => func(reboot_required), - Err(..) => bail!("Failed to load func install_update_driver"), + Err(e) => bail!("Failed to load func install_update_driver, {}", e), } }, Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e), @@ -71,11 +104,14 @@ pub fn install_update_driver(reboot_required: &mut bool) -> ResultType<()> { } pub fn uninstall_driver(reboot_required: &mut bool) -> ResultType<()> { + try_reload_lib(); match &*LIB_VIRTUAL_DISPLAY.lock().unwrap() { Ok(lib) => unsafe { - match lib.get:: ResultType<()>>>(b"uninstall_driver") { + match lib + .get:: ResultType<()>>>(b"uninstall_driver") + { Ok(func) => func(reboot_required), - Err(..) => bail!("Failed to load func uninstall_driver"), + Err(e) => bail!("Failed to load func uninstall_driver, {}", e), } }, Err(e) => bail!("Failed to load library {}, {}", LIB_NAME_VIRTUAL_DISPLAY, e), From 3e9d992db333869bccf0ce94239758ea1d2c1bac Mon Sep 17 00:00:00 2001 From: fufesou Date: Fri, 18 Nov 2022 17:09:52 +0800 Subject: [PATCH 4/5] build dylib Signed-off-by: fufesou --- build.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.py b/build.py index 07c571b11..a95c64dc1 100755 --- a/build.py +++ b/build.py @@ -317,6 +317,11 @@ def main(): os.system('python3 res/inline-sciter.py') portable = args.portable if windows: + # build virtual display dynamic library + os.chdir('libs/virtual_display/dylib') + os.system('cargo build --release') + os.chdir('../../..') + if flutter: build_flutter_windows(version, features) return From af68800f45357de52662f8144d09696c58c42c10 Mon Sep 17 00:00:00 2001 From: fufesou Date: Fri, 18 Nov 2022 18:46:00 +0800 Subject: [PATCH 5/5] remove redundant conditions Signed-off-by: fufesou --- src/client/io_loop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/io_loop.rs b/src/client/io_loop.rs index 86a9e2f2e..6ad4f96d6 100644 --- a/src/client/io_loop.rs +++ b/src/client/io_loop.rs @@ -1187,7 +1187,7 @@ impl Remote { #[cfg(windows)] fn handle_cliprdr_msg(&self, clip: hbb_common::message_proto::Cliprdr) { if !self.handler.lc.read().unwrap().disable_clipboard { - #[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))] + #[cfg(feature = "flutter")] if let Some(hbb_common::message_proto::cliprdr::Union::FormatList(_)) = &clip.union { if self.client_conn_id != clipboard::get_client_conn_id(&crate::flutter::get_cur_session_id())