Example #1
0
            public static FILEDESCRIPTOR[] GetFileDescriptors(System.Runtime.InteropServices.ComTypes.IDataObject DataObject, out IntPtr hGlobal)
            {
                FORMATETC _req = new FORMATETC();

                _req.tymed    = TYMED.TYMED_HGLOBAL;
                _req.dwAspect = DVASPECT.DVASPECT_CONTENT;
                _req.cfFormat = (short)(System.Windows.DataFormats.GetDataFormat("FileGroupDescriptorW").Id);
                _req.lindex   = -1;

                STGMEDIUM _val;

                DataObject.GetData(_req, out _val);

                hGlobal = _val.unionmember;
                IntPtr _fgptr = GlobalLock(_val.unionmember);

                NativeMethods.FILEGROUPDESCRIPTOR _fg;

                _fg = (NativeMethods.FILEGROUPDESCRIPTOR)Marshal.PtrToStructure(_fgptr, typeof(NativeMethods.FILEGROUPDESCRIPTOR));

                _fgptr = new IntPtr(_fgptr.ToInt64() + 4);

                NativeMethods.FILEDESCRIPTOR[] _fileDesc = new NativeMethods.FILEDESCRIPTOR[_fg.cItems];

                for (int _i = 0; _i < _fg.cItems; _i++)
                {
                    _fileDesc[_i] = (NativeMethods.FILEDESCRIPTOR)Marshal.PtrToStructure(_fgptr, typeof(NativeMethods.FILEDESCRIPTOR));

                    _fgptr = new IntPtr(_fgptr.ToInt64() + Marshal.SizeOf(typeof(NativeMethods.FILEDESCRIPTOR)));
                }

                return(_fileDesc);
            }
        /// <summary>
        /// Provides data for the specified data format (FILEGROUPDESCRIPTOR/FILEDESCRIPTOR)
        /// </summary>
        /// <param name="fileDescriptors">Collection of virtual files.</param>
        public void SetData(IEnumerable <FileDescriptor> fileDescriptors)
        {
            // Prepare buffer
            var bytes = new List <byte>();

            // Add FILEGROUPDESCRIPTOR header
            bytes.AddRange(StructureBytes(new NativeMethods.FILEGROUPDESCRIPTOR {
                cItems = (uint)(fileDescriptors.Count())
            }));
            // Add n FILEDESCRIPTORs
            foreach (var fileDescriptor in fileDescriptors)
            {
                // Set required fields
                var FILEDESCRIPTOR = new NativeMethods.FILEDESCRIPTOR
                {
                    cFileName = fileDescriptor.Name,
                };
                // Set optional timestamp
                if (fileDescriptor.ChangeTimeUtc.HasValue)
                {
                    FILEDESCRIPTOR.dwFlags |= NativeMethods.FD_CREATETIME | NativeMethods.FD_WRITESTIME;
                    var changeTime         = fileDescriptor.ChangeTimeUtc.Value.ToLocalTime().ToFileTime();
                    var changeTimeFileTime = new System.Runtime.InteropServices.ComTypes.FILETIME
                    {
                        dwLowDateTime  = (int)(changeTime & 0xffffffff),
                        dwHighDateTime = (int)(changeTime >> 32),
                    };
                    FILEDESCRIPTOR.ftLastWriteTime = changeTimeFileTime;
                    FILEDESCRIPTOR.ftCreationTime  = changeTimeFileTime;
                }
                // Set optional length
                if (fileDescriptor.Length.HasValue)
                {
                    FILEDESCRIPTOR.dwFlags      |= NativeMethods.FD_FILESIZE;
                    FILEDESCRIPTOR.nFileSizeLow  = (uint)(fileDescriptor.Length & 0xffffffff);
                    FILEDESCRIPTOR.nFileSizeHigh = (uint)(fileDescriptor.Length >> 32);
                }
                // Add structure to buffer
                bytes.AddRange(StructureBytes(FILEDESCRIPTOR));
            }

            // Set CFSTR_FILEDESCRIPTORW
            SetData(FILEDESCRIPTORW, bytes);
            // Set n CFSTR_FILECONTENTS
            var index = 0;

            foreach (var fileDescriptor in fileDescriptors)
            {
                SetData(FILECONTENTS, index, fileDescriptor.StreamContents);
                index++;
            }
        }
