From 0b88cb3670bb7acbb7a0dd6a90c2687cf2662764 Mon Sep 17 00:00:00 2001 From: Bod9001 Date: Sat, 14 Dec 2024 02:37:16 +0000 Subject: [PATCH] TTS update fix (#235) * TTS2 * fixes * addeds Colour --- UnitystationLauncher/App.xaml | 4 +- .../org.unitystation.StationHub.metainfo.xml | 8 +++ UnitystationLauncher/Constants/AppInfo.cs | 2 +- UnitystationLauncher/Services/TTSService.cs | 54 ++++++++++++++----- 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/UnitystationLauncher/App.xaml b/UnitystationLauncher/App.xaml index 274a848..60eaddb 100644 --- a/UnitystationLauncher/App.xaml +++ b/UnitystationLauncher/App.xaml @@ -6,9 +6,11 @@ - + \ No newline at end of file diff --git a/UnitystationLauncher/Assets/org.unitystation.StationHub.metainfo.xml b/UnitystationLauncher/Assets/org.unitystation.StationHub.metainfo.xml index 79d1666..d01e0b5 100644 --- a/UnitystationLauncher/Assets/org.unitystation.StationHub.metainfo.xml +++ b/UnitystationLauncher/Assets/org.unitystation.StationHub.metainfo.xml @@ -65,6 +65,14 @@ + + +

Fix:

+
    +
  • Fixed TTS update not working and resulting in build update not working
  • +
+
+

Fix:

diff --git a/UnitystationLauncher/Constants/AppInfo.cs b/UnitystationLauncher/Constants/AppInfo.cs index 3521b1f..2506b3b 100644 --- a/UnitystationLauncher/Constants/AppInfo.cs +++ b/UnitystationLauncher/Constants/AppInfo.cs @@ -4,5 +4,5 @@ public static class AppInfo { // Whenever you change the currentBuild here, please also update the one in // UnitystationLauncher/Assets/org.unitystation.StationHub.metainfo.xml - public const int CurrentBuild = 936; + public const int CurrentBuild = 937; } \ No newline at end of file diff --git a/UnitystationLauncher/Services/TTSService.cs b/UnitystationLauncher/Services/TTSService.cs index 3541827..ab4b6f4 100644 --- a/UnitystationLauncher/Services/TTSService.cs +++ b/UnitystationLauncher/Services/TTSService.cs @@ -115,13 +115,25 @@ public async Task CheckAndDownloadLatestVersion(Download Download) { if (localVersionModel == null || localVersionModel.Version != CurrentVersion.Version) { + Download.Active = true; + Download.DownloadState = DownloadState.InProgress; + StopTTS(); + await Task.Delay(2 * 1000); //to give it some grace period to shutdown + var LocalVersion = System.IO.Path.Combine(installationBasePath, "tts"); if (System.IO.Directory.Exists(LocalVersion)) { - System.IO.Directory.Delete(LocalVersion, true); + foreach (var file in System.IO.Directory.GetFiles(LocalVersion)) + { + System.IO.File.Delete(file); + } + + foreach (var directory in System.IO.Directory.GetDirectories(LocalVersion)) + { + System.IO.Directory.Delete(directory, true); + } } - var zip = _environmentService.GetCurrentEnvironment() switch { CurrentEnvironment.WindowsStandalone => "win.zip", @@ -130,8 +142,7 @@ public async Task CheckAndDownloadLatestVersion(Download Download) _ => null }; - Download.Active = true; - Download.DownloadState = DownloadState.InProgress; + HttpResponseMessage request = await _httpClient.GetAsync(ApiUrls.TTSFiles + "/" + zip, HttpCompletionOption.ResponseHeadersRead); @@ -166,14 +177,12 @@ private void ExtractTo(Stream progressStream, string LocalVersion, Download Down case CurrentEnvironment.WindowsStandalone: { ZipArchive archive = new(progressStream); - Download.DownloadState = DownloadState.Extracting; archive.ExtractToDirectory(LocalVersion, true); break; } case CurrentEnvironment.LinuxStandalone or CurrentEnvironment.LinuxFlatpak: { using var decompressedStream = DecompressXz(progressStream); // Decompress XZ stream to get .tar - ExtractTar(decompressedStream, LocalVersion); break; } @@ -183,6 +192,7 @@ private void ExtractTo(Stream progressStream, string LocalVersion, Download Down Download.Active = false; Download.DownloadState = DownloadState.InProgress; + StartTTS(); } private static Stream DecompressXz(Stream compressedStream) @@ -250,11 +260,19 @@ public void StartTTS() var Preference = _preferencesService.GetPreferences(); if ((Preference.TTSEnabled is true) == false) return; - if (process != null && process.HasExited == false) + try { - return; + if (process != null && process.HasExited == false) + { + return; + } + } + catch (Exception e) + { + Log.Error(e.ToString()); } + string installationBasePath = _preferencesService.GetPreferences().InstallationPath; var LocalVersion = System.IO.Path.Combine(installationBasePath, "tts"); if (System.IO.Directory.Exists(LocalVersion) == false) @@ -303,10 +321,14 @@ public void StartTTS() // Ensure subprocess ends when the main application exits AppDomain.CurrentDomain.ProcessExit += (sender, e) => { - if (process.HasExited == false) + if (process != null) { - process.Kill(); + if (process.HasExited == false) + { + process.Kill(); + } } + }; try @@ -324,10 +346,18 @@ public void StopTTS() { if (process != null) { - if (process.HasExited == false) + try + { + if (process.HasExited == false) + { + process.Kill(); + } + } + catch (Exception e) { - process.Kill(); + Log.Error(e.ToString()); } + } } } \ No newline at end of file