Skip to content

Commit 22b1ab0

Browse files
committed
fix: auto updater
1 parent d2fe7b7 commit 22b1ab0

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎DiscordLab.Bot/API/Updates/Module.cs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace DiscordLab.Bot.API.Updates;
22

3+
using LabApi.Features.Console;
34
using LabApi.Loader;
45
using LabApi.Loader.Features.Paths;
56

@@ -60,7 +61,8 @@ public Module(GitHubRelease release, GitHubReleaseAsset asset)
6061
/// <param name="modules">The modules to generate for.</param>
6162
/// <returns>The generated string.</returns>
6263
public static string GenerateUpdateString(IEnumerable<Module> modules) => string.Join(
63-
"\n- ", modules.Select(module =>
64+
"\n- ",
65+
modules.Select(module =>
6466
$"{module.Name} | Current Version: {module.ExistingPlugin!.Version} | Latest Version: {module.Version}"));
6567

6668
/// <summary>
@@ -77,8 +79,15 @@ internal async Task Download()
7779
File.Delete(ExistingPlugin.FilePath);
7880
}
7981

80-
byte[] data = await Updater.DownloadClient.GetByteArrayAsync($"/{Release.TagName}/{Asset.Name}");
82+
try
83+
{
84+
byte[] data = await Updater.DownloadClient.GetByteArrayAsync($"{Release.TagName}/{Asset.Name}");
8185

82-
File.WriteAllBytes(filePath, data);
86+
await File.WriteAllBytesAsync(filePath, data);
87+
}
88+
catch (Exception ex)
89+
{
90+
Logger.Error($"Had an error whilst updating {Name} at version {Version}:\n{ex}");
91+
}
8392
}
8493
}

‎DiscordLab.Bot/API/Updates/Updater.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static async Task<IReadOnlyCollection<Module>> CheckForUpdates()
5656

5757
foreach (GitHubReleaseAsset asset in release.Assets)
5858
{
59-
if (asset.Name is "dependencies.zip" or "DiscordLab.Bot.dll")
59+
if (asset.Name is "dependencies.zip")
6060
continue;
6161
string projectName = asset.Name.Replace(".dll", string.Empty);
6262
if (modules.Any(module => module.Name == projectName && module.Version >= version))
@@ -116,7 +116,7 @@ private static void Setup()
116116

117117
if (Plugin.Instance.Config.AutoUpdate)
118118
{
119-
DownloadClient.BaseAddress = new("https://github.com/DiscordLabSCP/DiscordLab/releases/download");
119+
DownloadClient.BaseAddress = new("https://github.com/DiscordLabSCP/DiscordLab/releases/download/");
120120
DownloadClient.DefaultRequestHeaders.Add("User-Agent", $"DiscordLab/{Plugin.Instance.Version}");
121121
}
122122

0 commit comments

Comments
 (0)