Updated EllieHub to 1.0.1.0
This commit is contained in:
parent
50f40f01d1
commit
fe5c273143
8 changed files with 114 additions and 90 deletions
|
@ -95,19 +95,16 @@ public static class AppResources
|
|||
/// </summary>
|
||||
public const string LightBackground = "LightBackground";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resource type: <see cref="ImmutableSolidColorBrush"/>
|
||||
/// </summary>
|
||||
public const string MediumBackground = "MediumBackground";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resource type: <see cref="ImmutableSolidColorBrush"/>
|
||||
/// </summary>
|
||||
public const string HeavyBackground = "HeavyBackground";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Resource type: <see cref="ImmutableSolidColorBrush"/>
|
||||
/// </summary>
|
||||
|
|
|
@ -1,41 +1,42 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<!--Project Settings-->
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<AnalysisLevel>latest</AnalysisLevel>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<WarningsAsErrors>Nullable</WarningsAsErrors>
|
||||
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<BuiltInComInteropSupport>True</BuiltInComInteropSupport>
|
||||
<ApplicationIcon>Assets/Light/ellieupdatericon.ico</ApplicationIcon>
|
||||
<PropertyGroup>
|
||||
<!--Project Settings-->
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<AnalysisLevel>latest</AnalysisLevel>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<WarningsAsErrors>Nullable</WarningsAsErrors>
|
||||
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<BuiltInComInteropSupport>True</BuiltInComInteropSupport>
|
||||
<ApplicationIcon>Assets/Light/ellieupdatericon.ico</ApplicationIcon>
|
||||
|
||||
<!--Publishing-->
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<DebugType>embedded</DebugType>
|
||||
<!--Publishing-->
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<SelfContained>true</SelfContained>
|
||||
<DebugType>embedded</DebugType>
|
||||
|
||||
<!--Version-->
|
||||
<VersionPrefix>1.0.0.0</VersionPrefix>
|
||||
<!--Version-->
|
||||
<VersionPrefix>1.0.1.0</VersionPrefix>
|
||||
|
||||
<!--Avalonia Settings-->
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
<!--Avalonia Settings-->
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
|
||||
<!--Generate app host, so the final MacOS .app binary works-->
|
||||
<UseAppHost>true</UseAppHost>
|
||||
</PropertyGroup>
|
||||
<!--Generate app host, so the final MacOS .app binary works-->
|
||||
<UseAppHost>true</UseAppHost>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AvaloniaResource Include="Assets\**" />
|
||||
<ItemGroup>
|
||||
<AvaloniaResource Include="Assets\**" />
|
||||
|
||||
<!--Watch XAML files for hot reload-->
|
||||
<Watch Include="**\*.xaml" />
|
||||
<Watch Include="**\*.axaml" />
|
||||
</ItemGroup>
|
||||
<!--Watch XAML files for hot reload-->
|
||||
<Watch Include="**\*.xaml" />
|
||||
<Watch Include="**\*.axaml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.0.4" />
|
||||
|
@ -54,9 +55,9 @@
|
|||
<PackageReference Include="SkiaImageView.Avalonia11" Version="1.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Views\Windows\AppView.axaml.cs">
|
||||
<DependentUpon>AppView.axaml</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Views\Windows\AppView.axaml.cs">
|
||||
<DependentUpon>AppView.axaml</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -30,12 +30,10 @@ public sealed class EllieOrchestrator : IBotOrchestrator
|
|||
public EllieOrchestrator(ReadOnlyAppConfig appConfig)
|
||||
=> _appConfig = appConfig;
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsBotRunning(Guid botId)
|
||||
=> _runningBots.ContainsKey(botId);
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Start(Guid botId)
|
||||
{
|
||||
|
|
|
@ -162,52 +162,15 @@ public sealed partial class EllieResolver : IBotResolver
|
|||
cToken
|
||||
);
|
||||
|
||||
// Move the bot root directory while renaming it
|
||||
// Move the bot root directory
|
||||
if (Environment.OSVersion.Platform is not PlatformID.Unix)
|
||||
{
|
||||
// Save the zip file
|
||||
using (var fileStream = new FileStream(zipTempLocation, FileMode.Create))
|
||||
await downloadStream.CopyToAsync(fileStream, cToken);
|
||||
|
||||
// Extract the zip file
|
||||
await Task.Run(() => ZipFile.ExtractToDirectory(zipTempLocation, _tempDirectory), cToken);
|
||||
|
||||
// Move the bot root directory while renaming it
|
||||
Directory.Move(botTempLocation, installationUri);
|
||||
}
|
||||
await InstallToWindowsAsync(downloadStream, installationUri, zipTempLocation, botTempLocation, cToken);
|
||||
else
|
||||
{
|
||||
// Extract the tar ball
|
||||
await TarFile.ExtractToDirectoryAsync(downloadStream, _tempDirectory, true, cToken);
|
||||
|
||||
// Move the bot root directory with "mv" to circumvent this issue on Unix systems: https://github.com/dotnet/runtime/issues/31149
|
||||
using var moveProcess = Utilities.StartProcess("mv", $"\"{botTempLocation}\" \"{installationUri}\"");
|
||||
await moveProcess.WaitForExitAsync(cToken);
|
||||
|
||||
// Set executable permission
|
||||
using var chmod = Utilities.StartProcess("chmod", $"+x \"{Path.Combine(installationUri, FileName)}\"");
|
||||
await chmod.WaitForExitAsync(cToken);
|
||||
}
|
||||
await InstallToUnixAsync(downloadStream, installationUri, botTempLocation, cToken);
|
||||
|
||||
// Reapply bot settings
|
||||
if (File.Exists(backupFileUri))
|
||||
{
|
||||
using var zipFile = ZipFile.OpenRead(backupFileUri);
|
||||
var zippedFiles = zipFile.Entries
|
||||
.Where(x =>
|
||||
x.Name is "creds.yml" or "creds_example.yml"
|
||||
|| (!string.IsNullOrWhiteSpace(x.Name) && x.FullName.Contains("data/"))
|
||||
);
|
||||
|
||||
foreach (var zippedFile in zippedFiles)
|
||||
{
|
||||
var fileDestinationPath = zippedFile.FullName.Split('/')
|
||||
.Prepend(Directory.GetParent(installationUri)?.FullName ?? string.Empty)
|
||||
.ToArray();
|
||||
|
||||
await RestoreFileAsync(zippedFile, Path.Combine(fileDestinationPath), cToken);
|
||||
}
|
||||
}
|
||||
await ReaplyBotSettingsAsync(installationUri, backupFileUri, cToken);
|
||||
|
||||
// Update settings
|
||||
await _appConfigManager.UpdateBotEntryAsync(Id, x => x with { Version = latestVersion }, cToken);
|
||||
|
@ -230,6 +193,73 @@ public sealed partial class EllieResolver : IBotResolver
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Installs the Nadeko instance on a Unix system.
|
||||
/// </summary>
|
||||
/// <param name="downloadStream">The stream of data downloaded from the source.</param>
|
||||
/// <param name="installationUri">The absolute path to the directory the bot got installed to.</param>
|
||||
/// <param name="botTempLocation">The absolute path to the temporary directory the bot is extracted to.</param>
|
||||
/// <param name="cToken">The cancellation token.</param>
|
||||
private async ValueTask InstallToUnixAsync(Stream downloadStream, string installationUri, string botTempLocation, CancellationToken cToken = default)
|
||||
{
|
||||
// Extract the tar ball
|
||||
await TarFile.ExtractToDirectoryAsync(downloadStream, _tempDirectory, true, cToken);
|
||||
|
||||
// Move the bot root directory with "mv" to circumvent this issue on Unix systems: https://github.com/dotnet/runtime/issues/31149
|
||||
using var moveProcess = Utilities.StartProcess("mv", $"\"{botTempLocation}\" \"{installationUri}\"");
|
||||
await moveProcess.WaitForExitAsync(cToken);
|
||||
|
||||
// Set executable permission
|
||||
using var chmod = Utilities.StartProcess("chmod", $"+x \"{Path.Combine(installationUri, FileName)}\"");
|
||||
await chmod.WaitForExitAsync(cToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Installs the Nadeko instance on a non-Unix system.
|
||||
/// </summary>
|
||||
/// <param name="downloadStream">The stream of data downloaded from the source.</param>
|
||||
/// <param name="installationUri">The absolute path to the directory the bot got installed to.</param>
|
||||
/// <param name="zipTempLocation">The absolute path to the zip file the bot is initially on.</param>
|
||||
/// <param name="botTempLocation">The absolute path to the temporary directory the bot is extracted to.</param>
|
||||
/// <param name="cToken">The cancellation token.</param>
|
||||
private async static ValueTask InstallToWindowsAsync(Stream downloadStream, string installationUri, string zipTempLocation, string botTempLocation, CancellationToken cToken = default)
|
||||
{
|
||||
// Save the zip file
|
||||
using (var fileStream = new FileStream(zipTempLocation, FileMode.Create))
|
||||
await downloadStream.CopyToAsync(fileStream, cToken);
|
||||
|
||||
// Extract the zip file
|
||||
await Task.Run(() => ZipFile.ExtractToDirectory(zipTempLocation, _tempDirectory), cToken);
|
||||
|
||||
// Move the bot root directory while renaming it
|
||||
Directory.Move(botTempLocation, installationUri);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reaplies the bot settings and user-defined data from the specified backup.
|
||||
/// </summary>
|
||||
/// <param name="installationUri">The absolute path to the directory the bot got installed to.</param>
|
||||
/// <param name="backupFileUri">The absolute path to the backup zip file.</param>
|
||||
/// <param name="cToken">The cancellation token.</param>
|
||||
private async static ValueTask ReaplyBotSettingsAsync(string installationUri, string backupFileUri, CancellationToken cToken = default)
|
||||
{
|
||||
using var zipFile = ZipFile.OpenRead(backupFileUri);
|
||||
var zippedFiles = zipFile.Entries
|
||||
.Where(x =>
|
||||
x.Name is "creds.yml" or "creds_example.yml"
|
||||
|| (!string.IsNullOrWhiteSpace(x.Name) && x.FullName.Contains("data/"))
|
||||
);
|
||||
|
||||
foreach (var zippedFile in zippedFiles)
|
||||
{
|
||||
var fileDestinationPath = zippedFile.FullName.Split('/')
|
||||
.Prepend(Directory.GetParent(installationUri)?.FullName ?? string.Empty)
|
||||
.ToArray();
|
||||
|
||||
await RestoreFileAsync(zippedFile, Path.Combine(fileDestinationPath), cToken);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts the specified <paramref name="zippedFile"/> to the <paramref name="destinationPath"/>.
|
||||
/// </summary>
|
||||
|
|
|
@ -48,7 +48,7 @@ public sealed class LogWriter : ILogWriter
|
|||
var botEntry = _appConfig.BotEntries[botId];
|
||||
var now = DateTimeOffset.Now;
|
||||
var date = new DateOnly(now.Year, now.Month, now.Day).ToShortDateString().Replace('/', '-');
|
||||
var fileUri = Path.Combine(_appConfig.LogsDirectoryUri, $"{botEntry.Name}_{date}-{now.ToUnixTimeSeconds()}.txt");
|
||||
var fileUri = Path.Combine(_appConfig.LogsDirectoryUri, $"{botEntry.Name}_v{botEntry.Version}_{date}-{now.ToUnixTimeSeconds()}.txt");
|
||||
|
||||
await File.WriteAllTextAsync(fileUri, logStringBuilder.ToString(), cToken);
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ using ReactiveUI;
|
|||
using SkiaSharp;
|
||||
using System.Diagnostics;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace EllieHub.ViewModels.Controls;
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Styling;
|
||||
using MsBox.Avalonia.Enums;
|
||||
|
|
Loading…
Reference in a new issue