mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-12-16 20:47:53 +08:00
a84ee7a6ec
Signed-off-by: fufesou <shuanglongchen@yeah.net>
87 lines
2.5 KiB
Rust
87 lines
2.5 KiB
Rust
// Specify the Windows subsystem to eliminate console window.
|
|
// Requires Rust 1.18.
|
|
//#![windows_subsystem = "windows"]
|
|
|
|
use librustdesk::*;
|
|
|
|
#[cfg(any(target_os = "android", target_os = "ios"))]
|
|
fn main() {
|
|
if !common::global_init() {
|
|
return;
|
|
}
|
|
common::test_rendezvous_server();
|
|
common::test_nat_type();
|
|
#[cfg(target_os = "android")]
|
|
crate::common::check_software_update();
|
|
common::global_clean();
|
|
}
|
|
|
|
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
|
|
fn main() {
|
|
if !common::global_init() {
|
|
return;
|
|
}
|
|
if let Some(args) = crate::core_main::core_main().as_mut() {
|
|
ui::start(args);
|
|
}
|
|
common::global_clean();
|
|
}
|
|
|
|
#[cfg(feature = "cli")]
|
|
fn main() {
|
|
if !common::global_init() {
|
|
return;
|
|
}
|
|
use clap::App;
|
|
use hbb_common::log;
|
|
let args = format!(
|
|
"-p, --port-forward=[PORT-FORWARD-OPTIONS] 'Format: remote-id:local-port:remote-port[:remote-host]'
|
|
-k, --key=[KEY] ''
|
|
-s, --server... 'Start server'",
|
|
);
|
|
let matches = App::new("rustdesk")
|
|
.version(crate::VERSION)
|
|
.author("CarrieZ Studio<info@rustdesk.com>")
|
|
.about("RustDesk command line tool")
|
|
.args_from_usage(&args)
|
|
.get_matches();
|
|
use hbb_common::{config::LocalConfig, env_logger::*};
|
|
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info"));
|
|
if let Some(p) = matches.value_of("port-forward") {
|
|
let options: Vec<String> = p.split(":").map(|x| x.to_owned()).collect();
|
|
if options.len() < 3 {
|
|
log::error!("Wrong port-forward options");
|
|
return;
|
|
}
|
|
let mut port = 0;
|
|
if let Ok(v) = options[1].parse::<i32>() {
|
|
port = v;
|
|
} else {
|
|
log::error!("Wrong local-port");
|
|
return;
|
|
}
|
|
let mut remote_port = 0;
|
|
if let Ok(v) = options[2].parse::<i32>() {
|
|
remote_port = v;
|
|
} else {
|
|
log::error!("Wrong remote-port");
|
|
return;
|
|
}
|
|
let mut remote_host = "localhost".to_owned();
|
|
if options.len() > 3 {
|
|
remote_host = options[3].clone();
|
|
}
|
|
let key = matches.value_of("key").unwrap_or("").to_owned();
|
|
let token = LocalConfig::get_option("access_token");
|
|
cli::start_one_port_forward(
|
|
options[0].clone(),
|
|
port,
|
|
remote_host,
|
|
remote_port,
|
|
key,
|
|
token,
|
|
);
|
|
}
|
|
common::global_clean();
|
|
}
|