using BrightIdeasSoftware; using Microsoft.Win32; using Newtonsoft.Json.Linq; using ryCommon; using ryCommonDb; using ryControls.Controls; using SuperDesign.Manager.FTP; using SuperDesign.Tools; using SuperDesign.Tools.UpLog; 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; using System.Windows.Forms; using System.Xml; using WeifenLuo.WinFormsUI.Docking; using 开发辅助工具.Manager; using static ScintillaNETV2.Style; namespace 开发辅助工具.Tools { public partial class FrmProject : DockContent { public string ProjectName { get; set; } = ""; public FrmProject(string ProjectPath) { InitializeComponent(); OlvUpVer.AspectGetter = delegate (object x) { return ((UpLogItem)x).Version; }; OlvUpdateDate.AspectGetter = delegate (object x) { var dt = ((UpLogItem)x).AddTime.ToDateTime(); if(dt.Date==DateTime.Now.Date) { return "今天 "+dt.ToString("HH:mm:ss"); } if (dt.Date.AddDays(1) == DateTime.Now.Date) { return "昨天 " + dt.ToString("HH:mm:ss"); } return dt.ToString("yyyy-MM-dd HH:mm:ss"); }; OlvUpVer.Renderer = new VerRenderer(); OlvTime.AspectGetter = delegate (object x) { return ((UpLogItem)x).IntervalTimeStr; }; olvProjectName.AspectGetter = delegate (object x) { return ((ProjectLogItem)x).ProjectName; }; olvPlatform.AspectGetter = delegate (object x) { return ((ProjectLogItem)x).BuildPlatform; }; LoadProject(ProjectPath); } public void LoadProject(string ProjectPath,bool forceRefresh=true) { if (forceRefresh) { tabControl1.TabPages.Clear(); LvUpdateLogList.ClearObjects(); LvProjectBuild.ClearObjects(); } _ProjectPath = ProjectPath; var _path = GetBFFolderPath(); try { if (_ProjectPath == "") { return; } System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); xml.Load(_ProjectPath); var xmlnsm = new XmlNamespaceManager(xml.NameTable); xmlnsm.AddNamespace("d", xml.DocumentElement.NamespaceURI); var root = @"d:Project//d:PropertyGroup//d:"; var project_name = GetValue("AssemblyName"); if (project_name != "") { Text = project_name; } ProjectName = project_name; groupBox1.Text = ProjectName+"项目管理"; #region 读取图标 var ApplicationIcon = GetValue("ApplicationIcon"); Icon = null; ApplicationIcon = System.IO.Path.GetDirectoryName(_ProjectPath) + "\\" + ApplicationIcon; if (System.IO.File.Exists(ApplicationIcon)) { try { Icon = new Icon(ApplicationIcon); } catch { } } #endregion LoadPath(); #region 读取条件编译信息 var DefineConstants = xml.SelectSingleNode(@"d:Project//d:PropertyGroup//d:DefineConstants", xmlnsm); if (DefineConstants != null) { string DefineConstants_Text = ";" + DefineConstants.InnerText + ";"; ChkTestOn.Checked = DefineConstants_Text.IndexOfEx(";TEST;") >= 0; if (DefineConstants_Text.IndexOfEx(";DY;") < 0 && DefineConstants_Text.IndexOfEx(";PERSONAL;") < 0) { RbGeneral.Checked = true; } else { RbCompany.Checked = DefineConstants_Text.IndexOfEx(";DY;") >= 0; RbPersonal.Checked = DefineConstants_Text.IndexOfEx(";PERSONAL;") >= 0; } } #endregion var folder = System.IO.Path.GetDirectoryName(_ProjectPath); TxtProjectVer.Text = Manager.RyProject.GetVerInfo(folder + "\\Properties\\AssemblyInfo.cs").Version; string GetValue(string name) { var node = xml.SelectSingleNode(root + name, xmlnsm); if (node != null) { return node.InnerText; } return ""; } } catch(Exception ex) { } Ini ini = new Ini(_path + "\\查看项目.ryp"); var Main_Project = ini.ReadIni("project", "MainProject", ""); IDbInterface db_global = new SQLiteDataProvider(); if (db_global.ConnDb(Application.StartupPath + "\\UserDb\\Project.dat") == 1) { RyQuickSQL mySQL = new RyQuickSQL("Projects"); mySQL.AddField("ProjectName", ""); mySQL.AddField("VerUpdateTime", 0L);//版本更新时间 mySQL.AddField("VerStr", "");//版本 mySQL.AddField("FolderName", "");// mySQL.AddField("BfFolder", "");// mySQL.AddField("ProjectPath", ""); mySQL.AddField("SaveTime", DateTime.Now.ToInt64()); mySQL.AddField("editTime", DateTime.Now.ToInt64()); mySQL.AddField("addTime", DateTime.Now.ToInt64()); db_global.CreateDb(mySQL); } db_global.Free(); if (forceRefresh) { IDbInterface db = new SQLiteDataProvider(); if (db.ConnDb(_path + "\\Res\\Setting\\UpdateLogs.dat") == 1) { #region 更新日志 RyQuickSQL mySQL = new RyQuickSQL("UpdateLogs"); mySQL.AddField("VerStr", ""); mySQL.AddField("LogText", ""); mySQL.AddField("LogJson", ""); mySQL.AddField("VerType", "");//版本类型(main表示主线版本,beta表示测试版) mySQL.AddField("editTime", DateTime.Now.ToInt64()); mySQL.AddField("addTime", DateTime.Now.ToInt64()); db.CreateDb(mySQL); #endregion #region 项目当前日志表 mySQL.Clear(); mySQL.TableName = "ProjectNowLogs"; mySQL.AddField("Name", ""); mySQL.AddField("ChsName", "");//值 mySQL.AddField("Value", "");//值 mySQL.AddField("ValueTime", "");//值 mySQL.AddField("editTime", DateTime.Now.ToInt64()); mySQL.AddField("addTime", DateTime.Now.ToInt64()); if (db.CreateDb(mySQL) == 1) { db.ExecuteNonQuery("CREATE INDEX index_Name ON ProjectNowLogs(Name); "); } #endregion #region 设置表 mySQL.Clear(); mySQL.TableName = "Settings"; mySQL.AddField("Name", ""); mySQL.AddField("Value", "");//值 mySQL.AddField("addTime", DateTime.Now); mySQL.AddField("EditTime", DateTime.Now); if (db.CreateDb(mySQL) == 1) { db.ExecuteNonQuery("CREATE INDEX index_Name ON Settings(Name); "); } #endregion var ds_logs = db.ReadData("select * from UpdateLogs order by addTime desc"); if (ds_logs.HaveData()) { List list = new List(); for (int i = 0; i < ds_logs.RowCount(); i++) { var row = ds_logs.GetRow(i); if (i == 0) { last_updatelog_time = row["addTime"].ToInt64().ToDateTime(); LblUseTime.Text = "距离上次更新已经过去:" + RyDate.DateDiff(DateTime.Now, last_updatelog_time, false); } var IntervalTime = 0L; if (i < ds_logs.RowCount() - 1) { IntervalTime = row["addTime"].ToInt64() - ds_logs.GetRow(i + 1)["addTime"].ToInt64(); } list.Add(new UpLogItem() { Id = row["id"].ToInt(), Version = row["VerStr"].ToString(), VerType = row["VerType"].ToString(), LogJson = row["LogJson"].ToString(), LogText = row["LogText"].ToString(), AddTime = row["addTime"].ToInt64(), IntervalTime = IntervalTime }); } LvUpdateLogList.AddObjects(list); OlvUpVer.Text = "版本(" + list.Count + ")"; tabPage4.Text = "更新日志(" + list.Count + ")"; } ds_logs?.Dispose(); var all_project_path = GetAllProjectFiles(out _); List list_project_build = new List(); List list_project_build_checked = new List(); Dictionary dict_build = new Dictionary(); if (_path.Length > 0) { var folder = _path; if (System.IO.File.Exists(folder + "\\Res\\Setting\\Build.json")) { JObject jo_set = JObject.Parse(RyFiles.ReadAllText(folder + "\\Res\\Setting\\Build.json")); JArray jarr_datas = jo_set.GetJsonValue("datas", new JArray()); for (int i = 0; i < jarr_datas.Count; i++) { var item = (JObject)jarr_datas[i]; dict_build[item.GetJsonValue("ProjectName", "")] = item; } } } for (int i = 0; i < all_project_path.Count; i++) { var p_name = ""; try { System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); xml.Load(all_project_path[i]); var xmlnsm = new XmlNamespaceManager(xml.NameTable); xmlnsm.AddNamespace("d", xml.DocumentElement.NamespaceURI); var root = @"d:Project//d:PropertyGroup//d:"; p_name = GetValue("AssemblyName"); if (p_name.Length == 0) { p_name = System.IO.Path.GetFileNameWithoutExtension(all_project_path[i]); } string GetValue(string name) { var node = xml.SelectSingleNode(root + name, xmlnsm); if (node != null) { return node.InnerText; } return ""; } } catch { } if (p_name.Length == 0) { continue; } ProjectLogItem projectLogItem = new ProjectLogItem { ProjectName = p_name, ProjectPath = all_project_path[i], VersionPath = System.IO.Path.GetDirectoryName(all_project_path[i]) + "\\Properties\\AssemblyInfo.cs", BuildPlatform = "Debug|Any CPU" }; if(dict_build.ContainsKey(p_name)) { projectLogItem.BuildPlatform = dict_build[p_name].GetJsonValue("Platform", "Debug|Any CPU"); list_project_build_checked.Add(projectLogItem); } if (!System.IO.File.Exists(projectLogItem.VersionPath)) { projectLogItem.VersionPath = all_project_path[i]; } list_project_build.Add(projectLogItem); TabPage tab = new TabPage() { Text = p_name, Tag = projectLogItem }; Label label_title = new Label { Parent = tab, Location = new Point(1, 10), AutoSize = true, Tag = "title", Text = "中文名:" }; ryControls.TextBoxEx2 txt_title = new ryControls.TextBoxEx2 { Parent = tab, Location = new Point(label_title.Left + label_title.Width + 1, 4), Width = 200, Height = 25, Tag = "", Text = "" }; Label label = new Label { Parent = tab, Location = new Point(txt_title.Left + txt_title.Width + 2, 10), AutoSize = true, Tag = "version", Text = "版本号:" + projectLogItem.Version }; RichTextBox2 rich = new RichTextBox2 { Parent = tab, Dock = DockStyle.Fill, Font = new Font("微软雅黑", 11), OnlyInputText = true, ScrollBars = RichTextBoxScrollBars.Both, WordWrap = false, Location = new Point(label_title.Left, label_title.Top + label_title.Height + 10), Size = new Size(tab.ClientSize.Width, tab.ClientSize.Height - (label_title.Top + label_title.Height + 8)), Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom }; rich.AddSeparatorMenu(); rich.AddMenu("添加一个[新增日志]", "log_add").Click += delegate (object s1, EventArgs e1) { AddUpLog("新增"); }; rich.AddMenu("添加一个[改进日志]", "log_up").Click += delegate (object s2, EventArgs e2) { AddUpLog("改进"); }; rich.AddMenu("添加一个[修复日志]", "log_fix").Click += delegate (object s3, EventArgs e3) { AddUpLog("修复"); }; rich.AddMenu("添加一个[删除日志]", "log_del").Click += delegate (object s4, EventArgs e4) { AddUpLog("删除"); }; rich.AddMenu("设置为开发日志", "log_dev").Click += delegate (object s4, EventArgs e4) { var iPos = rich.GetFirstCharIndexOfCurrentLine(); if (iPos >= 0) { var txt = rich.Text; var iPos2 = txt.IndexOf("]", iPos); if ((iPos2 - 5) >= iPos) { rich.SelectionStart = iPos2 + 1; rich.SelectionLength = 0; rich.SelectedText = "[开发]"; //txt = txt.Substring(0, iPos)+ txt.Substring(iPos, iPos2- iPos+1)+"[开发]"+txt.Substring(iPos2+1); } //rich.Text = txt; //rich.SelectionStart = iPos2 + 5; } }; rich.AddMenu("插入更新分组", "log_group").Click += delegate (object s4, EventArgs e4) { FrmGroupSelected frm = new FrmGroupSelected(); frm.DbPath = _path + "\\Res\\Setting\\UpdateLogs.dat"; frm.ProjectName = p_name; if (frm.ShowDialog() == DialogResult.OK) { var lines = rich.Lines; var line_index = rich.GetLineFromCharIndex(rich.SelectionStart); if (line_index < 0) { line_index = 0; } if (lines.Length == 0 || lines[line_index].Trim().Length == 0) { var iPos = rich.GetFirstCharIndexFromLine(line_index); rich.SelectionStart = iPos; rich.SelectionLength = 0; rich.SelectedText = "#### " + frm.SelectedGroupName; //lines[line_index] = "#### " + frm.SelectedGroupName; //rich.Lines = lines; } else if (lines[line_index].Trim() == "####") { var iPos = rich.GetFirstCharIndexFromLine(line_index); rich.SelectionStart = iPos; rich.SelectionLength = lines[line_index].Length; rich.SelectedText = "#### " + frm.SelectedGroupName; //lines[line_index] = "#### " + frm.SelectedGroupName; //rich.Lines = lines; } else { MessageBox.Show("请选择空行或者格式正确的行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } frm.Dispose(); }; void AddUpLog(string name) { var lines = rich.Lines.ToList(); var line_index = rich.GetLineFromCharIndex(rich.SelectionStart); if (line_index < 0) { line_index = 0; } else { if (lines.Count > 0) { var have = false; for (int j = line_index; j >= 0; j--) { if (lines[j].StartsWith("#### ")) { line_index = j + 1; have = true; break; } } if (!have) { line_index = 0; } } } var find_line = -1; var match = false; Dictionary dict_line = new Dictionary(); for (int i1 = line_index; i1 < lines.Count; i1++) { var line = lines[i1]; var stype = line.GetStr("[", "]"); if (line.StartsWith("#### ")) { rich.SelectionStart = rich.GetFirstCharIndexFromLine(i1); rich.SelectionLength = 0; rich.SelectedText = "*.[" + name + "]\n"; rich.SelectionStart--; //lines.Insert(find_line, "*.[" + name + "]"); match = true; break; } if (stype.Length > 0) { dict_line[stype] = i1; } if (line.IndexOfEx("[" + name + "]") >= 0) { find_line = i1; } else { if (find_line >= 0) { find_line++; rich.SelectionStart = rich.GetFirstCharIndexFromLine(find_line); rich.SelectionLength = 0; rich.SelectedText = "*.[" + name + "]\n"; rich.SelectionStart--; //lines.Insert(find_line, "*.[" + name + "]"); match = true; break; } } } if (find_line >= 0 && !match) { rich.SelectionStart = rich.Text.Length; rich.SelectionLength = 0; rich.SelectedText = "\n*.[" + name + "]"; //lines.Add("*.[" + name + "]"); find_line++; } if (find_line == -1) { if (name == "新增") { rich.SelectionStart = rich.GetFirstCharIndexFromLine(line_index); rich.SelectionLength = 0; rich.SelectedText = "*.[" + name + "]\n"; rich.SelectionStart--; //lines.Insert(line_index, "*.[" + name + "]"); find_line = line_index; } else if (name == "改进") { if (dict_line.ContainsKey("新增")) { var ii = rich.GetFirstCharIndexFromLine(dict_line["新增"] + 1); if (ii == -1) { rich.Text += "\n"; rich.SelectionStart = rich.Text.Length + 1; } else { rich.SelectionStart = ii; } rich.SelectionLength = 0; rich.SelectedText = "*.[" + name + "]\n"; rich.SelectionStart--; //lines.Insert(dict_line["新增"]+1, "*.[" + name + "]"); find_line = dict_line["新增"] + 1; } else { var ii = rich.GetFirstCharIndexFromLine(line_index); if (ii == -1) { rich.Text += "\n"; rich.SelectionStart = rich.Text.Length + 1; } else { rich.SelectionStart = ii; } rich.SelectionLength = 0; rich.SelectedText = "*.[" + name + "]\n"; rich.SelectionStart--; //lines.Insert(line_index, "*.[" + name + "]"); find_line = line_index; } } else { rich.SelectionStart = rich.Text.Trim().Length; rich.SelectionLength = 0; rich.SelectedText = (rich.Text.Trim().Length > 0 ? "\n" : "") + "*.[" + name + "]"; //lines.Add("*.[" + name + "]"); find_line = lines.Count - 1; } } //var txt = ""; //var SelectionStart = -1; //for (int t = 0; t < lines.Count; t++) //{ // if (lines[t].Length == 0) { continue; } // if (txt.Length > 0) { txt += "\n"; } // txt += lines[t]; // if(find_line==t) // { // SelectionStart = txt.Length; // } //} //rich.Text = txt; //rich.SelectionStart= SelectionStart; //rich.SelectionLength = 0; } var ds_now_up = db.ReadData("select * from ProjectNowLogs where Name='" + p_name + "'"); if (ds_now_up.HaveData()) { txt_title.Text = ds_now_up.GetRow(0)["ChsName"].ToString(); rich.Text = ds_now_up.GetRow(0)["Value"].ToString(); projectLogItem.LastSave = ds_now_up.GetRow(0)["EditTime"].ToInt64().ToDateTime(); } rich.TextChanged += delegate (object s0, EventArgs e0) { dict_changed[p_name] = true; }; ds_now_up?.Dispose(); tabControl1.TabPages.Add(tab); if (p_name == ProjectName) { tabControl1.SelectedTab = tab; } } LvProjectBuild.AddObjects(list_project_build); LvProjectBuild.CheckedObjects = list_project_build_checked; } db.Free(); } else { for (int i = 0; i < tabControl1.TabCount; i++) { var tab=tabControl1.TabPages[i]; if(tab.Tag is ProjectLogItem item) { if(item.ProjectName==ProjectName) { tabControl1.SelectedTab = tab; break; } } } } } class VerRenderer : BaseRenderer { public VerRenderer() { UseGdiTextRendering = false; } // // 摘要: // Draw the flags // // 参数: // g: // // r: public override void Render(Graphics g, Rectangle r) { DrawBackground(g, r); if (!(base.Aspect is IConvertible convertible)) { return; } r = ApplyCellPadding(r); if (base.RowObject is UpLogItem item1) { var start_x = 2; if (item1.VerType=="main") { start_x += DrawImage2(g, r, start_x,SuperDesign.Properties.Resources.fav); } else { start_x += 4; } start_x += DrawText2(g, r, start_x, item1.Version); } } } /// /// 获取毕方标准项目根路径 /// /// private string GetBFFolderPath() { var _path = _ProjectPath; while (true) { _path = System.IO.Path.GetDirectoryName(_path.TrimEnd('\\')).TrimEnd('\\'); if (System.IO.File.Exists(_path + "\\查看项目.ryp")) { return _path; } else { if (_path.Length < 4) { break; } } } return ""; } private bool IsMain { get; set; } = false; private void LoadPath() { var _path = GetBFFolderPath(); if (_path!="") { var folder = _path; Ini ini = new Ini(folder + "\\查看项目.ryp"); TxtName.Text = ini.ReadIni("project", "name"); TxtEngName.Text = ini.ReadIni("project", "engname"); Txtusqver.Text = ini.ReadIni("project", "usqver"); Txtproglang.Text = ini.ReadIni("project", "proglang"); ChkConfuse.Checked = ini.ReadIni("project", "confuse", false); TxtUploadName.Text = ini.ReadIni("project", "UploadName"); ProcUse = true; IsMain = ini.ReadIni("project", "MainProject", "")== ProjectName; ChkIsMain.Checked = IsMain; table1.TableModel.Rows.Clear(); ProcUse = false; AddPath(true,"Debug输出目录", "Bin\\Debug","包含调试信息的输出目录"); AddPath(true, "Release输出目录", "Bin\\Release", "不包含调试信息的输出目录"); AddPath(true,"源代码目录", "Source", "含有项目源码"); AddPath(true, "安装包目录", "Publish", "对外发布的安装文件"); AddPath(false, " - 免安装输出包目录", "Publish\\Green", "绿色免安装版本目录,通常为zip压缩包"); AddPath(false, " - 安装输出包目录", "Publish\\Install", "需要安装的版本目录,通常为exe压缩包"); AddPath(false, " - 输出底包目录", "Publish\\OriginalFiles", "输出底包,保留完整的文件结构,绿色版、安装包都以此来制作"); AddPath(false, " - 升级输出包目录", "Publish\\UpdateFile", "升级包目录,通常为zip压缩包,非完整输出包"); AddPath(true, "帮助文件目录", "Help", "帮助文档"); AddPath(true, "外部资源目录", "Res", "项目用到的资源备份,例外图标、图片、第三方项目"); AddPath(false, " - 第三方组件项目", "Res\\ThirdParty", "包含第三方组件的项目"); AddPath(false, " - 图片文件夹", "Res\\Images", "含下载的项目图片"); AddPath(true, "更新日志", "更新日志.txt", "当前项目更新日志文件"); AddPath(true, "更新日志", "更新日志.md", "当前项目更新日志文件"); AddPath(true, "更新日志", "CHANGELOG.md", "当前项目更新日志文件"); AddPath(true, "自述文件", "README.md", "当前项目自述文件"); void AddPath(bool bold,string name,string path,string des) { if (System.IO.File.Exists(folder + "\\" + path) || System.IO.Directory.Exists(folder + "\\" + path)) { XPTable.Models.Row itemList = new XPTable.Models.Row { Tag = folder + "\\" + path }; var cell_name = new XPTable.Models.Cell(name); if(bold) cell_name.ForeColor=Color.Blue; else { cell_name.ForeColor = Color.Tomato; } itemList.Cells.Add(cell_name); itemList.Cells.Add(new XPTable.Models.Cell(path)); var cell = new XPTable.Models.Cell(des); cell.ForeColor = Color.Gray; itemList.Cells.Add(cell); table1.TableModel.Rows.Add(itemList); } } } } string _ProjectPath = ""; private string GetPath(string _path) { var cur_dir = Environment.CurrentDirectory; Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(_ProjectPath); var tmp_path = System.IO.Path.GetFullPath(_path); Environment.CurrentDirectory = cur_dir; return tmp_path; } private string GetDebugPath() { if (_ProjectPath.Length==0) { return ""; } if (!System.IO.File.Exists(_ProjectPath)) { return ""; } System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); xml.Load(_ProjectPath); var xmlnsm = new XmlNamespaceManager(xml.NameTable); xmlnsm.AddNamespace("d", xml.DocumentElement.NamespaceURI); var node = xml.SelectSingleNode(@"d:Project//d:PropertyGroup//d:OutputPath", xmlnsm); if (node != null) { string path = node.InnerText; path = GetPath(path); return path; } return ""; } private void BtnCopyCMD_Click(object sender, EventArgs e) { ryCommon.RyFiles.CopyToClip("\"" + Application.ExecutablePath + "\" ver \"$(ProjectDir)\""); if (_ProjectPath == "") { MessageBox.Show("当前项目无效,无法设置", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); xml.Load(_ProjectPath); var xmlnsm = new XmlNamespaceManager(xml.NameTable); xmlnsm.AddNamespace("d", xml.DocumentElement.NamespaceURI); var node = xml.SelectSingleNode(@"d:Project//d:PropertyGroup//d:PreBuildEvent", xmlnsm); if (node != null) { if (node.InnerText == "") { node.InnerText = "\"" + Application.ExecutablePath + "\" ver \"$(ProjectDir)\""; xml.Save(_ProjectPath); } else { MessageBox.Show("当前项目已经存在生成动作,为防止误删,请手工操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } else { XmlElement ww = xml.CreateElement("PropertyGroup", xml.DocumentElement.NamespaceURI); XmlElement ww2 = xml.CreateElement("PreBuildEvent", xml.DocumentElement.NamespaceURI); //ww.("xmlns"); ww2.InnerText = "\"" + Application.ExecutablePath + "\" ver \"$(ProjectDir)\""; xml.DocumentElement.AppendChild(ww); ww.AppendChild(ww2); xml.Save(_ProjectPath); } MessageBox.Show("写入成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void CloseApp() { Itrycn_Db.IsCloseConfirm = false; this.DockPanel.FindForm().Close(); } private void BtnOpenOutput_Click(object sender, EventArgs e) { var debug_path = GetDebugPath(); if (System.IO.Directory.Exists(debug_path)) { ryCommon.RyFiles.OpenFile(debug_path); CloseApp(); } else { MessageBox.Show("打开输出目录失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } /// /// 获取Notepad++路径 /// /// private string GetNotepadPlusPath() { var path = ""; try { RegistryKey LMach = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); RegistryKey softwareRun = LMach.OpenSubKey(@"SOFTWARE\Notepad++", true); if (softwareRun.GetValue("") != null) { string notepad_plus_path = softwareRun.GetValue("").ToString() + "\\notepad++.exe"; if (System.IO.File.Exists(notepad_plus_path)) { path = notepad_plus_path; } } softwareRun.Close(); LMach.Close(); } catch { } return path; } private void BtnMessageBox_Click(object sender, EventArgs e) { ryCommon.RyFiles.CopyToClip("MessageBox.Show(\"这是一个测试\",\"提示\",MessageBoxButtons.OK,MessageBoxIcon.Information);"); CloseApp(); } private void BtnCustomMessageBox_Click(object sender, EventArgs e) { FrmMessageBox frm = new FrmMessageBox { Icon = Icon }; if (frm.ShowDialog() == DialogResult.OK) { CloseApp(); } } public List GetAllProjectFiles(out string sln_path) { sln_path = ""; var result = new List(); var _path = GetBFFolderPath(); if (_path.Length > 0) { var files = System.IO.Directory.GetFiles(_path+ "\\Source","*.sln"); if(files==null || files.Length==0) { var dirs = System.IO.Directory.GetDirectories(_path + "\\Source"); if(dirs!=null) { for (int i = 0; i < dirs.Length; i++) { files = System.IO.Directory.GetFiles(dirs[i], "*.sln"); if(files!=null && files.Length>0) { sln_path = files[0]; break; } } } } else { sln_path = files[0]; } if(sln_path.Length>0) { var lines = RyFiles.ReadAllLines(sln_path); if(lines!=null) { for (int i = 0; i < lines.Length; i++) { if (lines[i].StartsWith("Project(")) { var project_path = lines[i].GetStr(",", ",").Trim().Trim('"'); if(project_path.Length>0) { project_path = System.IO.Path.GetDirectoryName(sln_path).TrimEnd('\\') + "\\" + project_path; if(System.IO.File.Exists(project_path)) { result.Add(project_path); } } } } } } } return result; } private void FrmProject_Load(object sender, EventArgs e) { Ini ini = new Ini(Application.StartupPath+"\\UserDb\\Win.dat"); ini.WriteIni("ProjectHwnd", rySafe.MD5Sha1.GetMD5(GetBFFolderPath()), this.Handle.ToInt32()); } class ProjectLogItem { public string ProjectName { get; set; } = ""; public string ProjectPath { get; set; } = ""; public string BuildPlatform { get; set; } = "Debug|Any CPU"; public string Version { get { return RyProject.GetVerInfo(VersionPath).Version; } } /// ///更新版本号 /// public void UpdateVer() { Manager.RyProject.UpdateVer(VersionPath); } public string VersionPath { get; set; } = ""; public DateTime LastSave { get; set; } = DateTime.MinValue; } private void table1_DoubleClick(object sender, EventArgs e) { if (table1.SelectedItems.Length == 0) { return; } var path = table1.SelectedItems[0].Tag.ToString(); if (System.IO.Directory.Exists(path)) { ryCommon.RyFiles.OpenFile(path); } else if (System.IO.File.Exists(path)) { if (System.IO.Path.GetExtension(path).ToLower() == ".txt") { string notepad_plus_path = GetNotepadPlusPath(); if (System.IO.File.Exists(notepad_plus_path)) { ryCommon.RyFiles.RunFile(notepad_plus_path, "\"" + path + "\""); } else { ryCommon.RyFiles.OpenFile(path); } } else if (System.IO.Path.GetExtension(path).ToLower() == ".md") { ryCommon.RyFiles.OpenFile(path); } else { ryCommon.RyFiles.OpenFolderGotoFile(path); } } } private void BtnClean_Click(object sender, EventArgs e) { switch (MessageBox.Show("是否要进行清理不必要的文件,例如*.pdb", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information)) { case DialogResult.No: return; } var debug_path = GetDebugPath(); if (System.IO.Directory.Exists(debug_path)) { Itrycn_Db.DeleteFiles(debug_path, "*.pdb"); Itrycn_Db.DeleteFiles(debug_path, "*.dcu"); } var folder = GetBFFolderPath(); if(folder!="") { if(System.IO.Directory.Exists(folder + "\\Bin\\Release")) { Itrycn_Db.DeleteFiles(folder + "\\Bin\\Release", "*.pdb"); Itrycn_Db.DeleteFiles(folder + "\\Bin\\Release", "*.dcu"); } } MessageBox.Show("清理完成。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } /// /// 等待进程执行完毕 /// /// /// public static string Read_Prog(string exe,string cmd_text) { String cmd = exe; Process p = new Process { StartInfo = new System.Diagnostics.ProcessStartInfo { FileName = cmd,//设定程序名 Arguments = cmd_text, UseShellExecute = false, //关闭shell的使用 RedirectStandardInput = true, //重定向标准输入 RedirectStandardOutput = true, //重定向标准输出 RedirectStandardError = false, //重定向错误输出 CreateNoWindow = true//设置不显示窗口 } }; p.Start(); string result = p.StandardOutput.ReadToEnd(); p.WaitForExit(20000); p.Close(); return result; } private void BtnBatchZip_Click(object sender, EventArgs e) { BtnBatchZip.Enabled = false; bool PackByLite = ChkPackByLite.Checked; bool BuildOn = ChkBuildOn.Checked; Thread th = new Thread(Start); th.Start(); void Start() { var bf_folder = GetBFFolderPath(); if (bf_folder.Length > 0) { var projects = GetAllProjectFiles(out var sln_path); Dictionary dict_build = new Dictionary(); if (System.IO.File.Exists(bf_folder + "\\Res\\Setting\\Build.json")) { JObject jo_set = JObject.Parse(RyFiles.ReadAllText(bf_folder + "\\Res\\Setting\\Build.json")); JArray jarr_datas = jo_set.GetJsonValue("datas", new JArray()); for (int i = 0; i < jarr_datas.Count; i++) { var item = (JObject)jarr_datas[i]; dict_build[item.GetJsonValue("ProjectName", "")] = item; } } if (BuildOn)//开启编译选项 { bool can_next = true; this.Invoke(new Action(() => { FrmBuilding frm_build = new FrmBuilding(); frm_build.Text = "编译中"; foreach (var item in dict_build) { var Platform = item.Value.GetJsonValue("Platform", "Debug|Any CPU"); frm_build.BuildingList.Add(new BuildComand() {Name=item.Key, Comand = "\"" + sln_path + "\" /build \"" + Platform + "\" /PROJECT " + item.Key }); } if(frm_build.ShowDialog()!= DialogResult.OK) { can_next = false; BtnBatchZip.Enabled = true; } })); if (!can_next) { return; } } } RyProject project = new RyProject(); project.OnStateChanged += Project_OnStateChanged; project.Pack(GetBFFolderPath(), PackByLite); this.Invoke(new Action(() => { BtnBatchZip.Enabled = true; })); } } private void Project_OnStateChanged(object sender, string e) { this.Invoke(new Action(() => { LblState.Text = "状态:" + e; })); } private void GetVersBySln(string path) { var _bf_path = GetBFFolderPath(); RyProject project = new RyProject(); string update_logs_text = ""; if (System.IO.File.Exists(path)) { ryCommon.Ini ini = new Ini(_bf_path + "\\查看项目.ryp"); var sln_text = ryCommon.RyFiles.ReadAllLines(path); for (int i = 0; i < sln_text.Length; i++) { if(sln_text[i].StartsWith("Project")) { var item = sln_text[i].Replace(" = ",",").Split(','); if (item.Length>=3) { var project_name = item[1].Trim().Trim('"'); var project_path =System.IO.Path.GetDirectoryName(path).TrimEnd('\\')+"\\"+item[2].Trim().Trim('"'); var ver = project.GetAssemblyVersion(project_path); if (ver != "") { if(ini.ReadIni("NoVerMD", project_name,0) == 1) { continue; } if (update_logs_text != "") { update_logs_text += "\r\n"; } update_logs_text +="#### "+ project_name + " V" + ver+ "\r\n暂无\r\n"; } } } } } if (update_logs_text != "") { if (_bf_path != "") { var update_text = ryCommon.RyFiles.ReadAllText(_bf_path + "\\CHANGELOG.md"); RyFiles.WriteAllText(_bf_path+ "\\CHANGELOG.md", "### " + DateTime.Now.ToString("yyyy-MM-dd") + "更新\r\n------\r\n"+ update_logs_text + update_text, Encoding.UTF8); RyFiles.OpenFile(_bf_path + "\\CHANGELOG.md"); } } } private void BtnInsertUpdate_Click(object sender, EventArgs e) { var _path = GetBFFolderPath(); if (_path.Length>0) { var files = System.IO.Directory.GetFiles(_path+"\\Source"); for (int i = 0; i < files.Length; i++) { var ext = System.IO.Path.GetExtension(files[i]).ToLower(); if(ext==".sln") { GetVersBySln(files[i]); return; } } var dirs = System.IO.Directory.GetDirectories(_path + "\\Source"); for (int i = 0; i < dirs.Length; i++) { var files2 = System.IO.Directory.GetFiles(dirs[i]); for (int m = 0; m < files2.Length; m++) { var ext = System.IO.Path.GetExtension(files2[m]).ToLower(); if (ext == ".sln") { GetVersBySln(files2[m]); return; } } } //var sln_path = _path + "\\更新日志.md"; } } private void BtnUpdateDll_Click(object sender, EventArgs e) { BtnUpdateDll.Enabled = false; var debug_path = GetDebugPath(); int error = 0; var _error_str = ""; if (System.IO.Directory.Exists(debug_path)) { RyProject project = new RyProject { CopyDllToBin = true, ChangedOutputPath = false }; var bf_folder = GetBFFolderPath(); if(bf_folder!="") { error+= project.UpdateCSproj(bf_folder+"\\Source"); } else { project.SetCSproj(_ProjectPath, ""); } error +=project.UpdateDlls(debug_path,out _error_str); } BtnUpdateDll.Enabled = true; if (error == 0) { MessageBox.Show("更新dll完成。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("更新dll完成,共失败"+error+"项。\r\n\r\n"+ _error_str, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void BtnUpdateVer_Click(object sender, EventArgs e) { var folder = System.IO.Path.GetDirectoryName(_ProjectPath); Manager.RyProject.UpdateVer(folder + "\\Properties\\AssemblyInfo.cs"); CloseApp(); } private void BtnUpdateDllVer_Click(object sender, EventArgs e) { BtnUpdateDllVer.Enabled = false; int error = 0; RyProject project = new RyProject { CopyDllToBin = true, ChangedOutputPath = false }; var bf_folder = GetBFFolderPath(); var _error_str = ""; if (bf_folder != "") { error += project.UpdateDlls(bf_folder + "\\Bin",out _error_str); } var debug_path = GetDebugPath(); if(debug_path.IndexOfEx(bf_folder + "\\Bin")<0) { error += project.UpdateDlls(debug_path, out _error_str); } BtnUpdateDllVer.Enabled = true; if (error == 0) { MessageBox.Show("更新dll完成。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("更新dll完成,共失败" + error + "项。\r\n\r\n"+ _error_str, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void BtnRepairFolder_Click(object sender, EventArgs e) { var _path = GetBFFolderPath(); if (_path.Length > 0) { if (!System.IO.File.Exists(_path + "\\CHANGELOG.md")) { BtnInsertUpdate.PerformClick(); } ryCommon.Ini ini = new Ini(_path + "\\查看项目.ryp"); FrmCreateProject frm = new FrmCreateProject(); frm.TxtFolder.Text = _path; frm.ChkUnCreateProject.Checked = true; frm.TxtProjectEngName.Text = ini.ReadIni("project", "engname"); frm.TxtProjectName.Text = ini.ReadIni("project", "name"); frm.StartPosition = FormStartPosition.CenterParent; frm.ShowDialog(); } } private void BtnSave_Click(object sender, EventArgs e) { var _path = GetBFFolderPath(); if (_path.Length > 0) { var folder = _path; Ini ini = new Ini(folder + "\\查看项目.ryp"); ini.WriteIni("project", "name", TxtName.Text); ini.WriteIni("project", "engname", TxtEngName.Text); ini.WriteIni("project", "usqver", Txtusqver.Text); ini.WriteIni("project", "proglang", Txtproglang.Text); ini.WriteIni("project", "confuse", ChkConfuse.Checked); ini.WriteIni("project", "UploadName", TxtUploadName.Text); if (ChkIsMain.Checked) { ini.WriteIni("project", "MainProject", ProjectName); IsMain = true; } else { if(IsMain) { ini.WriteIni("project", "MainProject", ""); } } MessageBox.Show("保存成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void BtnSave2_Click(object sender, EventArgs e) { System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); xml.Load(_ProjectPath); var xmlnsm = new XmlNamespaceManager(xml.NameTable); xmlnsm.AddNamespace("d", xml.DocumentElement.NamespaceURI); #region 读取条件编译信息 var DefineConstants = xml.SelectSingleNode(@"d:Project//d:PropertyGroup//d:DefineConstants", xmlnsm); if (DefineConstants != null) { string DefineConstants_Text = ";" + DefineConstants.InnerText + ";"; if(ChkTestOn.Checked) { if(DefineConstants_Text.IndexOfEx(";TEST;") < 0) { DefineConstants_Text += "TEST;"; } } else { if (DefineConstants_Text.IndexOfEx(";TEST;")>=0) { DefineConstants_Text = DefineConstants_Text.Replace(";TEST;",";"); } } if(RbCompany.Checked) { if (DefineConstants_Text.IndexOfEx(";DY;") < 0) { DefineConstants_Text += "DY;"; } if (DefineConstants_Text.IndexOfEx(";PERSONAL;") >= 0) { DefineConstants_Text = DefineConstants_Text.Replace(";PERSONAL;", ";"); } } else if (RbPersonal.Checked) { if (DefineConstants_Text.IndexOfEx(";PERSONAL;") < 0) { DefineConstants_Text += "PERSONAL;"; } if (DefineConstants_Text.IndexOfEx(";DY;") >= 0) { DefineConstants_Text = DefineConstants_Text.Replace(";DY;", ";"); } } else { if (DefineConstants_Text.IndexOfEx(";DY;") >= 0) { DefineConstants_Text = DefineConstants_Text.Replace(";DY;", ";"); } if (DefineConstants_Text.IndexOfEx(";PERSONAL;") >= 0) { DefineConstants_Text = DefineConstants_Text.Replace(";PERSONAL;", ";"); } } DefineConstants.InnerText = DefineConstants_Text.Trim(';'); xml.Save(_ProjectPath); MessageBox.Show("保存成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("保存出错,找不到相关信息。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } #endregion } private void BtnUploadProject_Click(object sender, EventArgs e) { List list = new List(); var _path = GetBFFolderPath(); if (_path.Length > 0) { string ftp_setting_path = _path + "\\FTPUploadData.jryp"; if(System.IO.File.Exists(ftp_setting_path)) { var ouput_folder = GetDebugPath().Trim('\\'); if (ouput_folder.Length ==0 || !System.IO.Directory.Exists(ouput_folder)) { ryCommon.Ini ini = new ryCommon.Ini(_path + "\\查看项目.ryp"); var eng_name = ini.ReadIni("project", "engname"); var com_mode = "Debug"; ouput_folder = _path + "\\Bin\\" + com_mode + "\\" + eng_name; if (!System.IO.Directory.Exists(ouput_folder)) { ouput_folder = _path + "\\Bin\\" + com_mode; } } IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1) { var lines = RyFiles.ReadAllLines(ftp_setting_path); if (lines != null && lines.Length > 0) { for (int i = 0; i < lines.Length; i++) { var line = lines[i].Split('='); if (line.Length < 2) { continue; } var item = line[0]; if (item.Contains("<") && item.Contains(">")) { DataSet ds_var = db.ReadData("select * from VarInfo"); if (ds_var.HaveData()) { for (int n = 0; n < ds_var.Tables[0].Rows.Count; n++) { DataRow row_var = ds_var.Tables[0].Rows[n]; item = item.Replace("<" + row_var["VarName"].ToString() + ">", row_var["VarValue"].ToString()); if (!item.Contains("<") || !item.Contains(">")) { break; } } } } if (item.IndexOfEx(":") < 0 && item.IndexOfEx("<") < 0) { item = ouput_folder + "\\" + item; } if(System.IO.File.Exists(item)) list.Add(new UploadInfo() { FromPath = item, ToPath = line[1] }); } } } db.Free(); } } if(list.Count>0) { FrmUploadFilesToFtp frm= new FrmUploadFilesToFtp(); frm.UploadInfos.AddRange(list); if(frm.ShowDialog()==DialogResult.OK) { } frm.Dispose(); } } private bool SaveUpdateLog(bool clean=false) { var _path = GetBFFolderPath(); if (_path.Length > 0) { IDbInterface db_global = new SQLiteDataProvider(); IDbInterface db = new SQLiteDataProvider(); if (db.ConnDb(_path + "\\Res\\Setting\\UpdateLogs.dat") == 1 && db_global.ConnDb(Application.StartupPath + "\\UserDb\\Project.dat") == 1) { if (clean) { db.ExecuteNonQuery("update ProjectNowLogs set Value='',ValueTime='', editTime="+DateTime.Now.ToInt64()); for (int i = 0; i < tabControl1.TabPages.Count; i++) { var tab = tabControl1.TabPages[i]; for (int c = 0; c < tab.Controls.Count; c++) { var ctl = tab.Controls[c]; if (tab.Tag is ProjectLogItem p_item) { p_item.LastSave = DateTime.Now; if (ctl is RichTextBox2 rich) { rich.Text = ""; } } } } dict_changed.Clear(); } else { #region 当前日志表 JObject jo_group; try { var ds_group = db.ReadData("select * from Settings where Name='GroupList'"); if (ds_group.HaveData()) { jo_group = JObject.Parse(ds_group.GetRow(0)["Value"].ToString()); } else { jo_group = new JObject(); } ds_group?.Dispose(); } catch { jo_group = new JObject(); } for (int i = 0; i < tabControl1.TabPages.Count; i++) { var tab = tabControl1.TabPages[i]; RichTextBox2 rich = null; ryControls.TextBoxEx2 txt = null; if (tab.Tag is ProjectLogItem p_item) { for (int c = 0; c < tab.Controls.Count; c++) { var ctl = tab.Controls[c]; if (ctl is RichTextBox2 rich1) { rich = rich1; } else if (ctl is ryControls.TextBoxEx2 txt1) { txt = txt1; } } if (rich != null && txt != null) { if (dict_changed.ContainsKey(p_item.ProjectName)) { if (!dict_changed[p_item.ProjectName]) { continue; } } else { continue; } RyQuickSQL mySQL = new RyQuickSQL("ProjectNowLogs"); mySQL.AddField("Name", p_item.ProjectName); mySQL.AddField("ChsName", txt.Text); mySQL.AddField("Value", rich.Text);//值 mySQL.AddField("editTime", DateTime.Now.ToInt64()); var ds = db.ReadData("select * from ProjectNowLogs where Name=@Name",mySQL); var ValueTime = ""; if(ds.HaveData()) { ValueTime = ds.GetRow(0)["ValueTime"].ToString(); } var JSON_ValueTime = ValueTime.Length == 0 ? new JArray():JArray.Parse(ValueTime); Dictionary dict = new Dictionary(); for (int j = 0; j < JSON_ValueTime.Count; j++) { var item = JSON_ValueTime[j]; dict[item.GetJsonValue("text", "")] = item.GetJsonValue("time", 0L); } var lines = rich.Lines; var jarr_group = jo_group.GetJsonValue("group_"+p_item.ProjectName,new JArray()); for (int j = 0; j < lines.Length; j++) { if (lines[j].Length == 0) { continue; } if (lines[j].StartsWith("#### ")) { var group_name = lines[j].Substring(5).Trim(); if(!jarr_group.Any(x=>x.GetJsonValue("text","")== group_name)) { JObject _item_group = new JObject { ["text"] = group_name, ["time"] = DateTime.Now.ToInt64() }; jarr_group.Add(_item_group); } } if (!dict.ContainsKey(lines[j])) { JObject jo = new JObject { ["text"] = lines[j], ["time"] = DateTime.Now.ToInt64() }; JSON_ValueTime.Add(jo); dict[lines[j]] = DateTime.Now.ToInt64(); } } jo_group["group_" + p_item.ProjectName] = jarr_group; mySQL.AddField("ValueTime", JSON_ValueTime.ToString()); if (ds.HaveData()) { if (ds.GetRow(0)["editTime"].ToInt64().ToDateTime()> p_item.LastSave) { if(ds.GetRow(0)["Value"].ToString()!= rich.Text) { FrmCompareLog frm = new FrmCompareLog(); frm.Rich1.Text = ds.GetRow(0)["Value"].ToString(); frm.Lbl1.Text = "数据库(老)"; frm.Rich2.Text = rich.Text; frm.Lbl2.Text = "本地信息(最新)"; frm.Text = "[" + (txt.Text.Length == 0 ? p_item.ProjectName : txt.Text) + "]当前日志已被修改"; if (frm.ShowDialog()==DialogResult.OK) { db.Update(mySQL, "Name=@Name"); dict_changed[p_item.ProjectName] = false; frm.Dispose(); continue; } frm.Dispose(); } continue; } else { dict_changed[p_item.ProjectName] = false; db.Update(mySQL, "Name=@Name"); } } else { mySQL.AddField("addTime", DateTime.Now.ToInt64()); db.Insert(mySQL); dict_changed[p_item.ProjectName] = false; } ds?.Dispose(); RyQuickSQL mySQL_project = new RyQuickSQL("Projects"); mySQL_project.AddField("ProjectName", p_item.ProjectName); mySQL_project.AddField("FolderName", System.IO.Path.GetDirectoryName(_path));// mySQL_project.AddField("BfFolder", _path);// mySQL_project.AddField("ProjectPath", p_item.ProjectPath); mySQL_project.AddField("SaveTime", DateTime.Now.ToInt64()); mySQL_project.AddField("editTime", DateTime.Now.ToInt64()); if (db.Update(mySQL_project, "ProjectName=@ProjectName and FolderName=@FolderName") == 0) { //mySQL_project.AddField("VerUpdateTime", DateTime.Now.ToInt64());// //mySQL_project.AddField("VerStr", Version); mySQL_project.AddField("addTime", DateTime.Now.ToInt64()); db.Insert(mySQL_project); } p_item.LastSave = DateTime.Now; } } } RyQuickSQL MySQL_Setting = new RyQuickSQL("Settings"); MySQL_Setting.AddField("Name", "GroupList"); MySQL_Setting.AddField("Value", jo_group.ToString()); MySQL_Setting.AddField("EditTime", DateTime.Now); if (db.Update(MySQL_Setting, "Name=@Name") == 0) { MySQL_Setting.AddField("AddTime", DateTime.Now); db.Insert(MySQL_Setting); } db.Free(); return true; #endregion } } db.Free(); } return false; } private void BtnSaveLog_Click(object sender, EventArgs e) { if (SaveUpdateLog()) { MessageBox.Show("保存成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } protected override void WndProc(ref System.Windows.Forms.Message msg) { switch (msg.Msg) { case 17189: //处理消息 { #region 激活窗体 switch (msg.WParam.ToInt32()) { case 100:// var forms = Application.OpenForms; for (int i = 0; i < forms.Count; i++) { if (forms[i] is Form1 form) { var topmost = form.TopMost; form.TopMost = true; form.BringToFront(); RyForm.BringToTop(form.Handle); RyForm.ShowCenter(form,null); form.Show(); form.TopMost = topmost; } } break; } #endregion } break; default: base.WndProc(ref msg);//调用基类函数处理非自定义消息。 break; } } private void FrmProject_FormClosing(object sender, FormClosingEventArgs e) { SaveUpdateLog(); Ini ini = new Ini(Application.StartupPath + "\\UserDb\\Win.dat"); ini.DelKey("ProjectHwnd", rySafe.MD5Sha1.GetMD5(_ProjectPath)); //QuickMsg.RyMemoryShare.DelMemory("S" + rySafe.MD5Sha1.GetMD5(_ProjectPath)); } private void BtnPublishLogs_Click(object sender, EventArgs e) { switch (MessageBox.Show("是否确认要发布更新日志?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)) { case DialogResult.OK: break; default: return; } var _path = GetBFFolderPath(); if (_path.Length > 0) { var projects = GetAllProjectFiles(out var sln_path); IDbInterface db_global = new SQLiteDataProvider(); IDbInterface db = new SQLiteDataProvider(); if (db.ConnDb(_path + "\\Res\\Setting\\UpdateLogs.dat") == 1 && db_global.ConnDb(Application.StartupPath + "\\UserDb\\Project.dat") == 1) { Ini ini = new Ini(_path+ "\\查看项目.ryp"); var Main_Project = ini.ReadIni("project", "MainProject", ""); var Main_Version = ""; ProjectLogItem first_tag = null; JArray jarr = new JArray(); var index = 0; //List list_build = new List(); for (int i = 0; i < tabControl1.TabPages.Count; i++) { var tab = tabControl1.TabPages[i]; RichTextBox2 rich = null; ryControls.TextBoxEx2 txt = null; if (tab.Tag is ProjectLogItem p_item) { for (int c = 0; c < tab.Controls.Count; c++) { var ctl = tab.Controls[c]; if (ctl is RichTextBox2 rich1) { if (rich1.Text.Length == 0) { continue; } rich = rich1; } else if(ctl is ryControls.TextBoxEx2 txt1) { txt = txt1; } } if(rich!=null && txt!=null) { if (ChkUpdateVerByPublish.Checked) { p_item.UpdateVer(); } if(ChkBuildOn.Checked)//开启编译选项 { FrmBuilding frm_build = new FrmBuilding(); frm_build.Text = "编译=>"+p_item.ProjectName; frm_build.BuildingList.Add(new BuildComand() {Name=p_item.ProjectName, Comand = "\"" + sln_path + "\" /build \"Debug|Any CPU\" /PROJECT " + p_item.ProjectName }); frm_build.ShowDialog(); } var Version = p_item.Version; if (Main_Project.Length == 0) { if (index == 0) { Main_Version = Version; } } else { if (Main_Project == p_item.ProjectName) { Main_Version = Version; } } if (index == 0) { first_tag = p_item; } var ds_now_up = db.ReadData("select * from ProjectNowLogs where Name='" + p_item.ProjectName + "'"); var ValueTime = ""; if (ds_now_up.HaveData()) { ValueTime = ds_now_up.GetRow(0)["ValueTime"].ToString(); } ds_now_up?.Dispose(); var JSON_ValueTime = ValueTime.Length == 0 ? new JArray() : JArray.Parse(ValueTime); Dictionary dict = new Dictionary(); for (int j = 0; j < JSON_ValueTime.Count; j++) { var item = JSON_ValueTime[j]; dict[item.GetJsonValue("text", "")] = item.GetJsonValue("time", 0L); } var lines = rich.Lines; var now_jarr = new JArray(); var group = ""; for (int j = 0; j < lines.Length; j++) { if (lines[j].Length == 0) { continue; } if (lines[j].StartsWith("#### ")) { group = lines[j].Substring(5); } if (!dict.ContainsKey(lines[j])) { JObject jo = new JObject { ["text"] = lines[j], ["time"] = DateTime.Now.ToInt64(), ["group"]= group, }; now_jarr.Add(jo); dict[lines[j]] = DateTime.Now.ToInt64(); } else { JObject jo = new JObject { ["text"] = lines[j], ["time"] = dict[lines[j]], ["group"] = group, }; now_jarr.Add(jo); } } JObject jo_item = new JObject { { "ProjectName", p_item.ProjectName }, { "ProjectChsName", txt.Text }, { "VerStr", Version }, { "LogText",rich.Text }, { "LogTime",now_jarr } }; if (Main_Version.Length > 0) { jarr.Insert(0, jo_item); } else { jarr.Add(jo_item); } RyQuickSQL mySQL_project = new RyQuickSQL("Projects"); mySQL_project.AddField("ProjectName", p_item.ProjectName); mySQL_project.AddField("VerUpdateTime", DateTime.Now.ToInt64());// mySQL_project.AddField("VerStr", Version); mySQL_project.AddField("FolderName", System.IO.Path.GetDirectoryName(_path));// mySQL_project.AddField("BfFolder", _path); mySQL_project.AddField("ProjectPath", p_item.ProjectPath); mySQL_project.AddField("SaveTime", DateTime.Now.ToInt64()); mySQL_project.AddField("editTime", DateTime.Now.ToInt64()); if (db.Update(mySQL_project, "ProjectName=@ProjectName and FolderName=@FolderName") == 0) { mySQL_project.AddField("addTime", DateTime.Now.ToInt64()); db.Insert(mySQL_project); } index++; } } } for (int i = 0; i < tabControl1.TabPages.Count; i++) { var tab = tabControl1.TabPages[i]; if (tab.Tag is ProjectLogItem p_item) { for (int c = 0; c < tab.Controls.Count; c++) { var ctl = tab.Controls[c]; if (ctl is Label label && label.Tag!=null && label.Tag.ToString()=="version") { label.Text = "版本号:" + p_item.Version; } } } } if (Main_Version.Length==0 && first_tag!=null) { Main_Version = first_tag.Version; } #region 日志表 var log_text = SuperDesign.Manager.APIManager.GetMdLogText(jarr, DateTime.Now,true); var CHANGELOG = RyFiles.ReadAllText(_path+ "\\CHANGELOG.md").Trim(); CHANGELOG = log_text + "\r\n\r\n" + CHANGELOG; RyFiles.WriteAllText(_path + "\\CHANGELOG.md", CHANGELOG); RyQuickSQL mySQL = new RyQuickSQL("UpdateLogs"); var folder = System.IO.Path.GetDirectoryName(_ProjectPath); mySQL.AddField("VerStr", Main_Version); mySQL.AddField("LogText", log_text); mySQL.AddField("LogJson", jarr.ToString()); mySQL.AddField("editTime", DateTime.Now.ToInt64()); if (db.Update(mySQL, "VerStr=@VerStr") == 0) { mySQL.AddField("addTime", DateTime.Now.ToInt64()); db.Insert(mySQL); } SaveUpdateLog(true); LvUpdateLogList.ClearObjects(); var ds_logs = db.ReadData("select * from UpdateLogs order by addTime desc"); if (ds_logs.HaveData()) { List list = new List(); for (int i = 0; i < ds_logs.RowCount(); i++) { var row = ds_logs.GetRow(i); var IntervalTime = 0L; if (i == 0) { last_updatelog_time = row["addTime"].ToInt64().ToDateTime(); LblUseTime.Text = "距离上次更新已经过去:" + RyDate.DateDiff(DateTime.Now, last_updatelog_time, false); } if (i < ds_logs.RowCount() - 1) { IntervalTime = row["addTime"].ToInt64() - ds_logs.GetRow(i + 1)["addTime"].ToInt64(); } list.Add(new UpLogItem() { Id= row["id"].ToInt(), Version = row["VerStr"].ToString(), VerType = row["VerType"].ToString(), LogText = row["LogText"].ToString(), LogJson = row["LogJson"].ToString(), AddTime = row["addTime"].ToInt64(), IntervalTime= IntervalTime }); } LvUpdateLogList.AddObjects(list); OlvUpVer.Text = "版本(" + list.Count + ")"; tabPage4.Text = "更新日志(" + list.Count + ")"; } else { OlvUpVer.Text = "版本"; tabPage4.Text = "更新日志"; } ds_logs?.Dispose(); MessageBox.Show("发布成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); FrmPublishLogs frm = new FrmPublishLogs { Icon = Icon, BFFolderPath = GetBFFolderPath() }; frm.ShowLog(jarr.ToString()); frm.ShowDialog(); frm.Dispose(); #endregion } db.Free(); } } private void FrmProject_Deactivate(object sender, EventArgs e) { SaveUpdateLog(); } private void LvUpdateLogList_DoubleClick(object sender, EventArgs e) { if (LvUpdateLogList.SelectedObject == null) { return; } var item=(UpLogItem)LvUpdateLogList.SelectedObject; FrmUpdateLog frm = new FrmUpdateLog(); frm.Icon = Icon; frm.Text = "更新日志=>更新时间:" + item.AddTime.ToDateTime(); frm.ShowLog(item.LogJson); if (frm.ShowDialog()==DialogResult.OK) { } frm.Dispose(); } private void BtnSubmitGit_Click(object sender, EventArgs e) { var git_path = SuperDesign.Manager.APIManager.GetTortoiseGitProcPath(); if (git_path.Length > 0) { RyFiles.RunFile(git_path, "/command:commit", GetBFFolderPath()); } } private void 设为正式版本ToolStripMenuItem_Click(object sender, EventArgs e) { if (LvUpdateLogList.SelectedObject == null) { return; } var item = (UpLogItem)LvUpdateLogList.SelectedObject; var _path = GetBFFolderPath(); if (_path.Length > 0) { var VerType = item.VerType == "main"?"beta": "main"; IDbInterface db = new SQLiteDataProvider(); if (db.ConnDb(_path + "\\Res\\Setting\\UpdateLogs.dat") == 1) { RyQuickSQL mySQL = new RyQuickSQL("UpdateLogs"); mySQL.AddField("VerType", VerType); db.Update(mySQL,"id="+item.Id); item.VerType = VerType; LvUpdateLogList.RefreshObject(item); } db.Free(); } } private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) { if (LvUpdateLogList.SelectedObject == null) { 设为正式版本ToolStripMenuItem.Enabled = false; return; } 设为正式版本ToolStripMenuItem.Enabled = true; var item = (UpLogItem)LvUpdateLogList.SelectedObject; if(item.VerType=="main") { 设为正式版本ToolStripMenuItem.Text = "设为测试版本"; } else { 设为正式版本ToolStripMenuItem.Text = "设为正式版本"; } } DateTime last_updatelog_time = DateTime.MinValue; private void FrmProject_Shown(object sender, EventArgs e) { var _path = GetBFFolderPath(); if (_path.Length > 0) { string ftp_setting_path = _path + "\\FTPUploadData.jryp"; if(System.IO.File.Exists(ftp_setting_path)) { BtnUploadProject.Enabled = true; } else { BtnUploadProject.Enabled = false; } } } private Dictionary dict_changed = new Dictionary(); class UpContentInfo { public List AddInfo { get; set; } = new List(); public List DelInfo { get; set; } = new List(); /// /// 改进信息 /// public List BetterInfo { get; set; } = new List(); /// /// 修复信息 /// public List FixInfo { get; set; } = new List(); public List OtherInfo { get; set; } = new List(); } private string GetHtmlLogs() { ryCommon.Ini ini = new Ini(GetBFFolderPath() + "\\查看项目.ryp"); var list = LvUpdateLogList.SelectedObjects; List list2 = new List(); for (int i = 0; i < list.Count; i++) { var item = (UpLogItem)list[i]; list2.Add(item); } list2.Sort((x, y) => x.CompareTo(y)); var Main_Project = ini.ReadIni("project", "MainProject", ""); Dictionary> dict_up = new Dictionary>(); Dictionary dict_eng_to_chs = new Dictionary(); for (int i = 0; i < list2.Count; i++) { var item = list2[i]; try { JArray jarr = JArray.Parse(item.LogJson); for (int j = 0; j < jarr.Count; j++) { var item_json = jarr[j]; var eng_name = item_json.GetJsonValue("ProjectName", ""); if (ini.ReadIni("NoVerHtml", eng_name, 0) == 1) { continue; } var ProjectChsName = item_json.GetJsonValue("ProjectChsName", ""); if (ProjectChsName.Length > 0) { if (!dict_eng_to_chs.ContainsKey(eng_name)) { dict_eng_to_chs[eng_name] = ProjectChsName; } } if (!dict_up.ContainsKey(eng_name)) { dict_up[eng_name] = new Dictionary(); } var ValueTime = item_json.GetJsonValue("LogTime", ""); var JSON_ValueTime = ValueTime.Length == 0 ? new JArray() : JArray.Parse(ValueTime); Dictionary dict_group = new Dictionary(); for (int jj = 0; jj < JSON_ValueTime.Count; jj++) { var item_jarr = JSON_ValueTime[jj]; dict_group[item_jarr.GetJsonValue("text", "")] = item_jarr.GetJsonValue("group", ""); } var up_content_all = dict_up[eng_name]; var logs = item_json.GetJsonValue("LogText", "").Replace("\r", "\n").Replace("\n\n", "\n").Split('\n'); for (int m = 0; m < logs.Length; m++) { if (logs[m].Length == 0) { continue; } var log_item = logs[m]; if (log_item.StartsWith("- *.")) { log_item = log_item.Substring(2); } if (log_item.IndexOf("[开发]") >= 0) { continue; } if (log_item.StartsWith("#### ")) { continue; } #region 更新日志 var group = "主功能"; if (dict_group.ContainsKey(log_item)) { group = dict_group[log_item]; } UpContentInfo up_content = null; if (!up_content_all.ContainsKey(group)) { up_content = new UpContentInfo(); up_content_all[group] = up_content; } else { up_content = up_content_all[group]; } var name = log_item.GetStr("[", "]"); if (name == "新增") { up_content.AddInfo.Add(log_item); } else if (name == "改进" || name == "优化") { up_content.BetterInfo.Add(log_item); } else if (name == "删除") { up_content.DelInfo.Add(log_item); } else if (name == "修复") { up_content.FixInfo.Add(log_item); } else { up_content.OtherInfo.Add(log_item); } #endregion } } } catch (Exception ex) { } } string log_text = ""; if (dict_up.ContainsKey(Main_Project)) { log_text += "

" + System.Web.HttpUtility.HtmlEncode(dict_eng_to_chs.ContainsKey(Main_Project) ? dict_eng_to_chs[Main_Project] : Main_Project) + "

"; var main_info_all = dict_up[Main_Project]; foreach (var item in main_info_all) { var main_info = item.Value; if (item.Key.Length > 0) { log_text += "\r\n

" + System.Web.HttpUtility.HtmlEncode(item.Key) + "

"; } for (int i = 0; i < main_info.AddInfo.Count; i++) { log_text += "\r\n

" + System.Web.HttpUtility.HtmlEncode(main_info.AddInfo[i]) + "

"; } for (int i = 0; i < main_info.BetterInfo.Count; i++) { log_text += "\r\n

" + System.Web.HttpUtility.HtmlEncode(main_info.BetterInfo[i]) + "

"; } for (int i = 0; i < main_info.DelInfo.Count; i++) { log_text += "\r\n

" + System.Web.HttpUtility.HtmlEncode(main_info.DelInfo[i]) + "

"; } for (int i = 0; i < main_info.FixInfo.Count; i++) { log_text += "\r\n

" + System.Web.HttpUtility.HtmlEncode(main_info.FixInfo[i]) + "

"; } for (int i = 0; i < main_info.OtherInfo.Count; i++) { log_text += "\r\n

" + System.Web.HttpUtility.HtmlEncode(main_info.OtherInfo[i]) + "

"; } } } foreach (var item in dict_up) { if (item.Key == Main_Project) { continue; } log_text += "\r\n

" + System.Web.HttpUtility.HtmlEncode(dict_eng_to_chs.ContainsKey(item.Key) ? dict_eng_to_chs[item.Key] : item.Key) + "

"; var main_info_all = item.Value; foreach (var item2 in main_info_all) { var main_info = item2.Value; if (item2.Key.Length > 0) { log_text += "\r\n

" + System.Web.HttpUtility.HtmlEncode(item2.Key) + "

"; } for (int i = 0; i < main_info.AddInfo.Count; i++) { log_text += "\r\n

" + System.Web.HttpUtility.HtmlEncode(main_info.AddInfo[i]) + "

"; } for (int i = 0; i < main_info.BetterInfo.Count; i++) { log_text += "\r\n

" + System.Web.HttpUtility.HtmlEncode(main_info.BetterInfo[i]) + "

"; } for (int i = 0; i < main_info.DelInfo.Count; i++) { log_text += "\r\n

" + System.Web.HttpUtility.HtmlEncode(main_info.DelInfo[i]) + "

"; } for (int i = 0; i < main_info.FixInfo.Count; i++) { log_text += "\r\n

" + System.Web.HttpUtility.HtmlEncode(main_info.FixInfo[i]) + "

"; } for (int i = 0; i < main_info.OtherInfo.Count; i++) { log_text += "\r\n

" + System.Web.HttpUtility.HtmlEncode(main_info.OtherInfo[i]) + "

"; } } } return log_text.Trim(); } private void 生成Html日志ToolStripMenuItem_Click(object sender, EventArgs e) { if (LvUpdateLogList.SelectedObjects.Count==0) { return; } RyFiles.CopyToClip(GetHtmlLogs()); MessageBox.Show("已复制到剪切板。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } bool ProcUse = false; private void ChkIsMain_CheckedChanged(object sender, EventArgs e) { if (ProcUse) { return; } } private void timer1_Tick(object sender, EventArgs e) { if(DateTime.Now.Second==0) { if(last_updatelog_time!=DateTime.MinValue) { LblUseTime.Text = "距离上次更新已经过去:" + RyDate.DateDiff(DateTime.Now, last_updatelog_time,false); } else { LblUseTime.Text = "距离上次更新已经过去:首次更新"; } } } private void BtnFtpFiles_Click(object sender, EventArgs e) { var _path = GetBFFolderPath(); if (_path.Length > 0) { var txt = RyFiles.ReadAllText(_path+ "\\FTPUploadData.jryp"); FrmSaveContent frm=new FrmSaveContent(); frm.Text = "FTP上传文件列表"; frm.Rich1.Text = txt; if(frm.ShowDialog()==DialogResult.OK) { RyFiles.WriteAllText(_path + "\\FTPUploadData.jryp", frm.Rich1.Text); BtnUploadProject.Enabled = true; } frm.Dispose(); } } private void BtnPackFileList_Click(object sender, EventArgs e) { var _path = GetBFFolderPath(); if (_path.Length > 0) { var txt = RyFiles.ReadAllText(_path + "\\Publish\\Publish.set"); FrmSaveContent frm = new FrmSaveContent(); frm.Text = "打包文件列表"; frm.Rich1.Text = txt; if (frm.ShowDialog() == DialogResult.OK) { RyFiles.WriteAllText(_path + "\\Publish\\Publish.set", frm.Rich1.Text); } frm.Dispose(); } } private void 生成Html日志并上传到服务器ToolStripMenuItem_Click(object sender, EventArgs e) { if (LvUpdateLogList.SelectedObjects.Count == 0) { return; } var html = GetHtmlLogs(); IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType); if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1) { var ds = db.ReadData("select * from Settings where name='Setting'"); if (ds.HaveData()) { var row = ds.GetRow(0); ryCommon.Storage mStor = new ryCommon.Storage(row["value"].ToString()); mStor.SelectNodeBySet(); var bf_folder = GetBFFolderPath(); if (bf_folder != "") { ryCommon.Ini ini = new ryCommon.Ini(bf_folder + "\\查看项目.ryp"); var eng_name = ini.ReadIni("project", "engname"); var proglang = ini.ReadIni("project", "proglang"); var confuse = ini.ReadIni("project", "confuse", 1); var upload_name = ini.ReadIni("project", "UploadLogName"); if (upload_name.Trim().Length == 0) { upload_name = eng_name; } var ftpid = mStor.GetAttrValue("ftpid", 0); var ftp_remote_dir = mStor.GetAttrValue("ftp_remote_dir"); if (ftpid > 0) { this.Invoke(new Action(() => { RyFiles.WriteAllText(Application.StartupPath + "\\temp_"+ upload_name + ".html", html); SuperDesign.Manager.FTP.FrmUploadUpdateZipToFtp frm = new SuperDesign.Manager.FTP.FrmUploadUpdateZipToFtp(); frm.UpdateLogMode = true; frm.UpdateHtml = html; frm.LocalPath = Application.StartupPath + "\\temp_" + upload_name + ".html"; frm.EngName = upload_name; frm.FTPId = ftpid; frm.RemoteDir = ftp_remote_dir.TrimEnd('/')+ "/WebUpdateLogs/"; if (frm.ShowDialog() == DialogResult.OK) { //ShowState("上传完成..."); } frm.Dispose(); RyFiles.DeleteFile(Application.StartupPath + "\\temp_"+ upload_name + ".html"); })); } } } } } private void buttonEx1_Click(object sender, EventArgs e) { } private void LvProjectBuild_ItemChecked(object sender, ItemCheckedEventArgs e) { var _path = GetBFFolderPath(); if (_path.Length > 0) { var folder = _path; JArray jarr_datas = new JArray(); var list = LvProjectBuild.CheckedObjects; for (int i = 0; i < list.Count; i++) { var item=(ProjectLogItem)list[i]; JObject jo = new JObject(); jo["ProjectName"] = item.ProjectName; jo["Platform"] = item.BuildPlatform; jarr_datas.Add(jo); } JObject jo_set = new JObject(); jo_set["datas"] = jarr_datas; RyFiles.WriteAllText(folder + "\\Res\\Setting\\Build.json", jo_set.ToString()); } } } class UpLogItem { public int Id { get; set; } = 0; public string Version { get; set; } = ""; public string VerType { get; set; } = ""; public string LogText { get; set; } = ""; public string LogJson { get; set; } = ""; /// /// 开发周期 /// public long IntervalTime { get; set; } = 0; public string IntervalTimeStr { get { if (IntervalTime == 0) { return "无"; } return RyDate.DateDiff(DateTime.MinValue, DateTime.MinValue.AddSeconds(IntervalTime), seconds: false); } } public long AddTime { get; set; } = 0; public int CompareTo(UpLogItem other) { return RySoft.CompareVer(Version, other.Version); } } }