Skip to content

Commit

Permalink
TTS update fix (#235)
Browse files Browse the repository at this point in the history
* TTS2

* fixes

* addeds Colour
  • Loading branch information
Bod9001 authored Dec 14, 2024
1 parent bde7857 commit 0b88cb3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
4 changes: 3 additions & 1 deletion UnitystationLauncher/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
<Application.DataTemplates>
<local:ViewLocator />
</Application.DataTemplates>

<Application.Styles>
<FluentTheme />
<StyleInclude Source="/Styles.axaml" />
<Style Selector="TextBlock">
<Setter Property="Foreground" Value="White" />
</Style>
</Application.Styles>
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
</screenshots>

<releases>
<release version="937" date="2024-12-13">
<description>
<p>Fix:</p>
<ul>
<li>Fixed TTS update not working and resulting in build update not working</li>
</ul>
</description>
</release>
<release version="936" date="2024-12-13">
<description>
<p>Fix:</p>
Expand Down
2 changes: 1 addition & 1 deletion UnitystationLauncher/Constants/AppInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
54 changes: 42 additions & 12 deletions UnitystationLauncher/Services/TTSService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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());
}

}
}
}

0 comments on commit 0b88cb3

Please sign in to comment.