using System.IO;
using System.Security.Permissions;
namespace Vanara.PInvoke;
///
/// Items from the Remote Differential Compression (RDC) API which allows applications to synchronize data between two computers in an
/// efficient manner.
///
public static partial class MsRdc
{
///
public const uint MSRDC_DEFAULT_COMPAREBUFFER = 3200000;
///
public const uint MSRDC_DEFAULT_HASHWINDOWSIZE_1 = 48;
///
public const uint MSRDC_DEFAULT_HASHWINDOWSIZE_N = 2;
///
public const uint MSRDC_DEFAULT_HORIZONSIZE_1 = 1024;
///
public const uint MSRDC_DEFAULT_HORIZONSIZE_N = 128;
///
public const uint MSRDC_MAXIMUM_COMPAREBUFFER = (1 << 30);
///
public const uint MSRDC_MAXIMUM_DEPTH = 8;
///
public const uint MSRDC_MAXIMUM_HASHWINDOWSIZE = 96;
///
public const uint MSRDC_MAXIMUM_HORIZONSIZE = 1024 * 16;
///
public const uint MSRDC_MAXIMUM_MATCHESREQUIRED = 16;
///
public const uint MSRDC_MAXIMUM_TRAITVALUE = 63;
///
public const uint MSRDC_MINIMUM_COMPAREBUFFER = 100000;
///
public const uint MSRDC_MINIMUM_COMPATIBLE_APP_VERSION = 0x010000;
///
public const uint MSRDC_MINIMUM_DEPTH = 1;
///
public const uint MSRDC_MINIMUM_HASHWINDOWSIZE = 2;
///
public const uint MSRDC_MINIMUM_HORIZONSIZE = 128;
///
public const uint MSRDC_MINIMUM_INPUTBUFFERSIZE = 1024;
///
public const uint MSRDC_MINIMUM_MATCHESREQUIRED = 1;
///
public const int MSRDC_SIGNATURE_HASHSIZE = 16;
///
public const uint MSRDC_VERSION = 0x010000;
/// The GeneratorParametersType enumeration type defines the set of supported generator parameters.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ne-msrdc-generatorparameterstype typedef enum
// __MIDL___MIDL_itf_msrdc_0000_0000_0002 { RDCGENTYPE_Unused = 0, RDCGENTYPE_FilterMax } GeneratorParametersType;
[PInvokeData("msrdc.h", MSDNShortId = "NE:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0002")]
public enum GeneratorParametersType
{
///
/// Value:
/// 0
/// The generator parameters type is unknown.
///
RDCGENTYPE_Unused,
/// The FilterMax generator was used to generate the parameters.
RDCGENTYPE_FilterMax,
}
/// The RDC_ErrorCode enumeration type defines the set of RDC-specific error codes.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ne-msrdc-rdc_errorcode typedef enum
// __MIDL___MIDL_itf_msrdc_0000_0000_0001 { RDC_NoError = 0, RDC_HeaderVersionNewer, RDC_HeaderVersionOlder,
// RDC_HeaderMissingOrCorrupt, RDC_HeaderWrongType, RDC_DataMissingOrCorrupt, RDC_DataTooManyRecords, RDC_FileChecksumMismatch,
// RDC_ApplicationError, RDC_Aborted, RDC_Win32Error } RDC_ErrorCode;
[PInvokeData("msrdc.h", MSDNShortId = "NE:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0001")]
public enum RDC_ErrorCode
{
///
/// Value:
/// 0
/// The operation was completed successfully.
///
RDC_NoError,
/// The data header is incompatible with this library.
RDC_HeaderVersionNewer,
/// The data header is incompatible with this library.
RDC_HeaderVersionOlder,
/// The data header is missing or corrupt.
RDC_HeaderMissingOrCorrupt,
/// The data header format is incorrect.
RDC_HeaderWrongType,
/// The end of data was reached before all data expected was read.
RDC_DataMissingOrCorrupt,
/// Additional data was found past where the end of data was expected.
RDC_DataTooManyRecords,
/// The final file checksum doesn't match.
RDC_FileChecksumMismatch,
/// An application callback function returned failure.
RDC_ApplicationError,
/// The operation was aborted.
RDC_Aborted,
///
/// The failure of the function is not RDC-specific and the
/// HRESULT
/// returned by
/// the function contains the specific error code.
///
RDC_Win32Error,
}
/// Defines values that describe the state of the similarity traits table, similarity file ID table, or both.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ne-msrdc-rdccreatedtables typedef enum
// __MIDL___MIDL_itf_msrdc_0000_0000_0009 { RDCTABLE_InvalidOrUnknown = 0, RDCTABLE_Existing, RDCTABLE_New } RdcCreatedTables;
[PInvokeData("msrdc.h", MSDNShortId = "NE:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0009")]
public enum RdcCreatedTables
{
///
/// Value:
/// 0
/// The table contains data that is not valid.
///
RDCTABLE_InvalidOrUnknown,
/// The table is an existing table.
RDCTABLE_Existing,
/// The table is a new table.
RDCTABLE_New,
}
/// Defines the access mode values for RDC file mapping objects.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ne-msrdc-rdcmappingaccessmode typedef enum
// __MIDL___MIDL_itf_msrdc_0000_0000_0010 { RDCMAPPING_Undefined = 0, RDCMAPPING_ReadOnly, RDCMAPPING_ReadWrite } RdcMappingAccessMode;
[PInvokeData("msrdc.h", MSDNShortId = "NE:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0010")]
public enum RdcMappingAccessMode
{
///
/// Value:
/// 0
/// The mapping access mode is unknown.
///
RDCMAPPING_Undefined,
/// Specifies read-only access.
RDCMAPPING_ReadOnly,
/// Specifies read/write access.
RDCMAPPING_ReadWrite,
}
/// Defines the set of data chunks used to generate a remote copy.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ne-msrdc-rdcneedtype typedef enum __MIDL___MIDL_itf_msrdc_0000_0000_0003
// { RDCNEED_SOURCE = 0, RDCNEED_TARGET = 1, RDCNEED_SEED = 2, RDCNEED_SEED_MAX = 255 } RdcNeedType;
[PInvokeData("msrdc.h", MSDNShortId = "NE:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0003")]
public enum RdcNeedType
{
///
/// Value:
/// 0
/// The chunk is a source chunk.
///
RDCNEED_SOURCE,
///
/// Value:
/// 1
/// This value is reserved for future use.
///
RDCNEED_TARGET,
///
/// Value:
/// 2
/// The chunk is a seed chunk.
///
RDCNEED_SEED,
///
/// Value:
/// 255
/// This value is reserved for future use.
///
RDCNEED_SEED_MAX = 255,
}
/// Provides methods for retrieving information from the file list returned by the ISimilarity::FindSimilarFileId method.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-ifindsimilarresults
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.IFindSimilarResults")]
[ComImport, Guid("96236A81-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(FindSimilarResults))]
public interface IFindSimilarResults
{
///
/// Retrieves the number of entries in the file list that was returned by the ISimilarity::FindSimilarFileId method.
///
/// The actual number of similarity file IDs that are returned by the GetNextFileId method may be less than the number that is
/// returned by the GetSize method. GetNextFileId returns only valid similarity file IDs. However, GetSize
/// counts all entries, even if their similarity file IDs are not valid.
///
///
/// A pointer to a variable that receives the number of entries in the file list.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-ifindsimilarresults-getsize HRESULT GetSize( [out] DWORD
// *size );
uint GetSize();
///
/// Retrieves the next valid similarity file ID in the file list that was returned by the ISimilarity::FindSimilarFileId method.
///
/// A pointer to a variable that receives the number of traits that were matched.
///
/// A pointer to a SimilarityFileId structure that contains the similarity file ID of the matching file.
///
///
/// Returns S_OK on success, or an error HRESULT on failure.
/// This method can also return the following error code.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-ifindsimilarresults-getnextfileid HRESULT GetNextFileId(
// [out] DWORD *numTraitsMatched, [out] SimilarityFileId *similarityFileId );
[PreserveSig]
HRESULT GetNextFileId(out uint numTraitsMatched, out SimilarityFileId similarityFileId);
}
///
/// The IRdcComparator interface is used to compare two signature streams (seed and source) and produce the list of source and
/// seed file data chunks needed to create the target file.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-irdccomparator
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.IRdcComparator")]
[ComImport, Guid("96236A77-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(RdcComparator))]
public interface IRdcComparator
{
///
/// The Process method compares two signature streams (seed and source) and produces a needs list, which describes the
/// chunks of file data needed to create the target file. The seed signature file may be read multiple times, depending on the
/// size of the source signature file.
///
/// Set to TRUE if the inputBuffer parameter contains all remaining input.
///
/// Address of a BOOL that on successful completion is set to TRUE if all output data has been generated.
///
///
/// Address of a RdcBufferPointer structure containing information about the input buffer. The m_Used member of this
/// structure is used to indicate how much input, if any, was processed during this call.
///
///
/// Address of a RdcNeedPointer structure containing information about the output buffer. On input the m_Size member of
/// this structure must contain the number of RdcNeed structures in the array pointed to by the m_Data member, and the
/// m_Used member must be zero. On output the m_Used member will contain the number of RdcNeed structures in
/// the array pointed to by the m_Data member.
///
///
/// The address of a RDC_ErrorCode enumeration that is filled with an RDC specific error code if the return value from the
/// Process method is E_FAIL. If this value is RDC_Win32ErrorCode, then the return value of the
/// Process method contains the specific error code.
///
///
/// On successful return, iterate through each RdcNeed structure returned in the array pointed to by the m_Data member of
/// the outputBuffer parameter, and copy the specified chunk of the source or seed data to the target data.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdccomparator-process HRESULT Process( [in] BOOL
// endOfInput, [out] BOOL *endOfOutput, [in, out] RdcBufferPointer *inputBuffer, [in, out] RdcNeedPointer *outputBuffer, [out]
// RDC_ErrorCode *rdc_ErrorCode );
void Process([MarshalAs(UnmanagedType.Bool)] bool endOfInput, [MarshalAs(UnmanagedType.Bool)] out bool endOfOutput,
ref RdcBufferPointer inputBuffer, ref RdcNeedPointer outputBuffer, out RDC_ErrorCode rdc_ErrorCode);
}
///
/// The IRdcFileReader interface is used to provide the equivalent of a file handle, because the data being synchronized may
/// not exist as a file on disk.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-irdcfilereader
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.IRdcFileReader")]
[ComImport, Guid("96236A74-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(RdcFileReader))]
public interface IRdcFileReader
{
/// The GetFileSize method returns the size of a file.
///
/// Address of a ULONGLONG that on successful return will be filled with the size of the file, in bytes.
///
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcfilereader-getfilesize HRESULT GetFileSize( [out]
// ULONGLONG *fileSize );
[PreserveSig]
HRESULT GetFileSize(out ulong fileSize);
/// The Read method reads the specified amount of data starting at the specified position.
/// Offset from the start of the data at which to start the read.
/// Number of bytes to be read.
/// Address of a ULONG that will receive the number of bytes read.
///
/// Address of the buffer that receives the data read. This buffer must be at least bytesToRead bytes in size.
///
/// Address of a BOOL that is set to TRUE if the end of the file has been read.
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
///
///
/// Typically RDC will read the file sequentially from start to end. When reading signatures, the file may be read more than once.
///
///
/// If the BOOL pointed to by the eof parameter is not TRUE on return then the value pointed to by the
/// bytesActuallyRead parameter must equal the bytesToRead parameter. If the value pointed to by the eof
/// parameter is set, then the value pointed to by the bytesActuallyRead parameter can be any value between zero and the
/// bytesToRead parameter.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcfilereader-read HRESULT Read( [in] ULONGLONG
// offsetFileStart, [in] ULONG bytesToRead, [out] ULONG *bytesActuallyRead, [out] BYTE *buffer, [out] BOOL *eof );
[PreserveSig]
HRESULT Read(ulong offsetFileStart, uint bytesToRead, out uint bytesActuallyRead, [Out] byte[] buffer, [MarshalAs(UnmanagedType.Bool)] out bool eof);
/// The GetFilePosition method returns the current file position.
/// Address of a ULONGLONG that will receive the current offset from the start of the data.
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcfilereader-getfileposition HRESULT GetFilePosition(
// [out] ULONGLONG *offsetFromStart );
[PreserveSig]
HRESULT GetFilePosition(out ulong offsetFromStart);
}
///
/// Abstract interface to read from and write to a file.
///
/// The RDC application must implement this interface for use with ISimilarityFileIdTable::CreateTableIndirect. Note that this
/// interface does not include methods to open, close, or flush the file to disk. The application is responsible for properly opening
/// and closing the file represented by an instance of this interface.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-irdcfilewriter
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.IRdcFileWriter")]
[ComImport, Guid("96236A75-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(RdcFileReader))]
public interface IRdcFileWriter : IRdcFileReader
{
/// The GetFileSize method returns the size of a file.
///
/// Address of a ULONGLONG that on successful return will be filled with the size of the file, in bytes.
///
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcfilereader-getfilesize HRESULT GetFileSize( [out]
// ULONGLONG *fileSize );
[PreserveSig]
new HRESULT GetFileSize(out ulong fileSize);
/// The Read method reads the specified amount of data starting at the specified position.
/// Offset from the start of the data at which to start the read.
/// Number of bytes to be read.
/// Address of a ULONG that will receive the number of bytes read.
///
/// Address of the buffer that receives the data read. This buffer must be at least bytesToRead bytes in size.
///
/// Address of a BOOL that is set to TRUE if the end of the file has been read.
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
///
///
/// Typically RDC will read the file sequentially from start to end. When reading signatures, the file may be read more than once.
///
///
/// If the BOOL pointed to by the eof parameter is not TRUE on return then the value pointed to by the
/// bytesActuallyRead parameter must equal the bytesToRead parameter. If the value pointed to by the eof
/// parameter is set, then the value pointed to by the bytesActuallyRead parameter can be any value between zero and the
/// bytesToRead parameter.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcfilereader-read HRESULT Read( [in] ULONGLONG
// offsetFileStart, [in] ULONG bytesToRead, [out] ULONG *bytesActuallyRead, [out] BYTE *buffer, [out] BOOL *eof );
[PreserveSig]
new HRESULT Read(ulong offsetFileStart, uint bytesToRead, out uint bytesActuallyRead, [Out] byte[] buffer, [MarshalAs(UnmanagedType.Bool)] out bool eof);
/// The GetFilePosition method returns the current file position.
/// Address of a ULONGLONG that will receive the current offset from the start of the data.
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcfilereader-getfileposition HRESULT GetFilePosition(
// [out] ULONGLONG *offsetFromStart );
[PreserveSig]
new HRESULT GetFilePosition(out ulong offsetFromStart);
/// Write bytes to a file starting at a given offset.
/// Starting offset.
/// Number of bytes to be written to the file.
/// The data to be written to the file.
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcfilewriter-write HRESULT Write( [in] ULONGLONG
// offsetFileStart, [in] ULONG bytesToWrite, [out] BYTE *buffer );
[PreserveSig]
HRESULT Write(ulong offsetFileStart, uint bytesToWrite, out byte buffer);
/// Truncates a file to zero length.
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcfilewriter-truncate HRESULT Truncate();
[PreserveSig]
HRESULT Truncate();
/// Sets a file to be deleted (or truncated) on close.
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcfilewriter-deleteonclose HRESULT DeleteOnClose();
[PreserveSig]
HRESULT DeleteOnClose();
}
/// The IRdcGenerator interface is used to process the input data and read the parameters used by the generator.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-irdcgenerator
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.IRdcGenerator")]
[ComImport, Guid("96236A73-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(RdcGenerator))]
public interface IRdcGenerator
{
///
/// The GetGeneratorParameters method returns a copy of the parameters used to create the generator. The generator
/// parameters are fixed when the generator is created.
///
/// The generator level for the parameters to be returned. The range is MSRDC_MINIMUM_DEPTH to MSRDC_MAXIMUM_DEPTH.
///
/// Address of a pointer that on successful return will contain the IRdcGeneratorParameters interface pointer for the parameters
/// for the generator level specified in the level parameter.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcgenerator-getgeneratorparameters HRESULT
// GetGeneratorParameters( [in] ULONG level, [out] IRdcGeneratorParameters **iGeneratorParameters );
IRdcGeneratorParameters GetGeneratorParameters(uint level);
///
/// The Process method processes the input data and produces 0 or more output bytes. This method must be called repeatedly
/// until the BOOL pointed to by endOfOutput is set to TRUE.
///
///
/// Set to TRUE when the input buffer pointed to by the inputBuffer parameter contains the remaining input available.
///
/// Address of a BOOL that is set to TRUE when the processing is complete for all data.
///
/// Address of an RdcBufferPointer structure that contains the input buffer. On successful return, the m_Used member of
/// this structure will be filled with the number of bytes by this call.
///
///
/// The number of levels of signatures to generate. This must match the number of levels specified when the generator was created.
///
///
/// The address of an array of RdcBufferPointer structures that will receive the output buffers. The m_Used member of
/// these structures will be filled with the number of bytes returned in the buffer.
///
///
/// The address of an RDC_ErrorCode enumeration that is filled with an RDC specific error code if the return value from the
/// Process method is E_FAIL. If this value is RDC_Win32ErrorCode, then the return value of the
/// Process method contains the specific error code.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcgenerator-process HRESULT Process( [in] BOOL endOfInput,
// [out] BOOL *endOfOutput, [in, out] RdcBufferPointer *inputBuffer, [in] ULONG depth, [out] RdcBufferPointer * [] outputBuffers,
// [out] RDC_ErrorCode *rdc_ErrorCode );
void Process([MarshalAs(UnmanagedType.Bool)] bool endOfInput, [MarshalAs(UnmanagedType.Bool)] out bool endOfOutput, ref RdcBufferPointer inputBuffer, uint depth,
[Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] IntPtr[] outputBuffers, out RDC_ErrorCode rdc_ErrorCode);
}
/// The IRdcGeneratorFilterMaxParameters interface sets and retrieves parameters used by the FilterMax generator.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-irdcgeneratorfiltermaxparameters
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.IRdcGeneratorFilterMaxParameters")]
[ComImport, Guid("96236A72-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(RdcGeneratorFilterMaxParameters))]
public interface IRdcGeneratorFilterMaxParameters
{
///
/// The GetHorizonSize method returns the horizon size—the length over which the FilterMax generator looks for local
/// maxima. This determines the default smallest size for a chunk.
///
///
/// Address of a ULONG that will receive the length in bytes of the horizon size. The valid range is from
/// MSRDC_MINIMUM_HORIZONSIZE to MSRDC_MAXIMUM_HORIZONSIZE.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcgeneratorfiltermaxparameters-gethorizonsize HRESULT
// GetHorizonSize( [out] ULONG *horizonSize );
uint GetHorizonSize();
///
/// The SetHorizonSize method sets the horizon size—the length over which the FilterMax generator looks for local maxima.
/// This determines the default smallest size for a chunk.
///
///
/// Specifies the length in bytes of the horizon size. The valid range is from MSRDC_MINIMUM_HORIZONSIZE to
/// MSRDC_MAXIMUM_HORIZONSIZE. If this parameter is not set then a suitable default will be used.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcgeneratorfiltermaxparameters-sethorizonsize HRESULT
// SetHorizonSize( [in] ULONG horizonSize );
void SetHorizonSize(uint horizonSize);
///
/// The GetHashWindowSize method returns the hash window size—the size of the sliding window used by the FilterMax
/// generator for computing the hash used in the local maxima calculations.
///
///
/// Address of a ULONG that will receive the length in bytes of the hash window size. The valid range is from
/// MSRDC_MINIMUM_HASHWINDOWSIZE to MSRDC_MAXIMUM_HASHWINDOWSIZE.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcgeneratorfiltermaxparameters-gethashwindowsize HRESULT
// GetHashWindowSize( [out] ULONG *hashWindowSize );
uint GetHashWindowSize();
///
/// The SetHashWindowSize method sets the hash window size—the size of the sliding window used by the FilterMax generator
/// for computing the hash used in the local maxima calculations.
///
///
/// The length in bytes of the hash window size. The valid range is from MSRDC_MINIMUM_HASHWINDOWSIZE to MSRDC_MAXIMUM_HASHWINDOWSIZE.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcgeneratorfiltermaxparameters-sethashwindowsize HRESULT
// SetHashWindowSize( [in] ULONG hashWindowSize );
void SetHashWindowSize(uint hashWindowSize);
}
///
/// The IRdcGeneratorParameters interface is the generic interface for all types of generator parameters. All generator
/// parameter objects must support this interface.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-irdcgeneratorparameters
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.IRdcGeneratorParameters")]
[ComImport, Guid("96236A71-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(RdcGeneratorParameters))]
public interface IRdcGeneratorParameters
{
/// The GetGeneratorParametersType method returns the specific type of the parameters.
/// The address of a GeneratorParametersType that will receive the type of the parameters.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcgeneratorparameters-getgeneratorparameterstype HRESULT
// GetGeneratorParametersType( [out] GeneratorParametersType *parametersType );
GeneratorParametersType GetGeneratorParametersType();
/// The GetParametersVersion method returns information about the version of RDC used to serialize the parameters.
///
/// Address of a ULONG that will receive the version of RDC used to serialize the parameters for this object. This
/// corresponds to the MSRDC_VERSION constant.
///
///
/// Address of a ULONG that will receive the version of RDC that is compatible with the serialized parameters. This
/// corresponds to the MSRDC_MINIMUM_COMPATIBLE_APP_VERSION constant.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcgeneratorparameters-getparametersversion HRESULT
// GetParametersVersion( [out] ULONG *currentVersion, [out] ULONG *minimumCompatibleAppVersion );
void GetParametersVersion(out uint currentVersion, out uint minimumCompatibleAppVersion);
/// The GetSerializeSize method returns the size, in bytes, of the serialized parameter data.
///
/// Address of a ULONG that on successful completion is filled with the size, in bytes, of the serialized parameter data.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcgeneratorparameters-getserializesize HRESULT
// GetSerializeSize( [out] ULONG *size );
uint GetSerializeSize();
///
/// The Serialize method serializes the parameter data into a block of memory. This allows the parameters to be stored or transmitted.
///
/// The size of the buffer pointed to by the parametersBlob parameter.
/// The address of a buffer to receive the serialized parameter data.
///
/// Address of a ULONG that on successful completion is filled with the size, in bytes, of the serialized parameter data
/// written to the buffer pointed to by the parametersBlob parameter.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcgeneratorparameters-serialize HRESULT Serialize( [in]
// ULONG size, [out] BYTE *parametersBlob, [out] ULONG *bytesWritten );
void Serialize(uint size, out byte parametersBlob, out uint bytesWritten);
}
/// The IRdcLibrary interface is the primary interface for using RDC.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-irdclibrary
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.IRdcLibrary")]
[ComImport, Guid("96236A78-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(RdcLibrary))]
public interface IRdcLibrary
{
///
/// The ComputeDefaultRecursionDepth method computes the maximum level of recursion for the specified file size. The depth
/// returned by the method may be larger than MSRDC_MAXIMUM_DEPTH. The caller must compare the value returned through the
/// depth parameter with MSRDC_MAXIMUM_DEPTH.
///
/// The approximate size of the file.
/// Pointer to a ULONG that will receive the suggested maximum recursion depth.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdclibrary-computedefaultrecursiondepth HRESULT
// ComputeDefaultRecursionDepth( [in] ULONGLONG fileSize, [out] ULONG *depth );
uint ComputeDefaultRecursionDepth(ulong fileSize);
///
/// The CreateGeneratorParameters method returns an IRdcGeneratorParameters interface pointer initialized with the
/// parameters necessary for a signature generator.
///
///
/// Specifies the type of signature generator for the created parameters, enumerated by the GeneratorParametersType enumeration.
/// The initial release of RDC only supports one type, RDCGENTYPE_FilterMax.
///
///
/// The recursion level for this parameter block. A parameter block is needed for each level of generated signatures. The valid
/// range is from MSRDC_MINIMUM_DEPTH to MSRDC_MAXIMUM_DEPTH.
///
///
/// Pointer to a location that will receive an IRdcGeneratorParameters interface pointer. On a successful return the interface
/// will be initialized on return. Callers must release the interface.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdclibrary-creategeneratorparameters HRESULT
// CreateGeneratorParameters( [in] GeneratorParametersType parametersType, [in] ULONG level, [out] IRdcGeneratorParameters
// **iGeneratorParameters );
[return: MarshalAs(UnmanagedType.Interface)]
IRdcGeneratorParameters CreateGeneratorParameters(GeneratorParametersType parametersType, uint level);
///
/// The OpenGeneratorParameters method opens an existing serialized parameter block and returns an IRdcGeneratorParameters
/// interface pointer initialized with the data.
///
/// The size, in bytes, of the serialized parameter block.
/// Pointer to a serialized parameter block.
///
/// Pointer to a location that will receive the returned IRdcGeneratorParameters interface pointer. Callers must release the interface.
///
/// To create a serialized parameter block, use the IRdcGeneratorParameters::Serialize method.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdclibrary-opengeneratorparameters HRESULT
// OpenGeneratorParameters( [in] ULONG size, [in] const BYTE *parametersBlob, [out] IRdcGeneratorParameters
// **iGeneratorParameters );
[return: MarshalAs(UnmanagedType.Interface)]
IRdcGeneratorParameters OpenGeneratorParameters(uint size, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] byte[] parametersBlob);
/// The CreateGenerator method creates a signature generator that will generate the specified levels of signatures.
///
/// The number of levels of signatures to generate. The valid range is from MSRDC_MINIMUM_DEPTH to MSRDC_MAXIMUM_DEPTH.
///
///
/// Pointer to an array of initialized IRdcGeneratorParameters interface pointers. Each IRdcGeneratorParameters interface
/// pointer would have been initialized by IRdcLibrary::CreateGeneratorParameters or IRdcGenerator::GetGeneratorParameters.
///
///
/// Pointer to a location that will receive the returned IRdcGenerator interface pointer. Callers must release the interface.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdclibrary-creategenerator HRESULT CreateGenerator( [in]
// ULONG depth, [in] IRdcGeneratorParameters * [] iGeneratorParametersArray, [out] IRdcGenerator **iGenerator );
[return: MarshalAs(UnmanagedType.Interface)]
IRdcGenerator CreateGenerator(uint depth, [In, MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Interface, SizeParamIndex = 0)] IRdcGeneratorParameters[] iGeneratorParametersArray);
/// The CreateComparator method creates a signature comparator.
/// An IRdcFileReader interface pointer initialized to read the seed signatures.
///
/// Specifies the size of the comparator buffer. The range is from MSRDC_MINIMUM_COMPAREBUFFER to MSRDC_MAXIMUM_COMPAREBUFFER.
/// MSRDC_MINIMUM_COMPAREBUFFER (100000)
/// Minimum size of a comparator buffer.
/// MSRDC_DEFAULT_COMPAREBUFFER (3200000)
/// Default size of a comparator buffer. Used if zero (0) is passed for comparatorBufferSize.
/// MSRDC_MAXIMUM_COMPAREBUFFER (1073741824)
/// Maximum size of a comparator buffer. (1<<30)
///
///
/// Pointer to a location that will receive an IRdcComparator interface pointer. On a successful return the interface will be
/// initialized on return. Callers must release the interface.
///
/// The caller must create a separate signature comparator for each level of recursion.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdclibrary-createcomparator HRESULT CreateComparator( [in]
// IRdcFileReader *iSeedSignaturesFile, [in] ULONG comparatorBufferSize, [out] IRdcComparator **iComparator );
[return: MarshalAs(UnmanagedType.Interface)]
IRdcComparator CreateComparator([In, MarshalAs(UnmanagedType.Interface)] IRdcFileReader iSeedSignaturesFile, [Optional] uint comparatorBufferSize);
///
/// The CreateSignatureReader method creates a signature reader to allow an application to decode the contents of a
/// signature file.
///
/// An IRdcFileReader interface pointer initialized to read the signatures.
///
/// Pointer to a location that will receive an IRdcSignatureReader interface pointer. On a successful return the interface will
/// be initialized on return. Callers must release the interface.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdclibrary-createsignaturereader HRESULT
// CreateSignatureReader( [in] IRdcFileReader *iFileReader, [out] IRdcSignatureReader **iSignatureReader );
[return: MarshalAs(UnmanagedType.Interface)]
IRdcSignatureReader CreateSignatureReader([In] IRdcFileReader iFileReader);
///
/// The GetRDCVersion method retrieves the version of the installed RDC runtime and the oldest version of the RDC
/// interfaces supported by the installed runtime.
///
///
/// Address of a ULONG that will receive the installed version of RDC. This corresponds to the MSRDC_VERSION value.
///
///
/// Address of a ULONG that will receive the oldest version of RDC supported by the installed version of RDC. This
/// corresponds to the MSRDC_MINIMUM_COMPATIBLE_APP_VERSION value.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdclibrary-getrdcversion HRESULT GetRDCVersion( [out] ULONG
// *currentVersion, [out] ULONG *minimumCompatibleAppVersion );
void GetRDCVersion(out uint currentVersion, out uint minimumCompatibleAppVersion);
}
/// The IRdcSignatureReader interface reads the signatures and the parameters used to generate the signatures.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-irdcsignaturereader
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.IRdcSignatureReader")]
[ComImport, Guid("96236A76-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(RdcSignatureReader))]
public interface IRdcSignatureReader
{
///
/// The ReadHeader method reads the signature header and returns a copy of the parameters used to generate the signatures.
///
/// Address of a RDC_ErrorCode enumeration that will receive any RDC-specific error code.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcsignaturereader-readheader HRESULT ReadHeader( [out]
// RDC_ErrorCode *rdc_ErrorCode );
RDC_ErrorCode ReadHeader();
/// The ReadSignatures method reads a block of signatures from the current position.
///
/// Address of a RdcSignaturePointer structure. On input the m_Size member of this structure must contain the number of
/// RdcSignature structures in the array pointed to by the m_Data member, and the m_Used member must be zero. On
/// output the m_Used member will contain the number of RdcSignature structures in the array pointed to by the
/// m_Data member.
///
/// Address of a BOOL that is set to TRUE if the end of the signatures has been read.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcsignaturereader-readsignatures HRESULT ReadSignatures(
// [in, out] RdcSignaturePointer *rdcSignaturePointer, [out] BOOL *endOfOutput );
void ReadSignatures(ref RdcSignaturePointer rdcSignaturePointer, [MarshalAs(UnmanagedType.Bool)] out bool endOfOutput);
}
///
/// Defines methods for enabling the signature generator to generate similarity data and for retrieving the similarity data after it
/// is generated.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-irdcsimilaritygenerator
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.IRdcSimilarityGenerator")]
[ComImport, Guid("96236A80-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(RdcSimilarityGenerator))]
public interface IRdcSimilarityGenerator
{
///
/// Enables the signature generator to generate similarity data.
///
/// The EnableSimilarity method must be called before the IRdcGenerator::Process method is called to begin generating
/// signatures. Otherwise, this method will return an error.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcsimilaritygenerator-enablesimilarity HRESULT EnableSimilarity();
void EnableSimilarity();
///
/// Retrieves the similarity data that was generated for a file by the signature generator.
///
/// This method cannot be called until signature generation is completed. For more information, see the endOfOutput
/// parameter of the IRdcGenerator::Process method.
///
///
/// A pointer to a SimilarityData structure that will receive the similarity data.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-irdcsimilaritygenerator-results HRESULT Results( [out]
// SimilarityData *similarityData );
SimilarityData Results();
}
/// Defines methods for storing and retrieving per-file similarity data and file IDs in a similarity file.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-isimilarity
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.ISimilarity")]
[ComImport, Guid("96236A83-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(Similarity))]
public interface ISimilarity
{
/// Creates or opens a similarity traits table and a similarity file ID table.
///
/// A pointer to a null-terminated string that specifies the name of the file that will contain the tables. The similarity traits
/// table and the similarity file ID table will be created in two alternate file streams of this file. For more information, see
/// the path parameter of the ISimilarityFileIdTable::CreateTable and ISimilarityTraitsTable::CreateTable methods.
///
///
/// TRUE if a new similarity traits table and a new similarity file ID table should always be created or truncated. If
/// FALSE is specified and these tables exist and are valid, they may be used; otherwise, if one of the tables is not
/// valid or does not exist, any existing tables are overwritten.
///
///
/// A pointer to a security descriptor to use when opening the file. If this parameter is NULL, the file is assigned a
/// default security descriptor. The access control lists (ACL) in the file's default security descriptor are inherited from the
/// file's parent directory. For more information, see the lpSecurityAttributes parameter of the CreateFile function.
///
///
/// The size, in bytes, of each file ID to be stored in the similarity file id table. All similarity file IDs must be the same
/// size. The valid range is from SimilarityFileIdMinSize to SimilarityFileIdMaxSize. If existing tables are being
/// opened, the value of this parameter must match the file ID size of the existing similarity file ID table. Otherwise, the
/// existing tables are assumed to be not valid and will be overwritten.
///
///
/// A pointer to a variable that receives an RdcCreatedTables enumeration value that describes the state of the tables. If new
/// tables are created, this variable receives RDCTABLE_New. If existing tables are used, this variable receives
/// RDCTABLE_Existing. If this method fails, this variable receives RDCTABLE_InvalidOrUnknown.
///
///
/// If one of the tables can be created or opened successfully, but the other one cannot, both tables are marked as not valid,
/// and the variable that the isNew parameter points to receives RDCTABLE_InvalidOrUnknown.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarity-createtable HRESULT CreateTable( [in] wchar_t
// *path, [in] BOOL truncate, [in] BYTE *securityDescriptor, [in] DWORD recordSize, [out] RdcCreatedTables *isNew );
void CreateTable([MarshalAs(UnmanagedType.LPWStr)] string path, [MarshalAs(UnmanagedType.Bool)] bool truncate,
[In, Optional] PSECURITY_DESCRIPTOR securityDescriptor, uint recordSize, out RdcCreatedTables isNew);
///
/// Creates or opens a similarity traits table and a similarity file ID table using the RDC application's implementations of the
/// ISimilarityTraitsMapping and IRdcFileWriter interfaces.
///
///
/// An ISimilarityTraitsMapping interface pointer initialized to write the similarity traits table to the file.
///
/// An IRdcFileWriter interface pointer initialized to write the file ID table to the file.
///
/// TRUE if a new similarity traits table and a new similarity file ID table should always be created or truncated. If
/// FALSE is specified and these tables exist and are valid, they may be used; otherwise, if one of the tables is not
/// valid or does not exist, any existing tables are overwritten.
///
///
/// The size, in bytes, of each file ID to be stored in the similarity file ID table. All similarity file IDs must be the same
/// size. The valid range is from SimilarityFileIdMinSize to SimilarityFileIdMaxSize. If existing tables are being
/// opened, the value of this parameter must match the file ID size of the existing similarity file ID table. Otherwise, the
/// existing tables are assumed to be not valid and will be overwritten.
///
///
/// A pointer to a variable that receives an RdcCreatedTables enumeration value that describes the state of the tables. If new
/// tables are created, this variable receives RDCTABLE_New. If existing tables are used, this variable receives
/// RDCTABLE_Existing. If this method fails, this variable receives RDCTABLE_InvalidOrUnknown.
///
///
/// If one of the tables can be created or opened successfully, but the other one cannot, both tables are marked as not valid,
/// and the variable that the isNew parameter points to receives RDCTABLE_InvalidOrUnknown.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarity-createtableindirect HRESULT CreateTableIndirect(
// [in] ISimilarityTraitsMapping *mapping, [in] IRdcFileWriter *fileIdFile, [in] BOOL truncate, [in] DWORD recordSize, [out]
// RdcCreatedTables *isNew );
void CreateTableIndirect([In] ISimilarityTraitsMapping mapping, [In] IRdcFileWriter fileIdFile,
[MarshalAs(UnmanagedType.Bool)] bool truncate, uint recordSize, out RdcCreatedTables isNew);
/// Closes the tables in a similarity file.
///
/// FALSE if the similarity traits table and similarity file ID table should be deleted when they are closed; otherwise, TRUE.
///
///
///
/// If FALSE is specified for the isValid parameter, only the tables are deleted; the similarity file is not
/// deleted. The caller is responsible for deleting the similarity file.
///
/// When the CloseTable method returns, the tables are always closed, even if this method returns an error code.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarity-closetable HRESULT CloseTable( [in] BOOL isValid );
void CloseTable([MarshalAs(UnmanagedType.Bool)] bool isValid);
/// Adds the file ID and similarity data information to the tables in the similarity file.
/// A pointer to the SimilarityFileId structure to be added to the similarity file ID table.
/// A pointer to the SimilarityData structure to be added to the similarity traits table.
///
/// If this method fails, the similarity file ID table and the similarity traits table are marked as corrupted and must be
/// rebuilt by the application. The application must close the corrupted tables and create new tables.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarity-append HRESULT Append( [in] SimilarityFileId
// *similarityFileId, [in] SimilarityData *similarityData );
void Append(in SimilarityFileId similarityFileId, in SimilarityData similarityData);
/// Returns a list of files that are similar to a given file.
/// A pointer to a SimilarityData structure that contains similarity information for the file.
/// TBD
///
/// The number of file IDs that can be stored in the IFindSimilarResults object that the findSimilarResults parameter
/// points to.
///
///
/// A pointer to a location that will receive the returned IFindSimilarResults interface pointer. The caller must release this
/// interface when it is no longer needed.
///
///
/// The file IDs that are returned in the findSimilarResults parameter may include IDs of files that have been deleted.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarity-findsimilarfileid HRESULT FindSimilarFileId(
// [in] SimilarityData *similarityData, USHORT numberOfMatchesRequired, [in] DWORD resultsSize, [out, optional]
// IFindSimilarResults **findSimilarResults );
IFindSimilarResults? FindSimilarFileId(in SimilarityData similarityData, ushort numberOfMatchesRequired, uint resultsSize);
///
///
/// Creates copies of an existing similarity traits table and an existing similarity file ID table, swaps the internal pointers,
/// and deletes the existing tables.
///
///
/// After the CopyAndSwap method returns, the application continues to use the same ISimilarity object that it used before
/// calling this method. However, the ISimilarity object is now associated with a different similarity file on disk.
///
///
///
/// An optional pointer to a temporary ISimilarity object that is used to create temporary copies of the tables. Before calling
/// the CopyAndSwap method, the caller must call the CreateTable method to create the temporary tables. On return, the
/// caller must call the CloseTable method to close the temporary tables.
///
///
/// An optional pointer to an ISimilarityReportProgress object that will receive information on the progress of the copy-and-swap
/// operation and allow the application to stop the copy operation. The caller must release this interface when it is no longer needed.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarity-copyandswap HRESULT CopyAndSwap( [in, optional]
// ISimilarity *newSimilarityTables, [in, optional] ISimilarityReportProgress *reportProgress );
void CopyAndSwap([In] ISimilarity? newSimilarityTables, [In] ISimilarityReportProgress? reportProgress);
/// Retrieves the number of records that are stored in the similarity file ID table in a similarity file.
/// A pointer to a variable that receives the number of records.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarity-getrecordcount HRESULT GetRecordCount( [out]
// DWORD *recordCount );
uint GetRecordCount();
}
/// Defines methods for storing and retrieving similarity file ID information.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-isimilarityfileidtable
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.ISimilarityFileIdTable")]
[ComImport, Guid("96236A7F-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(SimilarityFileIdTable))]
public interface ISimilarityFileIdTable
{
/// Creates or opens a similarity file ID table.
///
/// A pointer to a null-terminated string that specifies the name of the file that will contain the similarity file ID table. The
/// alternate stream name ":FileId" will be appended to the end of this file name. For more information, see Naming a File.
///
///
/// TRUE if a new similarity file ID table should always be created or truncated. If FALSE is specified and the
/// table exists and is valid, it may be used; otherwise, if the table is not valid or does not exist, the existing table is overwritten.
///
///
/// A pointer to a security descriptor to use when opening the file. If this parameter is NULL, the file is assigned a
/// default security descriptor. The access control lists (ACL) in the file's default security descriptor are inherited from the
/// file's parent directory. For more information, see the lpSecurityAttributes parameter of the CreateFile function.
///
///
/// The size, in bytes, of the file IDs that will be stored in the similarity file ID table. All file IDs must be the same size.
/// The valid range is from SimilarityFileIdMinSize to SimilarityFileIdMaxSize. If an existing similarity file ID
/// table is being opened, the value of this parameter must match the file ID size of the existing table. Otherwise, the existing
/// table is assumed to be not valid and will be overwritten.
///
///
/// A pointer to a variable that receives an RdcCreatedTables enumeration value that describes the state of the similarity file
/// ID table. If a new table is created, this variable receives RDCTABLE_New. If an existing table is used, this variable
/// receives RDCTABLE_Existing. If this method fails, this variable receives RDCTABLE_InvalidOrUnknown.
///
///
/// If an existing table is being opened, the table must be valid, and the value of the recordSize parameter must match
/// the record size of the existing table. Otherwise, the existing table is overwritten, even if FALSE is specified for
/// the truncate parameter.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarityfileidtable-createtable HRESULT CreateTable( [in]
// wchar_t *path, [in] BOOL truncate, [in] BYTE *securityDescriptor, [in] DWORD recordSize, [out] RdcCreatedTables *isNew );
void CreateTable([MarshalAs(UnmanagedType.LPWStr)] string path, [MarshalAs(UnmanagedType.Bool)] bool truncate,
[In, Optional] PSECURITY_DESCRIPTOR securityDescriptor, uint recordSize, out RdcCreatedTables isNew);
///
/// Creates or opens a similarity file ID table using the RDC application's implementation of the IRdcFileWriter interface.
///
/// An IRdcFileWriter interface pointer initialized to write the file ID table to the file.
///
/// TRUE if a new similarity file ID table should always be created or truncated. If FALSE is specified and the
/// table exists and is valid, it may be used; otherwise, if the table is not valid or does not exist, the existing table is overwritten.
///
///
/// The size, in bytes, of the file IDs that will be stored in the similarity file ID table. All file IDs must be the same size.
/// The valid range is from SimilarityFileIdMinSize to SimilarityFileIdMaxSize. If an existing similarity file ID
/// table is being opened, the value of this parameter must match the file ID size of the existing table. Otherwise, the existing
/// table is assumed to be not valid and will be overwritten.
///
///
/// A pointer to a variable that receives an RdcCreatedTables enumeration value that describes the state of the similarity file
/// ID table. If a new table is created, this variable receives RDCTABLE_New. If an existing table is used, this variable
/// receives RDCTABLE_Existing. If this method fails, this variable receives RDCTABLE_InvalidOrUnknown.
///
///
/// If an existing table is being opened, the table must be valid, and the value of the recordSize parameter must match
/// the record size of the existing table. Otherwise, the existing table is overwritten, even if FALSE is specified for
/// the truncate parameter.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarityfileidtable-createtableindirect HRESULT
// CreateTableIndirect( [in] IRdcFileWriter *fileIdFile, [in] BOOL truncate, [in] DWORD recordSize, [out] RdcCreatedTables *isNew );
void CreateTableIndirect([In] IRdcFileWriter fileIdFile, [MarshalAs(UnmanagedType.Bool)] bool truncate, uint recordSize, out RdcCreatedTables isNew);
/// Closes a similarity file ID table.
/// FALSE if the similarity file ID table should be deleted when it is closed; otherwise, TRUE.
///
///
/// If FALSE is specified for the isValid parameter, only the table is deleted; the similarity file is not deleted.
/// The caller is responsible for deleting the similarity file.
///
/// When the CloseTable method returns, the table is always closed, even if this method returns an error code.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarityfileidtable-closetable HRESULT CloseTable( BOOL
// isValid );
void CloseTable([MarshalAs(UnmanagedType.Bool)] bool isValid);
/// Adds the file ID to the similarity file ID table.
/// The file ID to be added to the similarity file ID table.
///
/// A pointer to a variable that receives the file index for the file ID's entry in the similarity file ID table.
///
/// If the Append method fails, the similarity file ID table is marked as corrupted and must be rebuilt.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarityfileidtable-append HRESULT Append( [in]
// SimilarityFileId *similarityFileId, [out] SimilarityFileIndexT *similarityFileIndex );
void Append(in SimilarityFileId similarityFileId, out uint similarityFileIndex);
/// Retrieves the file ID that corresponds to a given file index in the similarity file ID table.
///
/// The file index that was previously returned for the file ID by the ISimilarityFileIdTable::Append method.
///
///
/// A pointer to a variable that receives the file ID. If the file has been marked as not valid, the file ID receives zero.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarityfileidtable-lookup HRESULT Lookup( [in]
// SimilarityFileIndexT similarityFileIndex, [out] SimilarityFileId *similarityFileId );
SimilarityFileId Lookup([In] uint similarityFileIndex);
///
/// Marks a file ID as not valid in the similarity file ID table.
/// This method should be called for files that have been deleted or are otherwise no longer available.
///
/// The index of the file ID's entry in the similarity file ID table.
///
/// The file ID is marked as not valid by setting the contents of the corresponding SimilarityFileId structure to all zeros. A
/// file ID that is marked as not valid will not be included in the results that are returned by the
/// ISimilarity::FindSimilarFileId method.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarityfileidtable-invalidate HRESULT Invalidate( [in]
// SimilarityFileIndexT similarityFileIndex );
void Invalidate([In] uint similarityFileIndex);
/// Retrieves the number of records that are stored in a similarity file ID table.
/// A pointer to a variable that receives the number of records.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarityfileidtable-getrecordcount HRESULT
// GetRecordCount( [out] DWORD *recordCount );
uint GetRecordCount();
}
/// Defines a method for RDC to report the current completion percentage of a similarity operation.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-isimilarityreportprogress
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.ISimilarityReportProgress")]
[ComImport, Guid("96236A7A-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(SimilarityReportProgress))]
public interface ISimilarityReportProgress
{
/// Reports the current completion percentage of a similarity operation in progress.
/// The current completion percentage of the task. The valid range is from 0 through 100.
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
///
///
/// The ISimilarity::CopyAndSwap method calls the ReportProgress method to report the progress of the copy-and-swap
/// operation. To receive the progress information, RDC applications must implement this method.
///
///
/// No guarantee is made as to how frequently this method is called, nor that it will be called with any specific values for the
/// percentCompleted parameter. For example, the percentCompleted parameter may not start at zero and may never
/// reach 100, and it may receive the same value more than once. However, each value is guaranteed to be greater than or equal to
/// the previous value.
///
///
/// If the application returns an error code such as E_FAIL, the similarity operation is stopped, and the error code is propagated.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilarityreportprogress-reportprogress HRESULT
// ReportProgress( [in] DWORD percentCompleted );
[PreserveSig]
HRESULT ReportProgress(uint percentCompleted);
}
///
/// Provides a method for retrieving information from the similarity traits list that was returned by the
/// ISimilarityTraitsTable::BeginDump method.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-isimilaritytabledumpstate
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.ISimilarityTableDumpState")]
[ComImport, Guid("96236A7B-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(SimilarityTableDumpState))]
public interface ISimilarityTableDumpState
{
///
/// Retrieves one or more SimilarityDumpData structures from the similarity traits list that was returned by the
/// ISimilarityTraitsTable::BeginDump method.
///
///
/// The number of SimilarityDumpData structures that can be stored in the buffer that the results parameter points to.
///
///
/// A pointer to a variable that receives the number of SimilarityDumpData structures that were returned in the buffer that the
/// results parameter points to.
///
/// A pointer to a variable that receives TRUE if the end of the file is reached; otherwise, FALSE.
/// A pointer to a buffer that receives the SimilarityDumpData structures.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytabledumpstate-getnextdata HRESULT GetNextData(
// [in] DWORD resultsSize, [out] DWORD *resultsUsed, [out] BOOL *eof, [in, out] SimilarityDumpData *results );
void GetNextData(uint resultsSize, out uint resultsUsed, [MarshalAs(UnmanagedType.Bool)] out bool eof, ref SimilarityDumpData results);
}
///
/// Provides methods that an RDC application can implement for manipulating a mapped view of a similarity traits table file.
///
/// This interface is used together with the ISimilarityTraitsMapping interface to allow the application to provide the I/O services
/// needed by the ISimilarityTraitsTable and ISimilarity interfaces. The implementation model is based on memory mapped files, but
/// the interface is rich enough to support other models as well, such as memory-only arrays or traditional file accesses.
///
///
/// A mapped view is used to map an area of the entire file into a contiguous block of memory. This mapping is valid until the view
/// is changed or unmapped. A possible implementation would call the ReadFile function when the view is mapped (see the Get method),
/// and would then write the changes back to disk when the view is changed (see Get) or released (see the Unmap method).
///
///
/// There can be multiple overlapping read-only mapped views of the same area of a file, and one or more read-only views can overlap
/// a read/write view, but there can be only one read/write view of a given area of a file.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-isimilaritytraitsmappedview
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.ISimilarityTraitsMappedView")]
[ComImport, Guid("96236A7C-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(SimilarityTraitsMappedView))]
public interface ISimilarityTraitsMappedView
{
/// Writes to the disk any dirty pages within a mapped view of a similarity traits table file.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitsmappedview-flush HRESULT Flush();
void Flush();
///
/// Unmaps a mapped view of a similarity traits table file. The view, if any, is not dirty or does not otherwise need to be
/// flushed to disk.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitsmappedview-unmap HRESULT Unmap();
void Unmap();
/// Returns information about the mapped view of a similarity traits table file.
/// Beginning file offset, in bytes, of the underlying file data to be mapped in the mapped view.
///
/// If TRUE is specified, the data in the currently mapped view has been changed; otherwise, the data has not changed.
/// This parameter can be used to determine if data may need to be written to disk.
///
/// Minimum number of bytes of data to be mapped in the mapped view.
///
/// Pointer to a location that receives a SimilarityMappedViewInfo structure containing information about the mapped view.
///
///
/// At least numElements bytes must be available in the mapped view, but depending on the application, more bytes may
/// actually be mapped. The data must be 8-byte aligned relative to the file offset. For example, the data at file offset 0x8001
/// must be mapped to some memory location whose address modulo 8 is 1.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitsmappedview-get HRESULT Get( [in] unsigned
// __int64 index, [in] BOOL dirty, [in] DWORD numElements, [out] SimilarityMappedViewInfo *viewInfo );
SimilarityMappedViewInfo Get([In] ulong index, [MarshalAs(UnmanagedType.Bool)] bool dirty, uint numElements);
/// Returns the beginning and ending addresses for the mapped view of a similarity traits table file.
/// Pointer to a location that receives the start of the data that is mapped for this view.
/// Pointer to a location that receives the end of the data that is mapped for this view, plus one.
/// None
///
/// If there is no mapped view, then must be set to zero. Otherwise, is set to a valid pointer, and equals the size, in bytes, of
/// the mapped area.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitsmappedview-getview void GetView( [out]
// const unsigned char **mappedPageBegin, [out] const unsigned char **mappedPageEnd );
[PreserveSig]
void GetView(out IntPtr mappedPageBegin, out IntPtr mappedPageEnd);
}
///
///
/// Provides methods that an RDC application can implement for creating and manipulating a file mapping object for a similarity
/// traits table file.
///
///
/// This interface is used together with the ISimilarityTraitsMappedView interface to allow the application to provide the I/O
/// services needed by the ISimilarityTraitsTable and ISimilarity interfaces. The implementation model is based on memory mapped
/// files, but the interface is rich enough to support other models as well, such as memory-only arrays or traditional file accesses.
///
///
/// This interface is used to represent the file on which multiple read-only or read/write views can be created. There can be
/// multiple overlapping read-only mapped views of the same area of a file, and one or more read-only views can overlap a read/write
/// view, but there can be only one read/write view of a given area of a file.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-isimilaritytraitsmapping
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.ISimilarityTraitsMapping")]
[ComImport, Guid("96236A7D-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(SimilarityTraitsMapping))]
public interface ISimilarityTraitsMapping
{
/// Closes a file mapping object for a similarity traits table file.
/// None
///
/// Note that there may still be valid views open on the file. No new views may be created after the mapping is closed, but
/// existing views continue to work.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitsmapping-closemapping void CloseMapping();
[PreserveSig]
void CloseMapping();
/// Sets the size of a similarity traits table file.
/// Pointer to a location that specifies the file size, in bytes.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitsmapping-setfilesize HRESULT SetFileSize(
// [in] unsigned __int64 fileSize );
void SetFileSize([In] ulong fileSize);
/// Returns the size of a similarity traits table file.
/// Pointer to a location that receives the file size, in bytes.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitsmapping-getfilesize HRESULT GetFileSize(
// [out] unsigned __int64 *fileSize );
ulong GetFileSize();
/// Opens the file mapping object for a similarity traits table file.
/// RdcMappingAccessMode enumeration value that specifies the desired access to the file mapping object.
/// File offset, in bytes, where the file mapping is to begin.
/// File offset, in bytes, where the file mapping is to end.
///
/// Pointer to a location that receives the file offset, in bytes, of the actual end of the file mapping, rounded up to the
/// nearest block size.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitsmapping-openmapping HRESULT OpenMapping(
// [in] RdcMappingAccessMode accessMode, [in] unsigned __int64 begin, [in] unsigned __int64 end, [out] unsigned __int64
// *actualEnd );
void OpenMapping([In] RdcMappingAccessMode accessMode, [In] ulong begin, [In] ulong end, out ulong actualEnd);
/// Resizes the file mapping object for a similarity traits table file.
/// RdcMappingAccessMode enumeration value that specifies the desired access to the file mapping object.
/// File offset, in bytes, where the file mapping is to begin.
/// File offset, in bytes, where the file mapping is to end.
///
/// Pointer to a location that receives the file offset, in bytes, of the actual end of the file mapping, rounded up to the
/// nearest block size.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitsmapping-resizemapping HRESULT
// ResizeMapping( [in] RdcMappingAccessMode accessMode, [in] unsigned __int64 begin, [in] unsigned __int64 end, [out] unsigned
// __int64 *actualEnd );
void ResizeMapping([In] RdcMappingAccessMode accessMode, [In] ulong begin, [In] ulong end, out ulong actualEnd);
/// Returns the page size (disk block size) for a similarity traits table file.
///
/// Pointer to a location that receives the page size, in bytes. This page size must be at least 65536 bytes.
///
/// None
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitsmapping-getpagesize void GetPageSize( [out]
// DWORD *pageSize );
[PreserveSig]
void GetPageSize(out uint pageSize);
/// Maps a view of the file mapping for a similarity traits table file.
/// Minimum number of pages of the file mapping to map to the view.
/// RdcMappingAccessMode enumeration value that specifies the desired access to the file mapping object.
///
/// Pointer to a location that will receive the returned ISimilarityTraitsMappedView interface pointer. Callers must release the interface.
///
/// Data accessed through read-only views will never be modified.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitsmapping-createview HRESULT CreateView( [in]
// DWORD minimumMappedPages, [in] RdcMappingAccessMode accessMode, [out] ISimilarityTraitsMappedView **mappedView );
ISimilarityTraitsMappedView CreateView(uint minimumMappedPages, [In] RdcMappingAccessMode accessMode);
}
/// Defines methods for storing per-file similarity data and performing similarity lookups.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nn-msrdc-isimilaritytraitstable
[PInvokeData("msrdc.h", MSDNShortId = "NN:msrdc.ISimilarityTraitsTable")]
[ComImport, Guid("96236A7E-9DBC-11DA-9E3F-0011114AE311"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(SimilarityTraitsTable))]
public interface ISimilarityTraitsTable
{
/// Creates or opens a similarity traits table.
///
/// A pointer to a null-terminated string that specifies the name of the file that will contain the similarity traits table. The
/// alternate stream name ":Traits" will be appended to the end of this file name. For more information, see Naming a File.
///
///
/// TRUE if a new similarity traits table should always be created or truncated. If FALSE is specified and the
/// table exists and is valid, it may be used; otherwise, if the table is not valid or does not exist, the existing table is overwritten.
///
///
/// A pointer to a security descriptor to use when opening the file. If this parameter is NULL, the file is assigned a
/// default security descriptor. The access control lists (ACL) in the file's default security descriptor are inherited from the
/// file's parent directory. For more information, see the lpSecurityAttributes parameter of the CreateFile function.
///
///
/// A pointer to a variable that receives an RdcCreatedTables enumeration value that describes the state of the similarity traits
/// table. If a new table is created, this variable receives RDCTABLE_New. If an existing table is used, this variable
/// receives RDCTABLE_Existing. If this method fails, this variable receives RDCTABLE_InvalidOrUnknown.
///
///
/// If an existing similarity traits table is being opened, the table must be valid. Otherwise, the existing table is
/// overwritten, even if FALSE is specified for the truncate parameter.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitstable-createtable HRESULT CreateTable( [in]
// wchar_t *path, [in] BOOL truncate, [in] BYTE *securityDescriptor, [out] RdcCreatedTables *isNew );
RdcCreatedTables CreateTable([MarshalAs(UnmanagedType.LPWStr)] string path, [MarshalAs(UnmanagedType.Bool)] bool truncate,
[In, Optional] PSECURITY_DESCRIPTOR securityDescriptor);
///
/// Creates or opens a similarity traits table using the RDC application's implementation of the ISimilarityTraitsMapping interface.
///
///
/// An ISimilarityTraitsMapping interface pointer initialized to write the similarity traits table to the file.
///
///
/// TRUE if a new similarity traits table should always be created or truncated. If FALSE is specified and the
/// table exists and is valid, it may be used; otherwise, if the table is not valid or does not exist, the existing table is overwritten.
///
///
/// A pointer to a variable that receives an RdcCreatedTables enumeration value that describes the state of the similarity traits
/// table. If a new table is created, this variable receives RDCTABLE_New. If an existing table is used, this variable
/// receives RDCTABLE_Existing. If this method fails, this variable receives RDCTABLE_InvalidOrUnknown.
///
///
/// If an existing similarity traits table is being opened, the table must be valid. Otherwise, the existing table is
/// overwritten, even if FALSE is specified for the truncate parameter.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitstable-createtableindirect HRESULT
// CreateTableIndirect( [in] ISimilarityTraitsMapping *mapping, [in] BOOL truncate, [out] RdcCreatedTables *isNew );
RdcCreatedTables CreateTableIndirect([In] ISimilarityTraitsMapping mapping, [MarshalAs(UnmanagedType.Bool)] bool truncate);
/// Closes a similarity traits table.
/// FALSE if the similarity traits table should be deleted when it is closed; otherwise, TRUE.
///
///
/// If FALSE is specified for the isValid parameter, only the table is deleted; the similarity file is not deleted.
/// The caller is responsible for deleting the similarity file.
///
/// When the CloseTable method returns, the table is always closed, even if this method returns an error code.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitstable-closetable HRESULT CloseTable( [in]
// BOOL isValid );
void CloseTable([MarshalAs(UnmanagedType.Bool)] bool isValid);
/// Adds a SimilarityData structure to the similarity traits table.
/// The SimilarityData structure to be added to the similarity traits table.
/// The index in the similarity traits table where the SimilarityData structure is to be inserted.
///
/// The application must supply fileIndex values that are greater than zero and are always increasing. Otherwise, this
/// method returns the E_INVALIDARG error code.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitstable-append HRESULT Append( [in]
// SimilarityData *data, [in] SimilarityFileIndexT fileIndex );
void Append(in SimilarityData data, uint fileIndex);
///
/// Returns a list of files that are similar to a given file. The results in the list are sorted in order of similarity,
/// beginning with the most similar file.
///
/// A pointer to a SimilarityData structure that contains similarity information for the file.
/// TBD
///
/// A pointer to a buffer that receives an array of FindSimilarFileIndexResults structures that contain the requested information.
///
///
/// The number of FindSimilarFileIndexResults structures that can be stored in the buffer that the
/// findSimilarFileIndexResults parameter points to.
///
///
/// The number of FindSimilarFileIndexResults structures that were returned in the buffer that the
/// findSimilarFileIndexResults parameter points to.
///
///
/// The list of files that is returned in the findSimilarFileIndexResults parameter may include files that have been deleted.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitstable-findsimilarfileindex HRESULT
// FindSimilarFileIndex( [in] SimilarityData *similarityData, USHORT numberOfMatchesRequired, [out] FindSimilarFileIndexResults
// *findSimilarFileIndexResults, [in] DWORD resultsSize, [out] DWORD *resultsUsed );
void FindSimilarFileIndex(in SimilarityData similarityData, ushort numberOfMatchesRequired,
out FindSimilarFileIndexResults findSimilarFileIndexResults, uint resultsSize, out uint resultsUsed);
/// Retrieves similarity data from the similarity traits table.
///
/// An optional pointer to a location that will receive the returned ISimilarityTableDumpState interface pointer. The caller must
/// release this interface when it is no longer needed.
///
///
/// The BeginDump method is used for debugging and garbage collection. It returns an interface pointer to an iterator
/// object that allows the application to efficiently dump all of the entries in the similarity traits table.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitstable-begindump HRESULT BeginDump( [out,
// optional] ISimilarityTableDumpState **similarityTableDumpState );
ISimilarityTableDumpState? BeginDump();
/// Retrieves the index of the last entry that was stored in the similarity traits table.
/// A pointer to a variable that receives the index of the last entry.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/nf-msrdc-isimilaritytraitstable-getlastindex HRESULT GetLastIndex(
// [out] SimilarityFileIndexT *fileIndex );
uint GetLastIndex();
}
///
/// Contains the file index information that the ISimilarityTraitsTable::FindSimilarFileIndex method returned for a matching file.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ns-msrdc-findsimilarfileindexresults typedef struct
// __MIDL___MIDL_itf_msrdc_0000_0000_0013 { SimilarityFileIndexT m_FileIndex; unsigned int m_MatchCount; } FindSimilarFileIndexResults;
[PInvokeData("msrdc.h", MSDNShortId = "NS:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0013")]
[StructLayout(LayoutKind.Sequential)]
public struct FindSimilarFileIndexResults
{
/// The index of the matching file in the similarity traits table.
public uint m_FileIndex;
/// The number of traits that were matched. The valid range is from MSRDC_MINIMUM_MATCHESREQUIRED to MSRDC_MAXIMUM_MATCHESREQUIRED.
public uint m_MatchCount;
}
/// The RdcBufferPointer structure describes a buffer.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ns-msrdc-rdcbufferpointer typedef struct
// __MIDL___MIDL_itf_msrdc_0000_0000_0005 { ULONG m_Size; ULONG m_Used; BYTE *m_Data; } RdcBufferPointer;
[PInvokeData("msrdc.h", MSDNShortId = "NS:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0005")]
[StructLayout(LayoutKind.Sequential)]
public struct RdcBufferPointer
{
/// Size, in bytes, of the buffer.
public uint m_Size;
///
/// For input buffers, IRdcComparator::Process and IRdcGenerator::Process will store here how much (if any) of the buffer was
/// used during processing.
///
public uint m_Used;
/// Pointer to the buffer.
public IntPtr m_Data;
}
/// The RdcNeed structure contains information about a chunk that is required to synchronize two sets of data.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ns-msrdc-rdcneed typedef struct __MIDL___MIDL_itf_msrdc_0000_0000_0004 {
// RdcNeedType m_BlockType; unsigned __int64 m_FileOffset; unsigned __int64 m_BlockLength; } RdcNeed;
[PInvokeData("msrdc.h", MSDNShortId = "NS:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0004")]
[StructLayout(LayoutKind.Sequential)]
public struct RdcNeed
{
/// Describes the type of data needed—source data or seed data.
public RdcNeedType m_BlockType;
/// Offset, in bytes, from the start of the data where the chunk should be copied from.
public ulong m_FileOffset;
/// Length, in bytes, of the chunk of data that is to be copied to the target data.
public ulong m_BlockLength;
}
///
/// The RdcNeedPointer structure describes an array of RdcNeed structures. The RdcNeedPointer structure is used as both
/// input and output by the IRdcComparator::Process method.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ns-msrdc-rdcneedpointer typedef struct
// __MIDL___MIDL_itf_msrdc_0000_0000_0006 { ULONG m_Size; ULONG m_Used; RdcNeed *m_Data; } RdcNeedPointer;
[PInvokeData("msrdc.h", MSDNShortId = "NS:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0006")]
[StructLayout(LayoutKind.Sequential)]
public struct RdcNeedPointer
{
/// Contains the number of RdcNeed structures in array pointed to by m_Data.
public uint m_Size;
///
/// When the structure is passed to the IRdcComparator::Process method, this member should be zero. On return this member will
/// contain the number of RdcNeed structures that were filled with data.
///
public uint m_Used;
///
/// Address of array of structures that describe the chunks required from the source and seed data.
///
public IntPtr m_Data;
/// Array of structures that describe the chunks required from the source and seed data.
public SafeNativeArray Data { get => new(m_Data, (int)m_Size, false); set => m_Data = value; }
}
/// The RdcSignature structure contains a single signature and the length of the chunk used to generate it.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ns-msrdc-rdcsignature typedef struct
// __MIDL___MIDL_itf_msrdc_0000_0000_0007 { BYTE m_Signature[16]; USHORT m_BlockLength; } RdcSignature;
[PInvokeData("msrdc.h", MSDNShortId = "NS:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0007")]
[StructLayout(LayoutKind.Sequential)]
public struct RdcSignature
{
/// Signature of a chunk of data.
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] m_Signature;
/// Length of the chunk represented by this signature.
public ushort m_BlockLength;
}
///
/// The RdcSignaturePointer structure describes an array of RdcSignature structures. The RdcSignaturePointer structure
/// is used as both input and output by the IRdcSignatureReader::ReadSignatures method.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ns-msrdc-rdcsignaturepointer typedef struct
// __MIDL___MIDL_itf_msrdc_0000_0000_0008 { ULONG m_Size; ULONG m_Used; RdcSignature *m_Data; } RdcSignaturePointer;
[PInvokeData("msrdc.h", MSDNShortId = "NS:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0008")]
[StructLayout(LayoutKind.Sequential)]
public struct RdcSignaturePointer
{
/// Contains the number of RdcSignature structures in array pointed to by m_Data.
public uint m_Size;
///
/// When the structure is passed to the IRdcSignatureReader::ReadSignatures method, this member should be zero. On return this
/// member will contain the number of RdcSignature structures that were filled.
///
public uint m_Used;
/// Address of an array of structures.
public IntPtr m_Data;
/// An array of structures.
public SafeNativeArray Data { get => new(m_Data, (int)m_Size, false); set => m_Data = value; }
}
/// Contains the similarity data for a file.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ns-msrdc-similaritydata typedef struct
// __MIDL___MIDL_itf_msrdc_0000_0000_0012 { unsigned char m_Data[16]; } SimilarityData;
[PInvokeData("msrdc.h", MSDNShortId = "NS:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0012")]
[StructLayout(LayoutKind.Sequential)]
public struct SimilarityData
{
/// The similarity data for the file.
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] m_Data;
}
/// Contains the similarity information that was returned for a file by the ISimilarityTableDumpState::GetNextData method.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ns-msrdc-similaritydumpdata typedef struct
// __MIDL___MIDL_itf_msrdc_0000_0000_0014 { SimilarityFileIndexT m_FileIndex; SimilarityData m_Data; } SimilarityDumpData;
[PInvokeData("msrdc.h", MSDNShortId = "NS:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0014")]
[StructLayout(LayoutKind.Sequential)]
public struct SimilarityDumpData
{
/// The index of the SimilarityData structure in the similarity traits table.
public uint m_FileIndex;
/// A SimilarityData structure that contains the similarity data for the file.
public SimilarityData m_Data;
}
/// Contains the similarity file ID for a file.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ns-msrdc-similarityfileid typedef struct
// __MIDL___MIDL_itf_msrdc_0000_0000_0015 { byte m_FileId[32]; } SimilarityFileId;
[PInvokeData("msrdc.h", MSDNShortId = "NS:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0015")]
[StructLayout(LayoutKind.Sequential)]
public struct SimilarityFileId
{
/// The similarity file ID for the file.
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] m_FileId;
}
/// Contains information about a similarity mapped view.
// https://docs.microsoft.com/en-us/windows/win32/api/msrdc/ns-msrdc-similaritymappedviewinfo typedef struct
// __MIDL___MIDL_itf_msrdc_0000_0000_0011 { unsigned char *m_Data; DWORD m_Length; } SimilarityMappedViewInfo;
[PInvokeData("msrdc.h", MSDNShortId = "NS:msrdc.__MIDL___MIDL_itf_msrdc_0000_0000_0011")]
[StructLayout(LayoutKind.Sequential)]
public struct SimilarityMappedViewInfo
{
/// The mapped view information.
public IntPtr m_Data;
/// Size, in bytes, of the mapped view information.
public uint m_Length;
}
/// CLSID_FindSimilarResults
[ComImport, Guid("96236A93-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class FindSimilarResults { }
/// CLSID_RdcComparator
[ComImport, Guid("96236A8B-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class RdcComparator { }
/// CLSID_RdcFileReader
[ComImport, Guid("96236A89-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class RdcFileReader { }
/// CLSID_RdcGenerator
[ComImport, Guid("96236A88-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class RdcGenerator { }
/// CLSID_RdcGeneratorFilterMaxParameters
[ComImport, Guid("96236A87-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class RdcGeneratorFilterMaxParameters { }
/// CLSID_RdcGeneratorParameters
[ComImport, Guid("96236A86-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class RdcGeneratorParameters { }
/// CLSID_RdcGenerator
[ComImport, Guid("96236A85-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class RdcLibrary { }
/// CLSID_RdcSignatureReader
[ComImport, Guid("96236A8A-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class RdcSignatureReader { }
/// CLSID_RdcSimilarityGenerator
[ComImport, Guid("96236A92-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class RdcSimilarityGenerator { }
/// An implementation of on top of a .
///
[ComVisible(true), Guid("01EED492-3E92-4DF1-AC94-A7CDD0F23699"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class RdcStreamReader : IRdcFileReader
{
private readonly Stream stream;
/// Initializes a new instance of the class with stream to read.
/// The stream to read from.
public RdcStreamReader(Stream stream) => this.stream = stream;
HRESULT IRdcFileReader.GetFilePosition(out ulong offsetFromStart)
{
offsetFromStart = (uint)stream.Position;
return HRESULT.S_OK;
}
HRESULT IRdcFileReader.GetFileSize(out ulong fileSize)
{
fileSize = (ulong)stream.Length;
return HRESULT.S_OK;
}
HRESULT IRdcFileReader.Read(ulong offsetFileStart, uint bytesToRead, out uint bytesActuallyRead, byte[] buffer, out bool eof)
{
if (stream.Position != (long)offsetFileStart)
{
stream.Seek((long)offsetFileStart, SeekOrigin.Begin);
}
var intBuff = new byte[bytesToRead];
int read = 0, lastRead;
do
{
lastRead = stream.Read(intBuff, read, ((int)bytesToRead - read));
read += lastRead;
} while (lastRead != 0 && read < bytesToRead);
bytesActuallyRead = (uint)read;
Array.Copy(intBuff, buffer, (int)bytesToRead);
eof = read < bytesToRead;
return HRESULT.S_OK;
}
}
/// CLSID_Similarity
[ComImport, Guid("96236A91-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class Similarity { }
/// CLSID_SimilarityFileIdTable
[ComImport, Guid("96236A90-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class SimilarityFileIdTable { }
/// CLSID_SimilarityReportProgress
[ComImport, Guid("96236A8D-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class SimilarityReportProgress { }
/// CLSID_SimilarityTableDumpState
[ComImport, Guid("96236A8E-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class SimilarityTableDumpState { }
/// CLSID_SimilarityTraitsMappedView
[ComImport, Guid("96236A95-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class SimilarityTraitsMappedView { }
/// CLSID_SimilarityTraitsMapping
[ComImport, Guid("96236A94-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class SimilarityTraitsMapping { }
/// CLSID_SimilarityTraitsTable
[ComImport, Guid("96236A8F-9DBC-11DA-9E3F-0011114AE311"), ClassInterface(ClassInterfaceType.None)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
public class SimilarityTraitsTable { }
}