/// <summary> /// Deletes the specified item. /// </summary> /// <param name="item">The item.</param> public void Delete(ContentItem item) { if (item == null) { throw new ArgumentNullException(); } // Fire events if (_enableEvents) { ItemRemoved?.Invoke(item); } item.OnDelete(); _itemsDeleted++; var path = item.Path; // Special case for folders if (item is ContentFolder folder) { // TODO: maybe don't remove folders recursive but at once? // Delete all children if (folder.Children.Count > 0) { var children = folder.Children.ToArray(); for (int i = 0; i < children.Length; i++) { Delete(children[0]); } } // Remove directory if (Directory.Exists(path)) { try { Directory.Delete(path, true); } catch (Exception ex) { // Error Editor.LogWarning(ex); Editor.LogWarning(string.Format("Cannot remove folder \'{0}\'", path)); return; } } // Unlink from the parent item.ParentFolder = null; // Delete tree node folder.Node.Dispose(); } else { // Check if it's an asset if (item.IsAsset) { // Delete asset by using content pool FlaxEngine.Content.DeleteAsset(path); } else { // Delete file if (File.Exists(path)) { File.Delete(path); } } // Unlink from the parent item.ParentFolder = null; // Delete item item.Dispose(); } if (_enableEvents) { OnWorkspaceModified?.Invoke(); } }