2010-07-08 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System / System.Diagnostics / ProcessStartInfo.cs
index dd790bfd391397d8fdadce032312e4a8d5fb77b7..41936f479e53b85b667046fffa0421e658abe8b5 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using Microsoft.Win32;
 using System.Collections;
 using System.Collections.Specialized;
 using System.ComponentModel;
+using System.IO;
+using System.Security;
 using System.Security.Permissions;
+using System.Text;
 
 namespace System.Diagnostics 
 {
@@ -40,20 +44,28 @@ namespace System.Diagnostics
        [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
        public sealed class ProcessStartInfo 
        {
-
+               /* keep these fields in this order and in sync with metadata/process.h */
                private string arguments = "";
-               private bool create_no_window = false;
-               private bool error_dialog = false;
                private IntPtr error_dialog_parent_handle = (IntPtr)0;
                private string filename = "";
+               private string verb = "";
+               private string working_directory = "";
+               private ProcessStringDictionary envVars;
+               private bool create_no_window = false;
+               private bool error_dialog = false;
                private bool redirect_standard_error = false;
                private bool redirect_standard_input = false;
                private bool redirect_standard_output = false;
                private bool use_shell_execute = true;
-               private string verb = "";
                private ProcessWindowStyle window_style = ProcessWindowStyle.Normal;
-               private string working_directory = "";
-               private ProcessStringDictionary envVars;
+               private Encoding encoding_stderr, encoding_stdout;
+               private string username, domain;
+#if NET_2_0
+               private SecureString password;
+#else
+               private object password; // dummy
+#endif
+               private bool load_user_profile;
 
                public ProcessStartInfo() 
                {
@@ -74,6 +86,9 @@ namespace System.Diagnostics
                [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
 
                [MonitoringDescription ("Command line agruments for this process.")]
+#if NET_2_0
+               [NotifyParentPropertyAttribute (true)]
+#endif
                public string Arguments {
                        get {
                                return(arguments);
@@ -85,6 +100,9 @@ namespace System.Diagnostics
                
                [DefaultValue (false)]
                [MonitoringDescription ("Start this process with a new window.")]
+#if NET_2_0
+               [NotifyParentPropertyAttribute (true)]
+#endif
                public bool CreateNoWindow {
                        get {
                                return(create_no_window);
@@ -94,10 +112,12 @@ namespace System.Diagnostics
                        }
                }
 
-               [MonoTODO("Need to read the env block somehow")]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Content), DefaultValue (null)]
                [Editor ("System.Diagnostics.Design.StringDictionaryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
                [MonitoringDescription ("Environment variables used for this process.")]
+#if NET_2_0
+               [NotifyParentPropertyAttribute (true)]
+#endif
                public StringDictionary EnvironmentVariables {
                        get {
                                if (envVars == null) {
@@ -111,11 +131,14 @@ namespace System.Diagnostics
                }
                
                internal bool HaveEnvVars {
-                       get { return (envVars != null && envVars.Count > 0); }
+                       get { return (envVars != null); }
                }
                
                [DefaultValue (false)]
                [MonitoringDescription ("Thread shows dialogboxes for errors.")]
+#if NET_2_0
+               [NotifyParentPropertyAttribute (true)]
+#endif
                public bool ErrorDialog {
                        get {
                                return(error_dialog);
@@ -139,6 +162,9 @@ namespace System.Diagnostics
                [Editor ("System.Diagnostics.Design.StartFileNameEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
                [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
                [MonitoringDescription ("The name of the resource to start this process.")]
+#if NET_2_0
+               [NotifyParentPropertyAttribute (true)]
+#endif
                public string FileName {
                        get {
                                return(filename);
@@ -150,6 +176,9 @@ namespace System.Diagnostics
                
                [DefaultValue (false)]
                [MonitoringDescription ("Errors of this process are redirected.")]
+#if NET_2_0
+               [NotifyParentPropertyAttribute (true)]
+#endif
                public bool RedirectStandardError {
                        get {
                                return(redirect_standard_error);
@@ -161,6 +190,9 @@ namespace System.Diagnostics
                
                [DefaultValue (false)]
                [MonitoringDescription ("Standard input of this process is redirected.")]
+#if NET_2_0
+               [NotifyParentPropertyAttribute (true)]
+#endif
                public bool RedirectStandardInput {
                        get {
                                return(redirect_standard_input);
@@ -172,6 +204,9 @@ namespace System.Diagnostics
                
                [DefaultValue (false)]
                [MonitoringDescription ("Standart output of this process is redirected.")]
+#if NET_2_0
+               [NotifyParentPropertyAttribute (true)]
+#endif
                public bool RedirectStandardOutput {
                        get {
                                return(redirect_standard_output);
@@ -181,8 +216,23 @@ namespace System.Diagnostics
                        }
                }
                
+#if NET_2_0
+               public Encoding StandardErrorEncoding {
+                       get { return encoding_stderr; }
+                       set { encoding_stderr = value; }
+               }
+
+               public Encoding StandardOutputEncoding {
+                       get { return encoding_stdout; }
+                       set { encoding_stdout = value; }
+               }
+#endif
+               
                [DefaultValue (true)]
                [MonitoringDescription ("Use the shell to start this process.")]
+#if NET_2_0
+               [NotifyParentPropertyAttribute (true)]
+#endif
                public bool UseShellExecute {
                        get {
                                return(use_shell_execute);
@@ -195,6 +245,9 @@ namespace System.Diagnostics
                [DefaultValue ("")]
                [TypeConverter ("System.Diagnostics.Design.VerbConverter, " + Consts.AssemblySystem_Design)]
                [MonitoringDescription ("The verb to apply to a used document.")]
+#if NET_2_0
+               [NotifyParentPropertyAttribute (true)]
+#endif
                public string Verb {
                        get {
                                return(verb);
@@ -204,16 +257,51 @@ namespace System.Diagnostics
                        }
                }
 
-               [MonoTODO]
+               static readonly string [] empty = new string [0];
+
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
                public string[] Verbs {
                        get {
-                               return(null);
+                               string ext = filename == null | filename.Length == 0 ? 
+                                       null : Path.GetExtension (filename);
+                               if (ext == null)
+                                       return empty;
+
+#if MONOTOUCH
+                               return empty;
+#else
+
+                               switch (Environment.OSVersion.Platform) {
+                               case (PlatformID)4:
+                               case (PlatformID)6:
+                               case (PlatformID)128:
+                                       return empty; // no verb on non-Windows
+                               default:
+                                       RegistryKey rk = null, rk2 = null, rk3 = null;
+                                       try {
+                                               rk = Registry.ClassesRoot.OpenSubKey (ext);
+                                               string k = rk != null ? rk.GetValue (null) as string : null;
+                                               rk2 = k != null ? Registry.ClassesRoot.OpenSubKey (k) : null;
+                                               rk3 = rk2 != null ? rk2.OpenSubKey ("shell") : null;
+                                               return rk3 != null ? rk3.GetSubKeyNames () : null;
+                                       } finally {
+                                               if (rk3 != null)
+                                                       rk3.Close ();
+                                               if (rk2 != null)
+                                                       rk2.Close ();
+                                               if (rk != null)
+                                                       rk.Close ();
+                                       }
+                               }
+#endif
                        }
                }
                
                [DefaultValue (typeof (ProcessWindowStyle), "Normal")]
                [MonitoringDescription ("The window style used to start this process.")]
+#if NET_2_0
+               [NotifyParentPropertyAttribute (true)]
+#endif
                public ProcessWindowStyle WindowStyle {
                        get {
                                return(window_style);
@@ -227,13 +315,41 @@ namespace System.Diagnostics
                [Editor ("System.Diagnostics.Design.WorkingDirectoryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
                [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
                [MonitoringDescription ("The initial directory for this process.")]
+#if NET_2_0
+               [NotifyParentPropertyAttribute (true)]
+#endif
                public string WorkingDirectory {
                        get {
                                return(working_directory);
                        }
                        set {
-                               working_directory = value;
+                               working_directory = value == null ? String.Empty : value;
                        }
                }
+
+#if NET_2_0
+               [NotifyParentPropertyAttribute (true)]
+               public bool LoadUserProfile {
+                       get { return load_user_profile; }
+                       set { load_user_profile = value; }
+               }
+
+               [NotifyParentPropertyAttribute (true)]
+               public string UserName {
+                       get { return username; }
+                       set { username = value; }
+               }
+
+               [NotifyParentPropertyAttribute (true)]
+               public string Domain {
+                       get { return domain; }
+                       set { domain = value; }
+               }
+
+               public SecureString Password {
+                       get { return password; }
+                       set { password = value; }
+               }
+#endif
        }
 }