Exemple #1
0
        /// <summary>
        /// Synchronous getter of an icon for PowerItem
        /// </summary>
        /// <param name="item">PowerItem we need icon extracted for</param>
        /// <param name="iconNeeded">type of icon needed - small or large</param>
        /// <returns>ImageContainer with ImageSources extracted. Can be null.</returns>
        public static ImageContainer GetImageContainerSync(PowerItem item, API.Shgfi iconNeeded)
        {
            Log.Raw("begin>>>>>>>>>>>>>>>", item.FriendlyName);
            //Checking if there's cached ImageContainer
            string resolvedArg, descr;

            try
            {
                resolvedArg = PowerItemTree.GetResolvedArgument(item);
                descr       = GetObjectDescriptor(item, resolvedArg);
            }
            catch (IOException)
            {
                return(null);
            }
            lock (Cache)
            {
                var container = (ImageContainer)(Cache.ContainsKey(descr) ? Cache[descr] : null);
                Log.Fmt("arg<={0}, descr<={1}, container<={2}", resolvedArg, descr,
                        (container != null ? "not " : "") + "null");
                if (container == null) //No cached instance
                {
                    container = new ImageContainer(resolvedArg, descr, item.SpecialFolderId);
                    Cache.Add(descr, container);
                    if (iconNeeded == API.Shgfi.SMALLICON)
                    {
                        container.ExtractSmall();
                    }
                    else
                    {
                        container.ExtractLarge();
                    }
                }
#if DEBUG
                Log.Raw("end<<<<<<<<<<<<<<", item.FriendlyName);
#endif
                return(container);
            }
        }
Exemple #2
0
 /// <summary>
 /// Synchronous getter of an icon for PowerItem
 /// </summary>
 /// <param name="item">PowerItem we need icon extracted for</param>
 /// <param name="iconNeeded">type of icon needed - small or large</param>
 /// <returns>ImageContainer with ImageSources extracted. Can be null.</returns>
 public static ImageContainer GetImageContainerSync(PowerItem item, API.Shgfi iconNeeded)
 {
     Log.Raw("begin>>>>>>>>>>>>>>>", item.FriendlyName);
     //Checking if there's cached ImageContainer
     string resolvedArg, descr;
     try
     {
         resolvedArg = PowerItemTree.GetResolvedArgument(item);
         descr = GetObjectDescriptor(item, resolvedArg);
     }
     catch (IOException)
     {
         return null;
     }
     lock (Cache)
     {
         var container = (ImageContainer)(Cache.ContainsKey(descr) ? Cache[descr] : null);
         Log.Fmt("arg<={0}, descr<={1}, container<={2}", resolvedArg, descr,
                 (container != null ? "not " : "") + "null");
         if (container == null) //No cached instance
         {
             container = new ImageContainer(resolvedArg, descr, item.SpecialFolderId);
             Cache.Add(descr, container);
             if (iconNeeded == API.Shgfi.SMALLICON)
                 container.ExtractSmall();
             else
                 container.ExtractLarge();
         }
     #if DEBUG
         Log.Raw("end<<<<<<<<<<<<<<", item.FriendlyName);
     #endif
         return container;
     }
 }