Beispiel #1
0
        /// <summary>
        /// Dictionary转List;包含已注册和未注册
        /// </summary>
        /// <returns>所有的程序信息</returns>
        public static List <LnkModel> DicThisToLnkList()
        {
            List <LnkModel> lnkList = new List <LnkModel>();

            //未注册快捷键的程序
            foreach (var item in Resources.dicThis)
            {
                LnkModel lnkModel = new LnkModel();
                lnkModel.LnkName = item.Value.LnkName;
                lnkModel.HotKey  = item.Value.HotKey;
                lnkModel.id      = 0;

                lnkList.Add(lnkModel);
            }
            //已注册快捷键的程序
            if (Resources.dicThisInt != null)
            {
                foreach (var item in Resources.dicThisInt)
                {
                    LnkModel lnkModel = new LnkModel();
                    lnkModel.LnkName = item.Value.LnkName;
                    lnkModel.HotKey  = item.Value.HotKey;
                    lnkModel.id      = item.Value.id;

                    lnkList.Add(lnkModel);
                }
            }
            return(lnkList);
        }
Beispiel #2
0
        /// <summary>
        /// 读取指定格式的xml文件,获取已注册过的快捷方式信息和文件夹路径
        /// </summary>
        /// <returns> Dictionary 对象</returns>
        public static Dictionary <int, LnkModel> ReadXmlFile()
        {
            //读取不到配置文件
            if (!File.Exists(Resources.exePath + "\\config.xml"))
            {
                ChoiceLnkFile();
                return(null);
            }

            Dictionary <int, LnkModel> dicThisInt = new Dictionary <int, LnkModel>();
            XmlDocument doc = new XmlDocument();

            doc.Load(Resources.exePath + "\\config.xml");
            XmlNodeList list   = doc.SelectNodes("/KeyRegister/dicThisInt");
            int         MaxNum = 0;

            foreach (XmlElement item in list)
            {
                LnkModel lnkModel = new LnkModel();
                lnkModel.id      = Convert.ToInt32(item.GetElementsByTagName("id")[0].InnerText);
                lnkModel.LnkName = item.GetElementsByTagName("LnkName")[0].InnerText;
                lnkModel.LnkPath = item.GetElementsByTagName("LnkPath")[0].InnerText;
                lnkModel.HotKey  = item.GetElementsByTagName("HotKey")[0].InnerText;

                dicThisInt.Add(lnkModel.id, lnkModel);
                if (lnkModel.id > MaxNum)
                {
                    MaxNum = lnkModel.id;
                }
            }
            Resources.MaxNum = MaxNum + 1;
            //读取文件夹路径
            XmlNodeList listLnkPath = doc.SelectNodes("/KeyRegister/lnkPath");

            if (listLnkPath.Count == 0)
            {
                ChoiceLnkFile();
            }
            else
            {
                foreach (XmlElement item in listLnkPath)
                {
                    try
                    {
                        Resources.lnkPath = item.GetElementsByTagName("path")[0].InnerText;
                    }
                    catch (Exception)
                    {
                        ChoiceLnkFile();
                    }
                    break;
                }
            }

            return(dicThisInt);
        }
Beispiel #3
0
        /// <summary>
        /// 路径文件读取
        /// </summary>
        /// <returns></returns>
        public List <LnkModel> ListLnkModel()
        {
            List <LnkModel> lnkList = new List <LnkModel>();
            List <string>   list    = new List <string>();//定义list变量,存放获取到的路径

            list = getPath(Resources.lnkPath);
            foreach (String item in list)
            {
                LnkModel lnkModel = new LnkModel();
                String   lnkPath  = ObtainLnkPath(item);
                if (lnkPath == "0")
                {
                    return(null);
                }
                lnkModel.LnkPath = lnkPath.Substring(0, lnkPath.LastIndexOf(".exe") + 4);
                //lnkModel.LnkPath = lnkPath.Substring(0,LnkPath);
                lnkModel.LnkName = item.Substring(item.LastIndexOf("\\") + 1, item.Count() - item.LastIndexOf("\\") - 5);

                lnkList.Add(lnkModel);
            }
            return(lnkList);
        }