changeset 1588:9bacada77a23 icedtea-web-1.8-branchpoint

Hidden console on Windows * rust-launcher/src/dirs_paths_helper.rs: factory for windows os now supply third parameter * rust-launcher/src/main.rs: (get_os) on windows now have three params. Call to get os if-windows cfged out (main) parent process is now checking ATTACH_PARENT_PROCESS before get_os on windows * rust-launcher/src/os_access.rs: oon windows, without console, no window is enforced. Trait got win-only inside_console method windows impl of os_access. Win module made public to expose AttachConsole function. * rust-launcher/src/utils.rs: test logger got windows-only inside_console
author Jiri Vanek <jvanek@redhat.com>
date Tue, 12 Mar 2019 18:11:00 +0100
parents fce279b33577
children 2ecb651a6f8d
files ChangeLog rust-launcher/src/dirs_paths_helper.rs rust-launcher/src/main.rs rust-launcher/src/os_access.rs rust-launcher/src/utils.rs
diffstat 5 files changed, 57 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Mar 12 15:42:25 2019 +0100
+++ b/ChangeLog	Tue Mar 12 18:11:00 2019 +0100
@@ -1,3 +1,13 @@
+2019-03-12  Lars Herschke <lhersch@dssgmbh.de>
+
+	Hidden console on Windows
+	* rust-launcher/src/dirs_paths_helper.rs: factory for windows os now supply third parameter
+	* rust-launcher/src/main.rs: (get_os) on windows now have three params. Call to get os if-windows cfged out
+	(main) parent process is now checking ATTACH_PARENT_PROCESS before get_os on windows
+	* rust-launcher/src/os_access.rs: oon windows, without console, no window is enforced. Trait got win-only  inside_console method
+	windows impl of os_access. Win module made public to expose AttachConsole function.
+	* rust-launcher/src/utils.rs: test logger got windows-only inside_console
+
 2019-03-12  Jiri Vanek <jvanek@redhat.com>
 
 	Pre-release tuning
--- a/rust-launcher/src/dirs_paths_helper.rs	Tue Mar 12 15:42:25 2019 +0100
+++ b/rust-launcher/src/dirs_paths_helper.rs	Tue Mar 12 18:11:00 2019 +0100
@@ -108,7 +108,7 @@
 
     #[cfg(windows)]
     fn get_os() -> os_access::Windows {
-        os_access::Windows::new(false, false)
+        os_access::Windows::new(false, false, true)
     }
 
 
--- a/rust-launcher/src/main.rs	Tue Mar 12 15:42:25 2019 +0100
+++ b/rust-launcher/src/main.rs	Tue Mar 12 18:11:00 2019 +0100
@@ -1,3 +1,5 @@
+#![windows_subsystem = "windows"]
+
 mod hardcoded_paths;
 mod property_from_file;
 mod os_access;
@@ -19,8 +21,8 @@
 }
 
 #[cfg(windows)]
-fn get_os(debug: bool, al: bool) -> os_access::Windows {
-    os_access::Windows::new(debug, al)
+fn get_os(debug: bool, al: bool, ic: bool) -> os_access::Windows {
+    os_access::Windows::new(debug, al, ic)
 }
 
 fn is_debug_on() -> bool {
@@ -29,7 +31,10 @@
             return val;
         }
         _none => {
+            #[cfg(not(windows))]
             let os = get_os(false, false);
+            #[cfg(windows)]
+            let os = get_os(false, false, true);
             return property_from_files_resolver::try_main_verbose_from_properties(&os);
         }
     }
