]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fixed cartridges installing more than once (#29187)
authorTruoizys <153248924+Truoizys@users.noreply.github.com>
Wed, 19 Jun 2024 13:21:05 +0000 (14:21 +0100)
committerGitHub <noreply@github.com>
Wed, 19 Jun 2024 13:21:05 +0000 (15:21 +0200)
* fixed cartridges installing more than once

* replaced prototypes with CartridgeComponent

* relocated checks from InstallProgram to InstallCartridge

Content.Server/CartridgeLoader/CartridgeLoaderSystem.cs

index 7896a7822e2de31903aea836918b120b15d42e3f..cd422328c3e183ff4f6a299a02608e00593cd8e6 100644 (file)
@@ -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);