Handle creds.yml placement in preparation for Ellie v6

This commit is contained in:
Toastie 2025-02-13 14:44:03 +13:00
parent 52fe269832
commit 091db6afeb
Signed by: toastie_t0ast
GPG key ID: 0861BE54AD481DC7
3 changed files with 20 additions and 7 deletions
EllieHub
EllieHub.csproj
Features/BotConfig

View file

@ -20,7 +20,7 @@
<DebugType>embedded</DebugType>
<!--Version-->
<VersionPrefix>1.0.4.0</VersionPrefix>
<VersionPrefix>1.0.5.0</VersionPrefix>
<!--Avalonia Settings-->
<ApplicationManifest>app.manifest</ApplicationManifest>

View file

@ -167,7 +167,7 @@ public sealed partial class EllieResolver : IBotResolver
try
{
using var downloadStream = await http.GetStreamAsync(
await using var downloadStream = await http.GetStreamAsync(
await GetDownloadUrlAsync(latestVersion, cToken),
cToken
);
@ -185,11 +185,17 @@ public sealed partial class EllieResolver : IBotResolver
// Update settings
await _appConfigManager.UpdateBotEntryAsync(Id, x => x with { Version = latestVersion }, cToken);
// Create creds.yml
var credsUri = Path.Join(installationUri, "creds.yml");
// Create creds.yml if it doesn't exist
// Old versions have creds.yml and example in ./
// New versions have creds.yml and example in ./data/
// If downloaded bot has creds example in ./, create creds.yml to ./, else create to ./data/
var credsExampleUri = Directory.EnumerateFiles(installationUri, "creds_example.yml", SearchOption.AllDirectories)
.Last();
var credsUri = Path.Join(Directory.GetParent(credsExampleUri)?.FullName ?? Path.Join(installationUri, "data"), "creds.yml");
if (!File.Exists(credsUri))
File.Copy(Path.Join(installationUri, "creds_example.yml"), credsUri);
File.Copy(Path.Join(installationUri, "data", "creds_example.yml"), credsUri);
return (currentVersion, latestVersion);
}
@ -264,7 +270,13 @@ public sealed partial class EllieResolver : IBotResolver
.Prepend(Directory.GetParent(installationUri)?.FullName ?? string.Empty)
.ToArray();
await RestoreFileAsync(zippedFile, Path.Join(fileDestinationPath), cToken);
// Old versions have creds.yml and example in ./
// New versions have creds.yml and example in ./data/
// If downloaded bot has creds example in the root, restore creds.yml to root, else restore to ./data/
if (zippedFile.Name is "creds.yml" && !File.Exists(Path.Join(installationUri, "creds_example.yml")))
await RestoreFileAsync(zippedFile, Path.Join(installationUri, "data", zippedFile.Name), cToken);
else
await RestoreFileAsync(zippedFile, Path.Join(fileDestinationPath), cToken);
}
}

View file

@ -261,8 +261,9 @@ public class BotConfigViewModel : ViewModelBase<BotConfigView>, IDisposable
{
try
{
// Get result from inner directories first, for compatibility with creds.yml being in the root (old versions) and in the data folder (newer versions).
var fileUri = Directory.EnumerateFiles(_appConfigManager.AppConfig.BotEntries[Resolver.Id].InstanceDirectoryUri, fileName, SearchOption.AllDirectories)
.First(x => x.Contains(fileName, StringComparison.Ordinal));
.Last();
var process = Process.Start(new ProcessStartInfo()
{