@@ -74,7 +79,18 @@
 }
 
 fn main() {
-    let os = get_os(is_debug_on(), true);
+    let os;
+    #[cfg(windows)]
+    {
+        use os_access::win;
+        let acr: i32;
+        unsafe { acr = win::AttachConsole(win::ATTACH_PARENT_PROCESS) };
+        os = get_os(is_debug_on(), true, acr != 0);
+    }
+    #[cfg(not(windows))]
+    {
+        os = get_os(is_debug_on(), true);
+    }
     os.log(&dirs_paths_helper::path_to_string(&dirs_paths_helper::current_program()));
     let java_dir = utils::find_jre(&os);
     let mut info2 = String::new();
--- a/rust-launcher/src/os_access.rs	Tue Mar 12 15:42:25 2019 +0100
+++ b/rust-launcher/src/os_access.rs	Tue Mar 12 18:11:00 2019 +0100
@@ -12,6 +12,13 @@
     for ar in args.into_iter() {
         cmd.arg(ar);
     }
+    #[cfg(windows)]
+    {
+        if !os.inside_console() {
+            use std::os::windows::process::CommandExt;
+            cmd.creation_flags(win::CREATE_NO_WINDOW);
+        }
+    }
     let mut info = String::new();
     write!(&mut info, "itw-rust-debug: command {}", format!("{:?}", cmd)).expect("unwrap failed");
     os.log(&info);
@@ -54,6 +61,8 @@
     fn get_classpath_separator(&self) -> char;
     fn get_exec_suffixes(&self) -> &'static [&'static str];
     fn is_verbose(&self) -> bool;
+    #[cfg(windows)]
+    fn inside_console(&self) -> bool;
 }
 
 #[cfg(not(windows))]
@@ -188,15 +197,16 @@
 pub struct Windows {
     verbose: bool,
     al: log_helper::AdvancedLogging,
+    ic: bool
 }
 
 #[cfg(windows)]
 impl Windows {
-        pub fn new(debug: bool, load_advanced: bool) -> Windows {
+        pub fn new(debug: bool, load_advanced: bool, ic: bool) -> Windows {
             if ! load_advanced {
-                Windows { verbose: debug, al: log_helper::AdvancedLogging::default() }
+                Windows { verbose: debug, al: log_helper::AdvancedLogging::default(), ic: ic }
             } else {
-                Windows { verbose: debug, al: log_helper::AdvancedLogging::load(&Windows::new(debug, false)) }
+                Windows { verbose: debug, al: log_helper::AdvancedLogging::load(&Windows::new(debug, false, ic)), ic: ic }
             }
         }
     }
@@ -226,6 +236,10 @@
         return self.verbose;
     }
 
+    fn inside_console(&self) -> bool {
+        return self.ic;
+    }
+
     fn get_registry_java(&self) -> Option<std::path::PathBuf> {
         std::panic::catch_unwind(|| {
             match win::java_registry_path() {
@@ -293,7 +307,7 @@
 #[cfg(windows)]
 #[allow(non_snake_case)]
 #[allow(non_camel_case_types)]
-mod win {
+pub mod win {
     // https://crates.io/crates/scopeguard
     macro_rules! defer {
         ($e:expr) => {
@@ -347,6 +361,8 @@
     use std::ptr::{null, null_mut};
 
     // constants
+    pub const ATTACH_PARENT_PROCESS: c_ulong = 0xFFFFFFFF;
+    pub const CREATE_NO_WINDOW: c_ulong = 0x08000000;
     const CP_UTF8: c_ulong = 65001;
     const FORMAT_MESSAGE_ALLOCATE_BUFFER: c_ulong = 0x00000100;
     const FORMAT_MESSAGE_FROM_SYSTEM: c_ulong = 0x00001000;
@@ -372,6 +388,8 @@
     // function declarations
 
     extern "system" {
+        pub fn AttachConsole(dwProcessId: c_ulong) -> c_int;
+        
         fn MultiByteToWideChar(
             CodePage: c_uint,
             dwFlags: c_ulong,
--- a/rust-launcher/src/utils.rs	Tue Mar 12 15:42:25 2019 +0100
+++ b/rust-launcher/src/utils.rs	Tue Mar 12 18:11:00 2019 +0100
@@ -241,6 +241,11 @@
             return true;
         }
 
+        #[cfg(windows)]
+        fn inside_console(&self) -> bool {
+            return true;
+        }
+
         fn log(&self, s: &str) {
             let ss = String::from(s);
             self.vec.borrow_mut().push(ss);