Fix bugs in sizing TableLayoutPanel (Xamarin bug 18638)
[mono.git] / mcs / class / System / System.Diagnostics / ProcessStartInfo.cs
1 //
2 // System.Diagnostics.ProcessStartInfo.cs
3 //
4 // Authors:
5 //   Dick Porter (dick@ximian.com)
6 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) 2002 Ximian, Inc.  http://www.ximian.com
9 //
10
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using Microsoft.Win32;
33 using System.Collections;
34 using System.Collections.Specialized;
35 using System.ComponentModel;
36 using System.IO;
37 using System.Security;
38 using System.Security.Permissions;
39 using System.Text;
40 using System.Runtime.InteropServices;
41
42 namespace System.Diagnostics 
43 {
44         [TypeConverter (typeof (ExpandableObjectConverter))]
45         [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
46         [StructLayout (LayoutKind.Sequential)]
47         public sealed class ProcessStartInfo 
48         {
49                 /* keep these fields in this order and in sync with metadata/process.h */
50                 private string arguments = "";
51                 private IntPtr error_dialog_parent_handle = (IntPtr)0;
52                 private string filename = "";
53                 private string verb = "";
54                 private string working_directory = "";
55                 private ProcessStringDictionary envVars;
56                 private bool create_no_window = false;
57                 private bool error_dialog = false;
58                 private bool redirect_standard_error = false;
59                 private bool redirect_standard_input = false;
60                 private bool redirect_standard_output = false;
61                 private bool use_shell_execute = true;
62                 private ProcessWindowStyle window_style = ProcessWindowStyle.Normal;
63                 private Encoding encoding_stderr, encoding_stdout;
64                 private string username, domain;
65                 private SecureString password;
66                 private bool load_user_profile;
67
68                 public ProcessStartInfo() 
69                 {
70                 }
71
72                 public ProcessStartInfo(string filename) 
73                 {
74                         this.filename = filename;
75                 }
76
77                 public ProcessStartInfo(string filename, string arguments) 
78                 {
79                         this.filename = filename;
80                         this.arguments = arguments;
81                 }
82
83                 [RecommendedAsConfigurable (true), DefaultValue ("")]
84                 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
85
86                 [MonitoringDescription ("Command line agruments for this process.")]
87                 [NotifyParentPropertyAttribute (true)]
88                 public string Arguments {
89                         get {
90                                 return(arguments);
91                         }
92                         set {
93                                 arguments = value;
94                         }
95                 }
96                 
97                 [DefaultValue (false)]
98                 [MonitoringDescription ("Start this process with a new window.")]
99                 [NotifyParentPropertyAttribute (true)]
100                 public bool CreateNoWindow {
101                         get {
102                                 return(create_no_window);
103                         }
104                         set {
105                                 create_no_window = value;
106                         }
107                 }
108
109                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content), DefaultValue (null)]
110                 [Editor ("System.Diagnostics.Design.StringDictionaryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
111                 [MonitoringDescription ("Environment variables used for this process.")]
112                 [NotifyParentPropertyAttribute (true)]
113                 public StringDictionary EnvironmentVariables {
114                         get {
115                                 if (envVars == null) {
116                                         envVars = new ProcessStringDictionary ();
117                                         foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables ())
118                                                 envVars.Add ((string) entry.Key, (string) entry.Value);
119                                 }
120
121                                 return envVars;
122                         }
123                 }
124                 
125                 internal bool HaveEnvVars {
126                         get { return (envVars != null); }
127                 }
128                 
129                 [DefaultValue (false)]
130                 [MonitoringDescription ("Thread shows dialogboxes for errors.")]
131                 [NotifyParentPropertyAttribute (true)]
132                 public bool ErrorDialog {
133                         get {
134                                 return(error_dialog);
135                         }
136                         set {
137                                 error_dialog = value;
138                         }
139                 }
140                 
141                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
142                 public IntPtr ErrorDialogParentHandle {
143                         get {
144                                 return(error_dialog_parent_handle);
145                         }
146                         set {
147                                 error_dialog_parent_handle = value;
148                         }
149                 }
150                 
151                 [RecommendedAsConfigurable (true), DefaultValue ("")]
152                 [Editor ("System.Diagnostics.Design.StartFileNameEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
153                 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
154                 [MonitoringDescription ("The name of the resource to start this process.")]
155                 [NotifyParentPropertyAttribute (true)]
156                 public string FileName {
157                         get {
158                                 return(filename);
159                         }
160                         set {
161                                 filename = value;
162                         }
163                 }
164                 
165                 [DefaultValue (false)]
166                 [MonitoringDescription ("Errors of this process are redirected.")]
167                 [NotifyParentPropertyAttribute (true)]
168                 public bool RedirectStandardError {
169                         get {
170                                 return(redirect_standard_error);
171                         }
172                         set {
173                                 redirect_standard_error = value;
174                         }
175                 }
176                 
177                 [DefaultValue (false)]
178                 [MonitoringDescription ("Standard input of this process is redirected.")]
179                 [NotifyParentPropertyAttribute (true)]
180                 public bool RedirectStandardInput {
181                         get {
182                                 return(redirect_standard_input);
183                         }
184                         set {
185                                 redirect_standard_input = value;
186                         }
187                 }
188                 
189                 [DefaultValue (false)]
190                 [MonitoringDescription ("Standart output of this process is redirected.")]
191                 [NotifyParentPropertyAttribute (true)]
192                 public bool RedirectStandardOutput {
193                         get {
194                                 return(redirect_standard_output);
195                         }
196                         set {
197                                 redirect_standard_output = value;
198                         }
199                 }
200                 
201                 public Encoding StandardErrorEncoding {
202                         get { return encoding_stderr; }
203                         set { encoding_stderr = value; }
204                 }
205
206                 public Encoding StandardOutputEncoding {
207                         get { return encoding_stdout; }
208                         set { encoding_stdout = value; }
209                 }
210                 
211                 [DefaultValue (true)]
212                 [MonitoringDescription ("Use the shell to start this process.")]
213                 [NotifyParentPropertyAttribute (true)]
214                 public bool UseShellExecute {
215                         get {
216                                 return(use_shell_execute);
217                         }
218                         set {
219                                 use_shell_execute = value;
220                         }
221                 }
222                 
223                 [DefaultValue ("")]
224                 [TypeConverter ("System.Diagnostics.Design.VerbConverter, " + Consts.AssemblySystem_Design)]
225                 [MonitoringDescription ("The verb to apply to a used document.")]
226                 [NotifyParentPropertyAttribute (true)]
227                 public string Verb {
228                         get {
229                                 return(verb);
230                         }
231                         set {
232                                 verb = value;
233                         }
234                 }
235
236                 static readonly string [] empty = new string [0];
237
238                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
239                 public string[] Verbs {
240                         get {
241                                 string ext = filename == null | filename.Length == 0 ? 
242                                         null : Path.GetExtension (filename);
243                                 if (ext == null)
244                                         return empty;
245
246 #if MOBILE
247                                 return empty;
248 #else
249
250                                 switch (Environment.OSVersion.Platform) {
251                                 case (PlatformID)4:
252                                 case (PlatformID)6:
253                                 case (PlatformID)128:
254                                         return empty; // no verb on non-Windows
255                                 default:
256                                         RegistryKey rk = null, rk2 = null, rk3 = null;
257                                         try {
258                                                 rk = Registry.ClassesRoot.OpenSubKey (ext);
259                                                 string k = rk != null ? rk.GetValue (null) as string : null;
260                                                 rk2 = k != null ? Registry.ClassesRoot.OpenSubKey (k) : null;
261                                                 rk3 = rk2 != null ? rk2.OpenSubKey ("shell") : null;
262                                                 return rk3 != null ? rk3.GetSubKeyNames () : null;
263                                         } finally {
264                                                 if (rk3 != null)
265                                                         rk3.Close ();
266                                                 if (rk2 != null)
267                                                         rk2.Close ();
268                                                 if (rk != null)
269                                                         rk.Close ();
270                                         }
271                                 }
272 #endif
273                         }
274                 }
275                 
276                 [DefaultValue (typeof (ProcessWindowStyle), "Normal")]
277                 [MonitoringDescription ("The window style used to start this process.")]
278                 [NotifyParentPropertyAttribute (true)]
279                 public ProcessWindowStyle WindowStyle {
280                         get {
281                                 return(window_style);
282                         }
283                         set {
284                                 window_style = value;
285                         }
286                 }
287                 
288                 [RecommendedAsConfigurable (true), DefaultValue ("")]
289                 [Editor ("System.Diagnostics.Design.WorkingDirectoryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
290                 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
291                 [MonitoringDescription ("The initial directory for this process.")]
292                 [NotifyParentPropertyAttribute (true)]
293                 public string WorkingDirectory {
294                         get {
295                                 return(working_directory);
296                         }
297                         set {
298                                 working_directory = value == null ? String.Empty : value;
299                         }
300                 }
301
302                 [NotifyParentPropertyAttribute (true)]
303                 public bool LoadUserProfile {
304                         get { return load_user_profile; }
305                         set { load_user_profile = value; }
306                 }
307
308                 [NotifyParentPropertyAttribute (true)]
309                 public string UserName {
310                         get { return username; }
311                         set { username = value; }
312                 }
313
314                 [NotifyParentPropertyAttribute (true)]
315                 public string Domain {
316                         get { return domain; }
317                         set { domain = value; }
318                 }
319
320                 public SecureString Password {
321                         get { return password; }
322                         set { password = value; }
323                 }
324         }
325 }