| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 | using PaintDotNet.SystemLayer;using System;using System.Collections;using System.Drawing;namespace PaintDotNet{    /// <summary>    /// 用于管理“最近使用的”文件列表    /// </summary>    internal class MostRecentFiles    {        /// <summary>        /// 表示先进先出的最近的文件实例        /// </summary>        private Queue files;        private int maxCount;        private const int iconSize = 56;        private bool loaded = false;        public MostRecentFiles(int maxCount)        {            this.maxCount = maxCount;            this.files = new Queue();        }        public bool Loaded        {            get            {                return this.loaded;            }        }        public int Count        {            get            {                if (!this.loaded)                {                    LoadMruList();                }                return this.files.Count;            }        }        public int MaxCount        {            get            {                return this.maxCount;            }        }        public int IconSize        {            get            {                return UI.ScaleWidth(iconSize);            }        }        public MostRecentFile[] GetFileList()        {            if (!Loaded)            {                LoadMruList();            }            object[] array = files.ToArray();            MostRecentFile[] mrfArray = new MostRecentFile[array.Length];            array.CopyTo(mrfArray, 0);            return mrfArray;        }        public bool Contains(string fileName)        {            if (!Loaded)            {                LoadMruList();            }            string lcFileName = fileName.ToLower();            foreach (MostRecentFile mrf in files)            {                string lcMrf = mrf.FileName.ToLower();                if (0 == String.Compare(lcMrf, lcFileName))                {                    return true;                }            }            return false;        }        public void Add(MostRecentFile mrf)        {            if (!Loaded)            {                LoadMruList();            }            if (!Contains(mrf.FileName))            {                files.Enqueue(mrf);                while (files.Count > maxCount)                {                    files.Dequeue();                }            }        }        public void Remove(string fileName)        {            if (!Loaded)            {                LoadMruList();            }            if (!Contains(fileName))            {                return;            }            Queue newQueue = new Queue();            foreach (MostRecentFile mrf in files)            {                if (0 != string.Compare(mrf.FileName, fileName, true))                {                    newQueue.Enqueue(mrf);                }            }            this.files = newQueue;        }        public void Clear()        {            if (!Loaded)            {                LoadMruList();            }            foreach (MostRecentFile mrf in this.GetFileList())            {                Remove(mrf.FileName);            }        }        public void LoadMruList()        {            try            {                this.loaded = true;                Clear();                for (int i = 0; i < MaxCount; ++i)                {                    try                    {                        string mruName = "MRU" + i.ToString();                        string fileName = (string)Settings.CurrentUser.GetString(mruName);                        if (fileName != null)                        {                            //Image thumb = Settings.CurrentUser.GetImage(mruName + "Thumb");                            if (fileName != null)// && thumb != null                            {                                MostRecentFile mrf = new MostRecentFile(fileName, null);//thumb                                Add(mrf);                            }                        }                    }                    catch                    {                        break;                    }                }            }            catch (Exception ex)            {                Tracing.Ping("Exception when loading MRU list: " + ex.ToString());                Clear();            }        }        public void SaveMruList()        {            if (Loaded)            {                MostRecentFile[] mrfArray = GetFileList();                for (int i = 0; i < MaxCount; ++i)                {                    string mruName = "MRU" + i.ToString();                    string mruThumbName = mruName + "Thumb";                    if (i >= mrfArray.Length)                    {                        Settings.CurrentUser.Delete(mruName);                        Settings.CurrentUser.Delete(mruThumbName);                    }                    else                    {                        MostRecentFile mrf = mrfArray[i];                        Settings.CurrentUser.SetString(mruName, mrf.FileName);                        //Settings.CurrentUser.SetImage(mruThumbName, mrf.Thumb);                    }                }            }        }    }}
 |