Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdateChecker: Use the installer to auto-update #153

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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