merge r67228-r67235, r67237, r67251 and r67256-67259 to trunk (they are
[mono.git] / mcs / class / corlib / System / AppDomainSetup.cs
1 //
2 // System.AppDomainSetup.cs
3 //
4 // Authors:
5 //      Dietmar Maurer (dietmar@ximian.com)
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // (C) 2001 Ximian, Inc.  http://www.ximian.com
9 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.IO;
32 using System.Runtime.CompilerServices;
33 using System.Runtime.InteropServices;
34
35 #if NET_2_0
36 using System.Runtime.Hosting;
37 #endif
38
39 namespace System
40 {
41         [Serializable]
42         [ClassInterface (ClassInterfaceType.None)]
43         [MonoTODO ("Fix serialization compatibility with MS.NET")]
44 #if NET_2_0
45         [ComVisible (true)]
46 #endif
47         public sealed class AppDomainSetup : IAppDomainSetup
48         {
49                 string application_base;
50                 string application_name;
51                 string cache_path;
52                 string configuration_file;
53                 string dynamic_base;
54                 string license_file;
55                 string private_bin_path;
56                 string private_bin_path_probe;
57                 string shadow_copy_directories;
58                 string shadow_copy_files;
59                 bool publisher_policy;
60                 private bool path_changed;
61                 private LoaderOptimization loader_optimization;
62                 bool disallow_binding_redirects;
63                 bool disallow_code_downloads;
64 #if NET_2_0
65                 private ActivationArguments _activationArguments;
66 #endif
67
68                 public AppDomainSetup ()
69                 {
70                 }
71
72                 internal AppDomainSetup (AppDomainSetup setup)
73                 {
74                         application_base = setup.application_base;
75                         application_name = setup.application_name;
76                         cache_path = setup.cache_path;
77                         configuration_file = setup.configuration_file;
78                         dynamic_base = setup.dynamic_base;
79                         license_file = setup.license_file;
80                         private_bin_path = setup.private_bin_path;
81                         private_bin_path_probe = setup.private_bin_path_probe;
82                         shadow_copy_directories = setup.shadow_copy_directories;
83                         shadow_copy_files = setup.shadow_copy_files;
84                         publisher_policy = setup.publisher_policy;
85                         path_changed = setup.path_changed;
86                         loader_optimization = setup.loader_optimization;
87                         disallow_binding_redirects = setup.disallow_binding_redirects;
88                         disallow_code_downloads = setup.disallow_code_downloads;
89                 }
90
91 #if NET_2_0
92                 public AppDomainSetup (ActivationArguments activationArguments)
93                 {
94                         _activationArguments = activationArguments;
95                 }
96
97                 public AppDomainSetup (ActivationContext activationContext)
98                 {
99                         _activationArguments = new ActivationArguments (activationContext);
100                 }
101 #endif
102
103                 static string GetAppBase (string appBase)
104                 {
105                         if (appBase == null)
106                                 return null;
107
108                         int len = appBase.Length;
109                         if (len >= 8 && appBase.ToLower ().StartsWith ("file://")) {
110                                 appBase = appBase.Substring (7);
111                                 if (Path.DirectorySeparatorChar != '/')
112                                         appBase = appBase.Replace ('/', Path.DirectorySeparatorChar);
113                                 if (Environment.IsRunningOnWindows) {
114                                         // Under Windows prepend "//" to indicate it's a local file
115                                         appBase = "//" + appBase;
116                                 }
117 #if NET_2_0
118                         } else {
119 #else
120                         // under 1.x the ":" gets a special treatment - but it doesn't make sense outside Windows
121                         } else if (!Environment.IsRunningOnWindows || (appBase.IndexOf (':') == -1)) {
122 #endif
123                                 appBase = Path.GetFullPath (appBase);
124                         }
125
126                         return appBase;
127                 }
128                 
129                 public string ApplicationBase {
130                         get { return GetAppBase (application_base); }
131                         set { application_base = value; } 
132                 }
133
134                 public string ApplicationName {
135                         get {
136                                 return application_name;
137                         }
138                         set {
139                                 application_name = value;
140                         }
141                 }
142
143                 public string CachePath {
144                         get {
145                                 return cache_path;
146                         }
147                         set {
148                                 cache_path = value;
149                         }
150                 }
151
152                 public string ConfigurationFile {
153                         get {
154                                 return configuration_file;
155                         }
156                         set {
157                                 configuration_file = value;
158                         }
159                 }
160
161                 public bool DisallowPublisherPolicy {
162                         get {
163                                 return publisher_policy;
164                         }
165                         set {
166                                 publisher_policy = value;
167                         }
168                 }
169
170                 public string DynamicBase {
171                         get {
172                                 if (dynamic_base == null)
173                                         return null;
174
175                                 if (Path.IsPathRooted (dynamic_base))
176                                         return dynamic_base;
177
178                                 if (ApplicationBase == null)
179                                         throw new MemberAccessException ("The ApplicationBase must be set before retrieving this property.");
180                                 
181                                 return Path.Combine (ApplicationBase, dynamic_base);
182                         }
183                         set {
184                                 if (application_name == null)
185                                         throw new MemberAccessException ("ApplicationName must be set before the DynamicBase can be set.");
186                                 uint id = (uint) application_name.GetHashCode ();
187                                 dynamic_base = Path.Combine (value, id.ToString("x"));
188                         }
189                 }
190
191                 public string LicenseFile {
192                         get {
193                                 return license_file;
194                         }
195                         set {
196                                 license_file = value;
197                         }
198                 }
199
200                 [MonoTODO ("--share-code")]
201                 public LoaderOptimization LoaderOptimization {
202                         get {
203                                 return loader_optimization;
204                         }
205                         set {
206                                 loader_optimization = value;
207                         }
208                 }
209
210                 public string PrivateBinPath {
211                         get {
212                                 return private_bin_path;
213                         }
214                         set {
215                                 private_bin_path = value;
216                                 path_changed = true;
217                         }
218                 }
219
220                 public string PrivateBinPathProbe {
221                         get {
222                                 return private_bin_path_probe;
223                         }
224                         set {
225                                 private_bin_path_probe = value;
226                                 path_changed = true;
227                         }
228                 }
229
230                 public string ShadowCopyDirectories {
231                         get {
232                                 return shadow_copy_directories;
233                         }
234                         set {
235                                 shadow_copy_directories = value;
236                         }
237                 }
238
239                 public string ShadowCopyFiles {
240                         get {
241                                 return shadow_copy_files;
242                         }
243                         set {
244                                 shadow_copy_files = value;
245                         }
246                 }
247
248 #if NET_1_1
249                 public bool DisallowBindingRedirects {
250                         get {
251                                 return disallow_binding_redirects;
252                         }
253                         set {
254                                 disallow_binding_redirects = value;
255                         }
256                 }
257
258                 public bool DisallowCodeDownload {
259                         get {
260                                 return disallow_code_downloads;
261                         }
262                         set {
263                                 disallow_code_downloads = value;
264                         }
265                 }
266 #endif
267
268 #if NET_2_0
269                 public ActivationArguments ActivationArguments {
270                         get { return _activationArguments; }
271                         set { _activationArguments = value; }
272                 }
273 #endif
274         }
275 }