Exemplo n.º 1
0
        private void combSolutionPlatform_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (this.combSolutionPlatform.SelectedItem == null)
                {
                    return;
                }
                string dllRootDir = this.txtLibRootDir.Text.Trim();
                if (string.IsNullOrEmpty(dllRootDir) || Directory.Exists(dllRootDir) == false)
                {
                    return;
                }
                if (_dirModel == null || _dirModel.DirectoryPath != dllRootDir)
                {
                    _dirModel = FileDirUtility.ReadAllDirAndFiles(dllRootDir);
                }
                string solPlatform = this.combSolutionPlatform.SelectedItem.ToString();
                for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
                {
                    Project proj = this.dataGridView1.Rows[i].Tag as Project;
                    if (proj != null)
                    {
                        foreach (Configuration config in proj.ConfigurationManager)
                        {
                            if (config.ConfigurationName == solPlatform)
                            {
                                string rootDir = Path.GetDirectoryName(proj.FileName);

                                string objDllPath = Path.Combine(rootDir, "obj");
                                objDllPath = Path.Combine(objDllPath, solPlatform);
                                objDllPath = Path.Combine(objDllPath, proj.Properties.Item("OutputFileName").Value.ToString());
                                if (File.Exists(objDllPath))
                                {
                                    this.dataGridView1[2, i].Value       = objDllPath.Substring(rootDir.Length + 1);
                                    this.dataGridView1[2, i].Tag         = objDllPath;
                                    this.dataGridView1[2, i].ToolTipText = objDllPath;
                                }
                                else
                                {
                                    string outputPath = config.Properties.Item("OutputPath").Value.ToString();
                                    char[] charList   = outputPath.ToCharArray();
                                    int    num        = 0;
                                    for (int j = 0; j < charList.Length; j++)
                                    {
                                        if (charList[j] == '.')
                                        {
                                            bool isOK = true;
                                            for (int k = 0; k < j; k++)
                                            {
                                                if (charList[k] != '.')
                                                {
                                                    isOK = false;
                                                }
                                            }
                                            if (isOK)
                                            {
                                                num++;
                                            }
                                        }
                                    }
                                    for (int j = 0; j < num - 1; j++)
                                    {
                                        rootDir = rootDir.Substring(0, rootDir.LastIndexOf('\\'));
                                    }
                                    string fileName = proj.Properties.Item("OutputFileName").Value.ToString();
                                    if (outputPath.StartsWith("."))
                                    {
                                        outputPath = outputPath.Substring(outputPath.LastIndexOf('.') + 2);
                                    }
                                    outputPath = Path.Combine(rootDir, outputPath);
                                    outputPath = Path.Combine(outputPath, fileName);
                                    if (outputPath.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase) == false)
                                    {
                                        continue;
                                    }
                                    this.dataGridView1[2, i].Value       = outputPath.Substring(rootDir.Length + 1);
                                    this.dataGridView1[2, i].Value       = outputPath;
                                    this.dataGridView1[2, i].ToolTipText = outputPath;
                                }
                                break;
                            }
                        }
                        //查找最佳目标dll路径
                        List <string> similarDlls = new List <string>();
                        this.FindSimilarDlls(_dirModel, proj.Name, ref similarDlls);
                        if (similarDlls.Count > 0)
                        {
                            string cellValue = string.Empty;
                            string toolTip   = string.Empty;
                            for (int j = 0; j < similarDlls.Count; j++)
                            {
                                if (j == 0)
                                {
                                    cellValue = similarDlls[j].Substring(dllRootDir.Length + 1);
                                    toolTip   = similarDlls[j];
                                }
                                else
                                {
                                    cellValue += "#" + similarDlls[j].Substring(dllRootDir.Length + 1);
                                    toolTip   += "#" + similarDlls[j];
                                }
                            }
                            this.dataGridView1[3, i].Value       = cellValue;
                            this.dataGridView1[3, i].Tag         = similarDlls;
                            this.dataGridView1[3, i].ToolTipText = toolTip;
                        }
                        this.dataGridView1[4, i].Value = similarDlls.Count;
                    }
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowTip(ex.Message);
            }
        }
Exemplo n.º 2
0
        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;
        }