11using ILMergeUI . ResourcesData . Source . Root ;
22using System . Collections . Generic ;
33using System . Threading . Tasks ;
4+ using System . IO . Compression ;
45using System . Linq ;
56using System . Net ;
7+ using System . IO ;
68using Octokit ;
79
810namespace 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}
0 commit comments