Rhino C++ API  7.21
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
ON_ContentHash Class Reference

#include <opennurbs_file_utilities.h>

Public Types

enum  CompareResult : unsigned char {
  CompareResult::Unset = 0, CompareResult::EqualContent = 1, CompareResult::DifferentContent = 2, CompareResult::DifferentContentFileIsOlder = 3,
  CompareResult::ContentDifferentFileIsNewer = 4, CompareResult::FileDoesNotExist = 5, CompareResult::FileSystemFailure = 6
}
 ON_ContentHash::Compare are the possible results of calling ON_ContentHash::CompareFile(). More...
 

Public Member Functions

 ON_ContentHash ()=default
 
 ON_ContentHash (const ON_ContentHash &)=default
 
 ~ON_ContentHash ()=default
 
ON__UINT64 ByteCount () const
 
ON_ContentHash::CompareResult Compare (const wchar_t *file_path, bool bFastTest) const
 
ON_ContentHash::CompareResult Compare (ON_ContentHash file_content_hash) const
 
ON_SHA1_Hash ContentHash () const
 
ON__UINT64 ContentLastModifiedTime () const
 
void Dump (class ON_TextLog &text_log) const
 
bool EqualFileNameSizeAndTime (const wchar_t *filename) const
 
ON__UINT64 HashCalculationTime () const
 
bool IsNotSet () const
 
bool IsSameBufferContent (const void *buffer, size_t byte_count) const
 
bool IsSameFileContent (const char *filename) const
 
bool IsSameFileContent (const wchar_t *filename) const
 
bool IsSameFileContent (FILE *fp) const
 
bool IsSet () const
 
ON_SHA1_Hash NameHash () const
 
ON_ContentHashoperator= (const ON_ContentHash &)=default
 
bool Read (class ON_BinaryArchive &archive)
 
bool Write (class ON_BinaryArchive &archive) const
 

Static Public Member Functions

static int Compare (const ON_ContentHash &a, const ON_ContentHash &b)
 
static int CompareContent (const ON_ContentHash &a, const ON_ContentHash &b)
 
static ON_ContentHash::CompareResult CompareResultFromUnsigned (unsigned int compare_result_as_unsigned)
 
static ON_ContentHash Create (ON_SHA1_Hash sha1_name_hash, ON__UINT64 byte_count, ON_SHA1_Hash sha1_content_hash, ON__UINT64 hash_time, ON__UINT64 content_last_modified_time)
 
static ON_ContentHash CreateFromBuffer (ON_SHA1_Hash sha1_name_hash, const void *buffer, size_t byte_count)
 
static ON_ContentHash CreateFromFile (const char *filename)
 
static ON_ContentHash CreateFromFile (const wchar_t *filename)
 
static ON_ContentHash CreateFromFile (ON_SHA1_Hash sha1_file_name_hash, FILE *fp)
 
static bool DifferentContent (const ON_ContentHash &a, const ON_ContentHash &b)
 
static bool EqualContent (const ON_ContentHash &a, const ON_ContentHash &b)
 

Static Public Attributes

static const ON_ContentHash Unset
 

Member Enumeration Documentation

◆ CompareResult

enum ON_ContentHash::CompareResult : unsigned char
strong

ON_ContentHash::Compare are the possible results of calling ON_ContentHash::CompareFile().

Enumerator
Unset 

Not set. This value is never returned by ON_ContentHash::CheckFile().

EqualContent 

File exists and its size and content matches the information used to set the content hash.

DifferentContent 

File exists and its size or content differs from the information used to set the content hash. Unable to reliably determine which is newer.

DifferentContentFileIsOlder 

File exists and its size or content differs from the information used to set the content hash. The file's laste modified time is older than ContentLastModifiedTime().

ContentDifferentFileIsNewer 

File exists and its size or content differs from the information used to set the content hash. The file's last modified time is newer than ContentLastModifiedTime().

FileDoesNotExist 

File does not exist.

FileSystemFailure 

File cannot be opened, read, or some other file system issue prevents checking.

Constructor & Destructor Documentation

◆ ON_ContentHash() [1/2]

ON_ContentHash::ON_ContentHash ( )
default

◆ ~ON_ContentHash()

ON_ContentHash::~ON_ContentHash ( )
default

◆ ON_ContentHash() [2/2]

ON_ContentHash::ON_ContentHash ( const ON_ContentHash )
default

Member Function Documentation

◆ ByteCount()

ON__UINT64 ON_ContentHash::ByteCount ( ) const

Returns: Number of bytes in the content (typically a file or buffer).

◆ Compare() [1/3]

