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