private void rMenuModifyAll_Click(object sender, EventArgs e) { if (this.combProjects.Tag == null) { return; } string dllRootDir = this.txtLibRootDir.Text.Trim(); string dotNetBarDir = this.txtDotNetBarDir.Text.Trim(); string infragisticsDir = this.txtInfragisticsDir.Text.Trim(); if (string.IsNullOrEmpty(dllRootDir) || Directory.Exists(dllRootDir) == false) { MsgBox.ShowTip("请先输入Lib根目录"); return; } bool proItemFirst = this.chkProItemFirst.Checked; string solPlatform = this.combSolutionPlatform.SelectedItem.ToString(); this.Cursor = Cursors.WaitCursor; //读取lib和第三方类库 _dirModel = FileDirUtility.ReadAllDirAndFiles(dllRootDir); if (string.IsNullOrEmpty(dotNetBarDir) == false && Directory.Exists(dotNetBarDir)) { _dotNetBarDirModel = FileDirUtility.ReadAllDirAndFiles(dotNetBarDir); } if (string.IsNullOrEmpty(infragisticsDir) == false && Directory.Exists(infragisticsDir)) { _infragisticsDirModel = FileDirUtility.ReadAllDirAndFiles(infragisticsDir); } List <Project> prjList = this.combProjects.Tag as List <Project>; for (int p = 0; p < prjList.Count; p++) { VSProject vsProj = prjList[p].Object as VSProject; References dllRefs = vsProj.References; if (dllRefs == null) { continue; } foreach (Reference dllRef in dllRefs) { if (this.IsNeedChangePath(dllRef.Path) == false) { continue; } //优先引用项目,再引用lib下的dll Project bestSimilarProj = null; if (proItemFirst) { string dllName = dllRef.Name; bestSimilarProj = this.FindProItem(dllName, solPlatform); if (bestSimilarProj != null) { string dllFilePath = this.GetOutPutDllPath(bestSimilarProj, solPlatform); if (dllFilePath.Equals(dllRef.Path, StringComparison.CurrentCultureIgnoreCase)) { continue; } dllRef.Remove(); dllRefs.AddProject(bestSimilarProj); } } if (bestSimilarProj == null) { List <string> similarDlls = new List <string>(); if (_dotNetBarDirModel != null && dllRef.Name.ToUpper().Contains("DevComponents".ToUpper())) { this.FindSimilarDlls(_dotNetBarDirModel, dllRef.Name, ref similarDlls); } else if (_infragisticsDirModel != null && dllRef.Name.ToUpper().Contains("Infragistics".ToUpper())) { this.FindSimilarDlls(_infragisticsDirModel, dllRef.Name, ref similarDlls); } if (similarDlls.Count == 0) { this.FindSimilarDlls(_dirModel, dllRef.Name, ref similarDlls); } if (similarDlls.Count < 1) { continue; } string bestSimilarDll = similarDlls[0]; if (similarDlls.Count > 1) { double maxSim = double.MinValue; int maxSimIndex = 0; for (int j = 0; j < similarDlls.Count; j++) { double sim = StrSimCalculator.CalculateSim(similarDlls[j], dllRef.Path); if (maxSim < sim) { maxSim = sim; maxSimIndex = j; } } bestSimilarDll = similarDlls[maxSimIndex]; } if (bestSimilarDll.Equals(dllRef.Path, StringComparison.CurrentCultureIgnoreCase)) { continue; } dllRef.Remove(); try { dllRefs.Add(bestSimilarDll); } catch { } } } } this.combProjects_SelectedIndexChanged(null, null); this.Cursor = Cursors.Default; }
private void rMenuModifySelection_Click(object sender, EventArgs e) { if (this.dataGridView1.SelectedRows == null || this.dataGridView1.SelectedRows.Count < 1) { return; } References dllRefs = this.dataGridView1.Tag as References; if (dllRefs == null) { return; } string dllRootDir = this.txtLibRootDir.Text.Trim(); string dotNetBarDir = this.txtDotNetBarDir.Text.Trim(); string infragisticsDir = this.txtInfragisticsDir.Text.Trim(); if (string.IsNullOrEmpty(dllRootDir) || Directory.Exists(dllRootDir) == false) { MsgBox.ShowTip("请先输入Lib根目录"); return; } bool proItemFirst = this.chkProItemFirst.Checked; string solPlatform = this.combSolutionPlatform.SelectedItem.ToString(); this.Cursor = Cursors.WaitCursor; //读取lib和第三方类库 _dirModel = FileDirUtility.ReadAllDirAndFiles(dllRootDir); if (string.IsNullOrEmpty(dotNetBarDir) == false && Directory.Exists(dotNetBarDir)) { _dotNetBarDirModel = FileDirUtility.ReadAllDirAndFiles(dotNetBarDir); } if (string.IsNullOrEmpty(infragisticsDir) == false && Directory.Exists(infragisticsDir)) { _infragisticsDirModel = FileDirUtility.ReadAllDirAndFiles(infragisticsDir); } for (int i = 0; i < this.dataGridView1.SelectedRows.Count; i++) { DataGridViewRow selRow = this.dataGridView1.SelectedRows[i]; Reference dllRef = selRow.Tag as Reference; if (dllRef == null) { continue; } //优先引用项目,再引用lib下的dll Project bestSimilarProj = null; if (proItemFirst) { string dllName = dllRef.Name; bestSimilarProj = this.FindProItem(dllName, solPlatform); string bestSimilarDll = this.FindProItemOutPath(dllName, solPlatform); if (bestSimilarProj != null) { string dllFilePath = this.GetOutPutDllPath(bestSimilarProj, solPlatform); if (dllFilePath.Equals(dllRef.Path, StringComparison.CurrentCultureIgnoreCase)) { continue; } selRow.Tag = null; dllRef.Remove(); dllRef = dllRefs.AddProject(bestSimilarProj); selRow.Tag = dllRef; selRow.Cells[0].Value = Path.GetFileNameWithoutExtension(bestSimilarDll); selRow.Cells[1].Value = bestSimilarDll; } } if (bestSimilarProj == null) { List <string> similarDlls = new List <string>(); if (_dotNetBarDirModel != null && dllRef.Name.ToUpper().Contains("DevComponents".ToUpper())) { this.FindSimilarDlls(_dotNetBarDirModel, dllRef.Name, ref similarDlls); } else if (_infragisticsDirModel != null && dllRef.Name.ToUpper().Contains("Infragistics".ToUpper())) { this.FindSimilarDlls(_infragisticsDirModel, dllRef.Name, ref similarDlls); } if (similarDlls.Count == 0) { this.FindSimilarDlls(_dirModel, dllRef.Name, ref similarDlls); } if (similarDlls.Count < 1) { continue; } string bestSimilarDll = similarDlls[0]; if (similarDlls.Count > 1) { double maxSim = double.MinValue; int maxSimIndex = 0; for (int j = 0; j < similarDlls.Count; j++) { double sim = StrSimCalculator.CalculateSim(similarDlls[j], dllRef.Path); if (maxSim < sim) { maxSim = sim; maxSimIndex = j; } } bestSimilarDll = similarDlls[maxSimIndex]; } if (bestSimilarDll.Equals(dllRef.Path, StringComparison.CurrentCultureIgnoreCase)) { continue; } selRow.Tag = null; dllRef.Remove(); try { dllRef = dllRefs.Add(bestSimilarDll); } catch { } selRow.Tag = dllRef; selRow.Cells[0].Value = Path.GetFileNameWithoutExtension(bestSimilarDll); selRow.Cells[1].Value = bestSimilarDll; } } this.Cursor = Cursors.Default; }
private void rMenuCopySelRefDlls_Click(object sender, EventArgs e) { if (this.dataGridView1.SelectedRows == null || this.dataGridView1.SelectedRows.Count < 1) { return; } string dllRootDir = this.txtLibRootDir.Text.Trim(); if (string.IsNullOrEmpty(dllRootDir) || Directory.Exists(dllRootDir) == false) { MsgBox.ShowTip("请先输入Lib根目录"); return; } string destDir = this.txtDestDir.Text.Trim(); if (string.IsNullOrEmpty(destDir) || Directory.Exists(destDir) == false) { MsgBox.ShowTip("请先输入目标路径"); return; } CopyStrategyModel strategy = this.lblSetHideRefStrategy.Tag as CopyStrategyModel; if (strategy == null) { strategy = new CopyStrategyModel(); } strategy.DeepCopy = this.chkDeepCopy.Checked; strategy.CopyHideRefDlls = this.chkCopyHideRefDlls.Checked; _copiedFiles.Clear(); _dirModel = FileDirUtility.ReadAllDirAndFiles(dllRootDir); this.Cursor = Cursors.WaitCursor; for (int i = 0; i < this.dataGridView1.SelectedRows.Count; i++) { DataGridViewRow selRow = this.dataGridView1.SelectedRows[i]; Reference dllRef = selRow.Tag as Reference; if (dllRef == null) { continue; } string dllPath = dllRef.Path; if (string.IsNullOrEmpty(dllPath) || File.Exists(dllPath) == false) { continue; } List <string> subRefDlls = DllRefReflectUtility.GetRefDlls(dllPath); if (subRefDlls == null || subRefDlls.Count < 1) { continue; } foreach (string subRef in subRefDlls) { if (subRef.StartsWith("System") || subRef.StartsWith("mscorlib")) { continue; } if (subRef == dllRef.Name) { continue; } List <string> similarDlls = new List <string>(); this.FindSimilarDlls(_dirModel, subRef, ref similarDlls); if (similarDlls.Count < 1) { continue; } string destFilePath = Path.Combine(destDir, Path.GetFileName(similarDlls[0])); if (_copiedFiles.Contains(destFilePath)) { continue; } _copiedFiles.Add(destFilePath); File.Copy(similarDlls[0], destFilePath, true); if (strategy.DeepCopy) { int count = 0; this.CopySubRefDlls(similarDlls[0], destDir, dllRootDir, ref count); } if (strategy.CopyHideRefDlls && strategy.UseStrStrategy) { this.CopyHideRefDlls(dllRootDir, similarDlls[0], destDir, strategy); } } } if (strategy.CopyHideRefDlls && strategy.UseDirStrategy) { this.CopyHideRefFiles(dllRootDir, destDir, strategy); } this.Cursor = Cursors.Default; }