示例#1
0
		public static extern int CreateAssemblyEnum(
			out IAssemblyEnum ppEnum,
			IApplicationContext pAppCtx,
			IAssemblyName pName,
			uint dwFlags,
			int pvReserved
			);
示例#2
0
        public void Dispose()
        {
            Marshal.ReleaseComObject(_enumerator);

            _enumerator = null;
            _current    = null;
        }
示例#3
0
        /// <summary>
        /// Rebuilds the GAC assembly cache.
        /// </summary>
        /// <param name="forceRebuild">if set to <c>true</c> [force rebuild].</param>
        /// <returns></returns>
        public static bool RebuildGACAssemblyCache(bool forceRebuild)
        {
            if (_gacNameCache.Length != 0 && !forceRebuild)
            {
                return(true);
            }

            IAssemblyEnum iterator = CreateGACEnum();

            if (iterator == null)
            {
                return(false);
            }
            IAssemblyName          currentName;
            List <GACAssemblyName> gacNames = new List <GACAssemblyName>();

            while (GetNextAssembly(iterator, out currentName) == 0)
            {
                if (currentName == null)
                {
                    continue;
                }
                string displayName = GetDisplayName(currentName, ASM_DISPLAY_FLAGS.PUBLIC_KEY_TOKEN | ASM_DISPLAY_FLAGS.VERSION | ASM_DISPLAY_FLAGS.CULTURE);
                gacNames.Add(new GACAssemblyName(displayName));
            }

            _gacNameCache = gacNames.ToArray();
            return(true);
        }
示例#4
0
            public static AssemblyName GetAssemblyName(string strName, Version version)
            {
                var           assemblyName = strName.ToLower();
                IAssemblyName an;

                try
                {
                    IAssemblyEnum ae = GacCache.CreateGACEnum();
                    while (GacCache.GetNextAssembly(ae, out an) == 0)
                    {
                        if (GacCache.GetName(an).ToLower().Contains(assemblyName))
                        {
                            if (version == null)
                            {
                                return(GetAssemblyName(an));
                            }
                            if (GetVersion(an) == version)
                            {
                                return(GetAssemblyName(an));
                            }
                        }
                    }
                }
                finally
                {
                }
                return(null);
            }
示例#5
0
 public static extern int CreateAssemblyEnum(
     out IAssemblyEnum ppEnum,
     IApplicationContext pAppCtx,
     IAssemblyName pName,
     uint dwFlags,
     int pvReserved
     );
示例#6
0
        public static void ReadCache(ArrayList alAssems, String name, uint nFlag)
        {
            IAssemblyEnum       aEnum     = null;
            IApplicationContext AppCtx    = null;
            IAssemblyName       aName     = null;
            IAssemblyName       pNameEnum = null;
            int hr;

            if (name != null)
            {
                hr = CreateAssemblyNameObject(out pNameEnum, name, CANOF.PARSE_DISPLAY_NAME, 0);
                if (hr != 0)
                {
                    return;
                }
            }

            hr = CreateAssemblyEnum(out aEnum, null, pNameEnum, nFlag, 0);
            while (hr == 0)
            {
                hr = aEnum.GetNextAssembly(out AppCtx, out aName, 0);
                if (hr == 0)
                {
                    uint   iLen         = 0;
                    IntPtr pDisplayName = (IntPtr)0;
                    // Get the length of the string we need
                    aName.GetDisplayName((IntPtr)0, ref iLen, 0);
                    if (iLen > 0)
                    {
                        // Do some yucky memory allocating here
                        // We need to assume that a wide character is 2 bytes.
                        pDisplayName = Marshal.AllocHGlobal(((int)iLen + 1) * 2);
                        aName.GetDisplayName(pDisplayName, ref iLen, 0);
                        String sDisplayName = Marshal.PtrToStringUni(pDisplayName);
                        Marshal.FreeHGlobal(pDisplayName);

                        // Our info is in a comma seperated list. Let's pull it out
                        String[] sFields = sDisplayName.Split(new char[] { ',' });

                        AssemblyInformation newguy = new AssemblyInformation();
                        newguy.FullName = sDisplayName;
                        newguy.Name     = sFields[0];
                        // The version string is represented as Version=######
                        // Let's take out the 'Version='
                        newguy.Version = sFields[1].Substring(sFields[1].IndexOf('=') + 1);
                        // Same goes for the locale
                        newguy.Locale = sFields[2].Substring(sFields[2].IndexOf('=') + 1);
                        // And the  key token
                        sFields[3] = sFields[3].Substring(sFields[3].IndexOf('=') + 1);
                        if (sFields[3].Equals("null"))
                        {
                            sFields[3] = "null";
                        }
                        newguy.PublicKeyToken = sFields[3];

                        alAssems.Add(newguy);
                    }
                }
            }
        }
