public void CopyChildren(TreeNode parent, TreeNode original) { TreeNode newTn; foreach (TreeNode tn in original.Nodes) { newTn = new TreeNode(tn.Text); parent.Nodes.Add(newTn); CopyChildren(newTn, tn); if (newTn.ToString().Contains(".")) { newTn.ImageIndex = 0; } else { newTn.ImageIndex = 1; } } }
public void CopyTreeNodes(TreeView treeview1, TreeView treeview2) { treeview2.ImageList = fileDirImgList; treeview2.SelectedImageIndex = 2; TreeNode newTn; foreach (TreeNode tn in treeview1.Nodes) { newTn = new TreeNode(tn.Text); CopyChildren(newTn, tn); if (newTn.ToString().Contains(".")) { newTn.ImageIndex = 0; } else { newTn.ImageIndex = 1; } treeview2.Nodes.Add(newTn); } }
public void FillTreeNode(TreeNode node, string root) { if (root == null) { throw new ArgumentNullException("root"); } try { Cursor = Cursors.WaitCursor; var text = node.FullPath; if (string.CompareOrdinal(text, "\\") == 0) { text = node.ToString(); } else { if (string.CompareOrdinal(text.Substring(1, 1), ":") != 0) { root = node.Text; text = root + text.Substring(text.IndexOf("\\", StringComparison.Ordinal)); } } var directoryInfo = new DirectoryInfo(text); var directories = directoryInfo.GetDirectories(); var comparer = new Comparer(CultureInfo.InvariantCulture); Array.Sort(directories, comparer); foreach (var current in from d in directories select new TreeNode(d.Name, 0, 1) { Tag = node.Tag.ToString() }) { node.Nodes.Add(current); current.Nodes.Add(""); } var files = Directory.GetFiles(text, FileExplorerControl.Instance.Filter); Array.Sort(files); var array = files; var array2 = array; foreach (var path in array2) { var treeNode = new TreeNode(Path.GetFileName(path)) { Tag = node.Tag.ToString() }; var extension = Path.GetExtension(path); if (extension != null) { var text2 = extension.ToLower(); var text3 = text2; // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (text3 == null) { goto IL_260; } if (text3 != ".src") { if (text3 != ".dat") { if (text3 != ".sub") { if (text3 != ".zip") { goto IL_260; } treeNode.SelectedImageIndex = 6; treeNode.ImageIndex = 6; } else { treeNode.SelectedImageIndex = 6; treeNode.ImageIndex = 6; } } else { treeNode.SelectedImageIndex = 6; treeNode.ImageIndex = 6; } } else { treeNode.SelectedImageIndex = 6; treeNode.ImageIndex = 6; } goto IL_275; IL_260: treeNode.SelectedImageIndex = 6; treeNode.ImageIndex = 6; } IL_275: node.Nodes.Add(treeNode); } Cursor = Cursors.Default; } catch (Exception ex) { var msg = new ErrorMessage("ExplorerClass.FillTreeNode", ex, MessageType.Error); Messenger.Default.Send<IMessage>(msg); Cursor = Cursors.Default; } }
/// <summary> /// Populate files info into listview /// </summary> /// <param name="nodeCurrent"></param> protected void PopulateFiles(TreeNode nodeCurrent) { //Populate listview with files string[] lvData = new string[4]; //update status updateStatus("Getting directory files..."); //clear list InitListView(); if (nodeCurrent.SelectedImageIndex != 0) { //check path if(Directory.Exists((string) getFullPath(nodeCurrent.FullPath)) == false) { MessageBox.Show("Directory or path " + nodeCurrent.ToString() + " does not exist."); } else { try { string[] stringFiles = Directory.GetFiles(getFullPath(nodeCurrent.FullPath)); string stringFileName = ""; DateTime dtCreateDate, dtModifyDate; Int64 lFileSize = 0; //loop throught all files foreach (string stringFile in stringFiles) { stringFileName = stringFile; FileInfo objFileSize = new FileInfo(stringFileName); lFileSize = objFileSize.Length; dtCreateDate = objFileSize.CreationTime; //GetCreationTime(stringFileName); dtModifyDate = objFileSize.LastWriteTime; //GetLastWriteTime(stringFileName); //create listview data lvData[0] = GetPathName(stringFileName); lvData[1] = formatSize(lFileSize); //check if this machine have Day light saving time set if (TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) == true) { //check if file is in local current day light saving time if (TimeZone.CurrentTimeZone.IsDaylightSavingTime(dtCreateDate) == false) { //not in day light saving time adjust time lvData[2] = formatDate(dtCreateDate.AddHours(1)); } else { //is in day light saving time adjust time lvData[2] = formatDate(dtCreateDate); } //check if file is in local current day light saving time if (TimeZone.CurrentTimeZone.IsDaylightSavingTime(dtModifyDate) == false) { //not in day light saving time adjust time lvData[3] = formatDate(dtModifyDate.AddHours(1)); } else { //not in day light saving time adjust time lvData[3] = formatDate(dtModifyDate); } } else { //machine Day Light Saving Time not set lvData[2] = formatDate(dtCreateDate); lvData[3] = formatDate(dtModifyDate); } //Create actual list item ListViewItem lvItem = new ListViewItem(lvData,0); lvFiles.Items.Add(lvItem); } } catch (IOException) { MessageBox.Show("Error: Drive not ready or directory does not exist."); } catch (UnauthorizedAccessException) { MessageBox.Show("Error: Drive or directory access denided."); } catch (Exception e) { MessageBox.Show("Error: " + e); } } } //update status updateStatus("Ready"); }
protected void PopulateDirectory(TreeNode nodeCurrent, TreeNodeCollection nodeCurrentCollection) { TreeNode nodeDir; int imageIndex = 2; //unselected image index int selectIndex = 3; //selected image index if (nodeCurrent.SelectedImageIndex != 0) { //populate treeview with folders try { //check path if(Directory.Exists(getFullPath(nodeCurrent.FullPath)) == false) { MessageBox.Show("Directory or path " + nodeCurrent.ToString() + " does not exist."); } else { //populate files PopulateFiles(nodeCurrent); string[] stringDirectories = Directory.GetDirectories(getFullPath(nodeCurrent.FullPath)); string stringFullPath = ""; string stringPathName = ""; //loop throught all directories foreach (string stringDir in stringDirectories) { stringFullPath = stringDir; stringPathName = GetPathName(stringFullPath); //create node for directories nodeDir = new TreeNode(stringPathName.ToString(),imageIndex,selectIndex); nodeCurrentCollection.Add(nodeDir); } //expand tree node nodeCurrent.ExpandAll(); } } catch (IOException) { MessageBox.Show("Error: Drive not ready or directory does not exist."); } catch (UnauthorizedAccessException) { MessageBox.Show("Error: Drive or directory access denided."); } catch (Exception e) { MessageBox.Show("Error: " + e); } } }
//显示目录列表 protected void PopulatePhoneDirectory(TreeNode nodeCurrent, TreeNodeCollection nodeCurrentCollection) { TreeNode nodeDir; int imageIndex = 2; //unselected image index int selectIndex = 3; //selected image index //if (nodeCurrent.SelectedImageIndex != 0) { //populate treeview with folders try { //check path if (AdbFile.DirExists((string)nodeCurrent.Tag) == false) { MessageBox.Show("Directory or path " + nodeCurrent.ToString() + " does not exist."); } else { //populate files /*PopulatePcFiles(nodeCurrent); string[] stringDirectories = Directory.GetDirectories(getPcFullPath(nodeCurrent.FullPath)); string stringFullPath = ""; string stringPathName = ""; //loop throught all directories foreach (string stringDir in stringDirectories) { stringFullPath = stringDir; stringPathName = GetPcFileName(stringFullPath); //create node for directories nodeDir = new TreeNode(stringPathName.ToString(), imageIndex, selectIndex); nodeCurrentCollection.Add(nodeDir); }*/ //clear list InitPhoneListView(); strPhoneDir = (string)nodeCurrent.Tag; bool bret = false; if (nodeCurrent.SelectedImageIndex == 0) bret = AdbFile.GetAllFileInfo("/", out phoneFiles); else bret = AdbFile.GetAllFileInfo(strPhoneDir, out phoneFiles); if (!bret) return; for (int i = 0; i < phoneFiles.Count; i++) { PhoneFileInfo info = phoneFiles[i]; string[] lvData = new string[5]; if (info != null) { lvData[0] = info.name; lvData[1] = info.size; lvData[2] = info.modifyDate+" "+info.modifyTime; lvData[3] = info.permission; if (!info.isFile) { //if (!info.isLink) { nodeDir = new TreeNode(info.name, imageIndex, selectIndex); if (info.isLink) nodeDir.Tag = strPhoneDir+info.linkName; else nodeDir.Tag = strPhoneDir + "/" + info.name; nodeCurrentCollection.Add(nodeDir); } if (info.isLink) { lvData[4] = info.linkName; } ListViewItem lvItem = new ListViewItem(lvData, 0); lvItem.ImageKey = fileIconKey[DIR_IMAGE_KEY]; lvItem.Tag = info; listPhoneFile.Items.Add(lvItem); } else { if (info.isLink) { lvData[4] = info.linkName; } ListViewItem lvItem = new ListViewItem(lvData, 0); string ext = ""; if (info.name.LastIndexOf('.') >=0) { ext = info.name.Substring(info.name.LastIndexOf('.')); } if (ext.Length > 0) { lvItem.ImageKey = GetFileIconKey(ext); } else { lvItem.ImageKey = fileIconKey[FILE_NOEXT_IMAGE_KEY]; } lvItem.Tag = info; listPhoneFile.Items.Add(lvItem); } } } } } catch (IOException e) { MessageBox.Show("Error: Drive not ready or directory does not exist."); } catch (UnauthorizedAccessException e) { MessageBox.Show("Error: Drive or directory access denided."); } catch (Exception e) { MessageBox.Show("Error: " + e); } } }
//显示目录列表 protected void PopulatePhoneDirectory(TreeNode nodeCurrent, TreeNodeCollection nodeCurrentCollection) { TreeNode nodeDir; int imageIndex = 2; //unselected image index int selectIndex = 3; //selected image index //if (nodeCurrent.SelectedImageIndex != 0) { //populate treeview with folders try { //check path if (AdbFile.DirExists(getPhoneFullPath(nodeCurrent.FullPath)) == false) { MessageBox.Show("Directory or path " + nodeCurrent.ToString() + " does not exist."); } else { //populate files /*PopulatePcFiles(nodeCurrent); string[] stringDirectories = Directory.GetDirectories(getPcFullPath(nodeCurrent.FullPath)); string stringFullPath = ""; string stringPathName = ""; //loop throught all directories foreach (string stringDir in stringDirectories) { stringFullPath = stringDir; stringPathName = GetPcFileName(stringFullPath); //create node for directories nodeDir = new TreeNode(stringPathName.ToString(), imageIndex, selectIndex); nodeCurrentCollection.Add(nodeDir); }*/ bool bret = false; if (nodeCurrent.SelectedImageIndex == 0) bret = AdbFile.GetAllFileInfo("/", out phoneFiles); else bret = AdbFile.GetAllFileInfo(getPhoneFullPath(nodeCurrent.FullPath), out phoneFiles); if (!bret) return; for (int i = 0; i < phoneFiles.Count; i++) { PhoneFileInfo info = phoneFiles[i]; if (info != null) { if (!info.isFile) { nodeDir = new TreeNode(info.name, imageIndex, selectIndex); nodeCurrentCollection.Add(nodeDir); } } } } } catch (IOException e) { MessageBox.Show("Error: Drive not ready or directory does not exist."); } catch (UnauthorizedAccessException e) { MessageBox.Show("Error: Drive or directory access denided."); } catch (Exception e) { MessageBox.Show("Error: " + e); } } }
//显示文件列表 protected void PopulatePcFiles(TreeNode nodeCurrent) { //Populate listview with files string[] lvData = new string[4]; //clear list InitPcListView(); if (nodeCurrent.SelectedImageIndex != 0) { //check path if (Directory.Exists((string)getPcFullPath(nodeCurrent.FullPath)) == false) { MessageBox.Show("Directory or path " + nodeCurrent.ToString() + " does not exist."); } else { try { string[] stringFiles = Directory.GetFiles(getPcFullPath(nodeCurrent.FullPath)); string stringFileName = ""; DateTime dtCreateDate, dtModifyDate; Int64 lFileSize = 0; //loop throught all files foreach (string stringFile in stringFiles) { stringFileName = stringFile; FileInfo objFileSize = new FileInfo(stringFileName); lFileSize = objFileSize.Length; dtCreateDate = objFileSize.CreationTime; //GetCreationTime(stringFileName); dtModifyDate = objFileSize.LastWriteTime; //GetLastWriteTime(stringFileName); //create listview data lvData[0] = GetPcFileName(stringFileName); lvData[1] = formatSize(lFileSize); //check if file is in local current day light saving time if (TimeZone.CurrentTimeZone.IsDaylightSavingTime(dtCreateDate) == false) { //not in day light saving time adjust time lvData[2] = formatDate(dtCreateDate.AddHours(1)); } else { //is in day light saving time adjust time lvData[2] = formatDate(dtCreateDate); } //check if file is in local current day light saving time if (TimeZone.CurrentTimeZone.IsDaylightSavingTime(dtModifyDate) == false) { //not in day light saving time adjust time lvData[3] = formatDate(dtModifyDate.AddHours(1)); } else { //not in day light saving time adjust time lvData[3] = formatDate(dtModifyDate); } //Create actual list item ListViewItem lvItem = new ListViewItem(lvData, 0); // Set a default icon for the file. Icon iconForFile = SystemIcons.WinLogo; iconForFile = Icon.ExtractAssociatedIcon(stringFileName); // Check to see if the image collection contains an image // for this extension, using the extension as a key. if (!imageListFile.Images.ContainsKey(objFileSize.Extension)) { // If not, add the image to the image list. iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(stringFileName); imageListFile.Images.Add(objFileSize.Extension, iconForFile); } lvItem.ImageKey = objFileSize.Extension; listPCFile.Items.Add(lvItem); } } catch (IOException e) { MessageBox.Show("Error: Drive not ready or directory does not exist."); } catch (UnauthorizedAccessException e) { MessageBox.Show("Error: Drive or directory access denided."); } catch (Exception e) { MessageBox.Show("Error: " + e); } } } }