1055 lines
34 KiB
C#
1055 lines
34 KiB
C#
// Decompiled with JetBrains decompiler
|
|
// Type: Rei.Com.DataObject
|
|
// Assembly: Rei.Com, Version=1.13.2.9255, Culture=neutral, PublicKeyToken=null
|
|
// MVID: 608BC623-FF3D-4118-BA82-AC691A688790
|
|
// Assembly location: F:\Eigene Dateien\Dropbox\portable Collection\Progs\CarotDAV\Rei.Com.dll
|
|
|
|
using Microsoft.VisualBasic.CompilerServices;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using System.Runtime.InteropServices.ComTypes;
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Rei.Com
|
|
{
|
|
public class DataObject : System.Runtime.InteropServices.ComTypes.IDataObject, IDisposable, IAsyncOperation
|
|
{
|
|
private static DateTime win32timeorigin = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
private static readonly byte[] serializedObjectID = new Guid("FD9EA796-3B13-4370-A679-56106BB288FB").ToByteArray();
|
|
public const int S_OK = 0;
|
|
public const int S_FALSE = 1;
|
|
public const int E_FAIL = -2147467259;
|
|
public const int E_UNEXPECTED = -2147418113;
|
|
public const int E_NOTIMPL = -2147483647;
|
|
public const int E_INVALIDARG = -2147483645;
|
|
public const int OLE_E_ADVISENOTSUPPORTED = -2147221501;
|
|
private const int DV_E_LINDEX = -2147221400;
|
|
private const int DV_E_FORMATETC = -2147221404;
|
|
private const int DV_E_TYMED = -2147221399;
|
|
private const int DV_E_DVASPECT = -2147221397;
|
|
private const int DV_E_DVTARGETDEVICE = -2147221403;
|
|
private const int STG_E_MEDIUMFULL = -2147286928;
|
|
public object Tag;
|
|
private List<DataObject.ObjectEntry> pData;
|
|
private bool disposedValue;
|
|
private bool pAsyncSupported;
|
|
private bool pInOperation;
|
|
private object pInOperationLock;
|
|
|
|
private List<DataObject.ObjectEntry> Data
|
|
{
|
|
get
|
|
{
|
|
return this.pData;
|
|
}
|
|
}
|
|
|
|
public DataObject()
|
|
{
|
|
this.disposedValue = false;
|
|
this.pData = new List<DataObject.ObjectEntry>();
|
|
this.pInOperationLock = RuntimeHelpers.GetObjectValue(new object());
|
|
this.pInOperation = false;
|
|
this.pAsyncSupported = false;
|
|
}
|
|
|
|
public virtual FORMATETC[] SupportedFormats()
|
|
{
|
|
return new FORMATETC[0];
|
|
}
|
|
|
|
[DllImport("ole32.dll")]
|
|
internal static extern int OleIsCurrentClipboard(System.Runtime.InteropServices.ComTypes.IDataObject pDataObject);
|
|
|
|
[DllImport("OLE32.DLL")]
|
|
internal static extern void ReleaseStgMedium(ref STGMEDIUM medium);
|
|
|
|
[DllImport("Kernel32.dll")]
|
|
internal static extern int GlobalSize(IntPtr handle);
|
|
|
|
[DllImport("Kernel32.dll")]
|
|
internal static extern IntPtr GlobalLock(IntPtr handle);
|
|
|
|
[DllImport("Kernel32.dll")]
|
|
internal static extern bool GlobalUnlock(IntPtr handle);
|
|
|
|
[DllImport("Kernel32.dll")]
|
|
internal static extern IntPtr GlobalFree(IntPtr handle);
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (!this.disposedValue && disposing)
|
|
{
|
|
int num1 = 0;
|
|
int num2 = checked (this.Data.Count - 1);
|
|
int index = num1;
|
|
while (index <= num2)
|
|
{
|
|
DataObject.ObjectEntry objectEntry = this.Data[index];
|
|
IDisposable receivedistream = objectEntry.receivedistream as IDisposable;
|
|
if (receivedistream != null)
|
|
receivedistream.Dispose();
|
|
objectEntry = this.Data[index];
|
|
if (objectEntry.istreamcreator != null)
|
|
this.Data[index].istreamcreator.Dispose();
|
|
checked { ++index; }
|
|
}
|
|
this.Data.Clear();
|
|
}
|
|
this.disposedValue = true;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
this.Dispose(true);
|
|
GC.SuppressFinalize((object) this);
|
|
}
|
|
|
|
~DataObject()
|
|
{
|
|
this.Dispose(false);
|
|
// ISSUE: explicit finalizer call
|
|
base.Finalize();
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public int DAdvise(ref FORMATETC pFormatetc, ADVF advf, IAdviseSink adviseSink, ref int connection)
|
|
{
|
|
return -2147221501;
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public void DUnadvise(int connection)
|
|
{
|
|
Marshal.ThrowExceptionForHR(-2147221501);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public int EnumDAdvise(ref IEnumSTATDATA enumAdvise)
|
|
{
|
|
return -2147221501;
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public int GetCanonicalFormatEtc(ref FORMATETC formatIn, ref FORMATETC formatOut)
|
|
{
|
|
formatOut = formatIn;
|
|
return -2147221404;
|
|
}
|
|
|
|
protected int IndexOf(FORMATETC format)
|
|
{
|
|
if (format.ptd != IntPtr.Zero)
|
|
return -2147221403;
|
|
if (format.dwAspect != DVASPECT.DVASPECT_CONTENT)
|
|
return -2147221397;
|
|
int num1 = 0;
|
|
int num2 = checked (this.Data.Count - 1);
|
|
int index = num1;
|
|
while (index <= num2)
|
|
{
|
|
if ((int) this.Data[index].Format.cfFormat == (int) format.cfFormat && this.Data[index].Format.dwAspect == format.dwAspect && this.Data[index].Format.lindex == format.lindex)
|
|
{
|
|
if ((this.Data[index].Format.tymed & format.tymed) != TYMED.TYMED_NULL)
|
|
return index;
|
|
return -2147221399;
|
|
}
|
|
checked { ++index; }
|
|
}
|
|
return -2147221404;
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
[DebuggerStepThrough]
|
|
public virtual int QueryGetData(ref FORMATETC format)
|
|
{
|
|
DataObject.DataEventArgs e = new DataObject.DataEventArgs(format);
|
|
this.OnDataQueried(e);
|
|
if (e.QueryResult == DataObject.QueryGetDataResultType.Exists)
|
|
return 0;
|
|
if (e.QueryResult == DataObject.QueryGetDataResultType.None)
|
|
return 1;
|
|
int num = this.IndexOf(format);
|
|
if (num >= 0)
|
|
return 0;
|
|
return num;
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
[DebuggerStepThrough]
|
|
public virtual void GetData(ref FORMATETC format, ref STGMEDIUM medium)
|
|
{
|
|
if ((format.tymed & (TYMED.TYMED_HGLOBAL | TYMED.TYMED_ISTREAM)) == TYMED.TYMED_NULL)
|
|
Marshal.ThrowExceptionForHR(-2147483647);
|
|
try
|
|
{
|
|
this.OnDataRequested(new DataObject.DataEventArgs(format));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ProjectData.SetProjectError(ex);
|
|
Marshal.ThrowExceptionForHR(-2147418113);
|
|
ProjectData.ClearProjectError();
|
|
}
|
|
int errorCode = this.IndexOf(format);
|
|
if (errorCode < 0)
|
|
Marshal.ThrowExceptionForHR(errorCode);
|
|
DataObject.ObjectEntry objectEntry = this.Data[errorCode];
|
|
medium.tymed = objectEntry.Format.tymed;
|
|
medium.pUnkForRelease = (object) null;
|
|
switch (objectEntry.Format.tymed)
|
|
{
|
|
case TYMED.TYMED_HGLOBAL:
|
|
medium.unionmember = Marshal.AllocHGlobal(objectEntry.hglobal.Length);
|
|
Marshal.Copy(objectEntry.hglobal, 0, medium.unionmember, objectEntry.hglobal.Length);
|
|
break;
|
|
case TYMED.TYMED_ISTREAM:
|
|
System.Runtime.InteropServices.ComTypes.IStream stream = objectEntry.istreamcreator.Create();
|
|
medium.unionmember = Marshal.GetIUnknownForObject((object) stream);
|
|
break;
|
|
}
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
[DebuggerStepThrough]
|
|
public virtual void GetDataHere(ref FORMATETC format, ref STGMEDIUM medium)
|
|
{
|
|
if ((format.tymed & (TYMED.TYMED_HGLOBAL | TYMED.TYMED_ISTREAM)) == TYMED.TYMED_NULL)
|
|
Marshal.ThrowExceptionForHR(-2147483647);
|
|
if (format.tymed != medium.tymed)
|
|
Marshal.ThrowExceptionForHR(-2147221404);
|
|
this.OnDataRequested(new DataObject.DataEventArgs(format));
|
|
int errorCode = this.IndexOf(format);
|
|
if (errorCode < 0)
|
|
Marshal.ThrowExceptionForHR(errorCode);
|
|
DataObject.ObjectEntry objectEntry = this.Data[errorCode];
|
|
medium.tymed = objectEntry.Format.tymed;
|
|
medium.pUnkForRelease = (object) null;
|
|
switch (objectEntry.Format.tymed)
|
|
{
|
|
case TYMED.TYMED_HGLOBAL:
|
|
if (DataObject.GlobalSize(medium.unionmember) < objectEntry.hglobal.Length)
|
|
Marshal.ThrowExceptionForHR(-2147286928);
|
|
Marshal.Copy(objectEntry.hglobal, 0, medium.unionmember, objectEntry.hglobal.Length);
|
|
break;
|
|
case TYMED.TYMED_ISTREAM:
|
|
Marshal.ThrowExceptionForHR(-2147483647);
|
|
break;
|
|
}
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
[DebuggerStepThrough]
|
|
public virtual void SetData([In] ref FORMATETC format, [In] ref STGMEDIUM medium, bool release)
|
|
{
|
|
if ((medium.tymed & medium.tymed - 1) != TYMED.TYMED_NULL)
|
|
Marshal.ThrowExceptionForHR(-2147221399);
|
|
if (format.tymed != medium.tymed)
|
|
Marshal.ThrowExceptionForHR(-2147221404);
|
|
if (medium.tymed != TYMED.TYMED_HGLOBAL && medium.tymed != TYMED.TYMED_ISTREAM)
|
|
Marshal.ThrowExceptionForHR(-2147483647);
|
|
if (medium.unionmember == IntPtr.Zero)
|
|
Marshal.ThrowExceptionForHR(-2147483645);
|
|
int i = this.IndexOf(format);
|
|
if (i >= 0)
|
|
this.RemoveAt(i);
|
|
DataObject.ObjectEntry objectEntry = new DataObject.ObjectEntry(format);
|
|
switch (objectEntry.Format.tymed)
|
|
{
|
|
case TYMED.TYMED_HGLOBAL:
|
|
int length = DataObject.GlobalSize(medium.unionmember);
|
|
objectEntry.hglobal = new byte[checked (length - 1 + 1)];
|
|
Marshal.Copy(DataObject.GlobalLock(medium.unionmember), objectEntry.hglobal, 0, length);
|
|
DataObject.GlobalUnlock(medium.unionmember);
|
|
break;
|
|
case TYMED.TYMED_ISTREAM:
|
|
objectEntry.receivedistream = (System.Runtime.InteropServices.ComTypes.IStream) Marshal.GetTypedObjectForIUnknown(medium.unionmember, typeof (System.Runtime.InteropServices.ComTypes.IStream));
|
|
break;
|
|
}
|
|
if (release)
|
|
DataObject.ReleaseStgMedium(ref medium);
|
|
this.Data.Add(objectEntry);
|
|
this.OnDataStored(new DataObject.DataEventArgs(format));
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
[DebuggerStepThrough]
|
|
public virtual IEnumFORMATETC EnumFormatEtc(DATADIR direction)
|
|
{
|
|
if (direction == DATADIR.DATADIR_SET)
|
|
Marshal.ThrowExceptionForHR(-2147221501);
|
|
FORMATETC[] formatetcArray = this.SupportedFormats();
|
|
List<FORMATETC> formatetcList = new List<FORMATETC>();
|
|
int num1 = 0;
|
|
int num2 = checked (formatetcArray.Length - 1);
|
|
int index1 = num1;
|
|
FORMATETC format1;
|
|
FORMATETC formatetc1;
|
|
while (index1 <= num2)
|
|
{
|
|
bool flag = false;
|
|
int num3 = 0;
|
|
int num4 = checked (formatetcList.Count - 1);
|
|
int index2 = num3;
|
|
while (index2 <= num4)
|
|
{
|
|
format1 = formatetcList[index2];
|
|
if ((int) format1.cfFormat == (int) formatetcArray[index1].cfFormat)
|
|
{
|
|
formatetc1 = formatetcList[index2];
|
|
if (formatetc1.dwAspect == formatetcArray[index1].dwAspect)
|
|
{
|
|
flag = true;
|
|
FORMATETC formatetc2 = formatetcList[index2];
|
|
// ISSUE: explicit reference operation
|
|
// ISSUE: variable of a reference type
|
|
FORMATETC& local = @formatetc2;
|
|
formatetc1 = formatetcList[index2];
|
|
int num5 = (int) (formatetc1.tymed | formatetcArray[index1].tymed);
|
|
// ISSUE: explicit reference operation
|
|
(^local).tymed = (TYMED) num5;
|
|
formatetcList[index2] = formatetc2;
|
|
break;
|
|
}
|
|
}
|
|
checked { ++index2; }
|
|
}
|
|
if (!flag)
|
|
{
|
|
FORMATETC formatetc2 = formatetcArray[index1];
|
|
formatetc2.lindex = -1;
|
|
formatetc2.ptd = new IntPtr();
|
|
formatetcList.Add(formatetc2);
|
|
}
|
|
checked { ++index1; }
|
|
}
|
|
int num6 = 0;
|
|
int num7 = checked (this.Data.Count - 1);
|
|
int index3 = num6;
|
|
while (index3 <= num7)
|
|
{
|
|
bool flag = false;
|
|
int num3 = 0;
|
|
int num4 = checked (formatetcList.Count - 1);
|
|
int index2 = num3;
|
|
DataObject.ObjectEntry objectEntry;
|
|
while (index2 <= num4)
|
|
{
|
|
formatetc1 = formatetcList[index2];
|
|
int cfFormat1 = (int) formatetc1.cfFormat;
|
|
format1 = this.Data[index3].Format;
|
|
int cfFormat2 = (int) format1.cfFormat;
|
|
if (cfFormat1 == cfFormat2)
|
|
{
|
|
FORMATETC format2 = formatetcList[index2];
|
|
int dwAspect1 = (int) format2.dwAspect;
|
|
objectEntry = this.Data[index3];
|
|
int dwAspect2 = (int) objectEntry.Format.dwAspect;
|
|
if (dwAspect1 == dwAspect2)
|
|
{
|
|
flag = true;
|
|
FORMATETC formatetc2 = formatetcList[index2];
|
|
// ISSUE: explicit reference operation
|
|
// ISSUE: variable of a reference type
|
|
FORMATETC& local = @formatetc2;
|
|
int tymed1 = (int) formatetcList[index2].tymed;
|
|
objectEntry = this.Data[index3];
|
|
format2 = objectEntry.Format;
|
|
int tymed2 = (int) format2.tymed;
|
|
int num5 = tymed1 | tymed2;
|
|
// ISSUE: explicit reference operation
|
|
(^local).tymed = (TYMED) num5;
|
|
formatetcList[index2] = formatetc2;
|
|
break;
|
|
}
|
|
}
|
|
checked { ++index2; }
|
|
}
|
|
if (!flag)
|
|
{
|
|
objectEntry = this.Data[index3];
|
|
FORMATETC format2 = objectEntry.Format;
|
|
format2.lindex = -1;
|
|
format2.ptd = new IntPtr();
|
|
formatetcList.Add(format2);
|
|
}
|
|
checked { ++index3; }
|
|
}
|
|
return (IEnumFORMATETC) new DataObject._EnumFormatEtc(formatetcList.ToArray(), direction, 0);
|
|
}
|
|
|
|
public bool AsyncSupported
|
|
{
|
|
get
|
|
{
|
|
return this.pAsyncSupported;
|
|
}
|
|
set
|
|
{
|
|
this.pAsyncSupported = value;
|
|
}
|
|
}
|
|
|
|
public bool IsInOperation
|
|
{
|
|
get
|
|
{
|
|
bool pfInAsyncOp;
|
|
this.InOperation(ref pfInAsyncOp);
|
|
return pfInAsyncOp;
|
|
}
|
|
}
|
|
|
|
public bool IsCurrentClipboard
|
|
{
|
|
get
|
|
{
|
|
return DataObject.OleIsCurrentClipboard((System.Runtime.InteropServices.ComTypes.IDataObject) this) == 0;
|
|
}
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public void GetAsyncMode(ref bool pfIsOpAsync)
|
|
{
|
|
pfIsOpAsync = this.AsyncSupported;
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public void SetAsyncMode(bool fDoOpAsync)
|
|
{
|
|
this.AsyncSupported = fDoOpAsync;
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public void StartOperation(IntPtr pbcReserved)
|
|
{
|
|
bool flag = false;
|
|
object pInOperationLock = this.pInOperationLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pInOperationLock);
|
|
Monitor.Enter(pInOperationLock);
|
|
try
|
|
{
|
|
if (!this.pInOperation)
|
|
{
|
|
this.pInOperation = true;
|
|
flag = true;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pInOperationLock);
|
|
}
|
|
if (!flag)
|
|
return;
|
|
this.OnAsyncOperationStart();
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public void EndOperation(IntPtr hResult, IntPtr pbcReserved, int dwEffects)
|
|
{
|
|
bool flag = false;
|
|
object pInOperationLock = this.pInOperationLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pInOperationLock);
|
|
Monitor.Enter(pInOperationLock);
|
|
try
|
|
{
|
|
if (this.pInOperation)
|
|
{
|
|
this.pInOperation = false;
|
|
flag = true;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pInOperationLock);
|
|
}
|
|
if (flag)
|
|
this.OnAsyncOperationFinished(new DataObject.AsyncOperationFinishedEventArgs(hResult, dwEffects));
|
|
if (hResult.ToInt32() == 0)
|
|
return;
|
|
Marshal.ThrowExceptionForHR(hResult.ToInt32());
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public void InOperation(ref bool pfInAsyncOp)
|
|
{
|
|
object pInOperationLock = this.pInOperationLock;
|
|
ObjectFlowControl.CheckForSyncLockOnValueType(pInOperationLock);
|
|
Monitor.Enter(pInOperationLock);
|
|
try
|
|
{
|
|
pfInAsyncOp = this.pInOperation;
|
|
}
|
|
finally
|
|
{
|
|
Monitor.Exit(pInOperationLock);
|
|
}
|
|
}
|
|
|
|
public static string FormatToString(FORMATETC format)
|
|
{
|
|
int id = (int) format.cfFormat >= 0 ? (int) format.cfFormat : checked ((int) format.cfFormat + 65536);
|
|
string str1 = DataFormats.GetFormat(id).Name + "(" + id.ToString() + ") / ";
|
|
if ((format.dwAspect & DVASPECT.DVASPECT_CONTENT) != (DVASPECT) 0)
|
|
str1 += "CONTENT ";
|
|
if ((format.dwAspect & DVASPECT.DVASPECT_DOCPRINT) != (DVASPECT) 0)
|
|
str1 += "DOCPRINT ";
|
|
if ((format.dwAspect & DVASPECT.DVASPECT_ICON) != (DVASPECT) 0)
|
|
str1 += "ICON ";
|
|
if ((format.dwAspect & DVASPECT.DVASPECT_THUMBNAIL) != (DVASPECT) 0)
|
|
str1 += "THUMBNAIL ";
|
|
string str2 = str1 + "/ " + format.lindex.ToString() + " ";
|
|
if ((format.tymed & TYMED.TYMED_ENHMF) != TYMED.TYMED_NULL)
|
|
str2 += "ENHMF ";
|
|
if ((format.tymed & TYMED.TYMED_FILE) != TYMED.TYMED_NULL)
|
|
str2 += "FILE ";
|
|
if ((format.tymed & TYMED.TYMED_GDI) != TYMED.TYMED_NULL)
|
|
str2 += "GDI ";
|
|
if ((format.tymed & TYMED.TYMED_HGLOBAL) != TYMED.TYMED_NULL)
|
|
str2 += "HGLOBAL ";
|
|
if ((format.tymed & TYMED.TYMED_ISTORAGE) != TYMED.TYMED_NULL)
|
|
str2 += "ISTORAGE ";
|
|
if ((format.tymed & TYMED.TYMED_ISTREAM) != TYMED.TYMED_NULL)
|
|
str2 += "ISTREAM ";
|
|
if ((format.tymed & TYMED.TYMED_MFPICT) != TYMED.TYMED_NULL)
|
|
str2 += "MFPICT ";
|
|
if (format.tymed == TYMED.TYMED_NULL)
|
|
str2 += "NULL ";
|
|
return str2;
|
|
}
|
|
|
|
private static string FormatToString(STGMEDIUM medium)
|
|
{
|
|
if (medium.pUnkForRelease == null)
|
|
return "medium(" + medium.tymed.ToString() + "[" + medium.unionmember.ToString() + "] null";
|
|
return "medium(" + medium.tymed.ToString() + "[" + medium.unionmember.ToString() + "] " + medium.pUnkForRelease.GetType().ToString();
|
|
}
|
|
|
|
public static short MakecfFormat(string format)
|
|
{
|
|
DataFormats.Format format1 = DataFormats.GetFormat(format);
|
|
if (format1.Id > (int) short.MaxValue)
|
|
return checked ((short) (format1.Id - 65536));
|
|
return checked ((short) format1.Id);
|
|
}
|
|
|
|
public byte[] GetHGlobal(string format)
|
|
{
|
|
FORMATETC format1;
|
|
format1.lindex = -1;
|
|
format1.dwAspect = DVASPECT.DVASPECT_CONTENT;
|
|
format1.tymed = TYMED.TYMED_HGLOBAL;
|
|
format1.cfFormat = DataObject.MakecfFormat(format);
|
|
int index = this.IndexOf(format1);
|
|
if (index < 0)
|
|
return (byte[]) null;
|
|
return this.Data[index].hglobal;
|
|
}
|
|
|
|
public DragDropEffects GetPreferredDropEffect()
|
|
{
|
|
byte[] hglobal = this.GetHGlobal(ShellClipboardFormats.PreferredDropEffect);
|
|
if (hglobal == null)
|
|
return DragDropEffects.None;
|
|
return (DragDropEffects) BitConverter.ToInt32(hglobal, 0);
|
|
}
|
|
|
|
public DragDropEffects GetPerformedDropEffect()
|
|
{
|
|
byte[] hglobal = this.GetHGlobal(ShellClipboardFormats.PerformedDropEffect);
|
|
if (hglobal == null)
|
|
return DragDropEffects.None;
|
|
return (DragDropEffects) BitConverter.ToInt32(hglobal, 0);
|
|
}
|
|
|
|
public DragDropEffects GetLogicalPerformedDropEffect()
|
|
{
|
|
byte[] hglobal = this.GetHGlobal(ShellClipboardFormats.LogicalPerformedDropEffect);
|
|
if (hglobal == null)
|
|
return DragDropEffects.None;
|
|
return (DragDropEffects) BitConverter.ToInt32(hglobal, 0);
|
|
}
|
|
|
|
public DragDropEffects GetPasteSucceeded()
|
|
{
|
|
byte[] hglobal = this.GetHGlobal(ShellClipboardFormats.PasteSucceeded);
|
|
if (hglobal == null)
|
|
return DragDropEffects.None;
|
|
return (DragDropEffects) BitConverter.ToInt32(hglobal, 0);
|
|
}
|
|
|
|
public Guid GetTargetCLSID()
|
|
{
|
|
byte[] hglobal = this.GetHGlobal(ShellClipboardFormats.TargetCLSID);
|
|
if (hglobal == null)
|
|
{
|
|
Guid guid;
|
|
return guid;
|
|
}
|
|
return new Guid(hglobal);
|
|
}
|
|
|
|
public DropDesctiption GetDropDesctiption()
|
|
{
|
|
byte[] hglobal = this.GetHGlobal(ShellClipboardFormats.DropDescription);
|
|
if (hglobal == null)
|
|
{
|
|
DropDesctiption dropDesctiption;
|
|
return dropDesctiption;
|
|
}
|
|
return new DropDesctiption()
|
|
{
|
|
type = BitConverter.ToInt32(hglobal, 0),
|
|
szMessage = Encoding.Unicode.GetString(hglobal, 4, 260),
|
|
szInsert = Encoding.Unicode.GetString(hglobal, 264, 260)
|
|
};
|
|
}
|
|
|
|
private void SetObjectEntry(DataObject.ObjectEntry e)
|
|
{
|
|
int i = this.IndexOf(e.Format);
|
|
if (i >= 0)
|
|
this.RemoveAt(i);
|
|
this.Data.Add(e);
|
|
}
|
|
|
|
private void SetHGlobal(string format, byte[] buf)
|
|
{
|
|
FORMATETC f;
|
|
f.cfFormat = DataObject.MakecfFormat(format);
|
|
f.dwAspect = DVASPECT.DVASPECT_CONTENT;
|
|
f.lindex = -1;
|
|
f.tymed = TYMED.TYMED_HGLOBAL;
|
|
this.SetObjectEntry(new DataObject.ObjectEntry(f)
|
|
{
|
|
hglobal = buf
|
|
});
|
|
}
|
|
|
|
public void SetPreferredDropEffect(DragDropEffects effect)
|
|
{
|
|
byte[] bytes = BitConverter.GetBytes((int) effect);
|
|
this.SetHGlobal(ShellClipboardFormats.PreferredDropEffect, bytes);
|
|
}
|
|
|
|
public void SetInDragLoop(bool value)
|
|
{
|
|
byte[] bytes = BitConverter.GetBytes(!value ? 0 : 1);
|
|
this.SetHGlobal(ShellClipboardFormats.InShellDragLoop, bytes);
|
|
}
|
|
|
|
public void SetUntrustedDragDrop()
|
|
{
|
|
byte[] bytes = BitConverter.GetBytes(6155);
|
|
this.SetHGlobal(ShellClipboardFormats.UntrustedDragDrop, bytes);
|
|
}
|
|
|
|
public void SetText(string str)
|
|
{
|
|
str += "\0";
|
|
byte[] bytes1 = Encoding.Default.GetBytes(str);
|
|
this.SetHGlobal(DataFormats.Text, bytes1);
|
|
byte[] bytes2 = Encoding.Unicode.GetBytes(str);
|
|
this.SetHGlobal(DataFormats.UnicodeText, bytes2);
|
|
}
|
|
|
|
public void SetTexts(string[] strs)
|
|
{
|
|
this.SetText(string.Join("\r\n", strs));
|
|
}
|
|
|
|
public void SetUri(Uri uri)
|
|
{
|
|
string s = uri.AbsoluteUri + "\0";
|
|
byte[] bytes1 = Encoding.Unicode.GetBytes(s);
|
|
this.SetHGlobal(ShellClipboardFormats.UniformResourceLocatorW, bytes1);
|
|
byte[] bytes2 = Encoding.Default.GetBytes(s);
|
|
this.SetHGlobal(ShellClipboardFormats.UniformResourceLocator, bytes2);
|
|
}
|
|
|
|
public void SetFileDropList(StringCollection paths)
|
|
{
|
|
string[] strArray = new string[checked (paths.Count - 1 + 1)];
|
|
paths.CopyTo(strArray, 0);
|
|
this.SetFileDropList(strArray);
|
|
}
|
|
|
|
public void SetFileDropList(string[] paths)
|
|
{
|
|
DropFiles dropFiles;
|
|
dropFiles.pFiles = Marshal.SizeOf((object) dropFiles);
|
|
dropFiles.pt = new POINTL();
|
|
dropFiles.fNC = false;
|
|
dropFiles.fWide = true;
|
|
byte[] bytes = Encoding.Unicode.GetBytes(string.Join("\0", paths) + "\0\0");
|
|
int num1 = Marshal.SizeOf((object) dropFiles);
|
|
byte[] numArray = new byte[checked (Marshal.SizeOf((object) dropFiles) + bytes.Length - 1 + 1)];
|
|
IntPtr num2 = Marshal.AllocHGlobal(Marshal.SizeOf((object) dropFiles));
|
|
try
|
|
{
|
|
Marshal.StructureToPtr((object) dropFiles, num2, false);
|
|
Marshal.Copy(num2, numArray, 0, num1);
|
|
bytes.CopyTo((Array) numArray, num1);
|
|
}
|
|
finally
|
|
{
|
|
Marshal.FreeHGlobal(num2);
|
|
}
|
|
this.SetHGlobal(DataFormats.FileDrop, numArray);
|
|
}
|
|
|
|
public void SetManagedObject(object data)
|
|
{
|
|
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
|
byte[] array;
|
|
using (MemoryStream memoryStream = new MemoryStream())
|
|
{
|
|
memoryStream.Write(DataObject.serializedObjectID, 0, DataObject.serializedObjectID.Length);
|
|
binaryFormatter.Serialize((Stream) memoryStream, RuntimeHelpers.GetObjectValue(data));
|
|
array = memoryStream.ToArray();
|
|
}
|
|
this.SetHGlobal(data.GetType().FullName, array);
|
|
}
|
|
|
|
public void SetVirtualFiles(VirtualFileInfo[] finfos, bool showprogress)
|
|
{
|
|
int num1 = 0;
|
|
int num2 = checked (finfos.Length - 1);
|
|
int index1 = num1;
|
|
while (index1 <= num2)
|
|
{
|
|
if (finfos[index1].IStreamCreator != null)
|
|
{
|
|
FORMATETC f;
|
|
f.cfFormat = DataObject.MakecfFormat(ShellClipboardFormats.FileContents);
|
|
f.dwAspect = DVASPECT.DVASPECT_CONTENT;
|
|
f.lindex = index1;
|
|
f.tymed = TYMED.TYMED_ISTREAM;
|
|
this.SetObjectEntry(new DataObject.ObjectEntry(f)
|
|
{
|
|
istreamcreator = finfos[index1].IStreamCreator
|
|
});
|
|
}
|
|
checked { ++index1; }
|
|
}
|
|
int num3 = Marshal.SizeOf(typeof (FileDescriptor));
|
|
byte[] numArray = new byte[checked (num3 * finfos.Length + 4 - 1 + 1)];
|
|
BitConverter.GetBytes(finfos.Length).CopyTo((Array) numArray, 0);
|
|
IntPtr num4 = Marshal.AllocHGlobal(num3);
|
|
try
|
|
{
|
|
int num5 = 0;
|
|
int num6 = checked (finfos.Length - 1);
|
|
int index2 = num5;
|
|
while (index2 <= num6)
|
|
{
|
|
FileDescriptor fileDescriptor = new FileDescriptor();
|
|
fileDescriptor.cFileName = finfos[index2].FileName;
|
|
fileDescriptor.dwFlags = finfos[index2].Flags & ~(FDFlags.FD_CLSID | FDFlags.FD_SIZEPOINT | FDFlags.FD_PROGRESSUI | FDFlags.FD_LINKUI);
|
|
if ((finfos[index2].Flags & FDFlags.FD_ATTRIBUTES) != (FDFlags) 0)
|
|
fileDescriptor.dwFileAttributes = finfos[index2].FileAttributes;
|
|
if ((finfos[index2].Flags & FDFlags.FD_CREATETIME) != (FDFlags) 0)
|
|
fileDescriptor.ftCreationTime = DataObject.ToFileTime(finfos[index2].CreationTime);
|
|
if ((finfos[index2].Flags & FDFlags.FD_ACCESSTIME) != (FDFlags) 0)
|
|
fileDescriptor.ftLastAccessTime = DataObject.ToFileTime(finfos[index2].LastAccessTime);
|
|
if ((finfos[index2].Flags & FDFlags.FD_WRITESTIME) != (FDFlags) 0)
|
|
fileDescriptor.ftLastWriteTime = DataObject.ToFileTime(finfos[index2].LastWriteTime);
|
|
if ((finfos[index2].Flags & FDFlags.FD_FILESIZE) != (FDFlags) 0)
|
|
fileDescriptor.FileSize = finfos[index2].FileSize;
|
|
if (showprogress)
|
|
fileDescriptor.dwFlags = fileDescriptor.dwFlags | FDFlags.FD_PROGRESSUI;
|
|
Marshal.StructureToPtr((object) fileDescriptor, num4, false);
|
|
Marshal.Copy(num4, numArray, checked (index2 * num3 + 4), num3);
|
|
checked { ++index2; }
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
Marshal.FreeHGlobal(num4);
|
|
}
|
|
this.SetHGlobal(ShellClipboardFormats.FileGroupDescriptorW, numArray);
|
|
}
|
|
|
|
public void RemoveAt(int i)
|
|
{
|
|
IDisposable receivedistream = this.Data[i].receivedistream as IDisposable;
|
|
if (receivedistream != null)
|
|
receivedistream.Dispose();
|
|
if (this.Data[i].istreamcreator != null)
|
|
this.Data[i].istreamcreator.Dispose();
|
|
this.Data.RemoveAt(i);
|
|
}
|
|
|
|
public bool Remove(FORMATETC format)
|
|
{
|
|
int i = this.IndexOf(format);
|
|
if (i < 0)
|
|
return false;
|
|
this.RemoveAt(i);
|
|
return true;
|
|
}
|
|
|
|
public void RemoveTexts()
|
|
{
|
|
FORMATETC format;
|
|
format.lindex = -1;
|
|
format.dwAspect = DVASPECT.DVASPECT_CONTENT;
|
|
format.tymed = TYMED.TYMED_HGLOBAL;
|
|
format.cfFormat = DataObject.MakecfFormat(DataFormats.UnicodeText);
|
|
this.Remove(format);
|
|
}
|
|
|
|
public void RemoveUris()
|
|
{
|
|
FORMATETC format;
|
|
format.lindex = -1;
|
|
format.dwAspect = DVASPECT.DVASPECT_CONTENT;
|
|
format.tymed = TYMED.TYMED_HGLOBAL;
|
|
format.cfFormat = DataObject.MakecfFormat(ShellClipboardFormats.UniformResourceLocatorW);
|
|
this.Remove(format);
|
|
}
|
|
|
|
public void RemoveVirtualFiles()
|
|
{
|
|
FORMATETC format;
|
|
format.cfFormat = DataObject.MakecfFormat(ShellClipboardFormats.FileContents);
|
|
format.dwAspect = DVASPECT.DVASPECT_CONTENT;
|
|
format.tymed = TYMED.TYMED_ISTREAM;
|
|
format.lindex = 0;
|
|
while (this.Remove(format))
|
|
format.lindex = checked (format.lindex + 1);
|
|
format.cfFormat = DataObject.MakecfFormat(ShellClipboardFormats.FileGroupDescriptorW);
|
|
format.dwAspect = DVASPECT.DVASPECT_CONTENT;
|
|
format.tymed = TYMED.TYMED_HGLOBAL;
|
|
format.lindex = -1;
|
|
this.Remove(format);
|
|
format.cfFormat = DataObject.MakecfFormat(ShellClipboardFormats.FileGroupDescriptor);
|
|
format.dwAspect = DVASPECT.DVASPECT_CONTENT;
|
|
format.tymed = TYMED.TYMED_HGLOBAL;
|
|
format.lindex = -1;
|
|
this.Remove(format);
|
|
}
|
|
|
|
public void RemoveAll()
|
|
{
|
|
while (this.Data.Count > 0)
|
|
this.RemoveAt(checked (this.Data.Count - 1));
|
|
}
|
|
|
|
internal static long ToFileTime(DateTime time)
|
|
{
|
|
if (DateTime.Compare(time, DataObject.win32timeorigin) < 0)
|
|
return 0;
|
|
return time.ToFileTime();
|
|
}
|
|
|
|
public event EventHandler AsyncOperationStart;
|
|
|
|
public event EventHandler<DataObject.AsyncOperationFinishedEventArgs> AsyncOperationFinished;
|
|
|
|
public event EventHandler<DataObject.DataEventArgs> DataRequested;
|
|
|
|
public event EventHandler<DataObject.DataEventArgs> DataStored;
|
|
|
|
public event EventHandler<DataObject.DataEventArgs> DataQueried;
|
|
|
|
protected virtual void OnAsyncOperationStart()
|
|
{
|
|
EventHandler operationStartEvent = this.AsyncOperationStartEvent;
|
|
if (operationStartEvent == null)
|
|
return;
|
|
operationStartEvent((object) this, EventArgs.Empty);
|
|
}
|
|
|
|
protected virtual void OnAsyncOperationFinished(DataObject.AsyncOperationFinishedEventArgs e)
|
|
{
|
|
EventHandler<DataObject.AsyncOperationFinishedEventArgs> operationFinishedEvent = this.AsyncOperationFinishedEvent;
|
|
if (operationFinishedEvent == null)
|
|
return;
|
|
operationFinishedEvent((object) this, e);
|
|
}
|
|
|
|
protected virtual void OnDataRequested(DataObject.DataEventArgs e)
|
|
{
|
|
EventHandler<DataObject.DataEventArgs> dataRequestedEvent = this.DataRequestedEvent;
|
|
if (dataRequestedEvent == null)
|
|
return;
|
|
dataRequestedEvent((object) this, e);
|
|
}
|
|
|
|
protected virtual void OnDataStored(DataObject.DataEventArgs e)
|
|
{
|
|
EventHandler<DataObject.DataEventArgs> dataStoredEvent = this.DataStoredEvent;
|
|
if (dataStoredEvent == null)
|
|
return;
|
|
dataStoredEvent((object) this, e);
|
|
}
|
|
|
|
protected virtual void OnDataQueried(DataObject.DataEventArgs e)
|
|
{
|
|
EventHandler<DataObject.DataEventArgs> dataQueriedEvent = this.DataQueriedEvent;
|
|
if (dataQueriedEvent == null)
|
|
return;
|
|
dataQueriedEvent((object) this, e);
|
|
}
|
|
|
|
public class AsyncOperationFinishedEventArgs : EventArgs
|
|
{
|
|
private IntPtr pResult;
|
|
private DragDropEffects pEffect;
|
|
|
|
public AsyncOperationFinishedEventArgs(IntPtr result, int effect)
|
|
{
|
|
this.pResult = result;
|
|
this.pEffect = (DragDropEffects) effect;
|
|
}
|
|
|
|
public IntPtr Result
|
|
{
|
|
get
|
|
{
|
|
return this.pResult;
|
|
}
|
|
}
|
|
|
|
public DragDropEffects Effect
|
|
{
|
|
get
|
|
{
|
|
return this.pEffect;
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum QueryGetDataResultType
|
|
{
|
|
None,
|
|
Exists,
|
|
FromData,
|
|
}
|
|
|
|
public class DataEventArgs : EventArgs
|
|
{
|
|
private FORMATETC pFormat;
|
|
private DataObject.QueryGetDataResultType pResponse;
|
|
|
|
public DataEventArgs(FORMATETC format)
|
|
{
|
|
this.pFormat = format;
|
|
this.pResponse = DataObject.QueryGetDataResultType.FromData;
|
|
}
|
|
|
|
public FORMATETC Format
|
|
{
|
|
get
|
|
{
|
|
return this.pFormat;
|
|
}
|
|
}
|
|
|
|
public DataObject.QueryGetDataResultType QueryResult
|
|
{
|
|
get
|
|
{
|
|
return this.pResponse;
|
|
}
|
|
set
|
|
{
|
|
this.pResponse = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
[DebuggerDisplay("{ToString()}")]
|
|
private struct ObjectEntry
|
|
{
|
|
public FORMATETC pformatetc;
|
|
public byte[] hglobal;
|
|
public IStreamCreator istreamcreator;
|
|
public System.Runtime.InteropServices.ComTypes.IStream receivedistream;
|
|
|
|
public ObjectEntry(FORMATETC f)
|
|
{
|
|
this = new DataObject.ObjectEntry();
|
|
this.pformatetc = f;
|
|
}
|
|
|
|
public FORMATETC Format
|
|
{
|
|
get
|
|
{
|
|
return this.pformatetc;
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return DataObject.FormatToString(this.pformatetc);
|
|
}
|
|
}
|
|
|
|
public class _EnumFormatEtc : IEnumFORMATETC
|
|
{
|
|
private FORMATETC[] pFormats;
|
|
private DATADIR pdirection;
|
|
private int pindex;
|
|
|
|
internal _EnumFormatEtc(FORMATETC[] list, DATADIR direction, int index)
|
|
{
|
|
this.pFormats = list;
|
|
this.pdirection = direction;
|
|
this.pindex = index;
|
|
}
|
|
|
|
public void Clone(ref IEnumFORMATETC newEnum)
|
|
{
|
|
newEnum = (IEnumFORMATETC) new DataObject._EnumFormatEtc(this.pFormats, this.pdirection, this.pindex);
|
|
}
|
|
|
|
public int Reset()
|
|
{
|
|
this.pindex = 0;
|
|
int num;
|
|
return num;
|
|
}
|
|
|
|
public int Next(int celt, FORMATETC[] rgelt, int[] pceltFetched)
|
|
{
|
|
int num1 = checked (this.pindex + celt) <= this.pFormats.Length ? celt : checked (this.pFormats.Length - this.pindex);
|
|
if (num1 == 0)
|
|
return 1;
|
|
int num2 = 0;
|
|
int num3 = checked (num1 - 1);
|
|
int index = num2;
|
|
while (index <= num3)
|
|
{
|
|
FORMATETC pFormat = this.pFormats[checked (this.pindex + index)];
|
|
rgelt[index] = pFormat;
|
|
checked { ++index; }
|
|
}
|
|
this.pindex = checked (this.pindex + num1);
|
|
if (pceltFetched != null)
|
|
pceltFetched[0] = num1;
|
|
return num1 != celt ? 1 : 0;
|
|
}
|
|
|
|
public int Skip(int celt)
|
|
{
|
|
if (checked (this.pindex + celt) >= this.pFormats.Length)
|
|
return 1;
|
|
this.pindex = checked (this.pindex + celt);
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|