Files
dnf-utils/libnpk/libNPK_Utils.h
T
2025-09-03 09:34:30 +08:00

43 lines
1.6 KiB
C++

#pragma once
#include <string>
// Convert a size in bytes to a human-readable string
std::string sizeToString(int64_t size);
// Convert a size string (e.g., "10k", "5M", "2G") to an integer size in bytes
int64_t sizeFromString(const char* sizeStr);
// Compare two file names, considering both long and short paths
int compareTwoFileName(const char* szFileName1, const char* szFileName2);
// Convert a standard ANSI string to a wide string (UTF-16)
std::wstring convertAnsiStringToWide(const char* szSource);
// Convert a wide string(UTF-16) to utf8 string
std::string convertWideStringToUtf8(const wchar_t* source);
// Convert a utf8 string to wide string(UTF-16)
std::wstring convertUtf8StringToWide(const char* szSource);
// Read a file into a buffer and return the buffer pointer.
uint8_t* readFileToBuffer(const char* filename, int64_t& outSize);
// Free the file buffer allocated by readFileToBuffer
void freeFileBuffer(uint8_t* buffer);
// Clears the specified path by deleting all files and optionally removing the directory itself.
bool clearPath(const wchar_t* szPath, bool recursion, bool removeSelf);
//Creates an empty directory at the specified path. If the path already exists and is a directory, clears its contents.
bool createEmptyPath(const wchar_t* szPath);
// Force create a directory path, ensuring all parent directories are created as needed.
bool forceCreatePath(const wchar_t* szPath);
// Force create a directory path for the file
bool forceCreatePathForFile(const wchar_t* szFilePath);
// Get the parent directory path of the specified path.
void getParentPath(wchar_t* szPath);