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