diff --git a/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll b/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll index e323f09e..58bc0f48 100644 Binary files a/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll and b/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll differ diff --git a/Distribution/Restock/GameData/ReStock/Restock.restockblacklist b/Distribution/Restock/GameData/ReStock/Restock.restockblacklist new file mode 100644 index 00000000..0ba3bde2 --- /dev/null +++ b/Distribution/Restock/GameData/ReStock/Restock.restockblacklist @@ -0,0 +1,96 @@ +Squad/Parts/Aero/aerodynamicNoseCone/ +Squad/Parts/Aero/cones/ConeA.mu +Squad/Parts/Aero/cones/ConeB.mu +Squad/Parts/Aero/cones/ConesDiffuse*.dds +Squad/Parts/Aero/cones/ConesHeat*.dds +Squad/Parts/Aero/cones/TinyCone.mu +Squad/Parts/Aero/fairings/fairingSize2.mu +Squad/Parts/Aero/HeatShield/HeatShield0.mu +Squad/Parts/Aero/HeatShield/HeatShield1.mu +Squad/Parts/Aero/HeatShield/HeatShield3.mu +Squad/Parts/Aero/protectiveRocketNoseMk7_v2/ +Squad/Parts/Command/cupola/ +Squad/Parts/Command/hitchhikerStorageContainer/ +Squad/Parts/Command/inlineReactionWheel/ +Squad/Parts/Command/Mk1-3Pod/ +Squad/Parts/Command/mk1LanderCan/ +Squad/Parts/Command/mk2LanderCan_v2/ +Squad/Parts/Command/probeCoreCube/probeCoreCube.mu +Squad/Parts/Command/probeCoreHex_v2/ +Squad/Parts/Command/probeCoreOcto2_v2/ +Squad/Parts/Command/probeCoreOcto_v2/ +Squad/Parts/Command/probeStackLarge/ +Squad/Parts/Command/probeStackSmall/ +Squad/Parts/Command/probeStackSphere_v2/ +Squad/Parts/Electrical/RTG/ +Squad/Parts/Electrical/z-100Battery/ +Squad/Parts/Electrical/z-1kBattery/ +Squad/Parts/Electrical/z-200Battery/ +Squad/Parts/Electrical/z-400Battery/ +Squad/Parts/Electrical/z-4kBattery/ +Squad/Parts/Engine/ionEngine/ +Squad/Parts/Engine/liquidEngine24-77/ +Squad/Parts/Engine/liquidEngine48-7S_v2/ +Squad/Parts/Engine/liquidEngineLV-1/ +Squad/Parts/Engine/liquidEngineLV-1R/ +Squad/Parts/Engine/liquidEngineLV-909_v2/ +Squad/Parts/Engine/liquidEngineLV-N/ +Squad/Parts/Engine/liquidEngineLV-T30/ +Squad/Parts/Engine/liquidEngineLV-T45/ +Squad/Parts/Engine/liquidEngineMainsail/ +Squad/Parts/Engine/liquidEnginePoodle_v2/ +Squad/Parts/Engine/liquidEngineSkipper/ +Squad/Parts/Engine/liquidEngineSSME/ +Squad/Parts/Engine/MassiveSRB/ +Squad/Parts/Engine/OMSEngine/ +Squad/Parts/Engine/Size1_SRBs/ +Squad/Parts/Engine/Size1_SRBs/ +Squad/Parts/Engine/Size2LFB/ +Squad/Parts/Engine/Size3AdvancedEngine/ +Squad/Parts/Engine/Size3EngineCluster/ +Squad/Parts/Engine/solidBoosterBACC/ +Squad/Parts/Engine/solidBoosterSep/ +Squad/Parts/FuelTank/FoilTanks/ +Squad/Parts/FuelTank/FoilTanks/ +Squad/Parts/FuelTank/FoilTanks/ +Squad/Parts/FuelTank/fuelTankOscarB/ +Squad/Parts/FuelTank/RCSFuelTankR1/ +Squad/Parts/FuelTank/RCSFuelTankR10/ +Squad/Parts/FuelTank/RCSFuelTankR25/ +Squad/Parts/FuelTank/RCSTankRadial/ +Squad/Parts/FuelTank/RCStankRadialLong/ +Squad/Parts/FuelTank/RockomaxTanks/ +Squad/Parts/FuelTank/Size1_Tanks/ +Squad/Parts/FuelTank/Size3Tanks/ +Squad/Parts/FuelTank/xenonTank/ +Squad/Parts/FuelTank/xenonTankLarge/ +Squad/Parts/FuelTank/xenonTankRadial/ +Squad/Parts/Misc/AsteroidDay/HECS2.mu +Squad/Parts/Misc/AsteroidDay/hecs*.dds +Squad/Parts/Science/AtmosphereSensor/ +Squad/Parts/Science/GooExperiment/ +Squad/Parts/Science/LargeCrewedLab/ +Squad/Parts/Science/MaterialBay/ +Squad/Parts/Science/sensorAccelerometer/ +Squad/Parts/Science/sensorBarometer/ +Squad/Parts/Science/sensorGravimeter/ +Squad/Parts/Science/sensorThermometer/ +Squad/Parts/Structural/FLAdapters/ +Squad/Parts/Structural/Size3To2Adapter_v2/ +Squad/Parts/Structural/structuralMicronode/ +Squad/Parts/Structural/strutCubicOcto/ +Squad/Parts/Structural/strutOcto/ +Squad/Parts/Utility/commDish88-88/ +Squad/Parts/Utility/DirectAntennas/HGAntenna.mu +Squad/Parts/Utility/dockingPort/ +Squad/Parts/Utility/dockingPortInline/ +Squad/Parts/Utility/dockingPortJr/ +Squad/Parts/Utility/dockingPortShielded/ +Squad/Parts/Utility/dockingPortSr/ +Squad/Parts/Utility/linearRCS/ +Squad/Parts/Utility/rcsBlockRV-105/ +Squad/Parts/Utility/RelayAntennas/ +Squad/Parts/Utility/rockomaxAdapters/ +Squad/Parts/Utility/ServiceBay/ +Squad/Parts/Utility/spotLightMk1/ +Squad/Parts/Utility/spotLightMk2/ diff --git a/Source/Restock/ResourceBlacklist.cs b/Source/Restock/ResourceBlacklist.cs new file mode 100644 index 00000000..2f3fc98d --- /dev/null +++ b/Source/Restock/ResourceBlacklist.cs @@ -0,0 +1,130 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using UnityEngine; + +namespace Restock +{ + [KSPAddon(KSPAddon.Startup.Instantly, true)] + public class ResourceBlacklist : MonoBehaviour + { + private void Start() + { + HashSet blacklist = new HashSet(); + HashSet whitelist = new HashSet(); + + UrlDir gameData = GameDatabase.Instance.root.children.Find(dir => dir.type == UrlDir.DirectoryType.GameData); + + foreach (UrlDir.UrlFile file in GameDatabase.Instance.root.AllFiles) + { + if (file.fileExtension == "restockblacklist") + { + Debug.Log($"[Restock] Reading blacklist {file.url}.{file.fileExtension}"); + foreach (string line in File.ReadAllLines(file.fullPath)) + { + foreach (UrlDir.UrlFile blacklistFile in FindFiles(line, gameData)) + { + blacklist.Add(blacklistFile); + } + } + } + else if (file.fileExtension == "restockwhitelist") + { + Debug.Log($"[Restock] Reading whitelist {file.url}.{file.fileExtension}"); + foreach (string line in File.ReadAllLines(file.fullPath)) + { + foreach (UrlDir.UrlFile whitelistFile in FindFiles(line, gameData)) + { + whitelist.Add(whitelistFile); + } + } + } + } + + Debug.Log("[Restock] Removing blacklisted assets"); + foreach (UrlDir.UrlFile file in blacklist) + { + if (whitelist.Contains(file)) continue; + + Debug.Log($"[Restock] Removing {file.url}.{file.fileExtension}"); + UrlDir.UrlFile newFile2 = new UrlDir.UrlFile(file.parent, new FileInfo(file.fullPath + ".disabled")); + file.parent.files[file.parent.files.IndexOf(file)] = newFile2; + } + + Destroy(gameObject); + } + + private readonly char[] sep = new[] { '/' }; + private IEnumerable FindFiles(string url, UrlDir dir) + { + string[] splits = url.Split(sep, 2); + + if (splits.Length == 1) + { + if (splits[0] == string.Empty) + { + foreach (UrlDir.UrlFile file in dir.files) + { + if (file.fileType == UrlDir.FileType.Config) continue; + yield return file; + } + + // Already excludes configs + foreach (UrlDir.UrlFile file in dir.AllFiles) + { + yield return file; + } + } + else + { + int idx = splits[0].LastIndexOf('.'); + string fileName; + string fileExtension; + + if (idx != -1) + { + fileName = splits[0].Substring(0, idx); + fileExtension = splits[0].Substring(idx + 1); + } + else + { + fileName = splits[0]; + fileExtension = null; + } + + string pattern = '^' + Regex.Escape(fileName).Replace(@"\*", ".*") + '$'; + Regex regex = new Regex(pattern); + + foreach (UrlDir.UrlFile file in dir.files) + { + if (file.fileType == UrlDir.FileType.Config) continue; + if (!regex.IsMatch(file.name)) continue; + if (fileExtension != null && fileExtension != file.fileExtension) continue; + yield return file; + } + } + } + else if (splits.Length == 2) + { + string pattern = '^' + Regex.Escape(splits[0]).Replace(@"\*", ".*") + '$'; + Regex regex = new Regex(pattern); + + foreach (UrlDir subDir in dir.children) + { + if (regex.IsMatch(subDir.name)) + { + foreach (UrlDir.UrlFile file in FindFiles(splits[1], subDir)) + { + yield return file; + } + } + } + } + else + { + throw new NotImplementedException("This code should never be reached"); + } + } + } +} diff --git a/Source/Restock/Restock.csproj b/Source/Restock/Restock.csproj index 5f036689..edf1073e 100644 --- a/Source/Restock/Restock.csproj +++ b/Source/Restock/Restock.csproj @@ -44,6 +44,7 @@ +