134 lines
5.7 KiB
C#
134 lines
5.7 KiB
C#
|
using ryCommon;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Data;
|
|||
|
using System.Diagnostics;
|
|||
|
using System.Drawing;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
|
|||
|
namespace SuperDesign.Tools.UpLog
|
|||
|
{
|
|||
|
public partial class FrmBuilding : Form
|
|||
|
{
|
|||
|
public FrmBuilding()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
public List<BuildComand> BuildingList { get; set; }=new List<BuildComand>();
|
|||
|
|
|||
|
private void FrmBuilding_Shown(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Task.Run(() =>
|
|||
|
{
|
|||
|
var err_count = 0;
|
|||
|
var success_count = 0;
|
|||
|
var index = 0;
|
|||
|
foreach (var item in BuildingList)
|
|||
|
{
|
|||
|
index++;
|
|||
|
this.Invoke(new Action(() =>
|
|||
|
{
|
|||
|
Text = "[" + item.Name + "]编译中["+index+"/"+ BuildingList.Count+ "]...";
|
|||
|
}));
|
|||
|
Process p = new Process
|
|||
|
{
|
|||
|
StartInfo = new System.Diagnostics.ProcessStartInfo
|
|||
|
{
|
|||
|
FileName = "D:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\Common7\\IDE\\devenv.com",//设定程序名
|
|||
|
Arguments = item.Comand,
|
|||
|
UseShellExecute = false, //关闭shell的使用
|
|||
|
RedirectStandardInput = true, //重定向标准输入
|
|||
|
RedirectStandardOutput = true, //重定向标准输出
|
|||
|
RedirectStandardError = false, //重定向错误输出
|
|||
|
WorkingDirectory = "",
|
|||
|
StandardOutputEncoding = Encoding.Default,
|
|||
|
CreateNoWindow = true//设置不显示窗口
|
|||
|
}
|
|||
|
};
|
|||
|
p.Start();
|
|||
|
while (!p.StandardOutput.EndOfStream)
|
|||
|
{
|
|||
|
string line = p.StandardOutput.ReadLine();
|
|||
|
if (line.StartsWith("版权所有"))
|
|||
|
{
|
|||
|
continue;
|
|||
|
}
|
|||
|
var color=Color.Black;
|
|||
|
//ryProcessManager=>========== 生成: 0 成功,0 失败,3 最新,0 已跳过
|
|||
|
if (line.IndexOfEx("生成:")>=0 && line.IndexOfEx("成功") >= 0 && line.IndexOfEx("失败") >= 0 && line.IndexOfEx("已跳过") >= 0)
|
|||
|
{
|
|||
|
if (line.IndexOfEx(",0 失败")<0)
|
|||
|
{
|
|||
|
err_count++;
|
|||
|
color = Color.Red;
|
|||
|
}
|
|||
|
else{
|
|||
|
success_count++;
|
|||
|
color = Color.Blue;
|
|||
|
}
|
|||
|
}
|
|||
|
this.Invoke(new Action(() =>
|
|||
|
{
|
|||
|
if (richTextBox1.Text.Length == 0)
|
|||
|
{
|
|||
|
richTextBox1.Text =item.Name+"=>"+line;
|
|||
|
if(color!=Color.Black)
|
|||
|
{
|
|||
|
richTextBox1.SelectionStart = 0;
|
|||
|
richTextBox1.SelectionLength = richTextBox1.Text.Length;
|
|||
|
richTextBox1.SelectionColor = color;
|
|||
|
richTextBox1.SelectionFont = new Font(richTextBox1.Font, FontStyle.Bold);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var start=richTextBox1.Text.Length;
|
|||
|
richTextBox1.AppendText("\n" + item.Name + "=>" + line);
|
|||
|
if (color != Color.Black)
|
|||
|
{
|
|||
|
richTextBox1.SelectionStart = start;
|
|||
|
richTextBox1.SelectionLength = richTextBox1.Text.Length- start;
|
|||
|
richTextBox1.SelectionColor = color;
|
|||
|
richTextBox1.SelectionFont = new Font(richTextBox1.Font, FontStyle.Bold);
|
|||
|
}
|
|||
|
}
|
|||
|
richTextBox1.SelectionStart = richTextBox1.Text.Length;
|
|||
|
richTextBox1.SelectionLength = 0;
|
|||
|
richTextBox1.SelectionColor = Color.Black;
|
|||
|
richTextBox1.SelectionFont = richTextBox1.Font;
|
|||
|
}));
|
|||
|
}
|
|||
|
}
|
|||
|
this.Invoke(new Action(() =>
|
|||
|
{
|
|||
|
Text = "编译完成";
|
|||
|
if(err_count>0)
|
|||
|
{
|
|||
|
canexit = true;
|
|||
|
MessageBox.Show("部分生成失败,成功:"+success_count+"个,失败"+err_count+"个", "部分生成失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|||
|
return;
|
|||
|
}
|
|||
|
DialogResult = DialogResult.OK;
|
|||
|
}));
|
|||
|
});
|
|||
|
}
|
|||
|
bool canexit = false;
|
|||
|
private void FrmBuilding_FormClosing(object sender, FormClosingEventArgs e)
|
|||
|
{
|
|||
|
if(DialogResult != DialogResult.OK && !canexit)
|
|||
|
{
|
|||
|
e.Cancel = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
public class BuildComand
|
|||
|
{
|
|||
|
public string Comand { get; set; } = "";
|
|||
|
public string Name { get; set; } = "";
|
|||
|
}
|
|||
|
}
|