static void CreateNode(string[] folder)
        {
            string dirName = new FileInfo(folder[0]).Name;
            dirName = dirName.ToUpper();
            for (int c = 0; c < dirName.Length; c++)
            {
                if (c == 4)
                    break;
                nodes[numNodesDone].type = nodes[numNodesDone].type + dirName[c];

            }
            nodes[numNodesDone].filenameOffset = (uint)stringTable.Length;
            stringTable = stringTable + dirName.ToLower() + (char)0x00;
            string[] numFiles = Directory.GetFileSystemEntries(folder[0]);
            nodes[numNodesDone].numFileEntries = (ushort)(numFiles.Length + 2);
            nodes[numNodesDone].firstFileEntryOffset = (uint)totalNumFilesAdded;

            dirName = new FileInfo(folder[0]).Name;
            nodes[numNodesDone].foldernameHash = Hash(dirName);

            numNodesDone++;
        }
        public override string GetSavedLicenseKey(Type type, Assembly resourceAssembly) {

            if (savedLicenseKeys == null || savedLicenseKeys[type.AssemblyQualifiedName]==null) {
                Debug.WriteLineIf(RuntimeLicenseContextSwitch.TraceVerbose, "savedLicenseKey is null or doesnt contain our type");
                if (savedLicenseKeys == null) {
                    savedLicenseKeys = new Hashtable();
                }
                
                Uri licenseFile = null;

                if (resourceAssembly == null) {
                    Debug.WriteLineIf(RuntimeLicenseContextSwitch.TraceVerbose,"resourceAssembly is null");
                    string rawFile = (string)AppDomain.CurrentDomain.SetupInformation.LicenseFile;
                    Debug.WriteLineIf(RuntimeLicenseContextSwitch.TraceVerbose,"rawfile: " + rawFile);
                    string codeBase;
                    
#if !DISABLE_CAS_USE
                    // FileIOPermission is required for ApplicationBase in URL-hosted domains
                    FileIOPermission perm = new FileIOPermission(PermissionState.Unrestricted);
                    perm.Assert();
                    try {
                        codeBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                    }
                    finally {
                        CodeAccessPermission.RevertAssert();
                    }
#else
                    codeBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
#endif
                    if (rawFile != null && codeBase != null) {
                        licenseFile = new Uri(new Uri(codeBase), rawFile);
                    }
                }

                if (licenseFile == null) {
                    if(resourceAssembly == null) {
                        resourceAssembly = Assembly.GetEntryAssembly();
                    }

                    if (resourceAssembly == null) {
                        Debug.WriteLineIf(RuntimeLicenseContextSwitch.TraceVerbose,"resourceAssembly is null");
                        // If Assembly.EntryAssembly returns null, then we will 
                        // try everything!
                        // 
                        foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) {

                            // Though, I could not repro this, we seem to be hitting an AssemblyBuilder
                            // when walking through all the assemblies in the current app domain. This throws an 
                            // exception on Assembly.CodeBase and we bail out. Catching exceptions here is not a 
                            // bad thing.
                            if (asm.IsDynamic)
                                continue;

                            // file://fullpath/foo.exe
                            //
                            string fileName;
#if !DISABLE_CAS_USE
                            FileIOPermission perm = new FileIOPermission(PermissionState.Unrestricted);
                            perm.Assert();
                            try
                            {
                                fileName = GetLocalPath(asm.EscapedCodeBase);
                                fileName = new FileInfo(fileName).Name;
                            }
                            finally
                            {
                                CodeAccessPermission.RevertAssert();
                            }
#else
                            fileName = GetLocalPath(asm.EscapedCodeBase);
                            fileName = new FileInfo(fileName).Name;
#endif

                            Stream s = asm.GetManifestResourceStream(fileName + ".licenses");
                            if (s == null) {
                                //Since the casing may be different depending on how the assembly was loaded, 
                                //we'll do a case insensitive lookup for this manifest resource stream...
                                s = CaseInsensitiveManifestResourceStreamLookup(asm, fileName + ".licenses");
                            }
                            
                            if (s != null) {
                                DesigntimeLicenseContextSerializer.Deserialize(s, fileName.ToUpper(CultureInfo.InvariantCulture), this);
                                break;
                            }
                        }
                    }
                    else if(!resourceAssembly.IsDynamic) { // EscapedCodeBase won't be supported by emitted assemblies anyway
                        Debug.WriteLineIf(RuntimeLicenseContextSwitch.TraceVerbose,"resourceAssembly is not null");
                        string fileName;
                        FileIOPermission perm = new FileIOPermission(PermissionState.Unrestricted);
                        perm.Assert();
                        try
                        {
                            fileName = GetLocalPath(resourceAssembly.EscapedCodeBase);
                        }
                        finally
                        {
                            CodeAccessPermission.RevertAssert();
                        }
                        fileName = Path.GetFileName(fileName); // we don't want to use FileInfo here... it requests FileIOPermission that we
                        // might now have... see VSWhidbey 527758
                        string licResourceName = fileName + ".licenses";
                        // first try the filename
                        Stream s = resourceAssembly.GetManifestResourceStream(licResourceName);
                        if (s == null) {
                            string resolvedName = null;
                            CompareInfo comparer = CultureInfo.InvariantCulture.CompareInfo;
                            string shortAssemblyName = resourceAssembly.GetName().Name;
                            //  if the assembly has been renamed, we try our best to find a good match in the available resources
                            // by looking at the assembly name (which doesn't change even after a file rename) + ".exe.licenses" or + ".dll.licenses"
                            foreach(String existingName in resourceAssembly.GetManifestResourceNames()) {
                                if (comparer.Compare(existingName, licResourceName, CompareOptions.IgnoreCase) == 0 ||
                                 comparer.Compare(existingName, shortAssemblyName + ".exe.licenses", CompareOptions.IgnoreCase) == 0 || 
                                 comparer.Compare(existingName, shortAssemblyName + ".dll.licenses", CompareOptions.IgnoreCase) == 0) {
                                    resolvedName = existingName;
                                    break;
                                }
                            }
                            if (resolvedName != null) {
                                s = resourceAssembly.GetManifestResourceStream(resolvedName);
                            }
                        }
                        if (s != null) {
                            DesigntimeLicenseContextSerializer.Deserialize(s, fileName.ToUpper(CultureInfo.InvariantCulture), this);
                        }
                    }
                }


                if (licenseFile != null) {
                    Debug.WriteLineIf(RuntimeLicenseContextSwitch.TraceVerbose,"licenseFile: " + licenseFile.ToString());
                    Debug.WriteLineIf(RuntimeLicenseContextSwitch.TraceVerbose,"opening licenses file over URI " + licenseFile.ToString());
                    Stream s = OpenRead(licenseFile);
                    if (s != null) {
                        string[] segments = licenseFile.Segments;
                        string licFileName = segments[segments.Length - 1];
                        string key = licFileName.Substring(0, licFileName.LastIndexOf("."));
                        DesigntimeLicenseContextSerializer.Deserialize(s, key.ToUpper(CultureInfo.InvariantCulture), this);
                    }
                }

            }
            Debug.WriteLineIf(RuntimeLicenseContextSwitch.TraceVerbose,"returning : " + (string)savedLicenseKeys[type.AssemblyQualifiedName]);
            return(string)savedLicenseKeys[type.AssemblyQualifiedName];
        }
 public override string GetSavedLicenseKey(Type type, Assembly resourceAssembly)
 {
     if ((this.savedLicenseKeys == null) || (this.savedLicenseKeys[type.AssemblyQualifiedName] == null))
     {
         if (this.savedLicenseKeys == null)
         {
             this.savedLicenseKeys = new Hashtable();
         }
         Uri resourceUri = null;
         if (resourceAssembly == null)
         {
             string applicationBase;
             string licenseFile = AppDomain.CurrentDomain.SetupInformation.LicenseFile;
             new FileIOPermission(PermissionState.Unrestricted).Assert();
             try
             {
                 applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
             }
             finally
             {
                 CodeAccessPermission.RevertAssert();
             }
             if ((licenseFile != null) && (applicationBase != null))
             {
                 resourceUri = new Uri(new Uri(applicationBase), licenseFile);
             }
         }
         if (resourceUri == null)
         {
             if (resourceAssembly == null)
             {
                 resourceAssembly = Assembly.GetEntryAssembly();
             }
             if (resourceAssembly == null)
             {
                 foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                 {
                     if (!assembly.IsDynamic)
                     {
                         string localPath;
                         new FileIOPermission(PermissionState.Unrestricted).Assert();
                         try
                         {
                             localPath = this.GetLocalPath(assembly.EscapedCodeBase);
                             localPath = new FileInfo(localPath).Name;
                         }
                         finally
                         {
                             CodeAccessPermission.RevertAssert();
                         }
                         Stream manifestResourceStream = assembly.GetManifestResourceStream(localPath + ".licenses");
                         if (manifestResourceStream == null)
                         {
                             manifestResourceStream = this.CaseInsensitiveManifestResourceStreamLookup(assembly, localPath + ".licenses");
                         }
                         if (manifestResourceStream != null)
                         {
                             DesigntimeLicenseContextSerializer.Deserialize(manifestResourceStream, localPath.ToUpper(CultureInfo.InvariantCulture), this);
                             break;
                         }
                     }
                 }
             }
             else if (!resourceAssembly.IsDynamic)
             {
                 string fileName;
                 new FileIOPermission(PermissionState.Unrestricted).Assert();
                 try
                 {
                     fileName = this.GetLocalPath(resourceAssembly.EscapedCodeBase);
                 }
                 finally
                 {
                     CodeAccessPermission.RevertAssert();
                 }
                 fileName = Path.GetFileName(fileName);
                 string name = fileName + ".licenses";
                 Stream o = resourceAssembly.GetManifestResourceStream(name);
                 if (o == null)
                 {
                     string str6 = null;
                     CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo;
                     string str7 = resourceAssembly.GetName().Name;
                     foreach (string str8 in resourceAssembly.GetManifestResourceNames())
                     {
                         if (((compareInfo.Compare(str8, name, CompareOptions.IgnoreCase) == 0) || (compareInfo.Compare(str8, str7 + ".exe.licenses", CompareOptions.IgnoreCase) == 0)) || (compareInfo.Compare(str8, str7 + ".dll.licenses", CompareOptions.IgnoreCase) == 0))
                         {
                             str6 = str8;
                             break;
                         }
                     }
                     if (str6 != null)
                     {
                         o = resourceAssembly.GetManifestResourceStream(str6);
                     }
                 }
                 if (o != null)
                 {
                     DesigntimeLicenseContextSerializer.Deserialize(o, fileName.ToUpper(CultureInfo.InvariantCulture), this);
                 }
             }
         }
         if (resourceUri != null)
         {
             Stream stream3 = OpenRead(resourceUri);
             if (stream3 != null)
             {
                 string[] segments = resourceUri.Segments;
                 string str9 = segments[segments.Length - 1];
                 string str10 = str9.Substring(0, str9.LastIndexOf("."));
                 DesigntimeLicenseContextSerializer.Deserialize(stream3, str10.ToUpper(CultureInfo.InvariantCulture), this);
             }
         }
     }
     return (string) this.savedLicenseKeys[type.AssemblyQualifiedName];
 }