2025-01-13 18:51:26 +00:00
using AIStudio.Tools.Rust ;
2025-02-15 14:41:12 +00:00
namespace AIStudio.Tools.Services ;
2025-01-13 18:51:26 +00:00
public sealed partial class RustService
{
public async Task < UpdateResponse > CheckForUpdate ( )
{
try
{
var cts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 45 ) ) ;
var response = await this . http . GetFromJsonAsync < UpdateResponse > ( "/updates/check" , this . jsonRustSerializerOptions , cts . Token ) ;
2026-04-17 17:30:13 +00:00
if ( response = = default )
{
this . logger ! . LogError ( "Failed to check for an update: the Rust endpoint returned an empty response." ) ;
return new UpdateResponse
{
Error = true ,
UpdateIsAvailable = false ,
NewVersion = string . Empty ,
Changelog = string . Empty
} ;
}
if ( response . Error )
this . logger ! . LogWarning ( "The Rust updater reported an error while checking for updates." ) ;
2025-01-13 18:51:26 +00:00
this . logger ! . LogInformation ( $"Checked for an update: update available='{response.UpdateIsAvailable}'; error='{response.Error}'; next version='{response.NewVersion}'; changelog len='{response.Changelog.Length}'" ) ;
return response ;
}
catch ( Exception e )
{
this . logger ! . LogError ( e , "Failed to check for an update." ) ;
return new UpdateResponse
{
Error = true ,
UpdateIsAvailable = false ,
2026-04-17 17:30:13 +00:00
NewVersion = string . Empty ,
Changelog = string . Empty
2025-01-13 18:51:26 +00:00
} ;
}
}
public async Task InstallUpdate ( )
{
try
{
var cts = new CancellationTokenSource ( ) ;
await this . http . GetAsync ( "/updates/install" , cts . Token ) ;
}
catch ( Exception e )
{
Console . WriteLine ( e ) ;
throw ;
}
}
}