From 5e0a89fa304ddaca9cdeb53e655183dec1c15213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 7 Feb 2016 14:21:33 +0100 Subject: [PATCH 1/3] Re-enabled All Packages which seems to be fast enough now. --- .../Widgets/Logic/AssetBrowserLogic.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index 1ee5cc5cc5..b7959cd51f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -343,9 +343,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return item; }; - // TODO: Re-enable "All Packages" once list generation is done in a background thread - // var sources = new[] { (IPackage)null }.Concat(GlobalFileSystem.MountedFolders); - var sources = Game.ModData.ModFiles.MountedPackages; + var sources = new[] { (IReadOnlyPackage)null }.Concat(Game.ModData.ModFiles.MountedPackages); dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 280, sources, setupItem); return true; } @@ -355,14 +353,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic assetList.RemoveChildren(); availableShps.Clear(); - // TODO: This is too slow to run in the main thread - // var files = AssetSource != null ? AssetSource.AllFileNames() : - // GlobalFileSystem.MountedFolders.SelectMany(f => f.AllFileNames()); - if (assetSource == null) - return; - - var files = assetSource.Contents.OrderBy(s => s); - foreach (var file in files) + var files = assetSource != null ? assetSource.Contents : Game.ModData.ModFiles.MountedPackages.SelectMany(f => f.Contents).Distinct(); + foreach (var file in files.OrderBy(s => s)) { if (allowedExtensions.Any(ext => file.EndsWith(ext, true, CultureInfo.InvariantCulture))) { From f87a4bf16f5d5b9c39a37f1b29e234bbeb42ba4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 7 Feb 2016 16:42:38 +0100 Subject: [PATCH 2/3] Default to the all packages instead of the first. --- OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index b7959cd51f..ad33313fb1 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -50,7 +50,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic this.world = world; panel = widget; - assetSource = Game.ModData.ModFiles.MountedPackages.First(); var ticker = panel.GetOrNull("ANIMATION_TICKER"); if (ticker != null) From aec74d8f7fd132a6b5106fef8e93875dc20417ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 7 Feb 2016 16:43:20 +0100 Subject: [PATCH 3/3] Only list packages with viewable contents. --- OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index ad33313fb1..ea4254fac4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -22,7 +22,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic { public class AssetBrowserLogic : ChromeLogic { - static string[] allowedExtensions; + readonly string[] allowedExtensions; + readonly IEnumerable acceptablePackages; readonly World world; @@ -216,6 +217,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic else allowedExtensions = new string[0]; + acceptablePackages = Game.ModData.ModFiles.MountedPackages.Where(p => + p.Contents.Any(c => allowedExtensions.Contains(Path.GetExtension(c).ToLowerInvariant()))); + assetList = panel.Get("ASSET_LIST"); template = panel.Get("ASSET_TEMPLATE"); PopulateAssetList(); @@ -342,7 +346,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return item; }; - var sources = new[] { (IReadOnlyPackage)null }.Concat(Game.ModData.ModFiles.MountedPackages); + var sources = new[] { (IReadOnlyPackage)null }.Concat(acceptablePackages); dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 280, sources, setupItem); return true; }