public TreeViewItem_Structure(bool isFile, string header, string baseFilePath, string baseStructPath, string partPath, TreeViewItem_Structure parent) { InitializeComponent(); mGrid_Header = FindResource("Grid_Header") as Grid; mCheckBox_Header = FindResource("CheckBox_Header") as CheckBox; mLabel_Header = FindResource("Label_Header") as Label; mGrid_Header.Children.Add(mCheckBox_Header); mGrid_Header.Children.Add(mLabel_Header); mIsFile = isFile; MHeader = header; mBaseFilePath = baseFilePath; mBaseStructPath = baseStructPath; mPartPath = partPath + "\\" + header; mStructFile = mBaseStructPath + partPath + "\\" + header; mMatchFile = mBaseFilePath + partPath + "\\" + header; mParent = parent; mIsChecked = false; DirectoryInfo dir = new DirectoryInfo(mStructFile); if (!isFile) { DirectoryInfo[] childDir = dir.GetDirectories(); foreach (DirectoryInfo select in childDir) { Items.Add(new TreeViewItem_Structure(false, select.Name, baseFilePath, baseStructPath, mPartPath, this)); } FileInfo[] childFile = dir.GetFiles(); foreach (FileInfo select in childFile) { Items.Add(new TreeViewItem_Structure(true, select.Name, baseFilePath, baseStructPath, mPartPath, this)); } } AddMenu(); }
private void Button_Generation_Click(object sender, RoutedEventArgs e) { try { if (!Directory.Exists(TextBox_StructurePath.Text)) { MessageBox.Show("无效的结构目录:" + TextBox_StructurePath.Text); return; } if (!Directory.Exists(TextBox_FilesPath.Text)) { MessageBox.Show("无效的文件目录:" + TextBox_FilesPath.Text); return; } if (!Directory.Exists(TextBox_OutputPath.Text)) { MessageBox.Show("无效的生成目录:" + TextBox_OutputPath.Text); return; } DirectoryInfo structDir = new DirectoryInfo(TextBox_StructurePath.Text); DirectoryInfo filesDir = new DirectoryInfo(TextBox_FilesPath.Text); DirectoryInfo outputDir = new DirectoryInfo(TextBox_OutputPath.Text); TreeView_Structure.Items.Clear(); root = new TreeViewItem_Structure(false, structDir.Name, outputDir.FullName, structDir.Parent.FullName, "", null); TreeView_Structure.Items.Add(root); List <ListViewItem_Base> items = filesDir.GetFiles().Select(r => new ListViewItem_Base(r)).ToList(); ListView_Files.Items.Clear(); foreach (ListViewItem_Base select in items) { ListView_Files.Items.Add(select); } root.CopyDirectory(items); SetNotMatchStructure(); SetOnlyUnusedFiles(); MessageBox.Show("生成完成!"); } catch (Exception error) { MessageBox.Show(error.Message); return; } }