示例#1
0
        void _AutoUpdateSingle(_AUData k)
        {
            //FUTURE: optimize.
            //	Don't load ico/exe file if not modified.
            //	Don't do too frequently for same file.
            //	Skip duplicate paths.
            //	Don't do for files where getting icon is very slow.

            if (!_LoadImage(out var b, k.file, k.giFlags, k.callback))
            {
                return;
            }
            if (b == k.oldImage)
            {
                return;                             //callback returned the same object
            }
            if (_CompareImages(b, k.oldImage))
            {
                if (k.canDispose)
                {
                    b.Dispose();
                }
                return;
            }
            lock (this) _AddImage(k.file, b, true);
            //k.autoUpdated?.Invoke(b, k.auParam);

            //AOutput.Write(k.auParam);
            //APerf.First();
            k.autoUpdated?.Invoke(b, k.auParam);
            //APerf.NW();
        }
示例#2
0
 static void _AutoUpdateAdd(_AUData d)
 {
     if (t_auTimer == null)
     {
         t_auTimer = new ATimer(t => _AutoUpdateTimer());
         t_auList  = new Queue <_AUData>();
     }
     t_auList.Enqueue(d);
     t_auTimer.Every(50);
 }
示例#3
0
        Bitmap _GetImage(string file, IconGetFlags giFlags, Func <Bitmap> callback, Action <Bitmap, object> autoUpdate, object auParam, bool auDispose)
        {
            bool cached = true;

            lock (this) {
                Bitmap R = null;

                //is in memory cache?
                if (_table == null)
                {
                    _table = new Hashtable(StringComparer.OrdinalIgnoreCase);
                }
                else
                {
                    R = _table[file] as Bitmap;
                }

                if (R == null)
                {
                    //is in file cache?
                    try {
                        if (_x == null && AFile.ExistsAsFile(_cacheFile))
                        {
                            _x = AExtXml.LoadElem(_cacheFile);
                            if (_iconSize != _x.Attr("size", 0) || ADpi.BaseDPI != _x.Attr("dpi", 0))
                            {
                                _x = null;
                                ADebug.Print("info: cleared icon cache");
                            }

                            //FUTURE: Delete unused entries. Maybe try to auto-update changed icons.
                            //	Not very important, because there is ClearCache.
                        }
                        if (_x != null)
                        {
                            var x = _x.Elem("i", "name", file, true);
                            if (x != null)
                            {
                                using var ms = new MemoryStream(Convert.FromBase64String(x.Value), false);
                                R            = new Bitmap(ms);
                            }
                        }
                    }
                    catch (Exception ex) {
                        ADebug.Print(ex.Message);
                    }

                    if (R != null)
                    {
                        _table[file] = R;                                //add to memory cache
                    }
                    else if (_LoadImage(out R, file, giFlags, callback)) //get file icon
                    {
                        _AddImage(file, R, false);                       //add to file cache and memory cache
                        cached = false;
                    }
                }

                //auto-update
                if (cached && autoUpdate != null)
                {
                    var d = new _AUData()
                    {
                        cache       = this, oldImage = R, file = file, callback = callback,
                        autoUpdated = autoUpdate, auParam = auParam, giFlags = giFlags, canDispose = auDispose,
                    };
                    _AutoUpdateAdd(d);
                }

                return(R);
            }
        }