Ejemplo n.º 1
0
 public override DragDropEffects DoDragDrop(UIElement source, Point cursorPos)
 {
     this.ThemeItem.Load();
     ImageResourceThemeItem resourceThemeItem = (ImageResourceThemeItem)this.ThemeItem;
     byte[] numArray = ((ResourceThemeItem)resourceThemeItem).Save(false);
     IDataObject dataObject1 = Advent.Common.Interop.DataObject.CreateDataObject();
     IDataObject dataObject2 = dataObject1;
     VirtualFile[] virtualFileArray = new VirtualFile[1];
     virtualFileArray[0] = new VirtualFile()
     {
         Name = this.ThemeItem.Name,
         LastWriteTime = DateTime.Now,
         Contents = numArray
     };
     VirtualFile[] files = virtualFileArray;
     DataObjectExtensions.SetVirtualFiles(dataObject2, files);
     try
     {
         VmcStudioUtil.DragDropObject = (object)this;
         return DataObjectExtensions.DoDragDrop(dataObject1, source, UIExtensions.Resize(resourceThemeItem.Image, 100), cursorPos, DragDropEffects.Copy);
     }
     finally
     {
         VmcStudioUtil.DragDropObject = (object)null;
     }
 }
Ejemplo n.º 2
0
 private static void WriteFileDescriptor(Stream stream, VirtualFile file)
 {
     FILEDESCRIPTOR filedescriptor = file.ToFileDescriptor();
     int length = Marshal.SizeOf((object)filedescriptor);
     byte[] numArray = new byte[length];
     IntPtr num = Marshal.AllocHGlobal(length);
     try
     {
         Marshal.StructureToPtr((object)filedescriptor, num, true);
         Marshal.Copy(num, numArray, 0, length);
     }
     finally
     {
         Marshal.FreeHGlobal(num);
     }
     stream.Write(numArray, 0, numArray.Length);
 }
Ejemplo n.º 3
0
 public static void SetVirtualFiles(this System.Windows.IDataObject dataObject, VirtualFile[] files)
 {
     if (files == null)
         throw new ArgumentNullException();
     MemoryStream memoryStream = new MemoryStream();
     memoryStream.Write(BitConverter.GetBytes(files.Length), 0, 4);
     for (int index = 0; index < files.Length; ++index)
     {
         VirtualFile file = files[index];
         if (file.Contents == null || file.Contents.Length == 0)
             throw new ArgumentException("VirtualFile does not have any contents.");
         FORMATETC formatIn = new FORMATETC()
         {
             cfFormat = (short)DataFormats.GetDataFormat("FileContents").Id,
             dwAspect = DVASPECT.DVASPECT_CONTENT,
             lindex = index,
             ptd = IntPtr.Zero,
             tymed = TYMED.TYMED_ISTREAM
         };
         STGMEDIUM medium = DataObjectExtensions.WriteBytesToMedium(file.Contents);
         ((System.Runtime.InteropServices.ComTypes.IDataObject)dataObject).SetData(ref formatIn, ref medium, true);
         DataObjectExtensions.WriteFileDescriptor((Stream)memoryStream, file);
     }
     IntPtr num = Marshal.AllocHGlobal((int)memoryStream.Length);
     try
     {
         Marshal.Copy(memoryStream.GetBuffer(), 0, num, (int)memoryStream.Length);
     }
     catch
     {
         Marshal.FreeHGlobal(num);
         throw;
     }
     STGMEDIUM medium1;
     medium1.pUnkForRelease = (object)null;
     medium1.tymed = TYMED.TYMED_HGLOBAL;
     medium1.unionmember = num;
     FORMATETC formatIn1 = new FORMATETC()
     {
         cfFormat = (short)DataFormats.GetDataFormat("FileGroupDescriptorW").Id,
         dwAspect = DVASPECT.DVASPECT_CONTENT,
         lindex = -1,
         ptd = IntPtr.Zero,
         tymed = TYMED.TYMED_HGLOBAL
     };
     ((System.Runtime.InteropServices.ComTypes.IDataObject)dataObject).SetData(ref formatIn1, ref medium1, true);
 }
