From fc40cd79fb1e4a9890b6b7eba3ab707ddbd35bf6 Mon Sep 17 00:00:00 2001 From: Truoizys <153248924+Truoizys@users.noreply.github.com> Date: Wed, 19 Jun 2024 14:21:05 +0100 Subject: [PATCH] Fixed cartridges installing more than once (#29187) * fixed cartridges installing more than once * replaced prototypes with CartridgeComponent * relocated checks from InstallProgram to InstallCartridge --- .../CartridgeLoader/CartridgeLoaderSystem.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Content.Server/CartridgeLoader/CartridgeLoaderSystem.cs b/Content.Server/CartridgeLoader/CartridgeLoaderSystem.cs index 7896a7822e..cd422328c3 100644 --- a/Content.Server/CartridgeLoader/CartridgeLoaderSystem.cs +++ b/Content.Server/CartridgeLoader/CartridgeLoaderSystem.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Server.DeviceNetwork.Systems; using Content.Server.PDA; @@ -164,6 +164,15 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem if (!Resolve(loaderUid, ref loader)) return false; + if (!TryComp(cartridgeUid, out CartridgeComponent? loadedCartridge)) + return false; + + foreach (var program in GetInstalled(loaderUid)) + { + if (TryComp(program, out CartridgeComponent? installedCartridge) && installedCartridge.ProgramName == loadedCartridge.ProgramName) + return false; + } + //This will eventually be replaced by serializing and deserializing the cartridge to copy it when something needs //the data on the cartridge to carry over when installing @@ -191,7 +200,6 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem if (container.Count >= loader.DiskSpace) return false; - // TODO cancel duplicate program installations var ev = new ProgramInstallationAttempt(loaderUid, prototype); RaiseLocalEvent(ref ev);