From 12830020f9abe78a108c8bf4cafb0cea3f16549a Mon Sep 17 00:00:00 2001 From: MaxED Date: Fri, 12 Dec 2014 14:14:52 +0000 Subject: [PATCH] Resource List Editor: fixed potential crash on pasting/replacing resources when there are duplicate resources in the list. Resource List Editor: duplicate resources are no longer added when adding resources using drag and drop. --- Source/Core/Controls/ResourceListEditor.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Source/Core/Controls/ResourceListEditor.cs b/Source/Core/Controls/ResourceListEditor.cs index fb7f9196..3fee227a 100644 --- a/Source/Core/Controls/ResourceListEditor.cs +++ b/Source/Core/Controls/ResourceListEditor.cs @@ -217,8 +217,11 @@ namespace CodeImp.DoomBuilder.Controls if(!data.GetDataPresent(DataFormats.FileDrop)) return; string[] paths = (string[])data.GetData(DataFormats.FileDrop); + Dictionary curlocations = GetLocationNames(); foreach(string path in paths) { + if(curlocations.ContainsKey(path)) continue; + if(File.Exists(path)) { string ext = Path.GetExtension(path); @@ -429,7 +432,7 @@ namespace CodeImp.DoomBuilder.Controls // Don't do stupid things if(copiedresources.Count == 0) return; - Dictionary curlocations = GetLocationNames(); + Dictionary curlocations = GetLocationNames(); int pastedcount = 0; foreach(DataLocation dl in copiedresources) { @@ -466,7 +469,7 @@ namespace CodeImp.DoomBuilder.Controls } // Paste new resources - Dictionary curlocations = GetLocationNames(); + Dictionary curlocations = GetLocationNames(); foreach(DataLocation dl in copiedresources) { if(curlocations.ContainsKey(dl.location)) continue; @@ -504,14 +507,14 @@ namespace CodeImp.DoomBuilder.Controls if(OnContentChanged != null) OnContentChanged(); } - private Dictionary GetLocationNames() + private Dictionary GetLocationNames() { - Dictionary dict = new Dictionary(resourceitems.Items.Count); + Dictionary dict = new Dictionary(resourceitems.Items.Count); foreach(ListViewItem item in resourceitems.Items) { if(!(item.Tag is DataLocation)) continue; DataLocation dl = (DataLocation)item.Tag; - dict.Add(dl.location, item); + if(!dict.ContainsKey(dl.location)) dict.Add(dl.location, false); } return dict;