Adds logging to BYOND service
This commit is contained in:
@@ -12,6 +12,7 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Google.Protobuf;
|
using Google.Protobuf;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace ASS.Server.Services
|
namespace ASS.Server.Services
|
||||||
{
|
{
|
||||||
@@ -23,13 +24,14 @@ namespace ASS.Server.Services
|
|||||||
HttpClient httpclient;
|
HttpClient httpclient;
|
||||||
IConfiguration config;
|
IConfiguration config;
|
||||||
IConfiguration globalConfig;
|
IConfiguration globalConfig;
|
||||||
|
ILogger logger;
|
||||||
|
|
||||||
public ByondService(HttpClient _httpClient, IConfiguration configuration)
|
public ByondService(HttpClient _httpClient, IConfiguration configuration, ILogger<ByondService> log)
|
||||||
{
|
{
|
||||||
httpclient = _httpClient;
|
httpclient = _httpClient;
|
||||||
globalConfig = configuration;
|
globalConfig = configuration;
|
||||||
config = configuration.GetSection("BYOND");
|
config = configuration.GetSection("BYOND");
|
||||||
|
logger = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetDownloadUrl(int major, int minor) => GetDownloadUrl(major.ToString(), minor.ToString());
|
public static string GetDownloadUrl(int major, int minor) => GetDownloadUrl(major.ToString(), minor.ToString());
|
||||||
@@ -83,9 +85,15 @@ namespace ASS.Server.Services
|
|||||||
public async Task SwitchToVersion(ByondVersion version)
|
public async Task SwitchToVersion(ByondVersion version)
|
||||||
{
|
{
|
||||||
if (version.Equals(getVersion()))
|
if (version.Equals(getVersion()))
|
||||||
|
{
|
||||||
|
logger.LogInformation($"Server is on {version.Major}.{version.Minor} version. No switch is needed.");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if (!Directory.Exists(GetByondDirectoryPath(version)))
|
if (!Directory.Exists(GetByondDirectoryPath(version)))
|
||||||
|
{
|
||||||
|
logger.LogInformation($"Version {version.Major}.{version.Minor} is not installed. Downloading and installing...");
|
||||||
await DownloadByond(version);
|
await DownloadByond(version);
|
||||||
|
}
|
||||||
if (!getVersion(GetByondDirectoryPath(version)).Equals(version))
|
if (!getVersion(GetByondDirectoryPath(version)).Equals(version))
|
||||||
throw new Exception($"Byond version '{version.Major}.{version.Minor}' data mismatches folder name or ByondVersion data. Please manually remove this version.");
|
throw new Exception($"Byond version '{version.Major}.{version.Minor}' data mismatches folder name or ByondVersion data. Please manually remove this version.");
|
||||||
if (Directory.Exists(GetByondDirectoryPath()))
|
if (Directory.Exists(GetByondDirectoryPath()))
|
||||||
|
Reference in New Issue
Block a user