From 95bbe9d826deaf049855036aa39dffceb09c3da7 Mon Sep 17 00:00:00 2001 From: you Date: Sat, 12 Dec 2020 04:06:58 +0800 Subject: [PATCH] Auto update --- Update/Update.Designer.cs | 4 +++- Update/Update.cs | 11 ++++++++--- Update/UpdateLite.cs | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Update/Update.Designer.cs b/Update/Update.Designer.cs index 91fdd708..2bac6ede 100644 --- a/Update/Update.Designer.cs +++ b/Update/Update.Designer.cs @@ -40,6 +40,7 @@ private void InitializeComponent() this.progressBar.Name = "progressBar"; this.progressBar.Size = new System.Drawing.Size(218, 26); this.progressBar.TabIndex = 0; + this.progressBar.Click += new System.EventHandler(this.progressBar_Click); // // Update // @@ -49,10 +50,11 @@ private void InitializeComponent() this.Controls.Add(this.progressBar); this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Margin = new System.Windows.Forms.Padding(2); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "Update"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "DEV C++ 更新程序"; this.Load += new System.EventHandler(this.Update_Load); this.ResumeLayout(false); diff --git a/Update/Update.cs b/Update/Update.cs index e03f6d41..92a639fb 100644 --- a/Update/Update.cs +++ b/Update/Update.cs @@ -24,7 +24,7 @@ public Update() int lasterVersion = int.Parse(updater.GetVersion(baseUrl + "version")); int currentVersion = int.Parse(File.ReadAllText(Directory.GetCurrentDirectory() + "/version")); - + if (lasterVersion - currentVersion > 0) { if (DialogResult.Yes == MessageBox.Show("检查到新版本,是否更新?", "更新", MessageBoxButtons.YesNo)) @@ -39,8 +39,8 @@ public Update() else updater.Download(baseUrl + "Build/devcpp_i.zip", DownloadProgressCallback, DownloadCompletedCallback); } } - - Application.Exit(); + System.Environment.Exit(0); + //Application.Exit(); } private void Update_Load(object sender, EventArgs e) { } @@ -77,5 +77,10 @@ private void DownloadCompletedCallback(object sender, AsyncCompletedEventArgs e) Application.Exit(); } } + + private void progressBar_Click(object sender, EventArgs e) + { + + } } } diff --git a/Update/UpdateLite.cs b/Update/UpdateLite.cs index 36270ffa..e7bf00a1 100644 --- a/Update/UpdateLite.cs +++ b/Update/UpdateLite.cs @@ -10,7 +10,7 @@ namespace Update { public class UpdateLite { - const string downloadPath = @"C:\Users\Blinking\AppData\Local\Temp\devcpp.zip"; + private string downloadPath = System.Environment.GetEnvironmentVariable("TEMP") + @"\devcpp.zip"; public WebClient webClient = new WebClient();