Example #3
0
            public static FILEDESCRIPTOR[] GetFileDescriptors(System.Runtime.InteropServices.ComTypes.IDataObject DataObject, out IntPtr hGlobal)
            {
                FORMATETC _req = new FORMATETC();
                _req.tymed = TYMED.TYMED_HGLOBAL;
                _req.dwAspect = DVASPECT.DVASPECT_CONTENT;
                _req.cfFormat = (short)(System.Windows.DataFormats.GetDataFormat("FileGroupDescriptorW").Id);
                _req.lindex = -1;

                STGMEDIUM _val;
                DataObject.GetData(_req, out _val);

                hGlobal = _val.unionmember;
                IntPtr _fgptr = GlobalLock(_val.unionmember);

                NativeMethods.FILEGROUPDESCRIPTOR _fg;

                _fg = (NativeMethods.FILEGROUPDESCRIPTOR)Marshal.PtrToStructure(_fgptr, typeof(NativeMethods.FILEGROUPDESCRIPTOR));

                _fgptr = new IntPtr(_fgptr.ToInt64() + 4);

                NativeMethods.FILEDESCRIPTOR[] _fileDesc = new NativeMethods.FILEDESCRIPTOR[_fg.cItems];

                for (int _i = 0; _i < _fg.cItems; _i++)
                {
                    _fileDesc[_i] = (NativeMethods.FILEDESCRIPTOR)Marshal.PtrToStructure(_fgptr, typeof(NativeMethods.FILEDESCRIPTOR));

                    _fgptr = new IntPtr(_fgptr.ToInt64() + Marshal.SizeOf(typeof(NativeMethods.FILEDESCRIPTOR)));
                }

                return _fileDesc;
            }
		public void SetData(List<FileDescriptor> fileDescriptors) {
			// Prepare buffer
			var bytes = new List<byte>();
			// Add FILEGROUPDESCRIPTOR header
			bytes.AddRange(StructureBytes(new NativeMethods.FILEGROUPDESCRIPTOR { cItems = (uint)(fileDescriptors.Count()) }));
			// Add n FILEDESCRIPTORs
			foreach (var fileDescriptor in fileDescriptors) {
				// Set required fields
				var FILEDESCRIPTOR = new NativeMethods.FILEDESCRIPTOR {
					cFileName = fileDescriptor.Name,
				};
				// Set optional timestamp
				if (fileDescriptor.ChangeTimeUtc.HasValue) {
					FILEDESCRIPTOR.dwFlags |= NativeMethods.FD_CREATETIME | NativeMethods.FD_WRITESTIME;
					var changeTime = fileDescriptor.ChangeTimeUtc.Value.ToLocalTime().ToFileTime();
					var changeTimeFileTime = new FILETIME {
						dwLowDateTime =
							(int)(changeTime & 0xffffffff),
						dwHighDateTime =
							(int)(changeTime >> 32),
					};
					FILEDESCRIPTOR.ftLastWriteTime = changeTimeFileTime;
					FILEDESCRIPTOR.ftCreationTime = changeTimeFileTime;
				}
				// Set optional length
				if (fileDescriptor.Length.HasValue) {
					FILEDESCRIPTOR.dwFlags |= NativeMethods.FD_FILESIZE;
					FILEDESCRIPTOR.nFileSizeLow = (uint)(fileDescriptor.Length & 0xffffffff);
					FILEDESCRIPTOR.nFileSizeHigh = (uint)(fileDescriptor.Length >> 32);
				}
				// Add structure to buffer
				bytes.AddRange(StructureBytes(FILEDESCRIPTOR));
			}

			// Set CFSTR_FILEDESCRIPTORW
			switch (Source) {
				case DragAndDropSource.ListView:
					SetData(FILESOURCE, Encoding.ASCII.GetBytes("ListView\0"));
					break;
				case DragAndDropSource.ListViewSearch:
					SetData(FILESOURCE, Encoding.ASCII.GetBytes("ListViewSearch\0"));
					break;
				case DragAndDropSource.TreeView:
					SetData(FILESOURCE, Encoding.ASCII.GetBytes("TreeView\0"));
					break;
				case DragAndDropSource.SpriteEditor:
					SetData(FILESOURCE, Encoding.ASCII.GetBytes("SpriteEditor\0"));
					break;
				case DragAndDropSource.ResourceExtractor:
					SetData(FILESOURCE, Encoding.ASCII.GetBytes("ResourceExtractor\0"));
					break;
				case DragAndDropSource.Other:
					SetData(FILESOURCE, Encoding.ASCII.GetBytes("Other\0"));
					break;
			}
			
			SetData(FILEDESCRIPTORW, bytes);
			// Set n CFSTR_FILECONTENTS
			var index = 0;
			foreach (var fileDescriptor in fileDescriptors) {
				SetData(FILECONTENTS, index, fileDescriptor);
				index++;
			}

		}
        public void SetData(List <FileDescriptor> fileDescriptors)
        {
            // Prepare buffer
            var bytes = new List <byte>();

            // Add FILEGROUPDESCRIPTOR header
            bytes.AddRange(StructureBytes(new NativeMethods.FILEGROUPDESCRIPTOR {
                cItems = (uint)(fileDescriptors.Count())
            }));
            // Add n FILEDESCRIPTORs
            foreach (var fileDescriptor in fileDescriptors)
            {
                // Set required fields
                var FILEDESCRIPTOR = new NativeMethods.FILEDESCRIPTOR {
                    cFileName = fileDescriptor.Name,
                };
                // Set optional timestamp
                if (fileDescriptor.ChangeTimeUtc.HasValue)
                {
                    FILEDESCRIPTOR.dwFlags |= NativeMethods.FD_CREATETIME | NativeMethods.FD_WRITESTIME;
                    var changeTime         = fileDescriptor.ChangeTimeUtc.Value.ToLocalTime().ToFileTime();
                    var changeTimeFileTime = new FILETIME {
                        dwLowDateTime =
                            (int)(changeTime & 0xffffffff),
                        dwHighDateTime =
                            (int)(changeTime >> 32),
                    };
                    FILEDESCRIPTOR.ftLastWriteTime = changeTimeFileTime;
                    FILEDESCRIPTOR.ftCreationTime  = changeTimeFileTime;
                }
                // Set optional length
                if (fileDescriptor.Length.HasValue)
                {
                    FILEDESCRIPTOR.dwFlags      |= NativeMethods.FD_FILESIZE;
                    FILEDESCRIPTOR.nFileSizeLow  = (uint)(fileDescriptor.Length & 0xffffffff);
                    FILEDESCRIPTOR.nFileSizeHigh = (uint)(fileDescriptor.Length >> 32);
                }
                // Add structure to buffer
                bytes.AddRange(StructureBytes(FILEDESCRIPTOR));
            }

            // Set CFSTR_FILEDESCRIPTORW
            switch (Source)
            {
            case DragAndDropSource.ListView:
                SetData(FILESOURCE, Encoding.ASCII.GetBytes("ListView\0"));
                break;

            case DragAndDropSource.ListViewSearch:
                SetData(FILESOURCE, Encoding.ASCII.GetBytes("ListViewSearch\0"));
                break;

            case DragAndDropSource.TreeView:
                SetData(FILESOURCE, Encoding.ASCII.GetBytes("TreeView\0"));
                break;

            case DragAndDropSource.SpriteEditor:
                SetData(FILESOURCE, Encoding.ASCII.GetBytes("SpriteEditor\0"));
                break;

            case DragAndDropSource.ResourceExtractor:
                SetData(FILESOURCE, Encoding.ASCII.GetBytes("ResourceExtractor\0"));
                break;

            case DragAndDropSource.Other:
                SetData(FILESOURCE, Encoding.ASCII.GetBytes("Other\0"));
                break;
            }

            SetData(FILEDESCRIPTORW, bytes);
            // Set n CFSTR_FILECONTENTS
            var index = 0;

            foreach (var fileDescriptor in fileDescriptors)
            {
                SetData(FILECONTENTS, index, fileDescriptor);
                index++;
            }
        }