From bd26b5f4df2c348e4615e7f1ebcd488969204ba9 Mon Sep 17 00:00:00 2001 From: laolarou Date: Mon, 2 Dec 2024 13:05:45 +0800 Subject: [PATCH] potential memory leak fix --- .../Installer/ForgeInstaller/HighVersionForgeInstaller.cs | 5 +++-- .../Installer/ModPackInstaller/ModPackInstallerBase.cs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs index 9f09326..0c38e6e 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs @@ -617,6 +617,9 @@ ForgeInstallResult GetCorruptedFileResult() void WhenCompleted(object? sender, DownloadFileCompletedEventArgs e) { if (sender is not DownloadFile file) return; + if (!e.Success) this._failedFiles.Add(file); + + file.Completed -= this.WhenCompleted; this._totalDownloaded++; @@ -627,7 +630,5 @@ void WhenCompleted(object? sender, DownloadFileCompletedEventArgs e) this.InvokeStatusChangedEvent( $"{retryStr}下载 - {file.FileName} ( {this._totalDownloaded} / {this._needToDownload} )", progress); - - if (!e.Success) this._failedFiles.Add(file); } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModPackInstallerBase.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModPackInstallerBase.cs index 7696379..b631447 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModPackInstallerBase.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ModPackInstaller/ModPackInstallerBase.cs @@ -13,6 +13,9 @@ public abstract class ModPackInstallerBase : InstallerBase protected void WhenCompleted(object? sender, DownloadFileCompletedEventArgs e) { if (sender is not DownloadFile file) return; + if (!e.Success) this.FailedFiles.Add(file); + + file.Completed -= this.WhenCompleted; this.TotalDownloaded++; @@ -25,7 +28,5 @@ protected void WhenCompleted(object? sender, DownloadFileCompletedEventArgs e) this.InvokeStatusChangedEvent( $"{retryStr}下载整合包中的 Mods - {fileName} ({this.TotalDownloaded} / {this.NeedToDownload})", progress); - - if (!e.Success) this.FailedFiles.Add(file); } } \ No newline at end of file