示例#7
0
 private static extern int CreateAssemblyEnum(
     out IAssemblyEnum ppEnum,
     FusionAssemblyIdentity.IApplicationContext pAppCtx,
     FusionAssemblyIdentity.IAssemblyName pName,
     ASM_CACHE dwFlags,
     IntPtr pvReserved
     );
示例#8
0
        /// <summary>
        /// Gets the names of all assemblies in the GAC.
        /// </summary>
        public static IEnumerable <AssemblyNameInfo> GetGacAssemblyFullNames()
        {
            IApplicationContext applicationContext = null;
            IAssemblyEnum       assemblyEnum       = null;
            IAssemblyName       assemblyName       = null;

            Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0);
            while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0)
            {
                uint nChars = 0;
                assemblyName.GetDisplayName(null, ref nChars, 0);

                StringBuilder name = new StringBuilder((int)nChars);
                assemblyName.GetDisplayName(name, ref nChars, 0);

                AssemblyNameInfo r = null;
                try {
                    r = new AssemblyNameInfo(name.ToString());
                } catch (ArgumentException) {
                } catch (FormatException) {
                } catch (OverflowException) {
                }
                if (r != null)
                {
                    yield return(r);
                }
            }
        }
示例#9
0
 public static extern uint CreateAssemblyEnum(
     out IAssemblyEnum ppEnum,
     IntPtr pUnkReserved,
     IAssemblyName pName,
     ASM_CACHE_FLAGS dwFlags,
     IntPtr pvReserved
     );
示例#10
0
        public IList <string> GetAllAssemblies()
        {
            List <string> assemblies = new List <string>();

            // Enumerate.

            IAssemblyEnum assemblyEnum = AssemblyCache.CreateGACEnum();
            IAssemblyName assemblyName;

            assemblyEnum.GetNextAssembly(IntPtr.Zero, out assemblyName, 0);
            while (assemblyName != null)
            {
                // Grab the name and the version.

                uint          size = 10000;
                StringBuilder sb   = new StringBuilder((int)size);
                int           ret  = assemblyName.GetDisplayName(sb, ref size, ASM_DISPLAY_FLAGS.VERSION);
                if (ret == 0)
                {
                    assemblies.Add(sb.ToString());
                }

                assemblyEnum.GetNextAssembly(IntPtr.Zero, out assemblyName, 0);
            }

            return(assemblies);
        }
示例#11
0
            public static IEnumerable <string> GetAssemblyStringNames()
            {
                IAssemblyName an;

                try
                {
                    IAssemblyEnum ae = GacCache.CreateGACEnum();
                    while (GacCache.GetNextAssembly(ae, out an) == 0)
                    {
                        yield return(GacCache.GetName(an));
                    }
                }
                finally
                {
                }
            }
示例#12
0
        public static IEnumerable <AssemblyName> GetAssemblies()
        {
            IAssemblyEnum assemblyEnum = null;

            ComCheck(FusionApi.CreateAssemblyEnum(out assemblyEnum, IntPtr.Zero, null, AssemblyCacheFlags.Gac, IntPtr.Zero));

            IAssemblyName fusionAssemblyName = null;

            do
            {
                ComCheck(assemblyEnum.GetNextAssembly(IntPtr.Zero, out fusionAssemblyName, 0));
                if (fusionAssemblyName != null)
                {
                    yield return(new AssemblyName(GlobalAssemblyCache.GetDisplayName(fusionAssemblyName)));
                }
            } while (fusionAssemblyName != null);
        }
