|
4 | 4 | using System.Diagnostics;
|
5 | 5 | using System.Drawing;
|
6 | 6 | using System.IO;
|
| 7 | +using System.IO.Compression; |
7 | 8 | using System.Net;
|
8 | 9 | using System.Runtime.InteropServices;
|
| 10 | +using System.Threading.Tasks; |
9 | 11 | using System.Windows.Forms;
|
10 | 12 |
|
11 | 13 | namespace BrightnessControl
|
@@ -34,7 +36,7 @@ public partial class BrightnessControl : Form
|
34 | 36 | public BrightnessControl()
|
35 | 37 | {
|
36 | 38 | InitializeComponent();
|
37 |
| - Opacity = 0; |
| 39 | + Opacity = 1; |
38 | 40 |
|
39 | 41 | //HotKey
|
40 | 42 | try
|
@@ -250,18 +252,7 @@ private void dynamicComponent()
|
250 | 252 | }
|
251 | 253 |
|
252 | 254 | // Check Update
|
253 |
| - try |
254 |
| - { |
255 |
| - using (WebClient client = new WebClient()) |
256 |
| - { |
257 |
| - client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); |
258 |
| - string CheckVersion = client.DownloadString("https://minormole.github.io/Brightness_Controller/update/version"); |
259 |
| - if (CheckVersion.Contains(".") & Application.ProductVersion != CheckVersion) |
260 |
| - { |
261 |
| - Updater(); |
262 |
| - } |
263 |
| - } |
264 |
| - } catch (Exception) {} |
| 255 | + Updater(); |
265 | 256 |
|
266 | 257 | }
|
267 | 258 |
|
@@ -572,36 +563,46 @@ private void RestartProgram(string location)
|
572 | 563 | Application.Exit();
|
573 | 564 | }
|
574 | 565 |
|
575 |
| - private void Updater() |
| 566 | + private async void Updater() |
576 | 567 | {
|
577 |
| - |
578 |
| - string ExeLocation = System.Reflection.Assembly.GetEntryAssembly().Location; |
579 |
| - |
| 568 | + await Task.Delay(1); |
| 569 | + string NewExeLocations = AppDomain.CurrentDomain.BaseDirectory + "Brightness Controller.exe"; |
| 570 | + MessageBox.Show(NewExeLocations); |
580 | 571 | try
|
581 | 572 | {
|
582 | 573 | using (WebClient client = new WebClient())
|
583 | 574 | {
|
584 | 575 | client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
|
585 |
| - client.DownloadFile("https://minormole.github.io/Brightness_Controller/update/Brightness%20Controller.exe", ExeLocation + ".new"); |
586 |
| - } |
587 |
| - |
588 |
| - if (File.Exists(ExeLocation + ".new")) |
589 |
| - { |
590 |
| - File.Move(ExeLocation, ExeLocation + ".old"); |
591 |
| - File.Move(ExeLocation + ".new", ExeLocation); |
592 |
| - RestartProgram(ExeLocation); |
593 |
| - } |
594 |
| - } |
595 |
| - catch (Exception) |
596 |
| - { |
597 |
| - try |
598 |
| - { |
599 |
| - File.Delete(ExeLocation + ".new"); |
| 576 | + string CheckVersion = client.DownloadString("https://minormole.github.io/Brightness_Controller/update/version"); |
| 577 | + if (CheckVersion.Contains(".") & Application.ProductVersion != CheckVersion) |
| 578 | + { |
| 579 | + string ExeLocation = System.Reflection.Assembly.GetEntryAssembly().Location; |
| 580 | + string NewExeLocation = AppDomain.CurrentDomain.BaseDirectory + @"\Brightness Controller.exe"; |
| 581 | + try |
| 582 | + { |
| 583 | + client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); |
| 584 | + client.DownloadFile("https://minormole.github.io/Brightness_Controller/update/Brightness%20Controller.zip", ExeLocation + ".new"); |
| 585 | + if (File.Exists(ExeLocation + ".new")) |
| 586 | + { |
| 587 | + File.Move(ExeLocation, ExeLocation + ".old"); |
| 588 | + ZipFile.ExtractToDirectory(ExeLocation + ".new", AppDomain.CurrentDomain.BaseDirectory); |
| 589 | + File.Delete(ExeLocation + ".new"); |
| 590 | + RestartProgram(ExeLocation); |
| 591 | + } |
| 592 | + } |
| 593 | + catch (Exception) |
| 594 | + { |
| 595 | + try |
| 596 | + { |
| 597 | + File.Delete(ExeLocation + ".new"); |
| 598 | + } |
| 599 | + catch (Exception) { } |
| 600 | + } |
| 601 | + } |
600 | 602 | }
|
601 |
| - catch (Exception) {} |
602 | 603 | }
|
| 604 | + catch (Exception) { } |
603 | 605 | }
|
604 |
| - |
605 | 606 | }
|
606 | 607 |
|
607 | 608 | public class BrightnessController : IDisposable
|
|
0 commit comments