private void GetFiles(XMLFileList xml, DirectoryInfo dir, string replaceFolder) { var rootFolder = new DirectoryInfo(GlobalData.config.config_Create.rootDirectory).Name; foreach (var item1 in Directory.GetFiles(dir.FullName, "*", SearchOption.AllDirectories)) { RunDoShowProgressBar(++pvalue, pmax); RunDoShowPercent((pvalue / (float)pmax).ToString("0%")); var item = new FileInfo(item1); RunDoShowCheckInfo("检测文件:" + item.Name + "\n"); var fileinfo = new XMLFileInfo(); var file = new FileInfo(item.FullName); fileinfo.Name = item.Name; RunDoShowCheckInfo("计算Hash值..\n"); fileinfo.Hash = Utility.GetMD5Value(item.FullName); RunDoShowCheckInfo("Hash值:" + fileinfo.Hash + "\n"); var oP = rootFolder + item.FullName.Split(new string[] { rootFolder }, StringSplitOptions.RemoveEmptyEntries)[1]; fileinfo.Address = oP; fileinfo.InstallPath = oP.Replace(replaceFolder, ""); RunDoShowCheckInfo("当前文件检测完毕!\n"); if (versionXML.x_ProcessInfo.path == item.FullName) { versionXML.x_ProcessInfo.path = fileinfo.InstallPath; } xml.Files.Add(fileinfo); } //foreach (var item in dir.GetDirectories()) //{ // RunDoShowCheckInfo("进入目录:" + item.FullName + "\n"); // GetFiles(xml, item, replaceFolder); //} }
private void GetFiles(XMLFileList xml, DirectoryInfo dir, string replaceFolder) { var rootFolder = new DirectoryInfo(root).Name; foreach (var item in dir.GetFiles()) { RunDoShowInfo("检测文件:" + item.Name + "\n"); var fileinfo = new XMLFileInfo(); var file = new FileInfo(item.FullName); fileinfo.Name = item.Name; RunDoShowInfo("计算Hash值..\n"); fileinfo.Hash = Utility.GetMD5Value(item.FullName); RunDoShowInfo("Hash值:" + fileinfo.Hash + "\n"); var oP = rootFolder + item.FullName.Split(new string[] { rootFolder }, StringSplitOptions.RemoveEmptyEntries)[1]; fileinfo.Address = oP; fileinfo.InstallPath = oP.Replace(replaceFolder, ""); RunDoShowInfo("当前文件检测完毕!\n"); if (versionXML.x_ProcessInfo.path == item.FullName) { versionXML.x_ProcessInfo.path = fileinfo.InstallPath; } xml.Files.Add(fileinfo); } foreach (var item in dir.GetDirectories()) { RunDoShowInfo("进入目录:" + item.FullName + "\n"); GetFiles(xml, item, replaceFolder); } }
private void Check(VersionXML xml, string rootPath) { pmax = Directory.GetFiles(Path.Combine(rootPath, "Base"), "*", SearchOption.AllDirectories).Length; pmax += Directory.GetFiles(Path.Combine(rootPath, "Other"), "*", SearchOption.AllDirectories).Length; pmax += Directory.GetFiles(Path.Combine(rootPath, "Change"), "*", SearchOption.AllDirectories).Length; var D = new DirectoryInfo(rootPath); foreach (var item in D.GetDirectories()) { RunDoShowCheckInfo("进入目录:" + item.FullName + "\n"); if (item.Name == "Change") { foreach (var item1 in item.GetDirectories()) { var v = new XMLFileList(); GetFiles(v, item1, "\\Change\\" + item1.Name); v.Folder = item1.Name; xml.x_FileList.x_change.Add(v); } } else if (item.Name == "Base") { GetFiles(xml.x_FileList.x_base, item, item.Name + "\\"); xml.x_FileList.x_base.Folder = "Base"; } else if (item.Name == "Other") { GetFiles(xml.x_FileList.x_other, item, item.Name + "\\"); xml.x_FileList.x_base.Folder = "Other"; } } }
/// <summary> /// 计算文件Hash值 /// </summary> void CalHash() { if (haveFTPIP) { RunDoShowInfo("更新FTPIP"); versionXML.x_FTPAddress = p2ftpadd_tbx.Text.Split(';'); RunDoShowInfo("更新FTPIP......完成!"); } if (haveBase) { RunDoShowInfo("检测Base文件夹"); string folder = "Base"; var d = new DirectoryInfo(Path.Combine(root, folder)); versionXML.x_FileList.x_base.Files.Clear(); GetFiles(versionXML.x_FileList.x_base, d, folder); RunDoShowInfo("更新Base文件夹......完成!"); } if (haveOther) { RunDoShowInfo("检测Other文件夹"); string folder = "Other"; var d = new DirectoryInfo(Path.Combine(root, folder)); versionXML.x_FileList.x_other.Files.Clear(); GetFiles(versionXML.x_FileList.x_other, d, folder); RunDoShowInfo("更新Ohter文件夹......完成!"); } if (changeChildFolders.Count > 0) { RunDoShowInfo("检测Change文件夹"); foreach (var item in changeChildFolders) { bool flag = false;///是否在x_change中找到 var d = new DirectoryInfo(Path.Combine(root, "Change\\" + item)); foreach (var item2 in versionXML.x_FileList.x_change) { if (item2.Folder == item) { flag = true; item2.Files.Clear(); GetFiles(item2, d, "\\Change\\" + item); } } if (!flag)///向x_change中添加元素 { var v = new XMLFileList(); GetFiles(v, d, "\\Change\\" + item); v.Folder = item; versionXML.x_FileList.x_change.Add(v); } } } }