/// <summary> /// 更改文件夹 单击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button1_Click(object sender, EventArgs e) { if (XmlFile.ChoiceLnkFile()) { Uninstall(); Resources.dicThis = new Dictionary <string, LnkModel>(); Resources.dicThisInt = new Dictionary <int, LnkModel>(); List <LnkModel> lnkList = new LnkPath().ListLnkModel(); if (lnkList != null) { foreach (LnkModel lnkModel in lnkList) { //没有注册 放入 if (Resources.HandleDicThisInt(lnkModel.LnkName) && Resources.HandleDicThis(lnkModel.LnkName)) { Resources.dicThis.Add(lnkModel.LnkName, lnkModel); } } lnkList = Resources.DicThisToLnkList(); dataGridView1.DataSource = lnkList; } BindingDgv(false); } }
/// <summary> /// 获取路径文件,绑定列表数据,同步程序数据 /// </summary> /// <param name="flagReset">是否同步数据</param> private void BindingDgv(bool flagReset) { List <LnkModel> lnkList = new LnkPath().ListLnkModel(); if (lnkList == null) //有其它的文件 { DialogResult dr = MessageBox.Show("文件夹有非 lnk 文件!请修改路径或者删除非 lnk 文件。", "选择提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (dr == DialogResult.Cancel) { Application.Exit(); } if (dr == DialogResult.OK) { XmlFile.ChoiceLnkFile(); BindingDgv(false); } } foreach (LnkModel lnkModel in lnkList) { if (Resources.HandleDicThisInt(lnkModel.LnkName)) { if (Resources.HandleDicThis(lnkModel.LnkName)) { Resources.dicThis.Add(lnkModel.LnkName, lnkModel); } } } List <LnkModel> lnkListData = Resources.DicThisToLnkList(); if (flagReset) { List <LnkModel> lnkListString = new List <LnkModel>(); foreach (LnkModel item in lnkListData) //有的数据 { bool flag = true; foreach (var item2 in lnkList) //获取到的数据 { if (item.LnkName == item2.LnkName) { flag = false; } } if (flag) { lnkListString.Add(item); } } foreach (LnkModel item in lnkListString) { if (item.id == 0) //没有注册过 { Resources.dicThis.Remove(item.LnkName); } else { Resources.dicThisInt.Remove(item.id); SystemHotKey.UnregisterHotKey(Handle, item.id); } } dataGridView1.DataSource = lnkList; } if (lnkList.Count == 0) { try { Resources.dicThis.Clear(); Resources.dicThisInt.Clear(); } catch (Exception) { //throw; } lnkListData.Clear(); } dataGridView1.DataSource = lnkListData; //注册快捷键 Resources.RegistrationKey(Handle); }