Skip to content

Commit 63292de

Browse files
committed
Changed Updates System
1 parent 3a86d7a commit 63292de

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

ILMergeUI/ILMergeUI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<SpecificVersion>False</SpecificVersion>
7171
<HintPath>ResourcesData\Libraries\Octokit.dll</HintPath>
7272
</Reference>
73+
<Reference Include="System.IO.Compression.FileSystem" />
7374
<Reference Include="System.Windows.Forms" />
7475
<Reference Include="System.Text.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL" />
7576
<Reference Include="System.Drawing" />

ILMergeUI/ResourcesData/Forms/Home.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private async void Program_Update()
4848
else
4949
{
5050
if (Classes.Class_SavedData.Int_AutoProgramUpdates == 0)
51-
{ Update_Download(); }
51+
{ Update_DownloadAndRun(); }
5252

5353
else
5454
{
@@ -71,11 +71,11 @@ private void Content_Scroll(int Int_MouseDelta)
7171
{ HtmlLabel_Content.Top -= 36; }
7272
}
7373

74-
private async void Update_Download()
74+
private async void Update_DownloadAndRun()
7575
{
7676
Translate_Get($"{_UpdateStatus}DownloadingUpdate", string.Empty);
7777

78-
try { await Classes.Class_UpdatesManager.Update_Download(); }
78+
try { await Classes.Class_UpdatesManager.Update_DownloadAndRun(); }
7979
catch { Program_Update(); }
8080
}
8181

@@ -86,10 +86,7 @@ private void HtmlLabel_Content_MouseWheel(object Object_Label, MouseEventArgs Mo
8686
{ Content_Scroll(MouseEventArgs_MouseWheel.Delta); }
8787

8888
private void Button_DownloadAndRun_Click(object Object_Button, EventArgs EventArgs_Click)
89-
{
90-
Update_Download();
91-
Classes.Class_UpdatesManager.Update_Run();
92-
}
89+
{ Update_DownloadAndRun(); }
9390

9491
private void LinkLabel_GitHub_LinkClicked(object Object_LinkLabel, LinkLabelLinkClickedEventArgs LinkLabelLinkClickedEventArgs_LinkClicked)
9592
{ Process.Start($"https://github.com/{Application.CompanyName}/{Application.ProductName}".Replace(" ", string.Empty)); }

ILMergeUI/ResourcesData/Source/Controllers/UpdatesController.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using ILMergeUI.ResourcesData.Source.Root;
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
4+
using System.IO.Compression;
45
using System.Linq;
56
using System.Net;
7+
using System.IO;
68
using Octokit;
79

810
namespace ILMergeUI.ResourcesData.Source.Controllers
@@ -11,14 +13,15 @@ public class UpdatesController
1113
{
1214
private readonly string String_CurrentVersion = Classes.Class_AdditionalMethods.Symbols_Remove(System.Windows.Forms.Application.ProductVersion);
1315

14-
private readonly string String_ExecutablePath = System.Windows.Forms.Application.ExecutablePath;
1516
private readonly string String_CompanyName = System.Windows.Forms.Application.CompanyName;
1617
private readonly string String_ProductName = System.Windows.Forms.Application.ProductName.Replace(" ", string.Empty);
1718

1819

1920
private GitHubClient GitHubClient_Update;
2021
public Release Release_Latest;
2122

23+
private string String_LatestVersion;
24+
2225

2326
private async Task<bool> Version_Check()
2427
{
@@ -43,14 +46,29 @@ public async Task Update_Download()
4346
ReleaseAsset ReleaseAsset_Latest = ReleaseAsset_All.FirstOrDefault();
4447

4548
using (WebClient WebClient_Update = new WebClient())
46-
{ WebClient_Update.DownloadFile(ReleaseAsset_Latest.BrowserDownloadUrl, $"{String_ProductName}_Latest.exe"); }
49+
{ WebClient_Update.DownloadFile(ReleaseAsset_Latest.BrowserDownloadUrl, $"{String_ProductName}_Latest.zip"); }
50+
51+
Update_Run();
52+
}
53+
54+
private string LatestVersion_Get()
55+
{
56+
int Int_Index = Release_Latest.TagName.IndexOf('v');
57+
return (Int_Index == -1) ? Release_Latest.TagName : Release_Latest.TagName.Substring(Int_Index);
4758
}
4859

4960
public void Update_Run()
5061
{
62+
string String_StartupDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.StartupPath);
63+
string String_OriginalProductName = System.Windows.Forms.Application.ProductName;
64+
65+
String_LatestVersion = LatestVersion_Get();
66+
ZipFile.ExtractToDirectory($"{String_ProductName}_Latest.zip", String_StartupDirectory);
67+
5168
Classes.Class_AdditionalMethods.Process_Start
52-
("CMD.exe", $"/C TaskKill /F /IM \"{String_ProductName}.exe\" && TimeOut /T 1 " +
53-
$"&& Del \"{String_ExecutablePath}\" && Ren {String_ProductName}_Latest.exe \"{String_ProductName}.exe\" && \"{String_ExecutablePath}\"");
69+
("CMD.exe", $"/C TaskKill /F /IM \"{String_ProductName}.exe\" && TimeOut /T 1 && Del /S /F /Q *.* " +
70+
$"&& start CMD.exe /C Move /Y \"{String_StartupDirectory}\\{String_OriginalProductName} {String_LatestVersion}\\*.*\" . " +
71+
$"&& TimeOut /T 1 && RMDir /S /Q \"{String_StartupDirectory}\\{String_OriginalProductName} {String_LatestVersion}\" && \"{String_OriginalProductName}.exe\"");
5472
}
5573
}
5674
}

ILMergeUI/ResourcesData/Source/Managers/UpdatesManager.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ public Task<int> Status_Get()
1111
public string Body_Get()
1212
{ return Classes.Class_UpdatesController.Release_Latest.Body; }
1313

14-
public async Task Update_Download()
14+
public async Task Update_DownloadAndRun()
1515
{ await Classes.Class_UpdatesController.Update_Download(); }
16-
17-
public void Update_Run()
18-
{ Classes.Class_UpdatesController.Update_Run(); }
1916
}
2017
}

0 commit comments

Comments
 (0)