2006-11-27 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[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 System.Collections;
33 using System.Collections.Specialized;
34 using System.ComponentModel;
35 using System.Security.Permissions;
36
37 namespace System.Diagnostics 
38 {
39         [TypeConverter (typeof (ExpandableObjectConverter))]
40         [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
41         public sealed class ProcessStartInfo 
42         {
43
44                 private string arguments = "";
45                 private bool create_no_window = false;
46                 private bool error_dialog = false;
47                 private IntPtr error_dialog_parent_handle = (IntPtr)0;
48                 private string filename = "";
49                 private bool redirect_standard_error = false;
50                 private bool redirect_standard_input = false;
51                 private bool redirect_standard_output = false;
52                 private bool use_shell_execute = true;
53                 private string verb = "";
54                 private ProcessWindowStyle window_style = ProcessWindowStyle.Normal;
55                 private string working_directory = "";
56                 private ProcessStringDictionary envVars;
57
58                 public ProcessStartInfo() 
59                 {
60                 }
61
62                 public ProcessStartInfo(string filename) 
63                 {
64                         this.filename = filename;
65                 }
66
67                 public ProcessStartInfo(string filename, string arguments) 
68                 {
69                         this.filename = filename;
70                         this.arguments = arguments;
71                 }
72
73                 [RecommendedAsConfigurable (true), DefaultValue ("")]
74                 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
75
76                 [MonitoringDescription ("Command line agruments for this process.")]
77                 public string Arguments {
78                         get {
79                                 return(arguments);
80                         }
81                         set {
82                                 arguments = value;
83                         }
84                 }
85                 
86                 [DefaultValue (false)]
87                 [MonitoringDescription ("Start this process with a new window.")]
88                 public bool CreateNoWindow {
89                         get {
90                                 return(create_no_window);
91                         }
92                         set {
93                                 create_no_window = value;
94                         }
95                 }
96
97                 [MonoTODO("Need to read the env block somehow")]
98                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content), DefaultValue (null)]
99                 [Editor ("System.Diagnostics.Design.StringDictionaryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
100                 [MonitoringDescription ("Environment variables used for this process.")]
101                 public StringDictionary EnvironmentVariables {
102                         get {
103                                 if (envVars == null) {
104                                         envVars = new ProcessStringDictionary ();
105                                         foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables ())
106                                                 envVars.Add ((string) entry.Key, (string) entry.Value);
107                                 }
108
109                                 return envVars;
110                         }
111                 }
112                 
113                 internal bool HaveEnvVars {
114                         get { return (envVars != null && envVars.Count > 0); }
115                 }
116                 
117                 [DefaultValue (false)]
118                 [MonitoringDescription ("Thread shows dialogboxes for errors.")]
119                 public bool ErrorDialog {
120                         get {
121                                 return(error_dialog);
122                         }
123                         set {
124                                 error_dialog = value;
125                         }
126                 }
127                 
128                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
129                 public IntPtr ErrorDialogParentHandle {
130                         get {
131                                 return(error_dialog_parent_handle);
132                         }
133                         set {
134                                 error_dialog_parent_handle = value;
135                         }
136                 }
137                 
138                 [RecommendedAsConfigurable (true), DefaultValue ("")]
139                 [Editor ("System.Diagnostics.Design.StartFileNameEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
140                 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
141                 [MonitoringDescription ("The name of the resource to start this process.")]
142                 public string FileName {
143                         get {
144                                 return(filename);
145                         }
146                         set {
147                                 filename = value;
148                         }
149                 }
150                 
151                 [DefaultValue (false)]
152                 [MonitoringDescription ("Errors of this process are redirected.")]
153                 public bool RedirectStandardError {
154                         get {
155                                 return(redirect_standard_error);
156                         }
157                         set {
158                                 redirect_standard_error = value;
159                         }
160                 }
161                 
162                 [DefaultValue (false)]
163                 [MonitoringDescription ("Standard input of this process is redirected.")]
164                 public bool RedirectStandardInput {
165                         get {
166                                 return(redirect_standard_input);
167                         }
168                         set {
169                                 redirect_standard_input = value;
170                         }
171                 }
172                 
173                 [DefaultValue (false)]
174                 [MonitoringDescription ("Standart output of this process is redirected.")]
175                 public bool RedirectStandardOutput {
176                         get {
177                                 return(redirect_standard_output);
178                         }
179                         set {
180                                 redirect_standard_output = value;
181                         }
182                 }
183                 
184                 [DefaultValue (true)]
185                 [MonitoringDescription ("Use the shell to start this process.")]
186                 public bool UseShellExecute {
187                         get {
188                                 return(use_shell_execute);
189                         }
190                         set {
191                                 use_shell_execute = value;
192                         }
193                 }
194                 
195                 [DefaultValue ("")]
196                 [TypeConverter ("System.Diagnostics.Design.VerbConverter, " + Consts.AssemblySystem_Design)]
197                 [MonitoringDescription ("The verb to apply to a used document.")]
198                 public string Verb {
199                         get {
200                                 return(verb);
201                         }
202                         set {
203                                 verb = value;
204                         }
205                 }
206
207                 [MonoTODO]
208                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
209                 public string[] Verbs {
210                         get {
211                                 return(null);
212                         }
213                 }
214                 
215                 [DefaultValue (typeof (ProcessWindowStyle), "Normal")]
216                 [MonitoringDescription ("The window style used to start this process.")]
217                 public ProcessWindowStyle WindowStyle {
218                         get {
219                                 return(window_style);
220                         }
221                         set {
222                                 window_style = value;
223                         }
224                 }
225                 
226                 [RecommendedAsConfigurable (true), DefaultValue ("")]
227                 [Editor ("System.Diagnostics.Design.WorkingDirectoryEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
228                 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
229                 [MonitoringDescription ("The initial directory for this process.")]
230                 public string WorkingDirectory {
231                         get {
232                                 return(working_directory);
233                         }
234                         set {
235                                 working_directory = value;
236                         }
237                 }
238         }
239 }