private void LoadHistory() { string strfile = Path.Combine(Application.StartupPath, "history.txt"); string strHistory = FileFolderHelper.FileToString(strfile); if (strHistory.Length == 0) { return; } string[] historys = strHistory.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string history in historys) { DevComponents.DotNetBar.ButtonItem newitemLeft = new DevComponents.DotNetBar.ButtonItem(); newitemLeft.ImagePaddingHorizontal = 8; newitemLeft.Name = history; newitemLeft.Text = history; newitemLeft.Click += new System.EventHandler(this.historyItem_Click_Left); this.bOpenFolder1.SubItems.Add(newitemLeft); DevComponents.DotNetBar.ButtonItem newitemRight = new DevComponents.DotNetBar.ButtonItem(); newitemRight.ImagePaddingHorizontal = 8; newitemRight.Name = history; newitemRight.Text = history; newitemRight.Click += new System.EventHandler(this.historyItem_Click_Right); this.bOpenFolder2.SubItems.Add(newitemRight); } }
private void CopyDiffFiles(string CurPathL, string CurPathR, string clientL, string clientR, string target) { DirectoryInfo leftDI = new DirectoryInfo(CurPathL); foreach (FileInfo fi1 in leftDI.GetFiles()) { if (FileExtensionNeedCompare(fi1.Extension)) { string filename2 = fi1.FullName.Replace(clientL, clientR); FileInfo fi2 = new FileInfo(filename2); if (fi2.Exists) { string content1 = FileFolderHelper.FileToString(fi1.FullName); string content2 = FileFolderHelper.FileToString(filename2); if (content1 != content2) { string targetL = fi1.FullName.Replace(clientL, target + "\\左"); string targetR = fi2.FullName.Replace(clientR, target + "\\右"); string targetDIRL = targetL.Substring(0, targetL.LastIndexOf('\\')); string targetDIRR = targetR.Substring(0, targetR.LastIndexOf('\\')); if (!Directory.Exists(targetDIRL)) { Directory.CreateDirectory(targetDIRL); } if (!Directory.Exists(targetDIRR)) { Directory.CreateDirectory(targetDIRR); } fi1.CopyTo(targetL); fi2.CopyTo(targetR); copyedFileCount++; string strStatus = string.Format("复制文件数:{0} 当前处理文件:{1}", copyedFileCount, fi1.FullName.Replace(clientL, string.Empty)); this.Invoke(new ThreadUIDelegate(DelegateMethod), new object[] { strStatus }); //this.labelStatus.Text = strStatus; } } } } foreach (DirectoryInfo di1 in leftDI.GetDirectories()) { if (!DirectoryNeedCompare(di1.FullName)) { continue; } DirectoryInfo di2 = new DirectoryInfo(di1.FullName.Replace(clientL, clientR)); if (di2.Exists) { CopyDiffFiles(di1.FullName, di2.FullName, clientL, clientR, target); } } }
private void UpdateHistory(string filename) { string strfile = Path.Combine(Application.StartupPath, "history.txt"); string strHistory = FileFolderHelper.FileToString(strfile); string[] historys = strHistory.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); if (historys.Length < 4) { bool bHistoryContainsThisDoc = false; foreach (string history in historys) { if (history == filename) { bHistoryContainsThisDoc = true; break; } } if (!bHistoryContainsThisDoc) { string strContent = strHistory + (historys.Length == 0 ? string.Empty : "\r\n") + filename; FileFolderHelper.StringToFile(strContent, strfile); } } else { bool bHistoryContainsThisDoc = false; foreach (string history in historys) { if (history == filename) { bHistoryContainsThisDoc = true; break; } } if (!bHistoryContainsThisDoc) { string[] newhistorys = new string[] { historys[1], historys[2], historys[3], filename }; string content = newhistorys[0] + "\r\n" + newhistorys[1] + "\r\n" + newhistorys[2] + "\r\n" + newhistorys[3]; FileFolderHelper.StringToFile(content, strfile); } } }
private bool AnynalizeTabKeysAndNameField(string filename, ref string keys, ref string names) { string content = FileFolderHelper.FileToString(filename); string[] lines = content.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); string[] colnames = lines[0].Split(new char[] { '\t' }); keys = colnames[0]; int keyindex = 0; //for (int i = colnames.Length - 1; i >= 0; i--) //{ // string col = colnames[i].ToLower(); // if (col.Contains("id")) // { // keys = colnames[i]; // keyindex = i; // } //} string[] firstRowCols = lines[1].Split(new char[] { '\t' }); int dummi = 0; return(Int32.TryParse(firstRowCols[keyindex], out dummi)); }
private void GenerateTabDiffOutput(string dir, string outFolder) { string dir1 = Path.Combine(leftFolder, dir); DirectoryInfo leftDirInfo = new DirectoryInfo(dir1); foreach (FileInfo fi in leftDirInfo.GetFiles()) { if (fi.Extension.ToLower() == ".tab" || fi.Extension.ToLower() == ".txt") { string rightFileName = fi.FullName.Replace(leftFolder, rightFolder); if (!File.Exists(rightFileName)) { continue; } if (FileFolderHelper.FileToString(fi.FullName) == FileFolderHelper.FileToString(rightFileName)) { continue; } DiffColInfo info = FindDiffColInfo(fi.Name); string postfix = "tab"; string keys = string.Empty; string namefield = string.Empty; string rowcondition = string.Empty; string content = string.Empty; string outputbasic = string.Empty; List <string> diffCols1 = new List <string>(); List <string> diffCols2 = new List <string>(); if (info != null) { keys = info.keys; namefield = info.displays; if (keys == "$" || namefield == "$") // ignore this file { continue; } } else { if (!AnynalizeTabKeysAndNameField(fi.FullName, ref keys, ref namefield)) { continue; } } // try here try { DiffGenerator.DiffGen(fi.FullName, rightFileName, postfix, keys, namefield, rowcondition, ref content, ref outputbasic, ref diffCols1, ref diffCols2); } catch (System.Exception e) { string strThisLog = string.Format("文件{0}的差异结果生成有误:{1}。\r\n", fi.FullName, e.Message); m_diffLog += strThisLog; } string destFilename = fi.FullName.Replace(leftFolder, outFolder); FileFolderHelper.CreatePath(destFilename); FileFolderHelper.StringToFile(content, destFilename); } } foreach (DirectoryInfo di in leftDirInfo.GetDirectories()) { if (di.Name.ToLower().Contains("svn")) { continue; } GenerateTabDiffOutput(di.FullName, outFolder); } }