示例#13
0
        static GAC()
        {
            assemblies = new ArrayList();
            IAssemblyEnum assemblyEnum = null;
            IAssemblyName assemblyName = null;

            Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, (uint)Fusion.AssemblyCacheFlags.GAC, IntPtr.Zero);
            assemblyEnum.GetNextAssembly(IntPtr.Zero, out assemblyName, 0);
            while (assemblyName != null)
            {
                uint          ccbuf = 1024;
                StringBuilder sb    = new StringBuilder((int)ccbuf);
                assemblyName.GetDisplayName(sb, ref ccbuf, (uint)Fusion.AssemblyNameDisplayFlags.ALL);
                assemblies.Add(new AssemblyName(sb.ToString()));
                assemblyEnum.GetNextAssembly(IntPtr.Zero, out assemblyName, 0);
            }
        }
示例#14
0
        public static void ReadCache(ArrayList alAssems, string name, uint nFlag)
        {
            IAssemblyEnum       ppEnum1  = (IAssemblyEnum)null;
            IAssemblyName       ppName   = (IAssemblyName)null;
            IAssemblyName       ppEnum2  = (IAssemblyName)null;
            IApplicationContext ppAppCtx = (IApplicationContext)null;

            if (name != null)
            {
                int assemblyNameObject = Win32Native.CreateAssemblyNameObject(out ppEnum2, name, 1U, IntPtr.Zero);
                if (assemblyNameObject != 0)
                {
                    Marshal.ThrowExceptionForHR(assemblyNameObject);
                }
            }
            int assemblyEnum = Win32Native.CreateAssemblyEnum(out ppEnum1, ppAppCtx, ppEnum2, nFlag, IntPtr.Zero);

            if (assemblyEnum != 0)
            {
                Marshal.ThrowExceptionForHR(assemblyEnum);
            }
            while (true)
            {
                string displayName;
                do
                {
                    int nextAssembly = ppEnum1.GetNextAssembly(out ppAppCtx, out ppName, 0U);
                    if (nextAssembly != 0)
                    {
                        if (nextAssembly < 0)
                        {
                            Marshal.ThrowExceptionForHR(nextAssembly);
                            return;
                        }
                        goto label_10;
                    }
                    else
                    {
                        displayName = Fusion.GetDisplayName(ppName, 0U);
                    }
                }while (displayName == null);
                alAssems.Add((object)displayName);
            }
            label_10 :;
        }
