protected override void WndProc(ref Message m) {
base.WndProc(ref m);
if (m.Msg == ShellNotifications.WM_SHNOTIFY) {
//MessageBox.Show("1");
if (this._NotificationGlobal.NotificationReceipt(m.WParam, m.LParam)) {
//var computerNode = this.ShellTreeView.Nodes.OfType<TreeNode>().Single(s => s.Tag != null && (s.Tag as IListItemEx).ParsingName == KnownFolders.Computer.ParsingName);
var computerNode = this.ShellTreeView.Nodes.OfType<TreeNode>().First(s => (s?.Tag as IListItemEx)?.ParsingName == KnownFolders.Computer.ParsingName);
foreach (NotifyInfos info in this._NotificationGlobal.NotificationsReceived.ToArray()) {
switch (info.Notification) {
case ShellNotifications.SHCNE.SHCNE_RENAMEFOLDER:
var objPrevDir = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, info.Item1);
var objNewDir = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, info.Item2);
this.RenameItem(objPrevDir, objNewDir);
break;
case ShellNotifications.SHCNE.SHCNE_MKDIR:
try {
this.AddItem(FileSystemListItem.ToFileSystemItem(IntPtr.Zero, info.Item1));
} catch (FileNotFoundException) { }
break;
case ShellNotifications.SHCNE.SHCNE_RMDIR:
var objDelDir = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, info.Item1);
if (objDelDir.IsFolder && objDelDir.IsFileSystem) {
this.DeleteItem(objDelDir);
}
break;
case ShellNotifications.SHCNE.SHCNE_MEDIAINSERTED:
case ShellNotifications.SHCNE.SHCNE_MEDIAREMOVED:
var objDm = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, info.Item1);
var exisitingMItem = computerNode.Nodes.OfType<TreeNode>().FirstOrDefault(s => s.Tag != null & (s.Tag as IListItemEx).Equals(objDm));
if (exisitingMItem != null) {
exisitingMItem.Text = objDm.DisplayName;
exisitingMItem.ImageIndex = objDm.GetSystemImageListIndex(objDm.PIDL, ShellIconType.SmallIcon, ShellIconFlags.OpenIcon);
exisitingMItem.SelectedImageIndex = exisitingMItem.ImageIndex;
}
break;
case ShellNotifications.SHCNE.SHCNE_DRIVEREMOVED:
var objDr = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, info.Item1);
var theNode = computerNode.Nodes.OfType<TreeNode>().FirstOrDefault(s => s.Tag != null & (s.Tag as IListItemEx).Equals(objDr));
if (theNode != null)
computerNode.Nodes.Remove(theNode);
objDr.Dispose();
break;
case ShellNotifications.SHCNE.SHCNE_DRIVEADD:
var objDa = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, info.Item1);
var exisitingItem = computerNode.Nodes.OfType<TreeNode>().FirstOrDefault(s => s.Tag != null && (s.Tag as IListItemEx).Equals(objDa));
if (exisitingItem == null && !this._PathsToBeAdd.Any(c => c.Equals(objDa.ParsingName, StringComparison.InvariantCultureIgnoreCase))) {
this._PathsToBeAdd.Add(objDa.ParsingName);
var newDrive = new TreeNode(objDa.DisplayName);
newDrive.Tag = objDa;
newDrive.ImageIndex = objDa.GetSystemImageListIndex(objDa.PIDL, ShellIconType.SmallIcon, ShellIconFlags.OpenIcon);
newDrive.SelectedImageIndex = newDrive.ImageIndex;
if (objDa.HasSubFolders)
newDrive.Nodes.Add(_EmptyItemString);
var nodesList = computerNode.Nodes.OfType<TreeNode>().Where(w => w.Tag != null).Select(s => s.Tag as IListItemEx).ToList();
nodesList.Add(objDa);
nodesList = nodesList.OrderBy(o => o.ParsingName).ToList();
var indexToInsert = nodesList.IndexOf(objDa);
nodesList = null;
GC.Collect();
computerNode.Nodes.Insert(indexToInsert, newDrive);
this._PathsToBeAdd.Clear();
}
break;
case ShellNotifications.SHCNE.SHCNE_UPDATEDIR:
break;
default:
break;
}
this._NotificationGlobal.NotificationsReceived.Remove(info);
}
}
if (this._NotificationNetWork.NotificationReceipt(m.WParam, m.LParam)) {
foreach (NotifyInfos info in _NotificationNetWork.NotificationsReceived.ToArray()) {
switch (info.Notification) {
case ShellNotifications.SHCNE.SHCNE_RENAMEITEM:
break;
case ShellNotifications.SHCNE.SHCNE_MKDIR:
//case ShellNotifications.SHCNE.SHCNE_CREATE:
try {
var sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, info.Item1);
if (sho.Parent == null || !sho.Parent.ParsingName.Equals(KnownFolders.Network.ParsingName, StringComparison.InvariantCultureIgnoreCase))
break;
//var existingItem = this.ShellTreeView.Nodes.OfType<TreeNode>().Last().Nodes.OfType<TreeNode>().Where(w => (w.Tag as IListItemEx) != null && (w.Tag as IListItemEx)?.ParsingName == sho.ParsingName).Count();
var existingItem = this.ShellTreeView.Nodes.OfType<TreeNode>().Last().Nodes.OfType<TreeNode>().Where(w => (w.Tag as IListItemEx)?.ParsingName == sho.ParsingName).Count();
if (existingItem > 0)
break;
var node = new TreeNode(sho.DisplayName);
node.ImageIndex = sho.GetSystemImageListIndex(sho.PIDL, ShellIconType.SmallIcon, ShellIconFlags.OpenIcon);// this.folderImageListIndex;
node.SelectedImageIndex = node.ImageIndex;
node.Tag = sho;
if (sho.HasSubFolders) {
node.Nodes.Add(this._SearchingForFolders);
}
//if (sho != null && sho.Parent != null && sho.Parent.ParsingName == KnownFolders.Network.ParsingName) {
//var firstNode = this.ShellTreeView.Nodes.OfType<TreeNode>().Last().Nodes.OfType<TreeNode>().FirstOrDefault();
//if (firstNode != null && firstNode.Text.Equals(this._SearchingForFolders)) {
// firstNode.Remove();
//}
this.ShellTreeView.Nodes.OfType<TreeNode>().Last().Nodes.Add(node);
//}
} catch (AccessViolationException) {
} catch (NullReferenceException) {
}
break;
case ShellNotifications.SHCNE.SHCNE_DELETE:
break;
case ShellNotifications.SHCNE.SHCNE_RMDIR:
break;
case ShellNotifications.SHCNE.SHCNE_MEDIAINSERTED:
break;
case ShellNotifications.SHCNE.SHCNE_MEDIAREMOVED:
break;
case ShellNotifications.SHCNE.SHCNE_DRIVEREMOVED:
break;
case ShellNotifications.SHCNE.SHCNE_DRIVEADD:
break;
case ShellNotifications.SHCNE.SHCNE_NETSHARE:
break;
case ShellNotifications.SHCNE.SHCNE_NETUNSHARE:
break;
case ShellNotifications.SHCNE.SHCNE_ATTRIBUTES:
break;
case ShellNotifications.SHCNE.SHCNE_UPDATEDIR:
break;
case ShellNotifications.SHCNE.SHCNE_UPDATEITEM:
break;
case ShellNotifications.SHCNE.SHCNE_SERVERDISCONNECT:
break;
case ShellNotifications.SHCNE.SHCNE_UPDATEIMAGE:
break;
case ShellNotifications.SHCNE.SHCNE_DRIVEADDGUI:
break;
case ShellNotifications.SHCNE.SHCNE_RENAMEFOLDER:
break;
case ShellNotifications.SHCNE.SHCNE_FREESPACE:
break;
case ShellNotifications.SHCNE.SHCNE_EXTENDED_EVENT:
break;
case ShellNotifications.SHCNE.SHCNE_ASSOCCHANGED:
break;
case ShellNotifications.SHCNE.SHCNE_DISKEVENTS:
break;
case ShellNotifications.SHCNE.SHCNE_GLOBALEVENTS:
break;
case ShellNotifications.SHCNE.SHCNE_ALLEVENTS:
break;
case ShellNotifications.SHCNE.SHCNE_INTERRUPT:
break;
default:
break;
}
_NotificationNetWork.NotificationsReceived.Remove(info);
}
}
}
}