Ejemplo n.º 4
0
 public static void SetVirtualFiles(this Advent.Common.Interop.DataObject dataObject, VirtualFile[] files)
 {
     MemoryStream memoryStream = new MemoryStream();
     memoryStream.Write(BitConverter.GetBytes(files.Length), 0, 4);
     for (int index = 0; index < files.Length; ++index)
     {
         VirtualFile file = files[index];
         if (file.ContentsFunc == null)
         {
             FORMATETC formatIn = new FORMATETC()
             {
                 cfFormat = (short)DataFormats.GetDataFormat("FileContents").Id,
                 dwAspect = DVASPECT.DVASPECT_CONTENT,
                 lindex = index,
                 ptd = IntPtr.Zero,
                 tymed = TYMED.TYMED_ISTREAM
             };
             STGMEDIUM medium = DataObjectExtensions.WriteBytesToMedium(file.Contents);
             dataObject.SetData(ref formatIn, ref medium, true);
         }
         DataObjectExtensions.WriteFileDescriptor((Stream)memoryStream, file);
     }
     dataObject.DataRequested += (EventHandler<DataRequestedEventArgs>)((sender, args) =>
     {
         int local_0 = (int)(short)DataFormats.GetDataFormat("FileContents").Id;
         if ((int)args.Format.cfFormat != local_0 || args.Format.lindex < 0 || (args.Format.lindex >= files.Length || files[args.Format.lindex].ContentsFunc == null))
             return;
         args.Medium = DataObjectExtensions.WriteBytesToMedium(files[args.Format.lindex].ContentsFunc());
         args.IsHandled = true;
     });
     IntPtr num = Marshal.AllocHGlobal((int)memoryStream.Length);
     try
     {
         Marshal.Copy(memoryStream.GetBuffer(), 0, num, (int)memoryStream.Length);
     }
     catch
     {
         Marshal.FreeHGlobal(num);
         throw;
     }
     STGMEDIUM medium1;
     medium1.pUnkForRelease = (object)null;
     medium1.tymed = TYMED.TYMED_HGLOBAL;
     medium1.unionmember = num;
     FORMATETC formatIn1 = new FORMATETC()
     {
         cfFormat = (short)DataFormats.GetDataFormat("FileGroupDescriptorW").Id,
         dwAspect = DVASPECT.DVASPECT_CONTENT,
         lindex = -1,
         ptd = IntPtr.Zero,
         tymed = TYMED.TYMED_HGLOBAL
     };
     dataObject.SetData(ref formatIn1, ref medium1, true);
 }
Ejemplo n.º 5
0
 public static VirtualFile[] GetVirtualFiles(this System.Windows.IDataObject dataObject, bool getContents)
 {
     System.Runtime.InteropServices.ComTypes.IDataObject dataObject1 = (System.Runtime.InteropServices.ComTypes.IDataObject)dataObject;
     FORMATETC formatETC1;
     DataObjectExtensions.FillFormatETC("FileGroupDescriptorW", TYMED.TYMED_HGLOBAL, out formatETC1);
     STGMEDIUM medium1;
     dataObject1.GetData(ref formatETC1, out medium1);
     int length = Marshal.ReadInt32(medium1.unionmember);
     IntPtr ptr = new IntPtr(medium1.unionmember.ToInt32() + 4);
     VirtualFile[] virtualFileArray = new VirtualFile[length];
     for (int index = 0; index < length; ++index)
     {
         VirtualFile virtualFile = VirtualFile.FromFileDescriptor((FILEDESCRIPTOR)Marshal.PtrToStructure(ptr, typeof(FILEDESCRIPTOR)));
         if (getContents)
         {
             FORMATETC formatETC2;
             DataObjectExtensions.FillFormatETC("FileContents", TYMED.TYMED_HGLOBAL, out formatETC2);
             formatETC2.lindex = index;
             formatETC2.tymed = TYMED.TYMED_ISTREAM;
             STGMEDIUM medium2;
             dataObject1.GetData(ref formatETC2, out medium2);
             if (medium2.tymed == TYMED.TYMED_ISTREAM)
             {
                 System.Runtime.InteropServices.ComTypes.IStream stream = (System.Runtime.InteropServices.ComTypes.IStream)Marshal.GetObjectForIUnknown(medium2.unionmember);
                 if (stream != null)
                 {
                     try
                     {
                         using (ComStream comStream = new ComStream(stream))
                         {
                             byte[] buffer = new byte[comStream.Length];
                             comStream.Read(buffer, 0, buffer.Length);
                             virtualFile.Contents = buffer;
                         }
                     }
                     finally
                     {
                         Marshal.ReleaseComObject((object)stream);
                     }
                 }
             }
         }
         virtualFileArray[index] = virtualFile;
         ptr = new IntPtr(ptr.ToInt32() + Marshal.SizeOf(typeof(FILEDESCRIPTOR)));
     }
     return virtualFileArray;
 }
Ejemplo n.º 6
0
 internal static VirtualFile FromFileDescriptor(FILEDESCRIPTOR fd)
 {
     VirtualFile virtualFile = new VirtualFile();
     virtualFile.Name = fd.cFileName;
     if ((fd.dwFlags & FileDescriptorFlags.FD_ATTRIBUTES) == FileDescriptorFlags.FD_ATTRIBUTES)
         virtualFile.Attributes = (FileAttributes)fd.dwFileAttributes;
     if ((fd.dwFlags & FileDescriptorFlags.FD_CREATETIME) == FileDescriptorFlags.FD_CREATETIME)
         virtualFile.CreationTime = NativeUtilities.ToDateTime(fd.ftCreationTime);
     if ((fd.dwFlags & FileDescriptorFlags.FD_ACCESSTIME) == FileDescriptorFlags.FD_ACCESSTIME)
         virtualFile.LastAccessTime = NativeUtilities.ToDateTime(fd.ftLastAccessTime);
     if ((fd.dwFlags & FileDescriptorFlags.FD_WRITESTIME) == FileDescriptorFlags.FD_WRITESTIME)
         virtualFile.LastWriteTime = NativeUtilities.ToDateTime(fd.ftLastWriteTime);
     return virtualFile;
 }