Beispiel #1
0
        private IFileOperation CreateOperation(ResourceOperation operation, IShellItem source, IShellItem target, string name, FileAttributes attributes, IPropertyChangeArray properties, FileOperationProgressSink sink)
        {
            var op = Shell32.CreateFileOperation();

            op.Advise(sink);
            op.SetOwnerWindow(OwnerHwnd);
            op.SetOperationFlags(0x0400 | 0x0004 | 0x0200 | 0x00100000);
            switch (operation)
            {
            case ResourceOperation.Create:
                op.NewItem(source, attributes, name, null, null);
                break;

            case ResourceOperation.Delete:
                op.DeleteItem(source, null);
                break;

            case ResourceOperation.Move:
                if (target == null)
                {
                    op.RenameItem(source, name, null);
                }
                else
                {
                    op.MoveItem(source, target, name, null);
                }
                break;

            case ResourceOperation.Copy:
                op.CopyItem(source, target, name, null);
                break;
            }
            return(op);
        }
Beispiel #2
0
            public void SetProperty <T>(PROPERTYKEY property, T value)
            {
                var item = GetItem();

                try{
                    var propvar    = Propsys.VariantToPropVariant(value);
                    var properties = Propsys.PSCreatePropertyChangeArray <IPropertyChangeArray>(new[] { Shell32.PKEY_FileAttributes }, new[] { Propsys.PKA_FLAGS.PKA_SET }, new[] { propvar });

                    var op = Shell32.CreateFileOperation();
                    op.SetOwnerWindow(fs.OwnerHwnd);
                    op.SetOperationFlags(0x0400 | 0x0004 | 0x0200 | 0x00100000);
                    op.SetProperties(properties);
                    op.ApplyPropertiesToItem(item);
                    op.PerformOperations();
                }finally{
                    Marshal.FinalReleaseComObject(item);
                }
            }