From 0bd4641035c04db4b3f9f34e2f73d95858e6f342 Mon Sep 17 00:00:00 2001 From: Daniel Walder Date: Mon, 26 May 2014 19:24:42 +1000 Subject: [PATCH] Add texture blacklist and whitelist, and add error handling for invalid WAD files --- Sledge.Editor/Documents/Document.cs | 2 +- .../Settings/SettingsForm.Designer.cs | 147 +++++++++++++----- Sledge.Editor/Settings/SettingsForm.cs | 4 + Sledge.Editor/Settings/SettingsForm.resx | 29 +++- .../Tools/TextureApplicationForm.Designer.cs | 2 +- Sledge.Packages/Wad/WadPackage.cs | 1 + Sledge.Providers/Texture/SprProvider.cs | 3 +- Sledge.Providers/Texture/TextureProvider.cs | 8 +- Sledge.Providers/Texture/VmtProvider.cs | 16 +- Sledge.Providers/Texture/WadProvider.cs | 42 +++-- Sledge.Settings/Models/Game.cs | 25 +++ Sledge.Tests/Vtf/VtfTest.cs | 2 +- 12 files changed, 215 insertions(+), 66 deletions(-) diff --git a/Sledge.Editor/Documents/Document.cs b/Sledge.Editor/Documents/Document.cs index a60e39df6..1e30acdbb 100644 --- a/Sledge.Editor/Documents/Document.cs +++ b/Sledge.Editor/Documents/Document.cs @@ -107,7 +107,7 @@ public Document(string mapFile, Map map, Game game) GameData.MapSizeHigh = game.OverrideMapSizeHigh; } - TextureCollection = TextureProvider.CreateCollection(Environment.GetGameDirectories(), Game.AdditionalPackages); + TextureCollection = TextureProvider.CreateCollection(Environment.GetGameDirectories(), Game.AdditionalPackages, Game.GetTextureBlacklist(), Game.GetTextureWhitelist()); var texList = Map.GetAllTextures(); var items = TextureCollection.GetItems(texList); diff --git a/Sledge.Editor/Settings/SettingsForm.Designer.cs b/Sledge.Editor/Settings/SettingsForm.Designer.cs index 9c0c79b69..58300573d 100644 --- a/Sledge.Editor/Settings/SettingsForm.Designer.cs +++ b/Sledge.Editor/Settings/SettingsForm.Designer.cs @@ -36,6 +36,7 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingsForm)); this.tbcSettings = new System.Windows.Forms.TabControl(); this.tabGeneral = new System.Windows.Forms.TabPage(); @@ -174,6 +175,7 @@ private void InitializeComponent() this.label35 = new System.Windows.Forms.Label(); this.SelectedGameOverrideSizeLow = new System.Windows.Forms.ComboBox(); this.label33 = new System.Windows.Forms.Label(); + this.SelectedGameIncludeFgdDirectoriesInEnvironment = new System.Windows.Forms.CheckBox(); this.SelectedGameOverrideMapSize = new System.Windows.Forms.CheckBox(); this.lblGameFGD = new System.Windows.Forms.Label(); this.SelectedGameAddFgd = new System.Windows.Forms.Button(); @@ -188,7 +190,6 @@ private void InitializeComponent() this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.label44 = new System.Windows.Forms.Label(); - this.label45 = new System.Windows.Forms.Label(); this.lblGameWAD = new System.Windows.Forms.Label(); this.SelectedGameLightmapScale = new System.Windows.Forms.NumericUpDown(); this.lblConfigLightmapScale = new System.Windows.Forms.Label(); @@ -305,12 +306,17 @@ private void InitializeComponent() this.btnCancelSettings = new System.Windows.Forms.Button(); this.btnApplyAndCloseSettings = new System.Windows.Forms.Button(); this.btnApplySettings = new System.Windows.Forms.Button(); + this.HelpTooltip = new System.Windows.Forms.ToolTip(this.components); this.SelectedBuildCsgParameters = new Sledge.Editor.Compiling.CompileParameterPanel(); this.SelectedBuildBspParameters = new Sledge.Editor.Compiling.CompileParameterPanel(); this.SelectedBuildVisParameters = new Sledge.Editor.Compiling.CompileParameterPanel(); this.SelectedBuildRadParameters = new Sledge.Editor.Compiling.CompileParameterPanel(); this.SelectedBuildSharedParameters = new Sledge.Editor.Compiling.CompileParameterPanel(); - this.SelectedGameIncludeFgdDirectoriesInEnvironment = new System.Windows.Forms.CheckBox(); + this.SelectedGameBlacklistTextbox = new System.Windows.Forms.TextBox(); + this.label45 = new System.Windows.Forms.Label(); + this.SelectedGameWhitelistTextbox = new System.Windows.Forms.TextBox(); + this.label46 = new System.Windows.Forms.Label(); + this.groupBox19 = new System.Windows.Forms.GroupBox(); this.tbcSettings.SuspendLayout(); this.tabGeneral.SuspendLayout(); this.tabIntegration.SuspendLayout(); @@ -379,6 +385,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).BeginInit(); this.groupBox7.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit(); + this.groupBox19.SuspendLayout(); this.SuspendLayout(); // // tbcSettings @@ -2053,6 +2060,18 @@ private void InitializeComponent() "en below."; this.label33.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // + // SelectedGameIncludeFgdDirectoriesInEnvironment + // + this.SelectedGameIncludeFgdDirectoriesInEnvironment.Checked = true; + this.SelectedGameIncludeFgdDirectoriesInEnvironment.CheckState = System.Windows.Forms.CheckState.Checked; + this.SelectedGameIncludeFgdDirectoriesInEnvironment.Location = new System.Drawing.Point(184, 246); + this.SelectedGameIncludeFgdDirectoriesInEnvironment.Name = "SelectedGameIncludeFgdDirectoriesInEnvironment"; + this.SelectedGameIncludeFgdDirectoriesInEnvironment.Size = new System.Drawing.Size(264, 24); + this.SelectedGameIncludeFgdDirectoriesInEnvironment.TabIndex = 19; + this.SelectedGameIncludeFgdDirectoriesInEnvironment.Text = "Load sprites and models from FGD directories"; + this.SelectedGameIncludeFgdDirectoriesInEnvironment.UseVisualStyleBackColor = true; + this.SelectedGameIncludeFgdDirectoriesInEnvironment.CheckedChanged += new System.EventHandler(this.SelectedGameOverrideMapSizeChanged); + // // SelectedGameOverrideMapSize // this.SelectedGameOverrideMapSize.Checked = true; @@ -2149,9 +2168,9 @@ private void InitializeComponent() // // tabConfigTextures // + this.tabConfigTextures.Controls.Add(this.groupBox19); this.tabConfigTextures.Controls.Add(this.SelectedGameAdditionalPackageList); this.tabConfigTextures.Controls.Add(this.label44); - this.tabConfigTextures.Controls.Add(this.label45); this.tabConfigTextures.Controls.Add(this.lblGameWAD); this.tabConfigTextures.Controls.Add(this.SelectedGameLightmapScale); this.tabConfigTextures.Controls.Add(this.lblConfigLightmapScale); @@ -2175,10 +2194,10 @@ private void InitializeComponent() this.columnHeader3}); this.SelectedGameAdditionalPackageList.FullRowSelect = true; this.SelectedGameAdditionalPackageList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; - this.SelectedGameAdditionalPackageList.Location = new System.Drawing.Point(6, 184); + this.SelectedGameAdditionalPackageList.Location = new System.Drawing.Point(6, 108); this.SelectedGameAdditionalPackageList.Name = "SelectedGameAdditionalPackageList"; this.SelectedGameAdditionalPackageList.ShowItemToolTips = true; - this.SelectedGameAdditionalPackageList.Size = new System.Drawing.Size(364, 160); + this.SelectedGameAdditionalPackageList.Size = new System.Drawing.Size(364, 123); this.SelectedGameAdditionalPackageList.TabIndex = 18; this.SelectedGameAdditionalPackageList.UseCompatibleStateImageBehavior = false; this.SelectedGameAdditionalPackageList.View = System.Windows.Forms.View.Details; @@ -2194,34 +2213,27 @@ private void InitializeComponent() // label44 // this.label44.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label44.Location = new System.Drawing.Point(6, 9); + this.label44.Location = new System.Drawing.Point(6, 48); this.label44.Name = "label44"; - this.label44.Size = new System.Drawing.Size(427, 20); + this.label44.Size = new System.Drawing.Size(457, 33); this.label44.TabIndex = 9; - this.label44.Text = "Sledge automatically includes textures from your game/mod directories."; + this.label44.Text = "Sledge automatically includes textures from your game/mod directories.\r\nYou can c" + + "hange or override this behaviour with these options."; this.label44.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // - // label45 - // - this.label45.Location = new System.Drawing.Point(6, 32); - this.label45.Name = "label45"; - this.label45.Size = new System.Drawing.Size(457, 121); - this.label45.TabIndex = 9; - this.label45.Text = resources.GetString("label45.Text"); - this.label45.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - // // lblGameWAD // - this.lblGameWAD.Location = new System.Drawing.Point(6, 161); + this.lblGameWAD.Location = new System.Drawing.Point(6, 85); this.lblGameWAD.Name = "lblGameWAD"; - this.lblGameWAD.Size = new System.Drawing.Size(220, 20); + this.lblGameWAD.Size = new System.Drawing.Size(364, 20); this.lblGameWAD.TabIndex = 9; - this.lblGameWAD.Text = "Additional Texture Packages"; + this.lblGameWAD.Text = "Additional Texture Packages (mouse over here for more information)"; this.lblGameWAD.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.HelpTooltip.SetToolTip(this.lblGameWAD, resources.GetString("lblGameWAD.ToolTip")); // // SelectedGameLightmapScale // - this.SelectedGameLightmapScale.Location = new System.Drawing.Point(319, 376); + this.SelectedGameLightmapScale.Location = new System.Drawing.Point(359, 12); this.SelectedGameLightmapScale.Name = "SelectedGameLightmapScale"; this.SelectedGameLightmapScale.Size = new System.Drawing.Size(51, 20); this.SelectedGameLightmapScale.TabIndex = 17; @@ -2233,7 +2245,7 @@ private void InitializeComponent() // // lblConfigLightmapScale // - this.lblConfigLightmapScale.Location = new System.Drawing.Point(196, 376); + this.lblConfigLightmapScale.Location = new System.Drawing.Point(236, 12); this.lblConfigLightmapScale.Name = "lblConfigLightmapScale"; this.lblConfigLightmapScale.Size = new System.Drawing.Size(117, 20); this.lblConfigLightmapScale.TabIndex = 9; @@ -2242,7 +2254,7 @@ private void InitializeComponent() // // SelectedGameAddAdditionalPackageFolder // - this.SelectedGameAddAdditionalPackageFolder.Location = new System.Drawing.Point(376, 213); + this.SelectedGameAddAdditionalPackageFolder.Location = new System.Drawing.Point(376, 137); this.SelectedGameAddAdditionalPackageFolder.Name = "SelectedGameAddAdditionalPackageFolder"; this.SelectedGameAddAdditionalPackageFolder.Size = new System.Drawing.Size(87, 23); this.SelectedGameAddAdditionalPackageFolder.TabIndex = 1; @@ -2252,7 +2264,7 @@ private void InitializeComponent() // // SelectedGameAddAdditionalPackageFile // - this.SelectedGameAddAdditionalPackageFile.Location = new System.Drawing.Point(376, 184); + this.SelectedGameAddAdditionalPackageFile.Location = new System.Drawing.Point(376, 108); this.SelectedGameAddAdditionalPackageFile.Name = "SelectedGameAddAdditionalPackageFile"; this.SelectedGameAddAdditionalPackageFile.Size = new System.Drawing.Size(87, 23); this.SelectedGameAddAdditionalPackageFile.TabIndex = 1; @@ -2268,7 +2280,7 @@ private void InitializeComponent() 0, 0, 131072}); - this.SelectedGameTextureScale.Location = new System.Drawing.Point(319, 350); + this.SelectedGameTextureScale.Location = new System.Drawing.Point(133, 10); this.SelectedGameTextureScale.Name = "SelectedGameTextureScale"; this.SelectedGameTextureScale.Size = new System.Drawing.Size(51, 20); this.SelectedGameTextureScale.TabIndex = 17; @@ -2280,7 +2292,7 @@ private void InitializeComponent() // // lblConfigTextureScale // - this.lblConfigTextureScale.Location = new System.Drawing.Point(196, 350); + this.lblConfigTextureScale.Location = new System.Drawing.Point(10, 10); this.lblConfigTextureScale.Name = "lblConfigTextureScale"; this.lblConfigTextureScale.Size = new System.Drawing.Size(117, 20); this.lblConfigTextureScale.TabIndex = 9; @@ -2289,7 +2301,7 @@ private void InitializeComponent() // // SelectedGameRemoveAdditionalPackage // - this.SelectedGameRemoveAdditionalPackage.Location = new System.Drawing.Point(376, 242); + this.SelectedGameRemoveAdditionalPackage.Location = new System.Drawing.Point(376, 166); this.SelectedGameRemoveAdditionalPackage.Name = "SelectedGameRemoveAdditionalPackage"; this.SelectedGameRemoveAdditionalPackage.Size = new System.Drawing.Size(87, 23); this.SelectedGameRemoveAdditionalPackage.TabIndex = 3; @@ -3437,6 +3449,16 @@ private void InitializeComponent() this.btnApplySettings.UseVisualStyleBackColor = true; this.btnApplySettings.Click += new System.EventHandler(this.Apply); // + // HelpTooltip + // + this.HelpTooltip.AutomaticDelay = 0; + this.HelpTooltip.AutoPopDelay = 32000; + this.HelpTooltip.InitialDelay = 500; + this.HelpTooltip.IsBalloon = true; + this.HelpTooltip.ReshowDelay = 100; + this.HelpTooltip.UseAnimation = false; + this.HelpTooltip.UseFading = false; + // // SelectedBuildCsgParameters // this.SelectedBuildCsgParameters.Dock = System.Windows.Forms.DockStyle.Fill; @@ -3482,17 +3504,59 @@ private void InitializeComponent() this.SelectedBuildSharedParameters.Size = new System.Drawing.Size(449, 408); this.SelectedBuildSharedParameters.TabIndex = 1; // - // SelectedGameIncludeFgdDirectoriesInEnvironment + // SelectedGameBlacklistTextbox // - this.SelectedGameIncludeFgdDirectoriesInEnvironment.Checked = true; - this.SelectedGameIncludeFgdDirectoriesInEnvironment.CheckState = System.Windows.Forms.CheckState.Checked; - this.SelectedGameIncludeFgdDirectoriesInEnvironment.Location = new System.Drawing.Point(184, 246); - this.SelectedGameIncludeFgdDirectoriesInEnvironment.Name = "SelectedGameIncludeFgdDirectoriesInEnvironment"; - this.SelectedGameIncludeFgdDirectoriesInEnvironment.Size = new System.Drawing.Size(264, 24); - this.SelectedGameIncludeFgdDirectoriesInEnvironment.TabIndex = 19; - this.SelectedGameIncludeFgdDirectoriesInEnvironment.Text = "Load sprites and models from FGD directories"; - this.SelectedGameIncludeFgdDirectoriesInEnvironment.UseVisualStyleBackColor = true; - this.SelectedGameIncludeFgdDirectoriesInEnvironment.CheckedChanged += new System.EventHandler(this.SelectedGameOverrideMapSizeChanged); + this.SelectedGameBlacklistTextbox.Location = new System.Drawing.Point(6, 53); + this.SelectedGameBlacklistTextbox.Multiline = true; + this.SelectedGameBlacklistTextbox.Name = "SelectedGameBlacklistTextbox"; + this.SelectedGameBlacklistTextbox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.SelectedGameBlacklistTextbox.Size = new System.Drawing.Size(208, 144); + this.SelectedGameBlacklistTextbox.TabIndex = 19; + // + // label45 + // + this.label45.Location = new System.Drawing.Point(6, 10); + this.label45.Name = "label45"; + this.label45.Size = new System.Drawing.Size(208, 40); + this.label45.TabIndex = 20; + this.label45.Text = "Blacklisted Packages (one per line)\r\n(mouse over here for more information)"; + this.label45.TextAlign = System.Drawing.ContentAlignment.BottomCenter; + this.HelpTooltip.SetToolTip(this.label45, "Type the names of all the packages or folders you\r\nwant to exclude from the textu" + + "re list. The name must\r\nmatch exactly: \"test\" will only match \"test.wad\", not \"t" + + "est1.wad\".\r\n"); + // + // SelectedGameWhitelistTextbox + // + this.SelectedGameWhitelistTextbox.Location = new System.Drawing.Point(232, 53); + this.SelectedGameWhitelistTextbox.Multiline = true; + this.SelectedGameWhitelistTextbox.Name = "SelectedGameWhitelistTextbox"; + this.SelectedGameWhitelistTextbox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.SelectedGameWhitelistTextbox.Size = new System.Drawing.Size(208, 144); + this.SelectedGameWhitelistTextbox.TabIndex = 19; + // + // label46 + // + this.label46.Location = new System.Drawing.Point(232, 10); + this.label46.Name = "label46"; + this.label46.Size = new System.Drawing.Size(208, 40); + this.label46.TabIndex = 20; + this.label46.Text = "Whitelisted Packages (one per line)\r\nUse with caution!\r\n(mouse over here for more" + + " information)"; + this.label46.TextAlign = System.Drawing.ContentAlignment.BottomCenter; + this.HelpTooltip.SetToolTip(this.label46, resources.GetString("label46.ToolTip")); + // + // groupBox19 + // + this.groupBox19.Controls.Add(this.label45); + this.groupBox19.Controls.Add(this.label46); + this.groupBox19.Controls.Add(this.SelectedGameBlacklistTextbox); + this.groupBox19.Controls.Add(this.SelectedGameWhitelistTextbox); + this.groupBox19.Location = new System.Drawing.Point(6, 237); + this.groupBox19.Name = "groupBox19"; + this.groupBox19.Size = new System.Drawing.Size(457, 203); + this.groupBox19.TabIndex = 21; + this.groupBox19.TabStop = false; + this.groupBox19.Text = "Blacklisting/Whitelisting"; // // SettingsForm // @@ -3591,6 +3655,8 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).EndInit(); this.groupBox7.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit(); + this.groupBox19.ResumeLayout(false); + this.groupBox19.PerformLayout(); this.ResumeLayout(false); } @@ -3865,8 +3931,13 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox SelectedBuildRunCsgCheckbox; private System.Windows.Forms.CheckBox SelectedBuildDontRedirectOutput; private System.Windows.Forms.Label label44; - private System.Windows.Forms.Label label45; private System.Windows.Forms.Button SelectedGameAddAdditionalPackageFolder; private System.Windows.Forms.CheckBox SelectedGameIncludeFgdDirectoriesInEnvironment; + private System.Windows.Forms.ToolTip HelpTooltip; + private System.Windows.Forms.Label label46; + private System.Windows.Forms.Label label45; + private System.Windows.Forms.TextBox SelectedGameWhitelistTextbox; + private System.Windows.Forms.TextBox SelectedGameBlacklistTextbox; + private System.Windows.Forms.GroupBox groupBox19; } } diff --git a/Sledge.Editor/Settings/SettingsForm.cs b/Sledge.Editor/Settings/SettingsForm.cs index 17acd7c97..13e13f07b 100644 --- a/Sledge.Editor/Settings/SettingsForm.cs +++ b/Sledge.Editor/Settings/SettingsForm.cs @@ -239,6 +239,8 @@ private void BindConfigControls() SelectedGameDefaultBrushEnt.SelectedIndexChanged += (s, e) => CheckNull(_selectedGame, x => x.DefaultBrushEntity = SelectedGameDefaultBrushEnt.Text); SelectedGameTextureScale.ValueChanged += (s, e) => CheckNull(_selectedGame, x => x.DefaultTextureScale = SelectedGameTextureScale.Value); SelectedGameLightmapScale.ValueChanged += (s, e) => CheckNull(_selectedGame, x => x.DefaultLightmapScale = SelectedGameLightmapScale.Value); + SelectedGameBlacklistTextbox.TextChanged += (s, e) => CheckNull(_selectedGame, x => x.PackageBlacklist = SelectedGameBlacklistTextbox.Text.Trim()); + SelectedGameWhitelistTextbox.TextChanged += (s, e) => CheckNull(_selectedGame, x => x.PackageWhitelist = SelectedGameWhitelistTextbox.Text.Trim()); SelectedGameIncludeFgdDirectoriesInEnvironment.CheckedChanged += (s, e) => CheckNull(_selectedGame, x => x.IncludeFgdDirectoriesInEnvironment = SelectedGameIncludeFgdDirectoriesInEnvironment.Checked); SelectedGameOverrideMapSize.CheckedChanged += (s, e) => CheckNull(_selectedGame, x => x.OverrideMapSize = SelectedGameOverrideMapSize.Checked); var sizes = new[] {4096, 8192, 16384, 32768, 65536}; @@ -1059,6 +1061,8 @@ private void UpdateSelectedGame() SelectedGameDefaultBrushEnt.SelectedText = _selectedGame.DefaultBrushEntity; SelectedGameTextureScale.Value = _selectedGame.DefaultTextureScale; SelectedGameLightmapScale.Value = _selectedGame.DefaultLightmapScale; + SelectedGameBlacklistTextbox.Text = _selectedGame.PackageBlacklist ?? ""; + SelectedGameWhitelistTextbox.Text = _selectedGame.PackageWhitelist ?? ""; SelectedGameIncludeFgdDirectoriesInEnvironment.Checked = _selectedGame.IncludeFgdDirectoriesInEnvironment; SelectedGameOverrideMapSize.Checked = _selectedGame.OverrideMapSize; var sizes = new[] { 4096, 8192, 16384, 32768, 65536 }; diff --git a/Sledge.Editor/Settings/SettingsForm.resx b/Sledge.Editor/Settings/SettingsForm.resx index f6647409a..deb5432e6 100644 --- a/Sledge.Editor/Settings/SettingsForm.resx +++ b/Sledge.Editor/Settings/SettingsForm.resx @@ -117,14 +117,33 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Only add entries in this section if you want to load textures that do not exist on your game path. They will not appear in-game unless you include them in the BSP using the compile tools. + + 17, 17 + + + Type the names of all the packages or folders you +want to include in the texture list. If packages are +specified in this list, no other packages will be loaded. +Put each package name on a line. The name must match +exactly: "test" will only match "test.wad", not "test1.wad". + +If this list is not blank, all other texture packages will be ignored! + + + Only add entries in this section if you want to load textures that +do not exist on your game path. They will not appear in-game +unless you include them in the BSP using the compile tools. -For Goldsource: Add WAD files or a folder containing WAD files (subfolders are not scanned). Auto-detection of wads is automatically performed when saving your map. +For Goldsource: Add WAD files or a folder containing WAD files +(subfolders are not scanned). Auto-detection of wads is +automatically performed when saving your map. -For Source: Add a folder containing VMT/VTF files (optionally, in a subfolder called "materials"). All subfolders are scanned. The VMT and VTF files must be in their correct relative locations within the folder, or they will not be loaded. +For Source: Add a folder containing VMT/VTF files (optionally, +in a subfolder called "materials"). All subfolders are scanned. +The VMT and VTF files must be in their correct relative locations +within the folder, or they will not be loaded. - 36 + 66 \ No newline at end of file diff --git a/Sledge.Editor/Tools/TextureApplicationForm.Designer.cs b/Sledge.Editor/Tools/TextureApplicationForm.Designer.cs index f12d8ca34..c75ad05f3 100644 --- a/Sledge.Editor/Tools/TextureApplicationForm.Designer.cs +++ b/Sledge.Editor/Tools/TextureApplicationForm.Designer.cs @@ -387,7 +387,7 @@ private void InitializeComponent() this.tableLayoutPanel1.ColumnCount = 3; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 65F)); - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 197F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 199F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.Controls.Add(this.ScaleXValue, 1, 1); diff --git a/Sledge.Packages/Wad/WadPackage.cs b/Sledge.Packages/Wad/WadPackage.cs index d35be3fb9..d32caece0 100644 --- a/Sledge.Packages/Wad/WadPackage.cs +++ b/Sledge.Packages/Wad/WadPackage.cs @@ -65,6 +65,7 @@ private void ReadTextureEntries(BinaryReader br) var name = br.ReadFixedLengthString(Encoding.ASCII, 16).ToLowerInvariant(); if (!validTypes.Contains(type)) continue; // Skip unsupported types + if (Entries.Any(x => x.Name == name)) continue; // Don't add duplicates Entries.Add(new WadEntry(this, name, (WadEntryType) type, offset, compressionType, compressedLength, fullLength)); } } diff --git a/Sledge.Providers/Texture/SprProvider.cs b/Sledge.Providers/Texture/SprProvider.cs index cd849f369..a871045cc 100644 --- a/Sledge.Providers/Texture/SprProvider.cs +++ b/Sledge.Providers/Texture/SprProvider.cs @@ -133,8 +133,9 @@ public override void LoadTextures(IEnumerable items) } } - public override IEnumerable CreatePackages(IEnumerable sourceRoots, IEnumerable additionalPackages) + public override IEnumerable CreatePackages(IEnumerable sourceRoots, IEnumerable additionalPackages, IEnumerable blacklist, IEnumerable whitelist) { + // Sprite provider ignores the black/whitelists var dirs = sourceRoots.Union(additionalPackages).Where(Directory.Exists).Select(Path.GetFullPath).Select(x => x.ToLowerInvariant()).Distinct().ToList(); var tp = new TexturePackage(String.Join(";", dirs), "sprites", this) {IsBrowsable = false}; foreach (var dir in dirs) diff --git a/Sledge.Providers/Texture/TextureProvider.cs b/Sledge.Providers/Texture/TextureProvider.cs index b3f243cbb..fa0a2893e 100644 --- a/Sledge.Providers/Texture/TextureProvider.cs +++ b/Sledge.Providers/Texture/TextureProvider.cs @@ -41,19 +41,21 @@ public static void Deregister(TextureProvider provider) #endregion protected string CachePath { get; private set; } - public abstract IEnumerable CreatePackages(IEnumerable sourceRoots, IEnumerable additionalPackages); + public abstract IEnumerable CreatePackages(IEnumerable sourceRoots, IEnumerable additionalPackages, IEnumerable blacklist, IEnumerable whitelist); public abstract void DeletePackages(IEnumerable packages); public abstract void LoadTextures(IEnumerable items); public abstract ITextureStreamSource GetStreamSource(int maxWidth, int maxHeight, IEnumerable packages); - public static TextureCollection CreateCollection(IEnumerable sourceRoots, IEnumerable additionalPackages = null) + public static TextureCollection CreateCollection(IEnumerable sourceRoots, IEnumerable additionalPackages, IEnumerable blacklist, IEnumerable whitelist) { var list = sourceRoots.ToList(); var additional = additionalPackages == null ? new List() : additionalPackages.ToList(); + var wl = whitelist == null ? new List() : whitelist.ToList(); + var bl = blacklist == null ? new List() : blacklist.ToList(); var pkgs = new List(); foreach (var provider in RegisteredProviders) { - pkgs.AddRange(provider.CreatePackages(list, additional)); + pkgs.AddRange(provider.CreatePackages(list, additional, bl, wl)); } var tc = new TextureCollection(pkgs); Packages.AddRange(pkgs); diff --git a/Sledge.Providers/Texture/VmtProvider.cs b/Sledge.Providers/Texture/VmtProvider.cs index 540deb3cc..f948d5693 100644 --- a/Sledge.Providers/Texture/VmtProvider.cs +++ b/Sledge.Providers/Texture/VmtProvider.cs @@ -12,10 +12,13 @@ namespace Sledge.Providers.Texture { public class VmtProvider : TextureProvider { - private Dictionary _roots = new Dictionary(); + private readonly Dictionary _roots = new Dictionary(); - public override IEnumerable CreatePackages(IEnumerable sourceRoots, IEnumerable additionalPackages) + public override IEnumerable CreatePackages(IEnumerable sourceRoots, IEnumerable additionalPackages, IEnumerable blacklist, IEnumerable whitelist) { + var blist = blacklist.Select(x => x.TrimEnd('/', '\\')).Where(x => !String.IsNullOrWhiteSpace(x)).Select(x => x + '/').ToList(); + var wlist = whitelist.Select(x => x.TrimEnd('/', '\\')).Where(x => !String.IsNullOrWhiteSpace(x)).Select(x => x + '/').ToList(); + var roots = sourceRoots.ToList(); var packages = new Dictionary(); @@ -62,6 +65,15 @@ public override IEnumerable CreatePackages(IEnumerable s packages[dir].AddTexture(new TextureItem(packages[dir], vmt, baseTexture, size.Width, size.Height)); } + foreach (var key in packages.Keys.ToList()) + { + if ((blist.Any(x => x.StartsWith(key, StringComparison.InvariantCultureIgnoreCase))) || + (wlist.Any() && !wlist.Any(x => x.StartsWith(key, StringComparison.InvariantCultureIgnoreCase)))) + { + packages.Remove(key); + } + } + vmtRoot.Dispose(); foreach (var tp in packages.Values) diff --git a/Sledge.Providers/Texture/WadProvider.cs b/Sledge.Providers/Texture/WadProvider.cs index a52ee581f..4575131dd 100644 --- a/Sledge.Providers/Texture/WadProvider.cs +++ b/Sledge.Providers/Texture/WadProvider.cs @@ -155,33 +155,47 @@ private void SaveToCache(TexturePackage package) private TexturePackage CreatePackage(string package) { - if (!File.Exists(package)) return null; + try + { + if (!File.Exists(package)) return null; - var tp = new TexturePackage(package, Path.GetFileNameWithoutExtension(package), this); - if (LoadFromCache(tp)) return tp; + var tp = new TexturePackage(package, Path.GetFileNameWithoutExtension(package), this); + if (LoadFromCache(tp)) return tp; - var list = new List(); - using (var pack = new WadPackage(new FileInfo(package))) - { - list.AddRange(pack.GetEntries().OfType().Select(x => new TextureItem(tp, x.Name, (int) x.Width, (int) x.Height))); + var list = new List(); + using (var pack = new WadPackage(new FileInfo(package))) + { + list.AddRange(pack.GetEntries().OfType().Select(x => new TextureItem(tp, x.Name, (int) x.Width, (int) x.Height))); + } + foreach (var ti in list) + { + tp.AddTexture(ti); + } + SaveToCache(tp); + return tp; } - foreach (var ti in list) + catch { - tp.AddTexture(ti); + return null; } - SaveToCache(tp); - return tp; } - public override IEnumerable CreatePackages(IEnumerable sourceRoots, IEnumerable additionalPackages) + public override IEnumerable CreatePackages(IEnumerable sourceRoots, IEnumerable additionalPackages, IEnumerable blacklist, IEnumerable whitelist) { + var blist = blacklist.Select(x => x.EndsWith(".wad") ? x.Substring(0, x.Length - 4) : x).Where(x => !String.IsNullOrWhiteSpace(x)).ToList(); + var wlist = whitelist.Select(x => x.EndsWith(".wad") ? x.Substring(0, x.Length - 4) : x).Where(x => !String.IsNullOrWhiteSpace(x)).ToList(); var wads = sourceRoots.Union(additionalPackages) .Where(Directory.Exists) .SelectMany(x => Directory.GetFiles(x, "*.wad", SearchOption.TopDirectoryOnly)) .Union(additionalPackages.Where(x => x.EndsWith(".wad") && File.Exists(x))) .GroupBy(Path.GetFileNameWithoutExtension) - .Select(x => x.First()); - return wads.AsParallel().Select(CreatePackage); + .Select(x => x.First()) + .Where(x => !blist.Any(b => String.Equals(Path.GetFileNameWithoutExtension(x) ?? x, b, StringComparison.InvariantCultureIgnoreCase))); + if (wlist.Any()) + { + wads = wads.Where(x => wlist.Contains(Path.GetFileNameWithoutExtension(x) ?? x, StringComparer.InvariantCultureIgnoreCase)); + } + return wads.AsParallel().Select(CreatePackage).Where(x => x != null); } public override void DeletePackages(IEnumerable packages) diff --git a/Sledge.Settings/Models/Game.cs b/Sledge.Settings/Models/Game.cs index d6006bfa3..ad6275402 100644 --- a/Sledge.Settings/Models/Game.cs +++ b/Sledge.Settings/Models/Game.cs @@ -40,6 +40,8 @@ public class Game public List Fgds { get; set; } public List AdditionalPackages { get; set; } + public string PackageBlacklist { get; set; } + public string PackageWhitelist { get; set; } public Game() { @@ -89,6 +91,9 @@ public void Read(GenericStructure gs) } } + PackageBlacklist = gs["PackageBlacklist"] ?? ""; + PackageWhitelist = gs["PackageWhitelist"] ?? ""; + var fgds = gs.Children.FirstOrDefault(x => x.Name == "Fgds"); if (fgds != null) { @@ -138,6 +143,9 @@ public void Write(GenericStructure gs) } gs.Children.Add(additional); + gs["PackageBlacklist"] = PackageBlacklist ?? ""; + gs["PackageWhitelist"] = PackageWhitelist ?? ""; + var fgds = new GenericStructure("Fgds"); i = 1; foreach (var fgd in Fgds) @@ -194,6 +202,23 @@ public string GetGameLaunchArgument() } } + public IEnumerable GetTextureBlacklist() + { + var bl = new List(); + if (Engine == Engine.Goldsource) + { + bl.Add("cached"); + bl.Add("gfx"); + } + bl.AddRange((PackageBlacklist ?? "").Trim().Split('\n').Select(x => x.Trim()).Where(x => !String.IsNullOrWhiteSpace(x))); + return bl; + } + + public IEnumerable GetTextureWhitelist() + { + return (PackageWhitelist ?? "").Trim().Split('\n').Select(x => x.Trim()).Where(x => !String.IsNullOrWhiteSpace(x)); + } + private int GetSteamAppId() { if (Engine == Engine.Goldsource) diff --git a/Sledge.Tests/Vtf/VtfTest.cs b/Sledge.Tests/Vtf/VtfTest.cs index 5dd6e3b1e..636d40d42 100644 --- a/Sledge.Tests/Vtf/VtfTest.cs +++ b/Sledge.Tests/Vtf/VtfTest.cs @@ -91,7 +91,7 @@ public void VpkVtfCollectionTest() var collection = TextureProvider.CreateCollection(new[] { @"F:\Steam\SteamApps\common\Team Fortress 2\tf" - }); + }, null, null, null); } [TestMethod]