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

TTS update fix #235

Merged
merged 3 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
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
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 @@ -28,7 +28,7 @@

public class TTSService : ITTSService
{
private static string _nameConfig = @"CodeScanList.json";

Check warning on line 31 in UnitystationLauncher/Services/TTSService.cs

View workflow job for this annotation

GitHub Actions / Build Windows

The field 'TTSService._nameConfig' is assigned but its value is never used

Check warning on line 31 in UnitystationLauncher/Services/TTSService.cs

View workflow job for this annotation

GitHub Actions / Build Linux Flatpak

The field 'TTSService._nameConfig' is assigned but its value is never used

Check warning on line 31 in UnitystationLauncher/Services/TTSService.cs

View workflow job for this annotation

GitHub Actions / Build Linux

The field 'TTSService._nameConfig' is assigned but its value is never used

Check warning on line 31 in UnitystationLauncher/Services/TTSService.cs

View workflow job for this annotation

GitHub Actions / Build MacOS

The field 'TTSService._nameConfig' is assigned but its value is never used

Check warning on line 31 in UnitystationLauncher/Services/TTSService.cs

View workflow job for this annotation

GitHub Actions / test

The field 'TTSService._nameConfig' is assigned but its value is never used

private readonly HttpClient _httpClient;

Expand Down Expand Up @@ -115,13 +115,25 @@
{
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))

Check failure on line 126 in UnitystationLauncher/Services/TTSService.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

UnitystationLauncher/Services/TTSService.cs#L126

Refactor this code to not nest more than 3 control flow statements.
{
System.IO.File.Delete(file);
}

foreach (var directory in System.IO.Directory.GetDirectories(LocalVersion))

Check failure on line 131 in UnitystationLauncher/Services/TTSService.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

UnitystationLauncher/Services/TTSService.cs#L131

Refactor this code to not nest more than 3 control flow statements.
{
System.IO.Directory.Delete(directory, true);
}
}


var zip = _environmentService.GetCurrentEnvironment() switch
{
CurrentEnvironment.WindowsStandalone => "win.zip",
Expand All @@ -130,8 +142,7 @@
_ => 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 @@
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 @@

Download.Active = false;
Download.DownloadState = DownloadState.InProgress;
StartTTS();
}

private static Stream DecompressXz(Stream compressedStream)
Expand Down Expand Up @@ -250,11 +260,19 @@
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 @@
// 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 @@
{
if (process != null)
{
if (process.HasExited == false)
try
{
if (process.HasExited == false)
{
process.Kill();
}
}
catch (Exception e)
{
process.Kill();
Log.Error(e.ToString());
}

}
}
}
Loading