static int ON_ContentHash::Compare ( const ON_ContentHash a,
const ON_ContentHash b 
)
static

Description: Compares all fields

◆ Compare() [2/3]

ON_ContentHash::CompareResult ON_ContentHash::Compare ( const wchar_t *  file_path,
bool  bFastTest 
) const

Description: Compare the information used to set this content hash with the contents of the file. Parameters: file_path - [in] bFastCompare - [in] If bFastCompare is true and the file_path, create time, last modified time, and size exactly match the values in ON_ContentHash, then ON_ContentHash::CompareResult::EqualContent is returned without performing the expensive SHA1 test on the file's content. If bFastCompare is false, the SHA-1 hash of the file's content will be calculated and compared before ON_ContentHash::CompareResult::EqualContent is returned. Returns: Result of compare test as a ON_ContentHash::CompareResult enum. ON_ContentHash::CompareResult::DifferentContentFileIsOlder means file_path content is different and older than "this". ON_ContentHash::CompareResult::DifferentContentFileIsNewer means file_path content is different and newer than "this".

◆ Compare() [3/3]

ON_ContentHash::CompareResult ON_ContentHash::Compare ( ON_ContentHash  file_content_hash) const

Description: Compare the byte count and SHA-1 content hash. Parameters: file_content_hash - [in] ON_ContentHash to compare against this one. Returns: Result of compare test as a ON_ContentHash::CompareResult enum. ON_ContentHash::CompareResult::DifferentContentFileIsOlder means file_content_hash is different and older than "this". ON_ContentHash::CompareResult::DifferentContentFileIsNewer means file_content_hash is different and newer than "this".

◆ CompareContent()

static int ON_ContentHash::CompareContent ( const ON_ContentHash a,
const ON_ContentHash b 
)
static

Description: Compares content byte count and content SHA-1

◆ CompareResultFromUnsigned()

static ON_ContentHash::CompareResult ON_ContentHash::CompareResultFromUnsigned ( unsigned int  compare_result_as_unsigned)
static

◆ ContentHash()

ON_SHA1_Hash ON_ContentHash::ContentHash ( ) const

Returns: SHA-1 hash of the content (typically a buffer or file).

◆ ContentLastModifiedTime()

ON__UINT64 ON_ContentHash::ContentLastModifiedTime ( ) const

Returns: Time the hashed content was last modifed in seconds since January 1, 1970 UCT. 0 is returned if this time is not known.

This time should be used for important decisions as a last resort.

When hash values differ, this time may be considered to which content is newer (or most recently copied).

Unfortunately, in many cases this time is often unknown and incorrectly set. For example, some file systems set the last modified time of a copy of an "old" file to the time the copy was created. Thus a copy of "old" content may appear to be newer than "new" content that has not been copied.

◆ Create()

static ON_ContentHash ON_ContentHash::Create ( ON_SHA1_Hash  sha1_name_hash,
ON__UINT64  byte_count,
ON_SHA1_Hash  sha1_content_hash,
ON__UINT64  hash_time,
ON__UINT64  content_last_modified_time 
)
static

Descripton: Create an ON_ContentHash class with the specified size, hash and times. Parameters: sha1_name_hash - [in] The SHA-1 hash of the name (typically a full path file name). When the content is identified by a file name in a file system, use ON_SHA1_Hash::FileSystemPathHash() to calculate this value. byte_count - [in] number of bytes in the content. sha1_content_hash - [in] The SHA-1 hash of the content (typically a buffer or file). You may use ON_SHA1_Has::FileContentHash() or ON_SHA1_Hash::BufferContentHash() to calculate this value. hash_time - [in] The time the sha1_hash was calculated in seconds since January 1, 1970 UCT. If 0 is passed in, the current time is used. content_last_modified_time - [in] Pass 0 if not known. The time the hashed information that was last modifed in seconds since January 1, 1970 UCT. If content_last_modified_time > hash_time, then 0 is used. Returns: An ON_ContentHash with size and SHA-1 hash and times set from the parameters,

◆ CreateFromBuffer()

static ON_ContentHash ON_ContentHash::CreateFromBuffer ( ON_SHA1_Hash  sha1_name_hash,
const void *  buffer,
size_t  byte_count 
)
static

Descripton: Create an ON_ContentHash from a memory buffer. Parameters: sha1_name_hash - [in] A SHA-1 hash of the name associated with this content. If the buffer has no name, pass ON_SHA1_Hash::ZeroDigest. If the buffer has an empty name, pass ON_SHA1_Hash::EmptyContentHash. buffer - [in]
byte_count - [in] number of bytes in buffer[] Returns: An ON_ContentHash with size and SHA-1 hash calculated from the parameters, hash time = now, and content last modified time = 0.

