--- trunk/RomCheater.UserSettingsSupport/IsolatedStoragePath.cs 2013/06/18 19:18:05 722 +++ trunk/RomCheater.UserSettingsSupport/IsolatedStoragePath.cs 2013/06/18 19:32:24 723 @@ -66,7 +66,7 @@ namespace RomCheater.UserSettingsSupport //path = builder.ToString(); //this.ConfigFilePath = path; - //var t = ClientConfigPaths.GetPaths(; + ClientConfigPaths t = new ClientConfigPaths(this.AssemblyInfo, true); } @@ -115,118 +115,119 @@ namespace RomCheater.UserSettingsSupport [FileIOPermission(SecurityAction.Assert, AllFiles = FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read)] [SecurityPermission(SecurityAction.Assert, UnmanagedCode = true)] - public ClientConfigPaths(string exePath, bool includeUserConfig) + public ClientConfigPaths(Assembly assembly, bool includeUserConfig) { - _includesUserConfig = includeUserConfig; + //_includesUserConfig = includeUserConfig; - Assembly exeAssembly = null; - string applicationUri = null; - string applicationFilename = null; - - // get the assembly and applicationUri for the file - if (exePath == null) - { - // First check if a configuration file has been set for this app domain. If so, we will use that. - // The CLR would already have normalized this, so no further processing necessary. - AppDomain domain = AppDomain.CurrentDomain; - AppDomainSetup setup = domain.SetupInformation; - _applicationConfigUri = setup.ConfigurationFile; - - // Now figure out the application path. - exeAssembly = Assembly.GetEntryAssembly(); - if (exeAssembly != null) - { - _hasEntryAssembly = true; - applicationUri = exeAssembly.CodeBase; - - bool isFile = false; - - // If it is a local file URI, convert it to its filename, without invoking Uri class. - // example: "file:///C:/WINNT/Microsoft.NET/Framework/v2.0.x86fre/csc.exe" - if (StringUtil.StartsWithIgnoreCase(applicationUri, FILE_URI_LOCAL)) - { - isFile = true; - applicationUri = applicationUri.Substring(FILE_URI_LOCAL.Length); - } - // If it is a UNC file URI, convert it to its filename, without invoking Uri class. - // example: "file://server/share/csc.exe" - else if (StringUtil.StartsWithIgnoreCase(applicationUri, FILE_URI_UNC)) - { - isFile = true; - applicationUri = applicationUri.Substring(FILE_URI.Length); - } - - if (isFile) - { - applicationUri = applicationUri.Replace('/', '\\'); - applicationFilename = applicationUri; - } - else - { - applicationUri = exeAssembly.EscapedCodeBase; - } - } - else - { - StringBuilder sb = new StringBuilder(MAX_PATH); - UnsafeNativeMethods.GetModuleFileName(new HandleRef(null, IntPtr.Zero), sb, sb.Capacity); - applicationUri = Path.GetFullPath(sb.ToString()); - applicationFilename = applicationUri; - } - } - else - { - applicationUri = Path.GetFullPath(exePath); - if (!FileUtil.FileExists(applicationUri, false)) - throw ExceptionUtil.ParameterInvalid("exePath"); - - applicationFilename = applicationUri; - } - - // Fallback if we haven't set the app config file path yet. - if (_applicationConfigUri == null) - { - _applicationConfigUri = applicationUri + ConfigExtension; - } - - // Set application path - _applicationUri = applicationUri; - - // In the case when exePath was explicitly supplied, we will not be able to - // construct user.config paths, so quit here. - if (exePath != null) - { - return; - } - - // Skip expensive initialization of user config file information if requested. - if (!_includesUserConfig) - { - return; - } - - bool isHttp = StringUtil.StartsWithIgnoreCase(_applicationConfigUri, HTTP_URI); - - SetNamesAndVersion(applicationFilename, exeAssembly, isHttp); - - // Check if this is a clickonce deployed application. If so, point the user config - // files to the clickonce data directory. - if (this.IsClickOnceDeployed(AppDomain.CurrentDomain)) - { - string dataPath = AppDomain.CurrentDomain.GetData(ClickOnceDataDirectory) as string; - string versionSuffix = Validate(_productVersion, false); - - // NOTE: No roaming config for clickonce - not supported. - if (Path.IsPathRooted(dataPath)) - { - _localConfigDirectory = CombineIfValid(dataPath, versionSuffix); - _localConfigFilename = CombineIfValid(_localConfigDirectory, UserConfigFilename); - } - - } - else if (!isHttp) - { + Assembly exeAssembly = assembly; + //string applicationUri = null; + //string applicationFilename = null; + + //// get the assembly and applicationUri for the file + //if (exePath == null) + //{ + // // First check if a configuration file has been set for this app domain. If so, we will use that. + // // The CLR would already have normalized this, so no further processing necessary. + // //AppDomain domain = AppDomain.CurrentDomain; + // //AppDomainSetup setup = domain.SetupInformation; + // //_applicationConfigUri = setup.ConfigurationFile; + + // // Now figure out the application path. + // exeAssembly = Assembly.GetEntryAssembly(); + // if (exeAssembly != null) + // { + // _hasEntryAssembly = true; + // applicationUri = exeAssembly.CodeBase; + + // bool isFile = false; + + // // If it is a local file URI, convert it to its filename, without invoking Uri class. + // // example: "file:///C:/WINNT/Microsoft.NET/Framework/v2.0.x86fre/csc.exe" + // if (StringUtil.StartsWithIgnoreCase(applicationUri, FILE_URI_LOCAL)) + // { + // isFile = true; + // applicationUri = applicationUri.Substring(FILE_URI_LOCAL.Length); + // } + // // If it is a UNC file URI, convert it to its filename, without invoking Uri class. + // // example: "file://server/share/csc.exe" + // else if (StringUtil.StartsWithIgnoreCase(applicationUri, FILE_URI_UNC)) + // { + // isFile = true; + // applicationUri = applicationUri.Substring(FILE_URI.Length); + // } + + // if (isFile) + // { + // applicationUri = applicationUri.Replace('/', '\\'); + // applicationFilename = applicationUri; + // } + // else + // { + // applicationUri = exeAssembly.EscapedCodeBase; + // } + // } + // else + // { + // StringBuilder sb = new StringBuilder(MAX_PATH); + // UnsafeNativeMethods.GetModuleFileName(new HandleRef(null, IntPtr.Zero), sb, sb.Capacity); + // applicationUri = Path.GetFullPath(sb.ToString()); + // applicationFilename = applicationUri; + // } + //} + ////else + ////{ + //// applicationUri = Path.GetFullPath(exePath); + //// if (!FileUtil.FileExists(applicationUri, false)) + //// throw ExceptionUtil.ParameterInvalid("exePath"); + + //// applicationFilename = applicationUri; + ////} + + //// Fallback if we haven't set the app config file path yet. + //if (_applicationConfigUri == null) + //{ + // _applicationConfigUri = applicationUri + ConfigExtension; + //} + + //// Set application path + //_applicationUri = applicationUri; + + //// In the case when exePath was explicitly supplied, we will not be able to + //// construct user.config paths, so quit here. + //if (exePath != null) + //{ + // return; + //} + + //// Skip expensive initialization of user config file information if requested. + //if (!_includesUserConfig) + //{ + // return; + //} + + ////bool isHttp = StringUtil.StartsWithIgnoreCase(_applicationConfigUri, HTTP_URI); + + //SetNamesAndVersion(applicationFilename, exeAssembly, false); + SetNamesAndVersion(exeAssembly, false); + + //// Check if this is a clickonce deployed application. If so, point the user config + //// files to the clickonce data directory. + //if (this.IsClickOnceDeployed(AppDomain.CurrentDomain)) + //{ + // string dataPath = AppDomain.CurrentDomain.GetData(ClickOnceDataDirectory) as string; + // string versionSuffix = Validate(_productVersion, false); + + // // NOTE: No roaming config for clickonce - not supported. + // if (Path.IsPathRooted(dataPath)) + // { + // _localConfigDirectory = CombineIfValid(dataPath, versionSuffix); + // _localConfigFilename = CombineIfValid(_localConfigDirectory, UserConfigFilename); + // } + + //} + //else if (!isHttp) + //{ // If we get the config from http, we do not have a roaming or local config directory, // as it cannot be edited by the app in those cases because it does not have Full Trust. @@ -234,10 +235,13 @@ namespace RomCheater.UserSettingsSupport string part1 = Validate(_companyName, true); - string validAppDomainName = Validate(AppDomain.CurrentDomain.FriendlyName, true); + //string validAppDomainName = Validate(AppDomain.CurrentDomain.FriendlyName, true); + string friendlyName = new FileInfo(exeAssembly.Location).Name; + string validAppDomainName = Validate(friendlyName, true); string applicationUriLower = !String.IsNullOrEmpty(_applicationUri) ? _applicationUri.ToLower(CultureInfo.InvariantCulture) : null; string namePrefix = !String.IsNullOrEmpty(validAppDomainName) ? validAppDomainName : Validate(_productName, true); - string hashSuffix = GetTypeAndHashSuffix(AppDomain.CurrentDomain, applicationUriLower); + //string hashSuffix = GetTypeAndHashSuffix(AppDomain.CurrentDomain, applicationUriLower); + string hashSuffix = GetTypeAndHashSuffix(exeAssembly, applicationUriLower); string part2 = (!String.IsNullOrEmpty(namePrefix) && !String.IsNullOrEmpty(hashSuffix)) ? namePrefix + hashSuffix : null; @@ -258,30 +262,30 @@ namespace RomCheater.UserSettingsSupport _localConfigDirectory = CombineIfValid(localFolderPath, dirSuffix); _localConfigFilename = CombineIfValid(_localConfigDirectory, UserConfigFilename); } - } + //} } - internal static ClientConfigPaths GetPaths(string exePath, bool includeUserConfig) - { - ClientConfigPaths result = null; - - if (exePath == null) - { - if (s_current == null || (includeUserConfig && !s_currentIncludesUserConfig)) - { - s_current = new ClientConfigPaths(null, includeUserConfig); - s_currentIncludesUserConfig = includeUserConfig; - } - - result = s_current; - } - else - { - result = new ClientConfigPaths(exePath, includeUserConfig); - } + //internal static ClientConfigPaths GetPaths(string exePath, bool includeUserConfig) + //{ + // ClientConfigPaths result = null; + + // if (exePath == null) + // { + // if (s_current == null || (includeUserConfig && !s_currentIncludesUserConfig)) + // { + // s_current = new ClientConfigPaths(null, includeUserConfig); + // s_currentIncludesUserConfig = includeUserConfig; + // } + + // result = s_current; + // } + // else + // { + // result = new ClientConfigPaths(exePath, includeUserConfig); + // } - return result; - } + // return result; + //} internal static void RefreshCurrent() { @@ -289,13 +293,13 @@ namespace RomCheater.UserSettingsSupport s_current = null; } - internal static ClientConfigPaths Current - { - get - { - return GetPaths(null, true); - } - } + //internal static ClientConfigPaths Current + //{ + // get + // { + // return GetPaths(null, true); + // } + //} internal bool HasEntryAssembly { @@ -437,7 +441,8 @@ namespace RomCheater.UserSettingsSupport // Returns a type and hash suffix based on app domain evidence. The evidence we use, in // priority order, is Strong Name, Url and Exe Path. If one of these is found, we compute a // SHA1 hash of it and return a suffix based on that. If none is found, we return null. - private string GetTypeAndHashSuffix(AppDomain appDomain, string exePath) + //private string GetTypeAndHashSuffix(AppDomain appDomain, string exePath) + private string GetTypeAndHashSuffix(Assembly appDomain, string exePath) { string suffix = null; string typeName = null; @@ -464,7 +469,8 @@ namespace RomCheater.UserSettingsSupport } // Mostly borrowed from IsolatedStorage, with some modifications - private static object GetEvidenceInfo(AppDomain appDomain, string exePath, out string typeName) + //private static object GetEvidenceInfo(AppDomain appDomain, string exePath, out string typeName) + private static object GetEvidenceInfo(Assembly appDomain, string exePath, out string typeName) { ControlEvidencePermission.Assert(); Evidence evidence = appDomain.Evidence; @@ -557,7 +563,8 @@ namespace RomCheater.UserSettingsSupport return new StrongName(sn.PublicKey, sn.Name, new Version(0, 0, 0, 0)); } - private void SetNamesAndVersion(string applicationFilename, Assembly exeAssembly, bool isHttp) + //private void SetNamesAndVersion(string applicationFilename, Assembly exeAssembly, bool isHttp) + private void SetNamesAndVersion(Assembly exeAssembly, bool isHttp) { Type mainType = null; @@ -614,10 +621,10 @@ namespace RomCheater.UserSettingsSupport } } - if (versionInfoFileName == null) - { - versionInfoFileName = applicationFilename; - } + //if (versionInfoFileName == null) + //{ + // versionInfoFileName = applicationFilename; + //} if (versionInfoFileName != null) { |