private void btnOK_Click(object sender, EventArgs e) { _copyStrategy = new CopyStrategyModel(); _copyStrategy.UseDirStrategy = this.chkDirStrategy.Checked; _copyStrategy.UseStrStrategy = this.chkStrStrategy.Checked; string str = this.txtDirStrategy.Text.Trim(); string[] strArray = str.Split('#'); if (strArray != null && strArray.Length > 0) { _copyStrategy.DirStrategyList.AddRange(strArray); _copyStrategy.DirStrategyList.Remove(string.Empty); } str = this.txtStrStrategy.Text.Trim(); strArray = str.Split('#'); if (strArray != null && strArray.Length > 0) { _copyStrategy.StrStrategyList.AddRange(strArray); _copyStrategy.StrStrategyList.Remove(string.Empty); } this.DialogResult = DialogResult.OK; }
private void CopyHideRefFiles(string dllRootDir, string destDir, CopyStrategyModel strategy) { string[] dirs = Directory.GetDirectories(dllRootDir, "*", SearchOption.AllDirectories); if (dirs == null || dirs.Length < 1) { return; } for (int i = 0; i < dirs.Length; i++) { if (dirs[i].Contains(".svn")) { continue; } DirectoryInfo dirInfo = new DirectoryInfo(dirs[i]); for (int j = 0; j < strategy.DirStrategyList.Count; j++) { if (dirInfo.Name.Equals(strategy.DirStrategyList[j], StringComparison.CurrentCultureIgnoreCase)) { string[] files = Directory.GetFiles(dirs[i]); for (int k = 0; k < files.Length; k++) { string destFilePath = Path.Combine(destDir, Path.GetFileName(files[k])); if (_copiedFiles.Contains(destFilePath)) { continue; } _copiedFiles.Add(destFilePath); File.Copy(files[k], destFilePath, true); } } } } }
private void lblSetHideRefStrategy_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { CopyStrategyModel strategy = this.lblSetHideRefStrategy.Tag as CopyStrategyModel; frmSetHideRefStrategy frm = new frmSetHideRefStrategy(strategy); if (frm.ShowDialog() == DialogResult.OK) { this.lblSetHideRefStrategy.Tag = frm.CopyStrategy; } }
public frmSetHideRefStrategy(CopyStrategyModel copyStrategy) { InitializeComponent(); _copyStrategy = copyStrategy; if (_copyStrategy != null) { if (_copyStrategy.DirStrategyList.Count > 0) { this.txtDirStrategy.Text = this.GetCombainStr(_copyStrategy.DirStrategyList); } if (_copyStrategy.StrStrategyList.Count > 0) { this.txtStrStrategy.Text = this.GetCombainStr(_copyStrategy.StrStrategyList); } this.chkDirStrategy.Checked = _copyStrategy.UseDirStrategy; this.chkStrStrategy.Checked = _copyStrategy.UseStrStrategy; } }
private void CopyHideRefDlls(string dllRootDir, string dllPath, string destDir, CopyStrategyModel strategy) { string dllName = Path.GetFileNameWithoutExtension(dllPath); if (dllName.IndexOf('.') < 1) { return; } dllName = dllName.Substring(0, dllName.LastIndexOf('.')); string dir = Path.GetDirectoryName(dllPath); string[] files = Directory.GetFiles(dir, "*.dll", SearchOption.TopDirectoryOnly); if (files == null || files.Length < 1) { return; } for (int i = 0; i < files.Length; i++) { string fileName = Path.GetFileName(files[i]); if (fileName.StartsWith(dllName) == false) { continue; } for (int j = 0; j < strategy.StrStrategyList.Count; j++) { if (fileName.Contains(strategy.StrStrategyList[j])) { string destFilePath = Path.Combine(destDir, fileName); if (_copiedFiles.Contains(destFilePath)) { continue; } _copiedFiles.Add(destFilePath); File.Copy(files[i], destFilePath, true); int count = 0; CopySubRefDlls(files[0], destDir, dllRootDir, ref count); } } } }
/// <summary> /// 保存用户配置信息,在protected override void Dispose(bool disposing)方法中调用 /// </summary> private void SaveUserConfig() { try { List <string> contexts = new List <string>(); if (File.Exists(ConfigFilePath) == false) { string dir = Path.GetDirectoryName(ConfigFilePath); if (Directory.Exists(dir) == false) { Directory.CreateDirectory(dir); } File.Create(ConfigFilePath).Close(); } else { string[] temp = File.ReadAllLines(ConfigFilePath, Encoding.UTF8); if (temp != null && temp.Length > 0) { contexts.AddRange(temp); } } string uiParam = this.txtLibRootDir.Text.Trim() + "=" + this.txtDestDir.Text.Trim(); //以sln的路径为键 string slnPath = _app.Solution.FileName; bool isExist = false; for (int i = 0; i < contexts.Count; i++) { if (contexts[i].StartsWith(slnPath)) { contexts[i] = slnPath + "=" + uiParam; isExist = true; break; } } if (isExist == false) { contexts.Add(slnPath + "=" + uiParam); } File.WriteAllLines(ConfigFilePath, contexts.ToArray(), Encoding.UTF8); } catch { } try { CopyStrategyModel strategy = this.lblSetHideRefStrategy.Tag as CopyStrategyModel; strategy.DeepCopy = this.chkDeepCopy.Checked; strategy.CopyHideRefDlls = this.chkCopyHideRefDlls.Checked; if (strategy == null) { return; } List <string> contexts = new List <string>(); if (File.Exists(HideRefStrategyConfigFilePath) == false) { string dir = Path.GetDirectoryName(HideRefStrategyConfigFilePath); if (Directory.Exists(dir) == false) { Directory.CreateDirectory(dir); } File.Create(HideRefStrategyConfigFilePath).Close(); } else { string[] temp = File.ReadAllLines(HideRefStrategyConfigFilePath, Encoding.UTF8); if (temp != null && temp.Length > 0) { contexts.AddRange(temp); } } string uiParam = this.GetCombainStr(strategy.DirStrategyList) + "=" + this.GetCombainStr(strategy.StrStrategyList) + "=" + strategy.UseDirStrategy.ToString() + "=" + strategy.UseStrStrategy.ToString(); uiParam += "=" + strategy.DeepCopy.ToString() + "=" + strategy.CopyHideRefDlls.ToString(); //以sln的路径为键 string slnPath = _app.Solution.FileName; bool isExist = false; for (int i = 0; i < contexts.Count; i++) { if (contexts[i].StartsWith(slnPath)) { contexts[i] = slnPath + "=" + uiParam; isExist = true; break; } } if (isExist == false) { contexts.Add(slnPath + "=" + uiParam); } File.WriteAllLines(HideRefStrategyConfigFilePath, contexts.ToArray(), Encoding.UTF8); } catch { } }
/// <summary> /// 加载用户配置信息 /// </summary> private void LoadUserConfig() { try { string slnPath = _app.Solution.FileName; string dir = Path.GetDirectoryName(slnPath); this.txtLibRootDir.Text = this.FindLibDir(dir); this.txtDestDir.Text = this.FindBinDir(dir); if (File.Exists(ConfigFilePath) == false) { return; } string[] contexts = File.ReadAllLines(ConfigFilePath, Encoding.UTF8); if (contexts != null && contexts.Length > 0) { //以sln的路径为键 for (int i = 0; i < contexts.Length; i++) { if (contexts[i].StartsWith(slnPath, StringComparison.CurrentCultureIgnoreCase)) { string[] strArray = contexts[i].Split('='); if (strArray != null && strArray.Length == 3) { if (Directory.Exists(strArray[1])) { this.txtLibRootDir.Text = strArray[1]; } if (Directory.Exists(strArray[2])) { this.txtDestDir.Text = strArray[2]; } } break; } } } } catch { } try { CopyStrategyModel strategy = new CopyStrategyModel(); if (File.Exists(HideRefStrategyConfigFilePath)) { string[] contexts = File.ReadAllLines(HideRefStrategyConfigFilePath, Encoding.UTF8); string slnPath = _app.Solution.FileName; if (contexts != null && contexts.Length > 0) { //以sln的路径为键 for (int i = 0; i < contexts.Length; i++) { if (contexts[i].StartsWith(slnPath, StringComparison.CurrentCultureIgnoreCase)) { string[] temp = contexts[i].Split('='); if (temp != null && temp.Length == 7) { string[] strArray = temp[1].Split('#'); if (strArray != null && strArray.Length > 0) { strategy.DirStrategyList.AddRange(strArray); strategy.DirStrategyList.Remove(string.Empty); } strArray = temp[2].Split('#'); if (strArray != null && strArray.Length > 0) { strategy.StrStrategyList.AddRange(strArray); strategy.StrStrategyList.Remove(string.Empty); } strategy.UseDirStrategy = bool.Parse(temp[3]); strategy.UseStrStrategy = bool.Parse(temp[4]); strategy.DeepCopy = bool.Parse(temp[5]); strategy.CopyHideRefDlls = bool.Parse(temp[6]); this.chkDeepCopy.Checked = strategy.DeepCopy; this.chkCopyHideRefDlls.Checked = strategy.CopyHideRefDlls; } break; } } } } this.lblSetHideRefStrategy.Tag = strategy; } catch { } }
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; }