/[RomCheater]/trunk/RomCheater.UserSettingsSupport/IsolatedStoragePath.cs
ViewVC logotype

Diff of /trunk/RomCheater.UserSettingsSupport/IsolatedStoragePath.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.UserSettingsSupport/IsolatedStoragePath.cs	2013/06/18 19:18:05	722
+++ trunk/RomCheater.UserSettingsSupport/IsolatedStoragePath.cs	2013/06/18 20:22:08	724
@@ -66,8 +66,12 @@
             //path = builder.ToString();
             //this.ConfigFilePath = path;
 
-            //var t = ClientConfigPaths.GetPaths(;
-            
+
+            //var asm_test = Assembly.LoadFile(this.AssemblyInfo.Location);
+
+            ClientConfigPaths t = new ClientConfigPaths(this.AssemblyInfo, true);
+
+            this.ConfigFilePath = t.LocalConfigFilename;
 
         }
 
@@ -95,15 +99,15 @@
                 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 
                 'y', 'z', '0', '1', '2', '3', '4', '5'};
 
-            static volatile ClientConfigPaths s_current;
-            static volatile bool s_currentIncludesUserConfig;
+            //static volatile ClientConfigPaths s_current;
+            //static volatile bool s_currentIncludesUserConfig;
             static SecurityPermission s_serializationPerm;
             static SecurityPermission s_controlEvidencePerm;
 
-            bool _hasEntryAssembly;
-            bool _includesUserConfig;
-            string _applicationUri;
-            string _applicationConfigUri;
+            //bool _hasEntryAssembly;
+            //bool _includesUserConfig;
+            //string _applicationUri;
+            //string _applicationConfigUri;
             string _roamingConfigDirectory;
             string _roamingConfigFilename;
             string _localConfigDirectory;
@@ -115,118 +119,119 @@
 
             [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;
-
-                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);
+                //_includesUserConfig = includeUserConfig;
 
-                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 +239,14 @@
 
                     string part1 = Validate(_companyName, true);
 
-                    string validAppDomainName = Validate(AppDomain.CurrentDomain.FriendlyName, true);
-                    string applicationUriLower = !String.IsNullOrEmpty(_applicationUri) ? _applicationUri.ToLower(CultureInfo.InvariantCulture) : null;
+                    //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 hashSuffix = GetTypeAndHashSuffix(exeAssembly);
 
                     string part2 = (!String.IsNullOrEmpty(namePrefix) && !String.IsNullOrEmpty(hashSuffix)) ? namePrefix + hashSuffix : null;
 
@@ -258,68 +267,68 @@
                         _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);
-                }
-
-                return result;
-            }
-
-            internal static void RefreshCurrent()
-            {
-                s_currentIncludesUserConfig = false;
-                s_current = null;
-            }
-
-            internal static ClientConfigPaths Current
-            {
-                get
-                {
-                    return GetPaths(null, true);
-                }
-            }
-
-            internal bool HasEntryAssembly
-            {
-                get
-                {
-                    return _hasEntryAssembly;
-                }
-            }
-
-            internal string ApplicationUri
-            {
-                get
-                {
-                    return _applicationUri;
-                }
-            }
-
-            internal string ApplicationConfigUri
-            {
-                get
-                {
-                    return _applicationConfigUri;
-                }
-            }
+            //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;
+            //}
+
+            //internal static void RefreshCurrent()
+            //{
+            //    s_currentIncludesUserConfig = false;
+            //    s_current = null;
+            //}
+
+            //internal static ClientConfigPaths Current
+            //{
+            //    get
+            //    {
+            //        return GetPaths(null, true);
+            //    }
+            //}
+
+            //internal bool HasEntryAssembly
+            //{
+            //    get
+            //    {
+            //        return _hasEntryAssembly;
+            //    }
+            //}
+
+            //internal string ApplicationUri
+            //{
+            //    get
+            //    {
+            //        return _applicationUri;
+            //    }
+            //}
+
+            //internal string ApplicationConfigUri
+            //{
+            //    get
+            //    {
+            //        return _applicationConfigUri;
+            //    }
+            //}
 
             internal string RoamingConfigFilename
             {
@@ -337,14 +346,14 @@
                 }
             }
 
-            internal bool HasRoamingConfig
-            {
-                get
-                {
-                    // Assume we have roaming config if we haven't loaded user config file information.
-                    return RoamingConfigFilename != null || !_includesUserConfig;
-                }
-            }
+            //internal bool HasRoamingConfig
+            //{
+            //    get
+            //    {
+            //        // Assume we have roaming config if we haven't loaded user config file information.
+            //        return RoamingConfigFilename != null || !_includesUserConfig;
+            //    }
+            //}
 
             internal string LocalConfigFilename
             {
@@ -362,14 +371,14 @@
                 }
             }
 
-            internal bool HasLocalConfig
-            {
-                get
-                {
-                    // Assume we have roaming config if we haven't loaded user config file information.
-                    return LocalConfigFilename != null || !_includesUserConfig;
-                }
-            }
+            //internal bool HasLocalConfig
+            //{
+            //    get
+            //    {
+            //        // Assume we have roaming config if we haven't loaded user config file information.
+            //        return LocalConfigFilename != null || !_includesUserConfig;
+            //    }
+            //}
 
             internal string ProductName
             {
@@ -437,13 +446,15 @@
             // 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)
+            private string GetTypeAndHashSuffix(Assembly appDomain)
             {
                 string suffix = null;
                 string typeName = null;
                 object evidenceObj = null;
-
-                evidenceObj = GetEvidenceInfo(appDomain, exePath, out typeName);
+                //evidenceObj = GetEvidenceInfo(appDomain, exePath, out typeName);
+                evidenceObj = GetEvidenceInfo(appDomain, out typeName);
 
                 if (evidenceObj != null && !String.IsNullOrEmpty(typeName))
                 {
@@ -464,7 +475,9 @@
             }
 
             // 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)
+            private static object GetEvidenceInfo(Assembly appDomain, out string typeName)
             {
                 ControlEvidencePermission.Assert();
                 Evidence evidence = appDomain.Evidence;
@@ -506,11 +519,11 @@
                     o = url.Value.ToUpperInvariant();
                     typeName = UrlDesc;
                 }
-                else if (exePath != null)
-                {
-                    o = exePath;
-                    typeName = PathDesc;
-                }
+                //else if (exePath != null)
+                //{
+                //    o = exePath;
+                //    typeName = PathDesc;
+                //}
                 else
                 {
                     typeName = null;
@@ -557,7 +570,8 @@
                 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 +628,10 @@
                         }
                     }
 
-                    if (versionInfoFileName == null)
-                    {
-                        versionInfoFileName = applicationFilename;
-                    }
+                    //if (versionInfoFileName == null)
+                    //{
+                    //    versionInfoFileName = applicationFilename;
+                    //}
 
                     if (versionInfoFileName != null)
                     {

 

  ViewVC Help
Powered by ViewVC 1.1.22