Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit bb5e93f

Browse files
committed
Test Zip Updater
1 parent 085123d commit bb5e93f

File tree

5 files changed

+48
-45
lines changed

5 files changed

+48
-45
lines changed

Brightness Controller/Brightness Controller.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<ItemGroup>
5858
<Reference Include="System" />
5959
<Reference Include="System.Core" />
60+
<Reference Include="System.IO.Compression.FileSystem" />
6061
<Reference Include="System.Xml.Linq" />
6162
<Reference Include="System.Data.DataSetExtensions" />
6263
<Reference Include="Microsoft.CSharp" />

Brightness Controller/Main.Designer.cs

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Brightness Controller/Main.cs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
using System.Diagnostics;
55
using System.Drawing;
66
using System.IO;
7+
using System.IO.Compression;
78
using System.Net;
89
using System.Runtime.InteropServices;
10+
using System.Threading.Tasks;
911
using System.Windows.Forms;
1012

1113
namespace BrightnessControl
@@ -34,7 +36,7 @@ public partial class BrightnessControl : Form
3436
public BrightnessControl()
3537
{
3638
InitializeComponent();
37-
Opacity = 0;
39+
Opacity = 1;
3840

3941
//HotKey
4042
try
@@ -250,18 +252,7 @@ private void dynamicComponent()
250252
}
251253

252254
// 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();
265256

266257
}
267258

@@ -572,36 +563,46 @@ private void RestartProgram(string location)
572563
Application.Exit();
573564
}
574565

575-
private void Updater()
566+
private async void Updater()
576567
{
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);
580571
try
581572
{
582573
using (WebClient client = new WebClient())
583574
{
584575
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+
}
600602
}
601-
catch (Exception) {}
602603
}
604+
catch (Exception) { }
603605
}
604-
605606
}
606607

607608
public class BrightnessController : IDisposable

Brightness Controller/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.0.0.3")]
36-
[assembly: AssemblyFileVersion("2.0.0.3")]
35+
[assembly: AssemblyVersion("2.0.0.4")]
36+
[assembly: AssemblyFileVersion("2.0.0.4")]

update/Brightness Controller.zip

242 KB
Binary file not shown.

0 commit comments

Comments
 (0)