From afd77181ff3570589a6e506c1abf2cc14fef8ffb Mon Sep 17 00:00:00 2001 From: rustdesk Date: Sat, 8 Jul 2023 12:34:40 +0800 Subject: [PATCH] println in winmain --- src/core_main.rs | 22 ++++++++++++++++++---- src/platform/mod.rs | 2 +- src/platform/windows.rs | 23 +++++++++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/core_main.rs b/src/core_main.rs index a4dee3fce..1f624d8c8 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -6,6 +6,18 @@ use hbb_common::log; #[cfg(not(any(target_os = "android", target_os = "ios")))] use hbb_common::platform::register_breakdown_handler; +#[macro_export] +macro_rules! my_println{ + ($($arg:tt)*) => { + #[cfg(not(windows))] + println!("{}", format_args!($($arg)*)); + #[cfg(windows)] + crate::platform::message_box( + &format!("{}", format_args!($($arg)*)) + ); + }; +} + /// shared by flutter and sciter main function /// /// [Note] @@ -83,7 +95,7 @@ pub fn core_main() -> Option> { args.clear(); } if args.len() > 0 && args[0] == "--version" { - println!("{}", crate::VERSION); + my_println!("{}", crate::VERSION); return None; } #[cfg(windows)] @@ -225,16 +237,18 @@ pub fn core_main() -> Option> { if args.len() == 2 { if crate::platform::is_root() { crate::ipc::set_permanent_password(args[1].to_owned()).unwrap(); + my_println!("Done!"); } else { - println!("Administrative privileges required!"); + my_println!("Administrative privileges required!"); } } return None; } else if args[0] == "--get-id" { + #[cfg(windows)] if crate::platform::is_root() { - println!("{}", crate::ipc::get_id()); + my_println!("{}", crate::ipc::get_id()); } else { - println!("Permission denied!"); + my_println!("Permission denied!"); } return None; } else if args[0] == "--check-hwcodec-config" { diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 60ef1806b..e962ef9d5 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -48,7 +48,7 @@ pub fn breakdown_callback() { pub fn change_resolution(name: &str, width: usize, height: usize) -> ResultType<()> { let cur_resolution = current_resolution(name)?; // For MacOS - // to-do: Make sure the following comparison works. + // to-do: Make sure the following comparison works. // For Linux // Just run "xrandr", dpi may not be taken into consideration. // For Windows diff --git a/src/platform/windows.rs b/src/platform/windows.rs index df783b781..5ca069b80 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -2297,3 +2297,26 @@ mod tests { assert_eq!(chr, None) } } + +pub fn message_box(text: &str) { + let mut text = text.to_owned(); + if !text.ends_with("!") { + use arboard::Clipboard as ClipboardContext; + match ClipboardContext::new() { + Ok(mut ctx) => { + ctx.set_text(&text).ok(); + text = format!("{}\n\nAbove text has been copied to clipboard", &text); + } + _ => {} + } + } + let text = text + .encode_utf16() + .chain(std::iter::once(0)) + .collect::>(); + let caption = "RustDesk Output" + .encode_utf16() + .chain(std::iter::once(0)) + .collect::>(); + unsafe { MessageBoxW(std::ptr::null_mut(), text.as_ptr(), caption.as_ptr(), MB_OK) }; +}