示例#15
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            SortedSet <string> gacList = new SortedSet <string>();

            StringBuilder result = new StringBuilder();

            Dev2Logger.Log.Info("Registered Assembly");
            try
            {
                IAssemblyName assemblyName;
                IAssemblyEnum assemblyEnum = GAC.CreateGACEnum();
                string        json         = "[";
                while (GAC.GetNextAssembly(assemblyEnum, out assemblyName) == 0)
                {
                    try
                    {
                        gacList.Add(GAC.GetDisplayName(assemblyName, ASM_DISPLAY_FLAGS.VERSION | ASM_DISPLAY_FLAGS.CULTURE | ASM_DISPLAY_FLAGS.PUBLIC_KEY_TOKEN));
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Log.Error(e.Message);
                    }
                }

                // now process each sorted entry
                foreach (string entry in gacList)
                {
                    json += @"{""AssemblyName"":""" + entry + @"""}";
                    json += ",";
                }

                json += "]";
                json  = json.Replace(",]", "]"); //remove the last comma in the string in order to have valid json
                result.Append("<JSON>");
                result.Append(json);
                result.Append("</JSON>");
            }
            catch (Exception ex)
            {
                Dev2Logger.Log.Error(ex);
                result.Append(ex.Message);
            }

            return(result);
        }
示例#16
0
        IEnumerable <DomAssemblyName> GetGacAssemblyFullNames()
        {
            IApplicationContext applicationContext = null;
            IAssemblyEnum       assemblyEnum       = null;
            IAssemblyName       assemblyName       = null;

            Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0);
            while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0)
            {
                uint nChars = 0;
                assemblyName.GetDisplayName(null, ref nChars, 0);

                StringBuilder name = new StringBuilder((int)nChars);
                assemblyName.GetDisplayName(name, ref nChars, 0);

                yield return(new DomAssemblyName(name.ToString()));
            }
        }
            private void InitializeEnum(string assemblyName)
            {
                IAssemblyName ppAssemblyNameObj = null;
                int           num = 0;

                if (assemblyName != null)
                {
                    num = Microsoft.Build.Tasks.NativeMethods.CreateAssemblyNameObject(out ppAssemblyNameObj, assemblyName, CreateAssemblyNameObjectFlags.CANOF_PARSE_DISPLAY_NAME, IntPtr.Zero);
                }
                if (num >= 0)
                {
                    num = Microsoft.Build.Tasks.NativeMethods.CreateAssemblyEnum(out this.assemblyEnum, IntPtr.Zero, ppAssemblyNameObj, AssemblyCacheFlags.GAC, IntPtr.Zero);
                }
                if (num < 0)
                {
                    this.assemblyEnum = null;
                }
            }
示例#18
0
        [System.Security.SecurityCritical]  // auto-generated
        public static void ReadCache(ArrayList alAssems, String name, uint nFlag)
        {
            IAssemblyEnum       aEnum     = null;
            IAssemblyName       aName     = null;
            IAssemblyName       aNameEnum = null;
            IApplicationContext AppCtx    = null;
            int hr;

            if (name != null)
            {
                hr = Win32Native.CreateAssemblyNameObject(out aNameEnum, name, CANOF.PARSE_DISPLAY_NAME, IntPtr.Zero);
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }

            hr = Win32Native.CreateAssemblyEnum(out aEnum, AppCtx, aNameEnum, nFlag, IntPtr.Zero);
            if (hr != 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            for (; ;)
            {
                hr = aEnum.GetNextAssembly(out AppCtx, out aName, 0);
                if (hr != 0)
                {
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                    break;
                }

                String sDisplayName = GetDisplayName(aName, 0);
                if (sDisplayName == null)
                {
                    continue;
                }

                alAssems.Add(sDisplayName);
            } // for (;;)
        }
        public static List <DomAssemblyName> GetAssemblyList()
        {
            IApplicationContext applicationContext = null;
            IAssemblyEnum       assemblyEnum       = null;
            IAssemblyName       assemblyName       = null;

            List <DomAssemblyName> l = new List <DomAssemblyName>();

            Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0);
            while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0)
            {
                uint nChars = 0;
                assemblyName.GetDisplayName(null, ref nChars, 0);

                StringBuilder sb = new StringBuilder((int)nChars);
                assemblyName.GetDisplayName(sb, ref nChars, 0);

                l.Add(new DomAssemblyName(sb.ToString()));
            }
            return(l);
        }
        public static void ReadCache(ArrayList alAssems, string name, uint nFlag)
        {
            IAssemblyEnum       assemblyEnum = null;
            IAssemblyName       aName        = null;
            IAssemblyName       pName        = null;
            IApplicationContext pAppCtx      = null;
            int num;

            if (name != null)
            {
                num = Win32Native.CreateAssemblyNameObject(out pName, name, 1U, IntPtr.Zero);
                if (num != 0)
                {
                    Marshal.ThrowExceptionForHR(num);
                }
            }
            num = Win32Native.CreateAssemblyEnum(out assemblyEnum, pAppCtx, pName, nFlag, IntPtr.Zero);
            if (num != 0)
            {
                Marshal.ThrowExceptionForHR(num);
            }
            for (;;)
            {
                num = assemblyEnum.GetNextAssembly(out pAppCtx, out aName, 0U);
                if (num != 0)
                {
                    break;
                }
                string displayName = Fusion.GetDisplayName(aName, 0U);
                if (displayName != null)
                {
                    alAssems.Add(displayName);
                }
            }
            if (num < 0)
            {
                Marshal.ThrowExceptionForHR(num);
                return;
            }
        }
示例#21
0
        /// <summary>
        /// Gets the names of all assemblies in the GAC.
        /// </summary>
        public static IEnumerable <AssemblyNameInfo> GetGacAssemblyFullNames()
        {
            IApplicationContext applicationContext = null;
            IAssemblyEnum       assemblyEnum       = null;
            IAssemblyName       assemblyName       = null;

            Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0);
            while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0)
            {
                uint nChars = 0;
                assemblyName.GetDisplayName(null, ref nChars, 0);

                StringBuilder name = new StringBuilder((int)nChars);
                assemblyName.GetDisplayName(name, ref nChars, 0);

                var r = new AssemblyNameInfo(name.ToString());
                if (r.Version != null)
                {
                    yield return(r);
                }
            }
        }
示例#22
0
            public static string GetAssemblyFullName(string strName)
            {
                var           assemblyName = strName.ToLower();
                IAssemblyName an;

                try
                {
                    IAssemblyEnum ae = GacCache.CreateGACEnum();
                    while (GacCache.GetNextAssembly(ae, out an) == 0)
                    {
                        var name = GacCache.GetName(an).ToLower();
                        if (name == assemblyName)
                        {
                            return(GetAssemblyName(an).ToString());
                        }
                    }
                }
                finally
                {
                }
                return(null);
            }
示例#23
0
        /// <summary>
        /// Gets the names of all assemblies in the GAC.
        /// </summary>
        public static IEnumerable <AssemblyNameReference> GetGacAssemblyFullNames()
        {
            IApplicationContext applicationContext = null;
            IAssemblyEnum       assemblyEnum       = null;
            IAssemblyName       assemblyName       = null;

            uint result = unchecked ((uint)Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0));

            if (result == 0x80070005)
            {
                MessageBox.Show($"Cannot access GAC, please restart with elevated privileges! (HRESULT 0x{result:X})", "ILSpy", MessageBoxButton.OK, MessageBoxImage.Error);
                yield break;
            }
            while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0)
            {
                if (assemblyName == null)
                {
                    continue;
                }
                uint nChars = 0;
                assemblyName.GetDisplayName(null, ref nChars, 0);

                StringBuilder name = new StringBuilder((int)nChars);
                assemblyName.GetDisplayName(name, ref nChars, 0);

                AssemblyNameReference r = null;
                try {
                    r = AssemblyNameReference.Parse(name.ToString());
                } catch (ArgumentException) {
                } catch (FormatException) {
                } catch (OverflowException) {
                }
                if (r != null)
                {
                    yield return(r);
                }
            }
        }
        public static void ReadCache(ArrayList alAssems, string name, uint nFlag)
        {
            IAssemblyEnum       ppEnum  = null;
            IAssemblyName       ppName  = null;
            IAssemblyName       name3   = null;
            IApplicationContext pAppCtx = null;
            int num;

            if (name != null)
            {
                num = Win32Native.CreateAssemblyNameObject(out name3, name, 1, IntPtr.Zero);
                if (num != 0)
                {
                    Marshal.ThrowExceptionForHR(num);
                }
            }
            num = Win32Native.CreateAssemblyEnum(out ppEnum, pAppCtx, name3, nFlag, IntPtr.Zero);
            if (num != 0)
            {
                Marshal.ThrowExceptionForHR(num);
            }
Label_0042:
            num = ppEnum.GetNextAssembly(out pAppCtx, out ppName, 0);
            if (num == 0)
            {
                string displayName = GetDisplayName(ppName, 0);
                if (displayName != null)
                {
                    alAssems.Add(displayName);
                }
                goto Label_0042;
            }
            if (num < 0)
            {
                Marshal.ThrowExceptionForHR(num);
            }
        }
示例#25
0
文件: GAC.cs 项目: kapiya/Warewolf
        public static bool RebuildGACAssemblyCache(bool forceRebuild)
        {
            if (_gacNameCache.Length != 0 && !forceRebuild)
            {
                return(true);
            }

            IAssemblyEnum iterator = null;

            try { iterator = GAC.CreateGACEnum(); }
            catch (Exception e)
            {
                TraceWriter.WriteTrace("Could not obtain GAC assembly enumerator, " + e.Message);
                iterator = null;
            }

            if (iterator == null)
            {
                return(false);
            }
            IAssemblyName          currentName = null;
            List <GACAssemblyName> gacNames    = new List <GACAssemblyName>();

            while (GAC.GetNextAssembly(iterator, out currentName) == 0)
            {
                if (currentName == null)
                {
                    continue;
                }
                string displayName = GAC.GetDisplayName(currentName, ASM_DISPLAY_FLAGS.PUBLIC_KEY_TOKEN | ASM_DISPLAY_FLAGS.VERSION | ASM_DISPLAY_FLAGS.CULTURE);
                gacNames.Add(new GACAssemblyName(displayName));
            }

            _gacNameCache = gacNames.ToArray();
            return(true);
        }
示例#26
0
        static IEnumerable <Mono.Cecil.AssemblyNameReference> _loadGAC(uint dwFlags)
        {
            IApplicationContext applicationContext = null;
            IAssemblyEnum       assemblyEnum       = null;
            IAssemblyName       assemblyName       = null;

            Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, dwFlags, 0);
            while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0)
            {
                uint nChars = 0;
                assemblyName.GetDisplayName(null, ref nChars, 0);
                StringBuilder name = new StringBuilder((int)nChars);
                assemblyName.GetDisplayName(name, ref nChars, 0);
                Mono.Cecil.AssemblyNameReference r = null;
                try { r = Mono.Cecil.AssemblyNameReference.Parse(name.ToString()); }
                catch (ArgumentException) { }
                catch (FormatException) { }
                catch (OverflowException) { }
                if (r != null)
                {
                    yield return(r);
                }
            }
        }
示例#27
0
 public static extern int CreateAssemblyEnum(
     out IAssemblyEnum ppEnum,
     IntPtr pUnkReserved,
     IAssemblyName pName,
     ASM_CACHE_FLAGS flags,
     IntPtr pvReserved);
示例#28
0
 public static extern void CreateAssemblyEnum(out IAssemblyEnum pEnum, IntPtr pUnkReserved, IAssemblyName pName,
     AssemblyCacheType dwFlags, IntPtr pvReserved);
示例#29
0
文件: GAC.cs 项目: LowerCode/tools
 internal static extern int CreateAssemblyEnum(
     out IAssemblyEnum ppEnum,
     IntPtr pUnkReserved,
     IAssemblyName pName,
     AssemblyCacheFlags flags,
     IntPtr pvReserved);
示例#30
0
 public static extern HRESULT CreateAssemblyEnum(out IAssemblyEnum assemblyEnum,
                                                 IApplicationContext applicationContext, IAssemblyName assemblyName, CreateAssemblyEnumFlags flags, int reserved);
示例#31
0
 internal static extern int CreateAssemblyEnum(
         out IAssemblyEnum ppEnum,
         IntPtr pUnkReserved,
         IAssemblyName pName,
         AssemblyCacheFlags flags,
         IntPtr pvReserved);
示例#32
0
 internal static int CreateAssemblyEnum(out IAssemblyEnum ppEnum, IApplicationContext pAppCtx, IAssemblyName pName, uint dwFlags, IntPtr pvReserved);
示例#33
0
 /// <summary>
 /// Get the next assembly name in the current enumerator or fail
 /// </summary>
 /// <param name="enumerator"></param>
 /// <param name="name"></param>
 /// <returns>0 if the enumeration is not at its end</returns>
 static int GetNextAssembly(IAssemblyEnum enumerator, out IAssemblyName name)
 {
     return(enumerator.GetNextAssembly((IntPtr)0, out name, 0));
 }
    	public int Clone(out IAssemblyEnum ppEnum)
		{
			ppEnum = null;
			Debug.Assert( false );
			return 0;
		}
示例#35
0
 private static extern int CreateAssemblyEnum(out IAssemblyEnum ppEnum, IApplicationContext /*?*/ pAppCtx, IAssemblyName /*?*/ pName, uint dwFlags, int pvReserved);
示例#36
0
文件: GAC.cs 项目: Robin--/Warewolf
 /// <summary>
 ///     Get the next assembly name in the current enumerator or fail
 /// </summary>
 /// <param name="enumerator"></param>
 /// <param name="name"></param>
 /// <returns>0 if the enumeration is not at its end</returns>
 public static int GetNextAssembly(IAssemblyEnum enumerator, out IAssemblyName name)
 {
     return enumerator.GetNextAssembly((IntPtr) 0, out name, 0);
 }
示例#37
0
文件: GAC.cs 项目: Robin--/Warewolf
 private static extern void CreateAssemblyEnum(out IAssemblyEnum pEnum, IntPtr pUnkReserved, IAssemblyName pName,
     ASM_CACHE_FLAGS dwFlags, IntPtr pvReserved);
        public static DomAssemblyName FindBestMatchingAssemblyName(DomAssemblyName name)
        {
            string[] info;
            string   version   = name.Version;
            string   publicKey = name.PublicKeyToken;

            IApplicationContext applicationContext = null;
            IAssemblyEnum       assemblyEnum       = null;
            IAssemblyName       assemblyName;

            Fusion.CreateAssemblyNameObject(out assemblyName, name.ShortName, 0, 0);
            Fusion.CreateAssemblyEnum(out assemblyEnum, null, assemblyName, 2, 0);
            List <string> names = new List <string>();

            while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0)
            {
                uint nChars = 0;
                assemblyName.GetDisplayName(null, ref nChars, 0);

                StringBuilder sb = new StringBuilder((int)nChars);
                assemblyName.GetDisplayName(sb, ref nChars, 0);

                string fullName = sb.ToString();
                if (publicKey != null)
                {
                    info = fullName.Split(',');
                    if (publicKey != info[3].Substring(info[3].LastIndexOf('=') + 1))
                    {
                        // Assembly has wrong public key
                        continue;
                    }
                }
                names.Add(fullName);
            }
            if (names.Count == 0)
            {
                return(null);
            }
            string  best        = null;
            Version bestVersion = null;
            Version currentVersion;

            if (version != null)
            {
                // use assembly with lowest version higher or equal to required version
                Version requiredVersion = new Version(version);
                for (int i = 0; i < names.Count; i++)
                {
                    info           = names[i].Split(',');
                    currentVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1));
                    if (currentVersion.CompareTo(requiredVersion) < 0)
                    {
                        continue;                         // version not good enough
                    }
                    if (best == null || currentVersion.CompareTo(bestVersion) < 0)
                    {
                        bestVersion = currentVersion;
                        best        = names[i];
                    }
                }
                if (best != null)
                {
                    return(new DomAssemblyName(best));
                }
            }
            // use assembly with highest version
            best        = names[0];
            info        = names[0].Split(',');
            bestVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1));
            for (int i = 1; i < names.Count; i++)
            {
                info           = names[i].Split(',');
                currentVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1));
                if (currentVersion.CompareTo(bestVersion) > 0)
                {
                    bestVersion = currentVersion;
                    best        = names[i];
                }
            }
            return(new DomAssemblyName(best));
        }
 private static extern int CreateAssemblyEnum(out IAssemblyEnum ppEnum, FusionAssemblyIdentity.IApplicationContext pAppCtx, FusionAssemblyIdentity.IAssemblyName pName, ASM_CACHE dwFlags, IntPtr pvReserved);
 private static extern int CreateAssemblyEnum(out IAssemblyEnum ppEnum, IApplicationContext/*?*/ pAppCtx, IAssemblyName/*?*/ pName, uint dwFlags, int pvReserved);