Skip to content

Commit 63a5276

Browse files
committed
Removed the use of weakref (in order to prevent maxisoft#13)
1 parent 21fd771 commit 63a5276

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ASFFreeGames/BotContext.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ internal sealed class BotContext : IDisposable {
1313
private const ulong TriesBeforeBlacklistingGameEntry = 5;
1414

1515
private readonly Dictionary<GameIdentifier, (ulong counter, DateTime date)> AppRegistrationContexts = new();
16-
private readonly WeakReference<Bot> Bot;
16+
private readonly string BotIdentifier;
1717
private readonly TimeSpan BlacklistTimeout = TimeSpan.FromDays(1);
1818
private readonly CompletedAppList CompletedApps = new();
1919
private long LastRunMilli;
2020

2121
public BotContext(Bot bot) {
22-
Bot = new WeakReference<Bot>(bot);
22+
BotIdentifier = bot.BotName;
2323
NewRun();
2424
}
2525

2626
private string CompletedAppFilePath() {
27-
if (!Bot.TryGetTarget(out var bot)) {
27+
Bot? bot = Bot.GetBot(BotIdentifier);
28+
29+
if (bot is null) {
2830
return string.Empty;
2931
}
3032

@@ -65,11 +67,9 @@ public bool HasApp(in GameIdentifier gameIdentifier) {
6567
return true;
6668
}
6769

68-
if (!Bot.TryGetTarget(out var bot)) {
69-
return false;
70-
}
70+
Bot? bot = Bot.GetBot(BotIdentifier);
7171

72-
return bot.OwnedPackageIDs.ContainsKey(checked((uint) gameIdentifier.Id));
72+
return bot is not null && bot.OwnedPackageIDs.ContainsKey(checked((uint) gameIdentifier.Id));
7373
}
7474

7575
public bool ShouldHideErrorLogForApp(in GameIdentifier gameIdentifier) => (AppTickCount(in gameIdentifier) > 0) || CompletedApps.ContainsInvalid(in gameIdentifier);

0 commit comments

Comments
 (0)