protected void updateFoldersByTreeNode(PathTreeNode AParentNode) { PathTreeNode thisParentNode = (PathTreeNode)AParentNode; String thisFullPath = AParentNode.ExpandPath(); thisFullPath = ukt4dotnet.shared.utilities.IO.Paths.MainModule.NormalizedPathToOSPath(thisFullPath); thisFullPath += @"\"; string[] Directories = System.IO.Directory.GetDirectories(thisFullPath); foreach (string eachFolderFullPath in Directories) { String eachPlainFolderName = System.IO.Path.GetFileName(eachFolderFullPath); ItemInfoStruct thisItemInfo = new ItemInfoStruct(); thisItemInfo.IsDrive = false; thisItemInfo.Code = eachPlainFolderName; thisItemInfo.Text = eachPlainFolderName; thisItemInfo.LinkDestPath = ""; thisItemInfo.IsFile = false; thisItemInfo.IsFolder = true; thisItemInfo.IsLink = false; PathTreeNode thisTreeNode = addFoldersTreeviewNode(AParentNode, thisItemInfo); String AFullPath = thisTreeNode.ExpandPath(); thisItemInfo.Code = AFullPath; addItemsListviewNode(thisItemInfo); } // foreach foreach (ItemInfoStruct eachFolderInfo in this.FolderLinks) { PathTreeNode thisTreeNode = addFoldersTreeviewNode(AParentNode, eachFolderInfo); addItemsListviewNode(eachFolderInfo); } // foreach }
protected void updateFilesByTreeNode(PathTreeNode AParentNode) { PathTreeNode thisParentNode = (PathTreeNode)AParentNode; String thisFullPath = AParentNode.ExpandPath(); thisFullPath = ukt4dotnet.shared.utilities.IO.Paths.MainModule.NormalizedPathToOSPath(thisFullPath); thisFullPath += @"\"; string[] Files = System.IO.Directory.GetFiles(thisFullPath); foreach (string eachFileFullPath in Files) { String eachPlainFileName = System.IO.Path.GetFileName(eachFileFullPath); String eachFileExtension = System.IO.Path.GetExtension(eachPlainFileName); bool IsLink = (eachFileExtension == ".lnk"); if (! IsLink) { ItemInfoStruct thisItemInfo = new ItemInfoStruct(); thisItemInfo.IsDrive = false; thisItemInfo.Code = eachPlainFileName; thisItemInfo.Text = eachPlainFileName; thisItemInfo.LinkDestPath = ""; thisItemInfo.IsFile = true; thisItemInfo.IsFolder = false; thisItemInfo.IsLink = false; String AFullPath = ukt4dotnet.shared.utilities.IO.Paths.MainModule.OSPathToNormalizedPath(eachFileFullPath); thisItemInfo.Code = AFullPath; addItemsListviewNode(thisItemInfo); } // if (! IsLink) } // foreach foreach (ItemInfoStruct eachFileInfo in this.FileLinks) { addItemsListviewNode(eachFileInfo); } // foreach }
protected void updateDrivesByTreeNode(PathTreeNode AParentNode) { System.IO.DriveInfo[] Drives = System.IO.DriveInfo.GetDrives(); foreach (System.IO.DriveInfo eachDriveInfo in Drives) { if (eachDriveInfo.IsReady) { ItemInfoStruct thisItemInfo = new ItemInfoStruct(); thisItemInfo.Code = ukt4dotnet.shared.utilities.StrUtils.LeftCopyByLength(eachDriveInfo.Name, 1); thisItemInfo.Text = ukt4dotnet.shared.utilities.StrUtils.LeftCopyByLength(eachDriveInfo.Name, 2); thisItemInfo.LinkDestPath = ""; thisItemInfo.IsDrive = true; thisItemInfo.IsFile = false; thisItemInfo.IsFolder = true; thisItemInfo.IsLink = false; PathTreeNode thisTreeNode = addFoldersTreeviewNode(AParentNode, thisItemInfo); String AFullPath = thisTreeNode.ExpandPath(); thisItemInfo.Code = AFullPath; addItemsListviewNode(thisItemInfo); } // if (eachDriveInfo.IsReady) } // foreach }
protected void loadLinksByTreeNode(PathTreeNode AParentNode) { PathTreeNode thisParentNode = (PathTreeNode)AParentNode; if (this.RootNode != thisParentNode) { String thisFullPath = AParentNode.ExpandPath(); thisFullPath = ukt4dotnet.shared.utilities.IO.Paths.MainModule.NormalizedPathToOSPath(thisFullPath); thisFullPath += @"\"; string[] Files = System.IO.Directory.GetFiles(thisFullPath); foreach (string eachFileFullPath in Files) { String eachPlainFileName = System.IO.Path.GetFileName(eachFileFullPath); String eachFileExtension = System.IO.Path.GetExtension(eachPlainFileName); bool IsLink = (eachFileExtension == ".lnk"); if (IsLink) { ItemInfoStruct thisItemInfo = new ItemInfoStruct(); thisItemInfo.IsDrive = false; thisItemInfo.IsLink = true; String AOSPath = string.Empty; String ADescr = string.Empty; // to-do: add showfilelinks, showfolderlinks bool Result = GetShortcutTargetFile(eachFileFullPath, out AOSPath, out ADescr); if (Result) { String ANormalizedPath = ukt4dotnet.shared.utilities.IO.Paths.MainModule.OSPathToNormalizedPath(AOSPath); thisItemInfo.LinkDestPath = ANormalizedPath; // file or folder ? thisItemInfo.IsFolder = (System.IO.Directory.Exists(AOSPath)); thisItemInfo.IsFile = (!thisItemInfo.IsFolder); String AFullPath = ukt4dotnet.shared.utilities.IO.Paths.MainModule.OSPathToNormalizedPath(eachFileFullPath); thisItemInfo.Code = AFullPath; String DestFullPath = System.IO.Path.GetFileName(AOSPath); //thisItemInfo.Text = DestFullPath; thisItemInfo.Text = ADescr; if (thisItemInfo.IsFolder) { this.FolderLinks.Add(thisItemInfo); } else { this.FileLinks.Add(thisItemInfo); } } } // if (IsLink) } // foreach } // if (this.RootNode != thisParentNode) }
protected void addItemsListviewNode(ItemInfoStruct thisItemInfo) { PathListViewItem eachListViewItem = new PathListViewItem(); eachListViewItem.Code = thisItemInfo.Code; eachListViewItem.Text = thisItemInfo.Text; eachListViewItem.IsFolder = thisItemInfo.IsFolder; eachListViewItem.IsFile = thisItemInfo.IsFile; eachListViewItem.IsLink = thisItemInfo.IsLink; eachListViewItem.LinkDestPath = thisItemInfo.LinkDestPath; if (thisItemInfo.IsDrive) { eachListViewItem.ImageIndex = (thisItemInfo.IsLink ? 4 : 2); } else { if (thisItemInfo.IsFolder) { eachListViewItem.ImageIndex = (thisItemInfo.IsLink ? 5 : 3); } else { eachListViewItem.ImageIndex = 0; } } this.ItemsListView.ItemsWrapper.Add(eachListViewItem); }
protected PathTreeNode addFoldersTreeviewNode(PathTreeNode AParentNode, ItemInfoStruct thisItemInfo) { PathTreeNode Result = null; // add new node as child of current node Result = new PathTreeNode(); Result.Code = thisItemInfo.Code; Result.Text = thisItemInfo.Text; Result.IsFolder = thisItemInfo.IsFolder; Result.IsFile = thisItemInfo.IsFile; Result.IsLink = thisItemInfo.IsLink; Result.LinkDestPath = thisItemInfo.LinkDestPath; if (thisItemInfo.IsDrive) { // drives doesn't have "shorcuts" Result.ImageIndex = 3; Result.SelectedImageIndex = 4; } else { Result.ImageIndex = (thisItemInfo.IsLink ? 7 : 5); Result.SelectedImageIndex = (thisItemInfo.IsLink ? 8 : 6); } AParentNode.Nodes.Add(Result); return Result; }