diff --git a/AutoUpdate/AutoUpdate.csproj b/AutoUpdate/AutoUpdate.csproj index 400953e..cfcccd4 100644 --- a/AutoUpdate/AutoUpdate.csproj +++ b/AutoUpdate/AutoUpdate.csproj @@ -44,6 +44,7 @@ + diff --git a/AutoUpdate/ClientVersion.cs b/AutoUpdate/ClientVersion.cs new file mode 100644 index 0000000..f06016b --- /dev/null +++ b/AutoUpdate/ClientVersion.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace AutoUpdate +{ + public class ClientVersion + { + public string Version { get; set; } + + public string ServerUrl { get; set; } + + private List _update = new List(); + public List UpdateFiles { get { return _update; } set { _update = value; } } + } + + public class UpdateFile + { + public string FileName { get; set; } + + public string Url { get; set; } + + public int Size { get; set; } + + public bool NeedRestart { get; set; } + } + + public static class XmlUtil + { + public static T XmlDeserializeObject(string xmlOfObject) where T : class + { + using (MemoryStream ms = new MemoryStream()) + { + using (StreamWriter sr = new StreamWriter(ms, Encoding.UTF8)) + { + sr.Write(xmlOfObject); + sr.Flush(); + ms.Seek(0, SeekOrigin.Begin); + XmlSerializer serializer = new XmlSerializer(typeof(T)); + return serializer.Deserialize(ms) as T; + } + } + } + + public static T DeserializeFromFile(string fileName = "") + { + if (string.IsNullOrWhiteSpace(fileName)) + { + fileName = typeof(T).Name + ".xml"; + } + if (!File.Exists(fileName)) + { + throw new FileNotFoundException("不存在文件:" + fileName); + } + using (var reader = new StreamReader(fileName)) + { + var xs = new XmlSerializer(typeof(T)); + object obj = xs.Deserialize(reader); + reader.Close(); + return (T)obj; + } + } + } +} diff --git a/AutoUpdate/Update.Designer.cs b/AutoUpdate/Update.Designer.cs index eca2b38..84b6cc0 100644 --- a/AutoUpdate/Update.Designer.cs +++ b/AutoUpdate/Update.Designer.cs @@ -28,24 +28,82 @@ /// private void InitializeComponent() { + this.progressBarTotal = new System.Windows.Forms.ProgressBar(); + this.progressBarCurrent = new System.Windows.Forms.ProgressBar(); + this.labelCurrentItem = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.labelCurrent = new System.Windows.Forms.Label(); this.SuspendLayout(); // + // progressBarTotal + // + this.progressBarTotal.Location = new System.Drawing.Point(28, 81); + this.progressBarTotal.Name = "progressBarTotal"; + this.progressBarTotal.Size = new System.Drawing.Size(438, 12); + this.progressBarTotal.Step = 1; + this.progressBarTotal.TabIndex = 6; + // + // progressBarCurrent + // + this.progressBarCurrent.Location = new System.Drawing.Point(27, 42); + this.progressBarCurrent.Name = "progressBarCurrent"; + this.progressBarCurrent.Size = new System.Drawing.Size(438, 12); + this.progressBarCurrent.Step = 1; + this.progressBarCurrent.TabIndex = 7; + // + // labelCurrentItem + // + this.labelCurrentItem.AutoSize = true; + this.labelCurrentItem.Location = new System.Drawing.Point(97, 27); + this.labelCurrentItem.Name = "labelCurrentItem"; + this.labelCurrentItem.Size = new System.Drawing.Size(0, 12); + this.labelCurrentItem.TabIndex = 3; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(26, 66); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(53, 12); + this.label1.TabIndex = 4; + this.label1.Text = "总进度:"; + // + // labelCurrent + // + this.labelCurrent.AutoSize = true; + this.labelCurrent.Location = new System.Drawing.Point(26, 27); + this.labelCurrent.Name = "labelCurrent"; + this.labelCurrent.Size = new System.Drawing.Size(65, 12); + this.labelCurrent.TabIndex = 5; + this.labelCurrent.Text = "正在下载:"; + // // Update // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(580, 148); + this.ClientSize = new System.Drawing.Size(483, 134); + this.ControlBox = false; + this.Controls.Add(this.progressBarTotal); + this.Controls.Add(this.progressBarCurrent); + this.Controls.Add(this.labelCurrentItem); + this.Controls.Add(this.label1); + this.Controls.Add(this.labelCurrent); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.MaximizeBox = false; - this.MinimizeBox = false; this.Name = "Update"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "自动更新"; this.Load += new System.EventHandler(this.Update_Load); this.ResumeLayout(false); + this.PerformLayout(); } #endregion + + private System.Windows.Forms.ProgressBar progressBarTotal; + private System.Windows.Forms.ProgressBar progressBarCurrent; + private System.Windows.Forms.Label labelCurrentItem; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label labelCurrent; } } \ No newline at end of file diff --git a/AutoUpdate/Update.cs b/AutoUpdate/Update.cs index d4f60b8..5616591 100644 --- a/AutoUpdate/Update.cs +++ b/AutoUpdate/Update.cs @@ -8,6 +8,7 @@ using System.IO; using System.Linq; using System.Net; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -15,29 +16,172 @@ namespace AutoUpdate { public partial class Update : Form { - string[] updateInfo; + const string serUri = "http://172.28.1.194:7799/AutoUpdate/ClientVersion.xml"; + const string PuKey = "c756e02cedb42a33f78091a466411bde8447d854"; + private bool isFinished = false; + private List downloadFileList = null; + private ManualResetEvent evtDownload = null; + private ManualResetEvent evtPerDonwload = null; + private WebClient clientDownload = null; + bool error = false; public Update(string[] args) { InitializeComponent(); - updateInfo = args; + if (args == null || args.Length == 0 || args[0] != PuKey) + error = true; } private void Update_Load(object sender, EventArgs e) { - if (updateInfo != null && updateInfo.Length > 0) + if (error) + Application.Exit(); + var versionFile = "ClientVersion.xml"; + ClientVersion old = new ClientVersion(); + if (File.Exists(versionFile)) + old = XmlUtil.DeserializeFromFile(versionFile); + if (string.IsNullOrEmpty(old.ServerUrl)) + old.ServerUrl = serUri; + + clientDownload = new WebClient(); + var version = XmlUtil.XmlDeserializeObject(clientDownload.DownloadString(old.ServerUrl)); + downloadFileList = version.UpdateFiles; + + evtDownload = new ManualResetEvent(true); + evtDownload.Reset(); + Thread t = new Thread(new ThreadStart(ProcDownload)); + t.Name = "download"; + t.Start(); + } + + long total = 0; + long nDownloadedTotal = 0; + string startFile = "ButcherManageClient.exe"; + string oldFolder; + private void ProcDownload() + { + evtPerDonwload = new ManualResetEvent(false); + + foreach (var file in this.downloadFileList) + { + total += file.Size; + } + oldFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "old"); + if (!Directory.Exists(oldFolder)) + Directory.CreateDirectory(oldFolder); + + while (!evtDownload.WaitOne(0, false)) + { + if (this.downloadFileList.Count == 0) + break; + + var file = this.downloadFileList[0]; + if (file.NeedRestart) + startFile = file.FileName; + + this.ShowCurrentDownloadFileName(file.FileName); + + //下载 + clientDownload = new WebClient(); + + clientDownload.DownloadProgressChanged += new DownloadProgressChangedEventHandler(OnDownloadProgressChanged); + clientDownload.DownloadFileCompleted += new AsyncCompletedEventHandler(OnDownloadFileCompleted); + + evtPerDonwload.Reset(); + + clientDownload.DownloadFileAsync(new Uri(file.Url), Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file.FileName + ".tmp"), file); + + //等待下载完成 + evtPerDonwload.WaitOne(); + + clientDownload.Dispose(); + clientDownload = null; + + //移除已下载的文件 + this.downloadFileList.Remove(file); + } + + if (this.downloadFileList.Count == 0) + { + Exit(true); + evtDownload.Set(); + Process.Start(Path.Combine(Application.StartupPath, startFile)); + Application.Exit(); + } + else + Exit(false); + + evtDownload.Set(); + } + + void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e) + { + var file = e.UserState as UpdateFile; + nDownloadedTotal += file.Size; + this.SetProcessBar(0, (int)(nDownloadedTotal * 100 / total)); + //备份文件 + string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file.FileName); + var oldFile = Path.Combine(oldFolder, file.FileName); + if (File.Exists(filePath)) + { + if (File.Exists(oldFile)) + File.Delete(oldFile); + + File.Move(filePath, oldFile); + } + + File.Move(filePath + ".tmp", filePath); + //继续下载其它文件 + evtPerDonwload.Set(); + } + + void OnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) + { + this.SetProcessBar(e.ProgressPercentage, (int)((nDownloadedTotal + e.BytesReceived) * 100 / total)); + } + + delegate void ShowCurrentDownloadFileNameCallBack(string name); + private void ShowCurrentDownloadFileName(string name) + { + if (this.labelCurrentItem.InvokeRequired) + { + ShowCurrentDownloadFileNameCallBack cb = new ShowCurrentDownloadFileNameCallBack(ShowCurrentDownloadFileName); + this.Invoke(cb, new object[] { name }); + } + else + { + this.labelCurrentItem.Text = name; + } + } + + delegate void SetProcessBarCallBack(int current, int total); + private void SetProcessBar(int current, int total) + { + if (this.progressBarCurrent.InvokeRequired) + { + SetProcessBarCallBack cb = new SetProcessBarCallBack(SetProcessBar); + this.Invoke(cb, new object[] { current, total }); + } + else + { + this.progressBarCurrent.Value = current; + this.progressBarTotal.Value = total; + } + } + + delegate void ExitCallBack(bool success); + private void Exit(bool success) + { + if (this.InvokeRequired) + { + ExitCallBack cb = new ExitCallBack(Exit); + this.Invoke(cb, new object[] { success }); + } + else { - var parameters = updateInfo[0].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); - var serverUrl = parameters[0]; - var files = parameters[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - foreach (var file in files) - { - var path = serverUrl + file; - var clientDownload = new WebClient(); - clientDownload.DownloadFileAsync(new Uri(path), file); - } + this.isFinished = success; + this.DialogResult = success ? DialogResult.OK : DialogResult.Cancel; + this.Close(); } - Process.Start(Path.Combine(Application.StartupPath, "ButcherManageClient.exe")); - Application.Exit(); } } } diff --git a/B3ButcherManageClient.sln b/B3ButcherManageClient.sln index d4ef8a1..ed54cc3 100644 --- a/B3ButcherManageClient.sln +++ b/B3ButcherManageClient.sln @@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WeighAndGrading", "WeighAnd EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoUpdate", "AutoUpdate\AutoUpdate.csproj", "{5751AEE3-83BD-4CBE-8E65-0727FEC0F6C4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreateUpdateXmlFile", "CreateUpdateXmlFile\CreateUpdateXmlFile.csproj", "{57BB1A02-118A-443D-A38A-BB36B9A77F6A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -61,6 +63,10 @@ Global {5751AEE3-83BD-4CBE-8E65-0727FEC0F6C4}.Debug|Any CPU.Build.0 = Debug|Any CPU {5751AEE3-83BD-4CBE-8E65-0727FEC0F6C4}.Release|Any CPU.ActiveCfg = Release|Any CPU {5751AEE3-83BD-4CBE-8E65-0727FEC0F6C4}.Release|Any CPU.Build.0 = Release|Any CPU + {57BB1A02-118A-443D-A38A-BB36B9A77F6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {57BB1A02-118A-443D-A38A-BB36B9A77F6A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {57BB1A02-118A-443D-A38A-BB36B9A77F6A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {57BB1A02-118A-443D-A38A-BB36B9A77F6A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BO/Utils/LoginRpcUtil.cs b/BO/Utils/LoginRpcUtil.cs index f6e902c..c50db0a 100644 --- a/BO/Utils/LoginRpcUtil.cs +++ b/BO/Utils/LoginRpcUtil.cs @@ -43,11 +43,5 @@ namespace BO.Utils userInfo.Role = obj.Get("Role"); } } - - public static string CheckVersion(string version) - { - const string method = "/MainSystem/B3ClientService/Rpcs/VersionRpc/CheckVersion"; - return RpcFacade.Call(method, version); - } } } diff --git a/BO/Utils/XmlUtil.cs b/BO/Utils/XmlUtil.cs index 5a886e9..38c65fd 100644 --- a/BO/Utils/XmlUtil.cs +++ b/BO/Utils/XmlUtil.cs @@ -23,7 +23,6 @@ namespace BO.Utils } } - public static T DeserializeFromFile(string fileName = "") { if (string.IsNullOrWhiteSpace(fileName)) @@ -42,5 +41,27 @@ namespace BO.Utils return (T)obj; } } + + public static T XmlDeserializeObject(string xmlOfObject) where T : class + { + using (MemoryStream ms = new MemoryStream()) + { + using (StreamWriter sr = new StreamWriter(ms, Encoding.UTF8)) + { + sr.Write(xmlOfObject); + sr.Flush(); + ms.Seek(0, SeekOrigin.Begin); + XmlSerializer serializer = new XmlSerializer(typeof(T)); + return serializer.Deserialize(ms) as T; + } + } + } + } + + public class ClientVersion + { + public string Version { get; set; } + + public string ServerUrl { get; set; } } } diff --git a/ButcherManageClient/Login.cs b/ButcherManageClient/Login.cs index 0ebc347..ed50240 100644 --- a/ButcherManageClient/Login.cs +++ b/ButcherManageClient/Login.cs @@ -99,31 +99,30 @@ namespace ButcherManageClient pwdTxt.Text = keyBoard.Result; } + const string serUri = "http://172.28.1.194:7799/AutoUpdate/ClientVersion.xml"; + const string puKey = "c756e02cedb42a33f78091a466411bde8447d854"; private void AutoUpdate() { if (!File.Exists("AutoUpdate.exe")) return; - var version = string.Empty; - if (File.Exists("Version.txt")) - { - version = File.ReadAllText("Version.txt"); - } - IniteRpcFacade(); - var files = LoginRpcUtil.CheckVersion(version); - if (string.IsNullOrEmpty(files)) + var versionInfo = new ClientVersion(); + if (File.Exists("ClientVersion.xml")) + versionInfo = XmlUtil.DeserializeFromFile(); + if (string.IsNullOrEmpty(versionInfo.ServerUrl)) + versionInfo.ServerUrl = serUri; + + var down = new System.Net.WebClient(); + var serverVersion = XmlUtil.XmlDeserializeObject(down.DownloadString(versionInfo.ServerUrl)); + if (versionInfo.Version == serverVersion.Version) return; - var serverUrl = ButcherAppContext.Context.UrlConfig.ServerUrl.Replace("Rest.aspx", ""); - if (!serverUrl.EndsWith("/")) - serverUrl += "/"; - serverUrl += "ClientVersion/"; - System.Diagnostics.Process.Start(Path.Combine(Application.StartupPath, "AutoUpdate.exe"), serverUrl + "|" + files); + System.Diagnostics.Process.Start(Path.Combine(Application.StartupPath, "AutoUpdate.exe"), puKey); Application.Exit(); } private void Login_Load(object sender, EventArgs e) { - //AutoUpdate(); + AutoUpdate(); } } } diff --git a/ButcherOrder/ButcherOrderForm.Designer.cs b/ButcherOrder/ButcherOrderForm.Designer.cs index 476e59f..8481133 100644 --- a/ButcherOrder/ButcherOrderForm.Designer.cs +++ b/ButcherOrder/ButcherOrderForm.Designer.cs @@ -48,7 +48,7 @@ this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.OrderDetail_ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.IsOk = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Ordre = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Order = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.PlanNumber = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.HotFadeNumber = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.updateBtn = new System.Windows.Forms.DataGridViewButtonColumn(); @@ -175,7 +175,7 @@ this.ID, this.OrderDetail_ID, this.IsOk, - this.Ordre, + this.Order, this.PlanNumber, this.HotFadeNumber, this.updateBtn, @@ -193,6 +193,7 @@ this.secondOrderGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.secondOrderGridView.Size = new System.Drawing.Size(513, 569); this.secondOrderGridView.TabIndex = 12; + this.secondOrderGridView.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.secondOrderGridView_CellClick); this.secondOrderGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.secondOrderGridView_CellContentClick); // // uDatePicker1 @@ -233,13 +234,13 @@ this.IsOk.ReadOnly = true; this.IsOk.Visible = false; // - // Ordre + // Order // - this.Ordre.DataPropertyName = "Order"; - this.Ordre.HeaderText = "顺序号"; - this.Ordre.Name = "Ordre"; - this.Ordre.ReadOnly = true; - this.Ordre.Width = 110; + this.Order.DataPropertyName = "Order"; + this.Order.HeaderText = "顺序号"; + this.Order.Name = "Order"; + this.Order.ReadOnly = true; + this.Order.Width = 110; // // PlanNumber // @@ -322,7 +323,7 @@ private System.Windows.Forms.DataGridViewTextBoxColumn ID; private System.Windows.Forms.DataGridViewTextBoxColumn OrderDetail_ID; private System.Windows.Forms.DataGridViewTextBoxColumn IsOk; - private System.Windows.Forms.DataGridViewTextBoxColumn Ordre; + private System.Windows.Forms.DataGridViewTextBoxColumn Order; private System.Windows.Forms.DataGridViewTextBoxColumn PlanNumber; private System.Windows.Forms.DataGridViewTextBoxColumn HotFadeNumber; private System.Windows.Forms.DataGridViewButtonColumn updateBtn; diff --git a/ButcherOrder/ButcherOrderForm.cs b/ButcherOrder/ButcherOrderForm.cs index 6744d74..f2bf0db 100644 --- a/ButcherOrder/ButcherOrderForm.cs +++ b/ButcherOrder/ButcherOrderForm.cs @@ -82,6 +82,7 @@ namespace ButcherOrder BindGrid(); } + int? lastSelectOrder = null; void BindGrid() { secondOrderGridView.DataSource = orderList.OrderBy(x => x.Order).OrderBy(x => x.IsOk).ToList(); @@ -89,6 +90,10 @@ namespace ButcherOrder { if ((bool)row.Cells["IsOk"].Value) row.DefaultCellStyle.BackColor = Color.YellowGreen; + if (lastSelectOrder.HasValue && lastSelectOrder == (int?)row.Cells["Order"].Value) + { + row.Selected = true; + } } if (secondOrderGridView.CurrentRow != null) { @@ -101,6 +106,10 @@ namespace ButcherOrder orderLabel.Text = "0"; InitScrollBar1(); secondOrderGridView.Refresh(); + if (roll != -1) + { + secondOrderGridView.FirstDisplayedScrollingRowIndex = roll;// secondOrderGridView.Rows[roll].Index; + } } private void okBtn_Click(object sender, EventArgs e) @@ -112,7 +121,7 @@ namespace ButcherOrder var entity = secondOrderGridView.CurrentRow.DataBoundItem as SecondOrder; if (entity.IsOk) { - var result = MessageBox.Show("当前行已更新\n确定要继续修改吗?","确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); + var result = MessageBox.Show("当前行已更新\n确定要继续修改吗?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result != DialogResult.OK) return; } @@ -140,8 +149,6 @@ namespace ButcherOrder if (e.RowIndex == -1) return; var entity = secondOrderGridView.CurrentRow.DataBoundItem as SecondOrder; - BindSelectColor(entity); - if (e.ColumnIndex < secondOrderGridView.ColumnCount - 2) return; @@ -163,6 +170,7 @@ namespace ButcherOrder } } + int roll = -1; private void InitScrollBar1() { vScrollBar1.Maximum = (secondOrderGridView.RowCount - secondOrderGridView.DisplayedRowCount(false) + 30) * secondOrderGridView.RowTemplate.Height; @@ -171,9 +179,18 @@ namespace ButcherOrder vScrollBar1.LargeChange = secondOrderGridView.RowTemplate.Height * 30; this.vScrollBar1.Scroll += (sender, e) => { - secondOrderGridView.FirstDisplayedScrollingRowIndex = e.NewValue / secondOrderGridView.RowTemplate.Height; - Application.DoEvents(); + roll = e.NewValue / secondOrderGridView.RowTemplate.Height; + secondOrderGridView.FirstDisplayedScrollingRowIndex = roll; }; } + + private void secondOrderGridView_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex == -1) + return; + var entity = secondOrderGridView.CurrentRow.DataBoundItem as SecondOrder; + lastSelectOrder = entity.Order; + BindSelectColor(entity); + } } } diff --git a/ButcherOrder/ButcherOrderForm.resx b/ButcherOrder/ButcherOrderForm.resx index 0df345f..15107e7 100644 --- a/ButcherOrder/ButcherOrderForm.resx +++ b/ButcherOrder/ButcherOrderForm.resx @@ -126,7 +126,7 @@ True - + True diff --git a/CreateUpdateXmlFile/App.config b/CreateUpdateXmlFile/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/CreateUpdateXmlFile/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CreateUpdateXmlFile/ClientVersion.cs b/CreateUpdateXmlFile/ClientVersion.cs new file mode 100644 index 0000000..5b19df9 --- /dev/null +++ b/CreateUpdateXmlFile/ClientVersion.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace CreateUpdateXmlFile +{ + public class ClientVersion + { + public string Version { get; set; } + + public string ServerUrl { get; set; } + + private List _update = new List(); + public List UpdateFiles { get { return _update; } set { _update = value; } } + } + + public class UpdateFile + { + public string FileName { get; set; } + + public string Url { get; set; } + + public int Size { get; set; } + + public bool NeedRestart { get; set; } + } + + public static class XmlUtil + { + public static void SerializerObjToFile(object obj, string fileName = "") + { + if (string.IsNullOrWhiteSpace(fileName)) + { + fileName = obj.GetType().Name + ".xml"; + } + var ser = new XmlSerializer(obj.GetType()); + using (var stream = File.Open(fileName, FileMode.Create)) + { + ser.Serialize(stream, obj); + } + } + } +} diff --git a/CreateUpdateXmlFile/CreateUpdateXmlFile.csproj b/CreateUpdateXmlFile/CreateUpdateXmlFile.csproj new file mode 100644 index 0000000..9d37841 --- /dev/null +++ b/CreateUpdateXmlFile/CreateUpdateXmlFile.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {57BB1A02-118A-443D-A38A-BB36B9A77F6A} + WinExe + Properties + CreateUpdateXmlFile + CreateUpdateXmlFile + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/CreateUpdateXmlFile/Form1.Designer.cs b/CreateUpdateXmlFile/Form1.Designer.cs new file mode 100644 index 0000000..5921c20 --- /dev/null +++ b/CreateUpdateXmlFile/Form1.Designer.cs @@ -0,0 +1,145 @@ +namespace CreateUpdateXmlFile +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.create = new System.Windows.Forms.Button(); + this.view = new System.Windows.Forms.Button(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.textBox3 = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // textBox1 + // + this.textBox1.Font = new System.Drawing.Font("宋体", 12F); + this.textBox1.Location = new System.Drawing.Point(97, 98); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(408, 59); + this.textBox1.TabIndex = 0; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(26, 98); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(65, 12); + this.label1.TabIndex = 1; + this.label1.Text = "目录选择:"; + // + // create + // + this.create.Location = new System.Drawing.Point(296, 178); + this.create.Name = "create"; + this.create.Size = new System.Drawing.Size(93, 38); + this.create.TabIndex = 2; + this.create.Text = "生成"; + this.create.UseVisualStyleBackColor = true; + this.create.Click += new System.EventHandler(this.create_Click); + // + // view + // + this.view.Location = new System.Drawing.Point(126, 178); + this.view.Name = "view"; + this.view.Size = new System.Drawing.Size(93, 38); + this.view.TabIndex = 3; + this.view.Text = "浏览"; + this.view.UseVisualStyleBackColor = true; + this.view.Click += new System.EventHandler(this.view_Click); + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(115, 67); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(390, 21); + this.textBox2.TabIndex = 4; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(26, 70); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(77, 12); + this.label2.TabIndex = 5; + this.label2.Text = "服务器地址:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(26, 27); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(53, 12); + this.label3.TabIndex = 6; + this.label3.Text = "主程序:"; + // + // textBox3 + // + this.textBox3.Location = new System.Drawing.Point(115, 24); + this.textBox3.Name = "textBox3"; + this.textBox3.Size = new System.Drawing.Size(285, 21); + this.textBox3.TabIndex = 7; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(545, 261); + this.Controls.Add(this.textBox3); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.view); + this.Controls.Add(this.create); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBox1); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button create; + private System.Windows.Forms.Button view; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox textBox3; + } +} + diff --git a/CreateUpdateXmlFile/Form1.cs b/CreateUpdateXmlFile/Form1.cs new file mode 100644 index 0000000..ba14cdd --- /dev/null +++ b/CreateUpdateXmlFile/Form1.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.IO; + +namespace CreateUpdateXmlFile +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + this.textBox2.Text = "http://172.28.1.194:7799/AutoUpdate/"; + this.textBox3.Text = "ButcherManageClient.exe"; + } + + private void view_Click(object sender, EventArgs e) + { + if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) + this.textBox1.Text = folderBrowserDialog1.SelectedPath; + } + + private void create_Click(object sender, EventArgs e) + { + if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "") + { + MessageBox.Show("请完善信息"); + return; + } + var entity = new ClientVersion(); + entity.ServerUrl = textBox2.Text + "ClientVersion.xml"; + entity.Version = DateTime.Now.ToString("yyyyMMddHHmm"); + var folder = new DirectoryInfo(textBox1.Text); + foreach (var file in folder.GetFiles()) + { + if (file.Name == "AutoUpdate.exe") + continue; + if (file.Extension == ".xml" && file.Name != "ClientVersion.xml") + continue; + var detail = new UpdateFile(); + detail.FileName = file.Name; + detail.NeedRestart = textBox3.Text == detail.FileName; + detail.Size = (int)file.Length; + detail.Url = textBox2.Text + detail.FileName; + entity.UpdateFiles.Add(detail); + } + XmlUtil.SerializerObjToFile(entity); + MessageBox.Show("OK"); + } + } +} diff --git a/CreateUpdateXmlFile/Form1.resx b/CreateUpdateXmlFile/Form1.resx new file mode 100644 index 0000000..69f943d --- /dev/null +++ b/CreateUpdateXmlFile/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/CreateUpdateXmlFile/Program.cs b/CreateUpdateXmlFile/Program.cs new file mode 100644 index 0000000..f0fdf25 --- /dev/null +++ b/CreateUpdateXmlFile/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CreateUpdateXmlFile +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/CreateUpdateXmlFile/Properties/AssemblyInfo.cs b/CreateUpdateXmlFile/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8b1875e --- /dev/null +++ b/CreateUpdateXmlFile/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("CreateUpdateXmlFile")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CreateUpdateXmlFile")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("9502ffc3-cd87-4eea-adbe-6bac36ca04f8")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CreateUpdateXmlFile/Properties/Resources.Designer.cs b/CreateUpdateXmlFile/Properties/Resources.Designer.cs new file mode 100644 index 0000000..6881bcb --- /dev/null +++ b/CreateUpdateXmlFile/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace CreateUpdateXmlFile.Properties +{ + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的、缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CreateUpdateXmlFile.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 为所有资源查找重写当前线程的 CurrentUICulture 属性, + /// 方法是使用此强类型资源类。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/CreateUpdateXmlFile/Properties/Resources.resx b/CreateUpdateXmlFile/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/CreateUpdateXmlFile/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CreateUpdateXmlFile/Properties/Settings.Designer.cs b/CreateUpdateXmlFile/Properties/Settings.Designer.cs new file mode 100644 index 0000000..cc24edb --- /dev/null +++ b/CreateUpdateXmlFile/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CreateUpdateXmlFile.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/CreateUpdateXmlFile/Properties/Settings.settings b/CreateUpdateXmlFile/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/CreateUpdateXmlFile/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Setup/Release/Setup.msi b/Setup/Release/Setup.msi index 446f984..af4c4f6 100644 Binary files a/Setup/Release/Setup.msi and b/Setup/Release/Setup.msi differ