Handle creds.yml placement in preparation for Ellie v6
This commit is contained in:
parent
52fe269832
commit
091db6afeb
3 changed files with 20 additions and 7 deletions
EllieHub
|
@ -20,7 +20,7 @@
|
||||||
<DebugType>embedded</DebugType>
|
<DebugType>embedded</DebugType>
|
||||||
|
|
||||||
<!--Version-->
|
<!--Version-->
|
||||||
<VersionPrefix>1.0.4.0</VersionPrefix>
|
<VersionPrefix>1.0.5.0</VersionPrefix>
|
||||||
|
|
||||||
<!--Avalonia Settings-->
|
<!--Avalonia Settings-->
|
||||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
|
|
|
@ -167,7 +167,7 @@ public sealed partial class EllieResolver : IBotResolver
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var downloadStream = await http.GetStreamAsync(
|
await using var downloadStream = await http.GetStreamAsync(
|
||||||
await GetDownloadUrlAsync(latestVersion, cToken),
|
await GetDownloadUrlAsync(latestVersion, cToken),
|
||||||
cToken
|
cToken
|
||||||
);
|
);
|
||||||
|
@ -185,11 +185,17 @@ public sealed partial class EllieResolver : IBotResolver
|
||||||
// Update settings
|
// Update settings
|
||||||
await _appConfigManager.UpdateBotEntryAsync(Id, x => x with { Version = latestVersion }, cToken);
|
await _appConfigManager.UpdateBotEntryAsync(Id, x => x with { Version = latestVersion }, cToken);
|
||||||
|
|
||||||
// Create creds.yml
|
// Create creds.yml if it doesn't exist
|
||||||
var credsUri = Path.Join(installationUri, "creds.yml");
|
// 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))
|
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);
|
return (currentVersion, latestVersion);
|
||||||
}
|
}
|
||||||
|
@ -264,7 +270,13 @@ public sealed partial class EllieResolver : IBotResolver
|
||||||
.Prepend(Directory.GetParent(installationUri)?.FullName ?? string.Empty)
|
.Prepend(Directory.GetParent(installationUri)?.FullName ?? string.Empty)
|
||||||
.ToArray();
|
.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -261,8 +261,9 @@ public class BotConfigViewModel : ViewModelBase<BotConfigView>, IDisposable
|
||||||
{
|
{
|
||||||
try
|
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)
|
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()
|
var process = Process.Start(new ProcessStartInfo()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue