public bool Contains(SynFile file) { return(file != null && this.IsDirectory == true && this.FileID.Length < file.FileID.Length && file.FileID.StartsWith(this.FileID, StringComparison.InvariantCultureIgnoreCase)); }
/// <summary> /// Packages the file. /// </summary> /// <param name="pkgFileInfo">The PKG file info.</param> public void PackageFile(FileInfo pkgFileInfo) { //pkgFileInfo.FullName.Replace(BaseDir, "").Replace('/', '\\').TrimStart('\\'); string md5Hash = "N/A"; try { md5Hash = GlobalUtil.GetMD5Hash(pkgFileInfo.FullName); } catch (Exception) { } //Console.WriteLine("MD5:" + md5Hash); string fileID = pkgFileInfo.FullName.Replace(BaseDir, "").Replace('\\', '/').TrimStart('/'); SynFile currentFile = new SynFile { IsDirectory = false, FileID = fileID, FileSize = pkgFileInfo.Length, HashCode = md5Hash, CreateDateUTC = pkgFileInfo.CreationTimeUtc, LastModifyDateUTC = pkgFileInfo.LastWriteTimeUtc }; if (!CurrentSynFile.Structure.ContainsKey(fileID)) { CurrentSynFile.Structure.Add(fileID, currentFile); CurrentSynFile.TotalFileCount++; CurrentSynFile.TotalFileSize += pkgFileInfo.Length; } if (CmpSynFile != null) { //旧的不存在而新的存在 if (!CmpSynFile.Structure.ContainsKey(fileID)) { CurrentSynFile.AddFiles.Add(fileID, currentFile); } else { SynFile oldFile = CmpSynFile.Structure[fileID]; if (!CurrentSynFile.Structure.ContainsKey(fileID)) { //CurrentSynFile.TotalFileSize -= oldFile.FileSize; CurrentSynFile.RemoveFiles.Add(fileID, currentFile); } else { if (string.Compare(oldFile.HashCode, currentFile.HashCode, true) != 0) { //CurrentSynFile.TotalFileSize -= oldFile.FileSize; //CurrentSynFile.TotalFileSize += pkgFileInfo.Length; CurrentSynFile.UpdateFiles.Add(fileID, currentFile); } } } } }
internal static SynFileRename[] FixedRename(Dictionary <string, SynFile> tDeleteDict, Dictionary <string, SynFile> tAddDict) { List <SynFileRename> rList = new List <SynFileRename>(); //如果任何一边为0,则没有修改记录 if (tDeleteDict.Count == 0 || tAddDict.Count == 0) { return(rList.ToArray()); } //通过比较文件扩展名和哈希码值 区分 Dictionary <string, string> dHashDict = ConvertHashIDDict(tDeleteDict); Dictionary <string, string> aHashDict = ConvertHashIDDict(tAddDict); string currentExt = string.Empty, cmpExt = string.Empty; string tAddFileID = string.Empty; SynFile tOldSynFile = null, tAddsynFile = null; List <string> tDeletList = new List <string>(); List <string> tAddList = new List <string>(); //hash code foreach (string key in dHashDict.Keys) { if (!aHashDict.ContainsKey(key)) { continue; } currentExt = Path.GetExtension(dHashDict[key]); cmpExt = Path.GetExtension(aHashDict[key]); //hascode and extension are equal if (aHashDict.ContainsKey(key) && currentExt.Equals(cmpExt, StringComparison.InvariantCultureIgnoreCase)) { foreach (SynFile file in tAddDict.Values) { if (file.HashCode.Equals(key, StringComparison.InvariantCultureIgnoreCase)) { //fileid tOldSynFile = (SynFile)tDeleteDict[dHashDict[key]].Clone(); tDeletList.Add(dHashDict[key]); //Console.WriteLine(); //Console.WriteLine("文件{0}\r\n改为:{1}", dHashDict[key], file.FileID); tAddsynFile = (SynFile)tAddDict[file.FileID].Clone(); rList.Add(new SynFileRename { OldSynFile = tOldSynFile, NewSynFile = tAddsynFile }); tAddList.Add(file.FileID); } } } } if (tDeletList.Count == tAddList.Count) { foreach (string dKey in tDeletList) { tDeleteDict.Remove(dKey); } foreach (string aKey in tAddList) { tAddDict.Remove(aKey); } } return(rList.ToArray()); }