66 |
|
//path = builder.ToString(); |
67 |
|
//this.ConfigFilePath = path; |
68 |
|
|
69 |
< |
//var t = ClientConfigPaths.GetPaths(; |
69 |
> |
ClientConfigPaths t = new ClientConfigPaths(this.AssemblyInfo, true); |
70 |
|
|
71 |
|
|
72 |
|
} |
115 |
|
|
116 |
|
[FileIOPermission(SecurityAction.Assert, AllFiles = FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read)] |
117 |
|
[SecurityPermission(SecurityAction.Assert, UnmanagedCode = true)] |
118 |
< |
public ClientConfigPaths(string exePath, bool includeUserConfig) |
118 |
> |
public ClientConfigPaths(Assembly assembly, bool includeUserConfig) |
119 |
|
{ |
120 |
|
|
121 |
< |
_includesUserConfig = includeUserConfig; |
121 |
> |
//_includesUserConfig = includeUserConfig; |
122 |
|
|
123 |
< |
Assembly exeAssembly = null; |
124 |
< |
string applicationUri = null; |
125 |
< |
string applicationFilename = null; |
126 |
< |
|
127 |
< |
// get the assembly and applicationUri for the file |
128 |
< |
if (exePath == null) |
129 |
< |
{ |
130 |
< |
// First check if a configuration file has been set for this app domain. If so, we will use that. |
131 |
< |
// The CLR would already have normalized this, so no further processing necessary. |
132 |
< |
AppDomain domain = AppDomain.CurrentDomain; |
133 |
< |
AppDomainSetup setup = domain.SetupInformation; |
134 |
< |
_applicationConfigUri = setup.ConfigurationFile; |
135 |
< |
|
136 |
< |
// Now figure out the application path. |
137 |
< |
exeAssembly = Assembly.GetEntryAssembly(); |
138 |
< |
if (exeAssembly != null) |
139 |
< |
{ |
140 |
< |
_hasEntryAssembly = true; |
141 |
< |
applicationUri = exeAssembly.CodeBase; |
142 |
< |
|
143 |
< |
bool isFile = false; |
144 |
< |
|
145 |
< |
// If it is a local file URI, convert it to its filename, without invoking Uri class. |
146 |
< |
// example: "file:///C:/WINNT/Microsoft.NET/Framework/v2.0.x86fre/csc.exe" |
147 |
< |
if (StringUtil.StartsWithIgnoreCase(applicationUri, FILE_URI_LOCAL)) |
148 |
< |
{ |
149 |
< |
isFile = true; |
150 |
< |
applicationUri = applicationUri.Substring(FILE_URI_LOCAL.Length); |
151 |
< |
} |
152 |
< |
// If it is a UNC file URI, convert it to its filename, without invoking Uri class. |
153 |
< |
// example: "file://server/share/csc.exe" |
154 |
< |
else if (StringUtil.StartsWithIgnoreCase(applicationUri, FILE_URI_UNC)) |
155 |
< |
{ |
156 |
< |
isFile = true; |
157 |
< |
applicationUri = applicationUri.Substring(FILE_URI.Length); |
158 |
< |
} |
159 |
< |
|
160 |
< |
if (isFile) |
161 |
< |
{ |
162 |
< |
applicationUri = applicationUri.Replace('/', '\\'); |
163 |
< |
applicationFilename = applicationUri; |
164 |
< |
} |
165 |
< |
else |
166 |
< |
{ |
167 |
< |
applicationUri = exeAssembly.EscapedCodeBase; |
168 |
< |
} |
169 |
< |
} |
170 |
< |
else |
171 |
< |
{ |
172 |
< |
StringBuilder sb = new StringBuilder(MAX_PATH); |
173 |
< |
UnsafeNativeMethods.GetModuleFileName(new HandleRef(null, IntPtr.Zero), sb, sb.Capacity); |
174 |
< |
applicationUri = Path.GetFullPath(sb.ToString()); |
175 |
< |
applicationFilename = applicationUri; |
176 |
< |
} |
177 |
< |
} |
178 |
< |
else |
179 |
< |
{ |
180 |
< |
applicationUri = Path.GetFullPath(exePath); |
181 |
< |
if (!FileUtil.FileExists(applicationUri, false)) |
182 |
< |
throw ExceptionUtil.ParameterInvalid("exePath"); |
183 |
< |
|
184 |
< |
applicationFilename = applicationUri; |
185 |
< |
} |
186 |
< |
|
187 |
< |
// Fallback if we haven't set the app config file path yet. |
188 |
< |
if (_applicationConfigUri == null) |
189 |
< |
{ |
190 |
< |
_applicationConfigUri = applicationUri + ConfigExtension; |
191 |
< |
} |
192 |
< |
|
193 |
< |
// Set application path |
194 |
< |
_applicationUri = applicationUri; |
195 |
< |
|
196 |
< |
// In the case when exePath was explicitly supplied, we will not be able to |
197 |
< |
// construct user.config paths, so quit here. |
198 |
< |
if (exePath != null) |
199 |
< |
{ |
200 |
< |
return; |
201 |
< |
} |
202 |
< |
|
203 |
< |
// Skip expensive initialization of user config file information if requested. |
204 |
< |
if (!_includesUserConfig) |
205 |
< |
{ |
206 |
< |
return; |
207 |
< |
} |
208 |
< |
|
209 |
< |
bool isHttp = StringUtil.StartsWithIgnoreCase(_applicationConfigUri, HTTP_URI); |
210 |
< |
|
211 |
< |
SetNamesAndVersion(applicationFilename, exeAssembly, isHttp); |
212 |
< |
|
213 |
< |
// Check if this is a clickonce deployed application. If so, point the user config |
214 |
< |
// files to the clickonce data directory. |
215 |
< |
if (this.IsClickOnceDeployed(AppDomain.CurrentDomain)) |
216 |
< |
{ |
217 |
< |
string dataPath = AppDomain.CurrentDomain.GetData(ClickOnceDataDirectory) as string; |
218 |
< |
string versionSuffix = Validate(_productVersion, false); |
219 |
< |
|
220 |
< |
// NOTE: No roaming config for clickonce - not supported. |
221 |
< |
if (Path.IsPathRooted(dataPath)) |
222 |
< |
{ |
223 |
< |
_localConfigDirectory = CombineIfValid(dataPath, versionSuffix); |
224 |
< |
_localConfigFilename = CombineIfValid(_localConfigDirectory, UserConfigFilename); |
225 |
< |
} |
226 |
< |
|
227 |
< |
} |
228 |
< |
else if (!isHttp) |
229 |
< |
{ |
123 |
> |
Assembly exeAssembly = assembly; |
124 |
> |
//string applicationUri = null; |
125 |
> |
//string applicationFilename = null; |
126 |
> |
|
127 |
> |
//// get the assembly and applicationUri for the file |
128 |
> |
//if (exePath == null) |
129 |
> |
//{ |
130 |
> |
// // First check if a configuration file has been set for this app domain. If so, we will use that. |
131 |
> |
// // The CLR would already have normalized this, so no further processing necessary. |
132 |
> |
// //AppDomain domain = AppDomain.CurrentDomain; |
133 |
> |
// //AppDomainSetup setup = domain.SetupInformation; |
134 |
> |
// //_applicationConfigUri = setup.ConfigurationFile; |
135 |
> |
|
136 |
> |
// // Now figure out the application path. |
137 |
> |
// exeAssembly = Assembly.GetEntryAssembly(); |
138 |
> |
// if (exeAssembly != null) |
139 |
> |
// { |
140 |
> |
// _hasEntryAssembly = true; |
141 |
> |
// applicationUri = exeAssembly.CodeBase; |
142 |
> |
|
143 |
> |
// bool isFile = false; |
144 |
> |
|
145 |
> |
// // If it is a local file URI, convert it to its filename, without invoking Uri class. |
146 |
> |
// // example: "file:///C:/WINNT/Microsoft.NET/Framework/v2.0.x86fre/csc.exe" |
147 |
> |
// if (StringUtil.StartsWithIgnoreCase(applicationUri, FILE_URI_LOCAL)) |
148 |
> |
// { |
149 |
> |
// isFile = true; |
150 |
> |
// applicationUri = applicationUri.Substring(FILE_URI_LOCAL.Length); |
151 |
> |
// } |
152 |
> |
// // If it is a UNC file URI, convert it to its filename, without invoking Uri class. |
153 |
> |
// // example: "file://server/share/csc.exe" |
154 |
> |
// else if (StringUtil.StartsWithIgnoreCase(applicationUri, FILE_URI_UNC)) |
155 |
> |
// { |
156 |
> |
// isFile = true; |
157 |
> |
// applicationUri = applicationUri.Substring(FILE_URI.Length); |
158 |
> |
// } |
159 |
> |
|
160 |
> |
// if (isFile) |
161 |
> |
// { |
162 |
> |
// applicationUri = applicationUri.Replace('/', '\\'); |
163 |
> |
// applicationFilename = applicationUri; |
164 |
> |
// } |
165 |
> |
// else |
166 |
> |
// { |
167 |
> |
// applicationUri = exeAssembly.EscapedCodeBase; |
168 |
> |
// } |
169 |
> |
// } |
170 |
> |
// else |
171 |
> |
// { |
172 |
> |
// StringBuilder sb = new StringBuilder(MAX_PATH); |
173 |
> |
// UnsafeNativeMethods.GetModuleFileName(new HandleRef(null, IntPtr.Zero), sb, sb.Capacity); |
174 |
> |
// applicationUri = Path.GetFullPath(sb.ToString()); |
175 |
> |
// applicationFilename = applicationUri; |
176 |
> |
// } |
177 |
> |
//} |
178 |
> |
////else |
179 |
> |
////{ |
180 |
> |
//// applicationUri = Path.GetFullPath(exePath); |
181 |
> |
//// if (!FileUtil.FileExists(applicationUri, false)) |
182 |
> |
//// throw ExceptionUtil.ParameterInvalid("exePath"); |
183 |
> |
|
184 |
> |
//// applicationFilename = applicationUri; |
185 |
> |
////} |
186 |
> |
|
187 |
> |
//// Fallback if we haven't set the app config file path yet. |
188 |
> |
//if (_applicationConfigUri == null) |
189 |
> |
//{ |
190 |
> |
// _applicationConfigUri = applicationUri + ConfigExtension; |
191 |
> |
//} |
192 |
> |
|
193 |
> |
//// Set application path |
194 |
> |
//_applicationUri = applicationUri; |
195 |
> |
|
196 |
> |
//// In the case when exePath was explicitly supplied, we will not be able to |
197 |
> |
//// construct user.config paths, so quit here. |
198 |
> |
//if (exePath != null) |
199 |
> |
//{ |
200 |
> |
// return; |
201 |
> |
//} |
202 |
> |
|
203 |
> |
//// Skip expensive initialization of user config file information if requested. |
204 |
> |
//if (!_includesUserConfig) |
205 |
> |
//{ |
206 |
> |
// return; |
207 |
> |
//} |
208 |
> |
|
209 |
> |
////bool isHttp = StringUtil.StartsWithIgnoreCase(_applicationConfigUri, HTTP_URI); |
210 |
> |
|
211 |
> |
//SetNamesAndVersion(applicationFilename, exeAssembly, false); |
212 |
> |
SetNamesAndVersion(exeAssembly, false); |
213 |
> |
|
214 |
> |
//// Check if this is a clickonce deployed application. If so, point the user config |
215 |
> |
//// files to the clickonce data directory. |
216 |
> |
//if (this.IsClickOnceDeployed(AppDomain.CurrentDomain)) |
217 |
> |
//{ |
218 |
> |
// string dataPath = AppDomain.CurrentDomain.GetData(ClickOnceDataDirectory) as string; |
219 |
> |
// string versionSuffix = Validate(_productVersion, false); |
220 |
> |
|
221 |
> |
// // NOTE: No roaming config for clickonce - not supported. |
222 |
> |
// if (Path.IsPathRooted(dataPath)) |
223 |
> |
// { |
224 |
> |
// _localConfigDirectory = CombineIfValid(dataPath, versionSuffix); |
225 |
> |
// _localConfigFilename = CombineIfValid(_localConfigDirectory, UserConfigFilename); |
226 |
> |
// } |
227 |
> |
|
228 |
> |
//} |
229 |
> |
//else if (!isHttp) |
230 |
> |
//{ |
231 |
|
// If we get the config from http, we do not have a roaming or local config directory, |
232 |
|
// as it cannot be edited by the app in those cases because it does not have Full Trust. |
233 |
|
|
235 |
|
|
236 |
|
string part1 = Validate(_companyName, true); |
237 |
|
|
238 |
< |
string validAppDomainName = Validate(AppDomain.CurrentDomain.FriendlyName, true); |
238 |
> |
//string validAppDomainName = Validate(AppDomain.CurrentDomain.FriendlyName, true); |
239 |
> |
string friendlyName = new FileInfo(exeAssembly.Location).Name; |
240 |
> |
string validAppDomainName = Validate(friendlyName, true); |
241 |
|
string applicationUriLower = !String.IsNullOrEmpty(_applicationUri) ? _applicationUri.ToLower(CultureInfo.InvariantCulture) : null; |
242 |
|
string namePrefix = !String.IsNullOrEmpty(validAppDomainName) ? validAppDomainName : Validate(_productName, true); |
243 |
< |
string hashSuffix = GetTypeAndHashSuffix(AppDomain.CurrentDomain, applicationUriLower); |
243 |
> |
//string hashSuffix = GetTypeAndHashSuffix(AppDomain.CurrentDomain, applicationUriLower); |
244 |
> |
string hashSuffix = GetTypeAndHashSuffix(exeAssembly, applicationUriLower); |
245 |
|
|
246 |
|
string part2 = (!String.IsNullOrEmpty(namePrefix) && !String.IsNullOrEmpty(hashSuffix)) ? namePrefix + hashSuffix : null; |
247 |
|
|
262 |
|
_localConfigDirectory = CombineIfValid(localFolderPath, dirSuffix); |
263 |
|
_localConfigFilename = CombineIfValid(_localConfigDirectory, UserConfigFilename); |
264 |
|
} |
265 |
< |
} |
265 |
> |
//} |
266 |
|
} |
267 |
|
|
268 |
< |
internal static ClientConfigPaths GetPaths(string exePath, bool includeUserConfig) |
269 |
< |
{ |
270 |
< |
ClientConfigPaths result = null; |
271 |
< |
|
272 |
< |
if (exePath == null) |
273 |
< |
{ |
274 |
< |
if (s_current == null || (includeUserConfig && !s_currentIncludesUserConfig)) |
275 |
< |
{ |
276 |
< |
s_current = new ClientConfigPaths(null, includeUserConfig); |
277 |
< |
s_currentIncludesUserConfig = includeUserConfig; |
278 |
< |
} |
279 |
< |
|
280 |
< |
result = s_current; |
281 |
< |
} |
282 |
< |
else |
283 |
< |
{ |
284 |
< |
result = new ClientConfigPaths(exePath, includeUserConfig); |
285 |
< |
} |
268 |
> |
//internal static ClientConfigPaths GetPaths(string exePath, bool includeUserConfig) |
269 |
> |
//{ |
270 |
> |
// ClientConfigPaths result = null; |
271 |
> |
|
272 |
> |
// if (exePath == null) |
273 |
> |
// { |
274 |
> |
// if (s_current == null || (includeUserConfig && !s_currentIncludesUserConfig)) |
275 |
> |
// { |
276 |
> |
// s_current = new ClientConfigPaths(null, includeUserConfig); |
277 |
> |
// s_currentIncludesUserConfig = includeUserConfig; |
278 |
> |
// } |
279 |
> |
|
280 |
> |
// result = s_current; |
281 |
> |
// } |
282 |
> |
// else |
283 |
> |
// { |
284 |
> |
// result = new ClientConfigPaths(exePath, includeUserConfig); |
285 |
> |
// } |
286 |
|
|
287 |
< |
return result; |
288 |
< |
} |
287 |
> |
// return result; |
288 |
> |
//} |
289 |
|
|
290 |
|
internal static void RefreshCurrent() |
291 |
|
{ |
293 |
|
s_current = null; |
294 |
|
} |
295 |
|
|
296 |
< |
internal static ClientConfigPaths Current |
297 |
< |
{ |
298 |
< |
get |
299 |
< |
{ |
300 |
< |
return GetPaths(null, true); |
301 |
< |
} |
302 |
< |
} |
296 |
> |
//internal static ClientConfigPaths Current |
297 |
> |
//{ |
298 |
> |
// get |
299 |
> |
// { |
300 |
> |
// return GetPaths(null, true); |
301 |
> |
// } |
302 |
> |
//} |
303 |
|
|
304 |
|
internal bool HasEntryAssembly |
305 |
|
{ |
441 |
|
// Returns a type and hash suffix based on app domain evidence. The evidence we use, in |
442 |
|
// priority order, is Strong Name, Url and Exe Path. If one of these is found, we compute a |
443 |
|
// SHA1 hash of it and return a suffix based on that. If none is found, we return null. |
444 |
< |
private string GetTypeAndHashSuffix(AppDomain appDomain, string exePath) |
444 |
> |
//private string GetTypeAndHashSuffix(AppDomain appDomain, string exePath) |
445 |
> |
private string GetTypeAndHashSuffix(Assembly appDomain, string exePath) |
446 |
|
{ |
447 |
|
string suffix = null; |
448 |
|
string typeName = null; |
469 |
|
} |
470 |
|
|
471 |
|
// Mostly borrowed from IsolatedStorage, with some modifications |
472 |
< |
private static object GetEvidenceInfo(AppDomain appDomain, string exePath, out string typeName) |
472 |
> |
//private static object GetEvidenceInfo(AppDomain appDomain, string exePath, out string typeName) |
473 |
> |
private static object GetEvidenceInfo(Assembly appDomain, string exePath, out string typeName) |
474 |
|
{ |
475 |
|
ControlEvidencePermission.Assert(); |
476 |
|
Evidence evidence = appDomain.Evidence; |
563 |
|
return new StrongName(sn.PublicKey, sn.Name, new Version(0, 0, 0, 0)); |
564 |
|
} |
565 |
|
|
566 |
< |
private void SetNamesAndVersion(string applicationFilename, Assembly exeAssembly, bool isHttp) |
566 |
> |
//private void SetNamesAndVersion(string applicationFilename, Assembly exeAssembly, bool isHttp) |
567 |
> |
private void SetNamesAndVersion(Assembly exeAssembly, bool isHttp) |
568 |
|
{ |
569 |
|
Type mainType = null; |
570 |
|
|
621 |
|
} |
622 |
|
} |
623 |
|
|
624 |
< |
if (versionInfoFileName == null) |
625 |
< |
{ |
626 |
< |
versionInfoFileName = applicationFilename; |
627 |
< |
} |
624 |
> |
//if (versionInfoFileName == null) |
625 |
> |
//{ |
626 |
> |
// versionInfoFileName = applicationFilename; |
627 |
> |
//} |
628 |
|
|
629 |
|
if (versionInfoFileName != null) |
630 |
|
{ |