Skip to content

Commit

Permalink
UpdateChecker: Use the installer to auto-update (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianxhokaxhiu authored Nov 19, 2023
1 parent 42af4ac commit a45533f
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions SeventhHeavenUI/Classes/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private string GetUpdateReleaseUrl(dynamic assets)
{
string url = asset.browser_download_url.Value;

if (url.Contains("7thHeaven-v") && url.EndsWith(".zip"))
if (url.Contains("7thHeaven-v") && url.EndsWith(".exe"))
return url;
}

Expand Down Expand Up @@ -179,29 +179,12 @@ private void DownloadAndExtract(string url, string version)
if (success)
{
string ExtractPath = Path.Combine(Sys.PathToTempFolder, $"7thHeaven-v{version}");
Directory.CreateDirectory(ExtractPath);
using (var archive = ZipArchive.Open(download.SaveFilePath))
{
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
{
entry.WriteToDirectory(ExtractPath, new ExtractionOptions()
{
ExtractFullPath = true,
Overwrite = true
});
}
}
SwitchToModPanel();
MessageDialogWindow.Show($"Successfully downloaded version {version}.\n\nWe will now start the update process. 7th Heaven will restart automatically when the update is completed.\n\nEnjoy!", "Success", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
Sys.Message(new WMessage() { Text = $"Successfully extracted the 7th Heaven version {version}. Ready to launch the update." });
File.Delete(download.SaveFilePath);
StartUpdate(ExtractPath);
StartUpdate(download.SaveFilePath);
}
else
{
Expand All @@ -218,7 +201,7 @@ private void DownloadAndExtract(string url, string version)
}
}

private void StartUpdate(string sourcePath)
private void StartUpdate(string installerFullPath)
{
string fileName = Path.Combine(Sys.PathToTempFolder, "update.bat");

Expand All @@ -227,12 +210,16 @@ private void StartUpdate(string sourcePath)
$@"@echo off
@echo Waiting for 7th Heaven to be closed, please wait...
@taskkill /IM ""7th Heaven.exe"" /F >NUL 2>NUL
@timeout /t 5 /nobreak
@xcopy ""{sourcePath}"" ""{Sys._7HFolder}"" /S /Y >NUL 2>NUL
@timeout /t 5 /nobreak >NUL 2>NUL
@echo ----------------------------------------------------
@echo Waiting for the update to take place, please wait...
@timeout /t 5 /nobreak
@rmdir /s /q ""{sourcePath}""
@echo ATTENTION: The update may ask you to install some dependencies. It is safe to proceed with the installation when prompted.
@start """" /wait /d ""{Sys._7HFolder}"" ""{installerFullPath}"" /SILENT /DIR=""{Sys._7HFolder}""
@echo ----------------------------------------------------
@echo Update completed. Restarting 7th Heaven now...
@timeout /t 5 /nobreak >NUL 2>NUL
@start """" /d ""{Sys._7HFolder}"" ""{Sys._7HExe}""
@del ""{installerFullPath}""
@del ""{fileName}""
"
);
Expand Down

0 comments on commit a45533f

Please sign in to comment.