// --- 导入文件夹 --- /// <summary> /// 将文件夹导入 /// </summary> /// <param name="Dir">当前目录信息</param> /// <param name="Node">当前目录的节点</param> private void importFloder(DirectoryInfo Dir, TreeNode Node) { // 获得节点 FCYResPackageFloderNode tFloder = (FCYResPackageFloderNode)Node.Tag; // 处理所有文件夹 foreach (DirectoryInfo x in Dir.GetDirectories()) { TreeNode tNewNode = new TreeNode(Path.GetFileName(x.FullName), 0, 0); tNewNode.Tag = new FCYResPackageFloderNode(tFloder, tNewNode.Text); try { tFloder.Add((FCYResPackageNode)tNewNode.Tag); } catch (FCYExcpNameErr) { showErr("添加节点时遭遇错误,该节点可能已经存在。\n\n文件:" + x.FullName); continue; } importFloder(x, tNewNode); Node.Nodes.Add(tNewNode); } // 处理所有文件 foreach (FileInfo x in Dir.GetFiles()) { TreeNode tNewNode = new TreeNode(Path.GetFileName(x.FullName), 1, 1); tNewNode.Tag = new FCYResPackageDataNode((FCYResPackage)treeView_Main.Tag, tFloder, tNewNode.Text, x.FullName); try { tFloder.Add((FCYResPackageNode)tNewNode.Tag); } catch (FCYExcpNameErr) { showErr("添加节点时遭遇错误,该节点可能已经存在。\n\n文件:" + x.FullName); continue; } Node.Nodes.Add(tNewNode); } GC.Collect(); }
// --- 创建文件夹 --- private void ToolStripMenuItem_CreateFloder_Click(object sender, EventArgs e) { // 获得父节点 TreeNode tParent = treeView_Main.SelectedNode; if (tParent != null) { // 检查父节点 if (!((FCYResPackageNode)tParent.Tag).IsFloder()) { showErr("请选择一个文件夹节点。"); return; } // 获得父节点 FCYResPackageFloderNode tParentFloder = (FCYResPackageFloderNode)tParent.Tag; // 获得新节点名称 string tNodeName = ""; if (!CreateFloderForm.OpenCreateFloderForm(treeView_Main.SelectedNode.FullPath, ref tNodeName)) { return; } if (tNodeName == "") { showErr("无效的名称。"); return; } // 创建节点 FCYResPackageFloderNode tNewSubNode = new FCYResPackageFloderNode(tParentFloder, tNodeName); // 尝试加入 try { tParentFloder.Add(tNewSubNode); } catch { showErr("节点名已存在或者无效。"); return; } // 创建树节点 TreeNode tTreeNode = new TreeNode(tNodeName, 0, 0); tTreeNode.Tag = tNewSubNode; // 加入 tParent.Nodes.Add(tTreeNode); tParent.Expand(); } }
// --- 创建流 --- private void ToolStripMenuItem_CreateStream_Click(object sender, EventArgs e) { // 获得父节点 TreeNode tParent = treeView_Main.SelectedNode; if (tParent != null) { // 检查父节点 if (!((FCYResPackageNode)tParent.Tag).IsFloder()) { showErr("请选择一个文件夹节点。"); return; } // 获得父节点 FCYResPackageFloderNode tParentFloder = (FCYResPackageFloderNode)tParent.Tag; // 获得新节点名称 string tNodeName = ""; string tFileName = ""; string tAddition = ""; bool tCompress = false; if (!CreateStreamForm.OpenCreateStreamForm(treeView_Main.SelectedNode.FullPath, ref tNodeName, ref tFileName, ref tAddition, ref tCompress)) { return; } if (tNodeName == "") { showErr("无效的名称。"); return; } // 创建节点 FCYResPackageDataNode tNewSubNode = new FCYResPackageDataNode((FCYResPackage)treeView_Main.Tag, tParentFloder, tNodeName, tFileName); // 尝试加入 try { tParentFloder.Add(tNewSubNode); } catch { showErr("节点名已存在或者无效。"); return; } // 设置属性 tNewSubNode.IsCompressed = tCompress; tNewSubNode.AdditionData = tAddition; // 创建树节点 TreeNode tTreeNode = new TreeNode(tNodeName, 1, 1); tTreeNode.Tag = tNewSubNode; // 加入 tParent.Nodes.Add(tTreeNode); tParent.Expand(); } }