45 lines
1.6 KiB
C
45 lines
1.6 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <string>
|
||
|
|
|
||
|
|
namespace Md5Utils {
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Compute MD5 hash of a file, reading in chunks to avoid memory issues.
|
||
|
|
* @param filePath Path to the file on SD card
|
||
|
|
* @return MD5 hash as lowercase hex string, or empty string on error
|
||
|
|
*/
|
||
|
|
std::string computeFileMd5(const std::string& filePath);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get cached MD5 for a book file.
|
||
|
|
* Validates that the cached hash was computed for the current file size.
|
||
|
|
* @param bookPath Full path to the book file (e.g., "/Books/mybook.epub")
|
||
|
|
* @param cacheDir The .crosspoint cache directory (e.g., "/.crosspoint")
|
||
|
|
* @param currentFileSize Current size of the book file for validation
|
||
|
|
* @return Cached MD5 hash, or empty string if not cached or invalid
|
||
|
|
*/
|
||
|
|
std::string getCachedMd5(const std::string& bookPath, const std::string& cacheDir, size_t currentFileSize);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Cache MD5 hash for a book file.
|
||
|
|
* Stores the hash along with the file size for later validation.
|
||
|
|
* @param bookPath Full path to the book file
|
||
|
|
* @param cacheDir The .crosspoint cache directory
|
||
|
|
* @param md5 The MD5 hash to cache
|
||
|
|
* @param fileSize The file size when hash was computed
|
||
|
|
* @return true if successfully cached
|
||
|
|
*/
|
||
|
|
bool cacheMd5(const std::string& bookPath, const std::string& cacheDir, const std::string& md5, size_t fileSize);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Compute and cache MD5 hash for a book file.
|
||
|
|
* Combines computeFileMd5 and cacheMd5 into a single operation.
|
||
|
|
* @param bookPath Full path to the book file
|
||
|
|
* @param cacheDir The .crosspoint cache directory
|
||
|
|
* @return MD5 hash as lowercase hex string, or empty string on error
|
||
|
|
*/
|
||
|
|
std::string computeAndCacheMd5(const std::string& bookPath, const std::string& cacheDir);
|
||
|
|
|
||
|
|
} // namespace Md5Utils
|