private void Refresh() { MenusLib.CanEdit = false; try { listV.Items.Clear(); BackUp(_typeStr); _winOneMenuList = MenusLib.GetDescriptionByXml(_winOneMenuList); if (_winOneMenuList.Count <= 0) { ClearTextBoxInGroupBox(); } BindingListV(_winOneMenuList); if (listV.Items.Count > 0) { listV.Items[0].Selected = true; } MenusLib.CanEdit = true; } catch (Exception ex) { MessageBox.Show(ex.ToString()); //this.Text = " ----修改失败" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } }
public new List <OneMenu> GetMenuList(string[] strPathArr) { List <OneMenu> oneMenuList = new List <OneMenu>(); foreach (string path in strPathArr) { string sourcePath = path; List <OneMenu> sourceOneMenuList = MenusLib.GetMenuList(sourcePath); string backupPath = AddBackupName(sourcePath); List <OneMenu> backupOneMenuList = MenusLib.GetMenuList(backupPath); oneMenuList = oneMenuList.AddOneMenuList(sourceOneMenuList).AddOneMenuList(backupOneMenuList); } return(oneMenuList); }
public List <OneMenu> GetMenuList() { //string[] strArr = new[] //{ // @"HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell" //}; List <OneMenu> oneMenuList = new List <OneMenu>(); //= GetMenuList(strArr) if (Directory.Exists(_sendToSource)) { var files = Directory.GetFiles(_sendToSource, "*.*"); foreach (var file in files) { OneMenu oneMenu = new OneMenu(); oneMenu.Checked = true; oneMenu.FileName = MenusLib.GetFileName(file); oneMenu.Name = MenusLib.GetFileName(file); oneMenu.FilePath = GetFilePath(file); oneMenu.RegPath = file; oneMenuList.Add(oneMenu); } } if (Directory.Exists(_sendToBackup)) { var files = Directory.GetFiles(_sendToBackup, "*.*"); foreach (var file in files) { OneMenu oneMenu = new OneMenu(); oneMenu.Checked = false; oneMenu.FileName = MenusLib.GetFileName(file); oneMenu.Name = MenusLib.GetFileName(file); oneMenu.FilePath = GetFilePath(file); oneMenu.RegPath = file; oneMenuList.Add(oneMenu); } } else { Directory.CreateDirectory(_sendToBackup); } GetVersionInfo(oneMenuList); return(oneMenuList); }
private void AddFileType() { if (_xml == null) { XmlDocument doc = new XmlDocument(); doc.Load("info.xml"); _xml = doc.SelectNodes("/RightMenus/FileType"); foreach (XmlNode item in _xml) { _fileNameStr = item.Attributes["Name"].Value; bool exist = MenusLib.ExistFileType(_fileNameStr); if (exist) { string text = item.Attributes["Text"].Value; TreeNode lnkFile = new TreeNode() { Text = text, Name = "FileType" }; exFilesType.Nodes.Add(lnkFile); } } //string names = _xml[0].Attributes["Name"].Value; //if (names.EndsWith(";")) //{ // names = names.TrimEnd(';'); //} //string[] nameArr = names.Split(';'); //foreach (string name in nameArr) //{ // string regPath = @"HKEY_CLASSES_ROOT\"+ name; // string str = RegHelper.GetValueData(regPath,"").ToString(); // FileType fileType = new FileType(); // List<OneMenu> oneMenuList = fileType.GetMenuList(str); //} } }
private void GetVersionInfo(List <OneMenu> oneMenuList) { foreach (OneMenu oneMenu in oneMenuList) { try { string filePath = MenusLib.GetFilePath(oneMenu.FilePath); oneMenu.FilePath = filePath; oneMenu.FileName = MenusLib.GetFileName(filePath); oneMenu.Md5 = MenusLib.GetMd5(filePath).ToUpper(); FileVersionInfo fileVerInfo = MenusLib.GetFileVersionInfo(filePath); oneMenu.Version = fileVerInfo.ProductVersion; oneMenu.Company = fileVerInfo.LegalCopyright; FileInfo fileInfo = MenusLib.GetFileInfo(filePath); oneMenu.Size = MenusLib.GetFileSize(fileInfo.Length) + " (" + (fileInfo.Length + "字节)"); oneMenu.Create = fileInfo.CreationTime.ToString("yyyy/MM/dd HH:mm:ss"); } catch (Exception ex) { } } }
private void BindingListV(List <OneMenu> oneMenuList) { if (oneMenuList == null) { listV.Items.Clear(); ClearTextBoxInGroupBox(); MessageBox.Show("没有找到数据!"); return; } int chkIndex = 0; ListViewItem[] itemsBakUp = new ListViewItem[oneMenuList.Count]; _imageListSmall.Images.Clear(); _imageListSmall.ColorDepth = ColorDepth.Depth32Bit; //防止图片失真 if (oneMenuList != null) { foreach (var oneMenu in oneMenuList) { System.Drawing.Icon icon = null; if (!string.IsNullOrEmpty(oneMenu.DefaultIcon)) { string[] iconStrArr = oneMenu.DefaultIcon.Split(','); if (!string.IsNullOrEmpty(oneMenu.DefaultIcon) && iconStrArr.Length == 2) { if (!iconStrArr[0].Contains(":") && (iconStrArr[0].EndsWith(".dll") || iconStrArr[0].EndsWith(".exe"))) { string sysStrPath = System.Environment.GetEnvironmentVariable("path"); string[] sysPathArr = sysStrPath.Split(';'); string filePath = sysPathArr + "\\" + iconStrArr[0]; if (File.Exists(filePath)) { iconStrArr[0] = filePath; } } GetSystemIcon getSystemIcon = new GetSystemIcon(); icon = getSystemIcon.extractIcon(iconStrArr[0], int.Parse(iconStrArr[1])); } } else { icon = MenusLib.GetIcon(oneMenu.FilePath); } if (icon == null) { string selfPath = this.GetType().Assembly.Location; icon = Icon.ExtractAssociatedIcon(selfPath); } _imageListSmall.Images.Add(icon); ListViewItem lvItem = new ListViewItem("", chkIndex); lvItem.Text = oneMenu.Name; lvItem.Name = oneMenu.FilePath; lvItem.ToolTipText = oneMenu.RegPath; lvItem.SubItems.Add(oneMenu.Description); lvItem.SubItems.Add(oneMenu.FilePath); lvItem.SubItems.Add(oneMenu.Company); //lvItem.SubItems.Add(oneMenu.Ssid); lvItem.Checked = oneMenu.Checked; itemsBakUp[chkIndex] = lvItem; chkIndex++; } } listV.Items.AddRange(itemsBakUp); listV.SmallImageList = _imageListSmall; _winOneMenuList = oneMenuList; }