◆ CreateFromFile() [1/3]

static ON_ContentHash ON_ContentHash::CreateFromFile ( const char *  filename)
static

◆ CreateFromFile() [2/3]

static ON_ContentHash ON_ContentHash::CreateFromFile ( const wchar_t *  filename)
static

Descripton: Create an ON_ContentHash from a file stream. Parameters: filename - [in] name of file. Returns: An ON_ContentHash with size and SHA-1 hash and times set from the file, hash time = now, and content last modifed time set from the file system information returned by ON_FileStream::GetFileInformation().

◆ CreateFromFile() [3/3]

static ON_ContentHash ON_ContentHash::CreateFromFile ( ON_SHA1_Hash  sha1_file_name_hash,
FILE *  fp 
)
static

Descripton: Create an ON_ContentHash from a file stream. Parameters: sha1_file_name_hash - [in] A SHA-1 hash of the file name associated with fp. Use ON_SHA1_Has::FileSystemPathHash() to create the value. If the name is not known, pass ON_SHA1_Hash::ZeroDigest. fp - [in] pointer to a file opened with ON:FileOpen(...,"rb") Returns: An ON_ContentHash with size and SHA-1 hash and times set from the file, hash time = now, and content last modifed time set from the file system information returned by ON_FileStream::GetFileInformation().

◆ DifferentContent()

static bool ON_ContentHash::DifferentContent ( const ON_ContentHash a,
const ON_ContentHash b 
)
static

Returns: true if a and b have differnt ByteCount() or SHA-1 content hash values.

◆ Dump()

void ON_ContentHash::Dump ( class ON_TextLog text_log) const

◆ EqualContent()

static bool ON_ContentHash::EqualContent ( const ON_ContentHash a,
const ON_ContentHash b 
)
static

Returns: true if a and b have identical ByteCount() and SHA-1 content hash values.

◆ EqualFileNameSizeAndTime()

bool ON_ContentHash::EqualFileNameSizeAndTime ( const wchar_t *  filename) const

Parameters: filename - [in] Returns: True if the file exists, has size > 0, has the same name, same size, and same last modified time than this content hash. False otherwise. Remarks: Faster than the ON_ContentHash::EqualContent() and reliable if this content hash was set on the same file system. Unreliable if the file system does not correctly set last modified times or the file was modified less than 2 seconds before the call.

◆ HashCalculationTime()

ON__UINT64 ON_ContentHash::HashCalculationTime ( ) const

Returns: Time the hash SHA-1 hash was cacluated in seconds since January 1, 1970 UCT.

◆ IsNotSet()

bool ON_ContentHash::IsNotSet ( ) const

Returns: True if the SHA-1 hash is not set.

◆ IsSameBufferContent()

bool ON_ContentHash::IsSameBufferContent ( const void *  buffer,
size_t  byte_count 
) const

Description: Test a buffer to see if it has a matching size and SHA-1 hash. Parameters: buffer - [in]
byte_count - [in] number of bytes in buffer[] Returns: True if the buffer has a matching byte_count and SHA-1 hash.

◆ IsSameFileContent() [1/3]

bool ON_ContentHash::IsSameFileContent ( const char *  filename) const

◆ IsSameFileContent() [2/3]

bool ON_ContentHash::IsSameFileContent ( const wchar_t *  filename) const

Description: Test a file to see if it has a matching size and SHA-1 content hash. Paramters: filename - [in] Returns: True if the file exists, can be read, and has a matching byte_count and SHA-1 content hash.

◆ IsSameFileContent() [3/3]

bool ON_ContentHash::IsSameFileContent ( FILE *  fp) const

Description: Test a file to see if it has a matching size and SHA-1 hash. Paramters: fp - [in] pointer to file opened with ON::OpenFile(...,"rb") bSkipTimeCheck - [in] if true, the time of last modification is not checked. Returns: True if the file existes, can be read, and has a matching byte_count and SHA-1 hash.

◆ IsSet()

bool ON_ContentHash::IsSet ( ) const

Returns: True if the SHA-1 hash has been set.

◆ NameHash()

ON_SHA1_Hash ON_ContentHash::NameHash ( ) const

Returns: SHA-1 hash of the name (typically a full path file name).

◆ operator=()

ON_ContentHash& ON_ContentHash::operator= ( const ON_ContentHash )
default

◆ Read()

bool ON_ContentHash::Read ( class ON_BinaryArchive archive)

◆ Write()

bool ON_ContentHash::Write ( class ON_BinaryArchive archive) const

Member Data Documentation

◆ Unset

const ON_ContentHash ON_ContentHash::Unset
static