PMT Renovated main-branch
Partition Manager Tool is a fast, reliable, and feature-rich CLI application for Android devices that enables advanced partition operations such as backup, flashing, erasing, information retrieval, and more.
Loading...
Searching...
No Matches
Helper Namespace Reference

Main namespace of libhelper library. More...

Classes

class  AsyncManager
 A simple class for easily managing asynchronous operations. More...
 
class  BasicUniqueFD
 A class that helps with easy file descriptor management. More...
 
class  BasicUniqueFP
 A class that helps with easy file pointer management. More...
 
class  Capsule
 A "capsule" class that stores references. More...
 
struct  CleanupTraits
 It offers a ready-made cleanup() function. It is used by other classes. The default defination takes the type pointer and clears it with delete. More...
 
struct  CleanupTraits< DIR >
 
struct  CleanupTraits< FILE >
 
struct  CleanupTraits< T[]>
 
class  Closer
 Valid file descriptor, file pointer and directory pointer closer class structure. Used by default. More...
 
struct  ConstIfCharPointer
 Add the const qualifier if input type is char*. More...
 
struct  DeepConst
 Add the const qualifier to the input type. More...
 
class  Error
 A modern, throwable error class. It provides the << operator and offers usage in the std::print style of modern C++23. More...
 
class  Logger
 Modern, functional logger class. More...
 
class  PureTuple
 A class that stores tuple data in a list. More...
 
class  Random
 Generate random numbers with std::mt19937. More...
 
class  ScopeGuard
 When an object created within a given scope leaves that scope, the corresponding input function is executed. More...
 
class  Silencer
 Silence stdout and stderr. More...
 

Concepts

concept  HasCStrFunction
 Checks whether the input type provides a c_str() member function.
 
concept  Invocable
 Checks whether the input is invocable and returns requested type.
 
concept  PointerDeletable
 The deletionability of the entry is checked using the delete key. Only for pointers/classes! This check is performed using CleanupTraits. It is used by other classes.
 
concept  ArrayDeletable
 The deletionability of the entry is checked using the delete key. Only for arrays! This check is performed using CleanupTraits. It is used by other classes.
 
concept  Deletable
 The deletionability of the entry is checked using the delete key. This check is performed using CleanupTraits. It is used by other classes.
 
concept  IsCloser
 Checks if the input class can close the needed thing, either as a operator() or using the close() function.
 
concept  IsFullCloser
 Checks if the input class can close the needed thing, either as a operator() and using the close() function.
 
concept  IsCloserWithOperator
 Check the ownership of operator() in the closer class.
 
concept  IsCloserWithFunction
 Check the ownership of close() in the closer class.
 

Typedefs

using UniqueFD = BasicUniqueFD< Closer >
 
using UniqueFP = BasicUniqueFP< Closer >
 

Enumerations

enum  LogLevels { INFO = static_cast<int>('I') , WARNING = static_cast<int>('W') , ERROR = static_cast<int>('E') , ABORT = static_cast<int>('A') }
 Logging levels.
 

Functions

template<typename PathType >
bool isExists (PathType &&entry)
 Checks whether the file/directory exists.
 
template<typename PathType >
bool fileIsExists (PathType &&file)
 Checks whether the file exists.
 
template<typename PathType >
bool directoryIsExists (PathType &&path)
 Checks whether the directory exists.
 
template<typename PathType >
bool isLink (PathType &&entry)
 Checks if the entry is a symbolic link.
 
template<typename PathType >
bool isSymbolicLink (PathType &&entry)
 Checks if the entry is a symbolic link.
 
template<typename PathType >
bool isHardLink (PathType &&entry)
 Checks if the entry is a hard link.
 
template<typename PathType >
bool linkIsExists (PathType &&entry)
 Checks whether the link (symbolic or hard) exists.
 
template<typename PathType , typename StringType = std::string>
bool writeFile (PathType &&file, StringType &&text)
 Writes given text into file. If file does not exist, it is automatically created.
 
template<typename PathType , typename StringType = std::string>
std::optional< ConstIfCharPointer_t< StringType > > readFile (PathType &&file)
 Reads file content into string.
 
template<typename PathType >
bool copyFile (PathType &&file, PathType &&dest)
 Copy file to destination.
 
bool makeDirectory (const std::filesystem::path &path)
 Create directory.
 
bool makeRecursiveDirectory (const std::filesystem::path &paths)
 Create recursive directory.
 
bool createFile (const std::filesystem::path &path)
 Create file.
 
bool createSymlink (const std::filesystem::path &entry1, const std::filesystem::path &entry2)
 Symlink entries.
 
bool eraseEntry (const std::filesystem::path &entry)
 Remove file or empty directory.
 
bool eraseDirectoryRecursive (const std::filesystem::path &directory)
 Remove directory and all directory contents recursively.
 
template<typename ReturnType = int64_t>
requires std::is_integral_v<ReturnType>
ReturnType fileSize (const std::filesystem::path &file)
 Get file size.
 
std::string readSymlink (const std::filesystem::path &entry)
 Read symlinks.
 
bool areLinked (const std::filesystem::path &entry1, const std::filesystem::path &entry2)
 It checks if the two entries are linked.
 
bool sha256Compare (const std::filesystem::path &file1, const std::filesystem::path &file2)
 Compare SHA-256 values of files.
 
std::optional< std::stringsha256Of (const std::filesystem::path &path)
 Get SHA-256 of file.
 
bool runCommand (const std::string &cmd)
 Run shell command.
 
bool confirmPropt (const std::string &message, int maxTries=10)
 Shows message and asks for y/N from user.
 
bool changeMode (const std::filesystem::path &file, mode_t mode)
 Changes file permissions.
 
bool changeOwner (const std::filesystem::path &file, uid_t uid, gid_t gid)
 Change file owner (user ID and group ID).
 
std::string currentWorkingDirectory ()
 Get current working directory as string.
 
std::string currentDate ()
 Get current date as string (format: YYYY-MM-DD).
 
std::string currentTime ()
 Get current time as string (format: HH:MM:SS).
 
template<typename ExitCodeType = int>
requires std::is_integral_v<ExitCodeType>
std::pair< std::string, ExitCodeType > runCommandWithOutput (const std::string &cmd)
 Run shell command return output as string.
 
std::filesystem::path pathJoin (std::filesystem::path base, const std::filesystem::path &relative)
 Joins base path with relative path and returns result.
 
std::filesystem::path pathBasename (const std::filesystem::path &entry)
 @briefGet the filename part of given path.
 
std::filesystem::path pathDirname (const std::filesystem::path &entry)
 Get the directory part of given path.
 
template<typename Ret = uint64_t, typename T = Ret>
requires std::is_integral_v<Ret> && std::is_integral_v<T> && std::is_unsigned_v<Ret> && std::is_unsigned_v<T>
Ret getRandomOffset (T &&size, T &&bufferSize)
 Get random offset depending on size and bufferSize.
 
template<typename Ret = int, typename SizeType = uint64_t>
requires std::is_integral_v<Ret> && std::is_integral_v<SizeType>
Ret convertTo (SizeType size, sizeCastTypes type)
 Convert input size to input multiple.
 
std::string multipleToString (sizeCastTypes type)
 Convert input multiple variable to string.
 
template<typename... Args>
std::string format (std::format_string< Args... > fmt, Args &&...args)
 Format it input and return as std::string.
 
template<uint64_t size>
int convertTo (const sizeCastTypes &type)
 Convert input size to input multiple.
 
std::string getLibVersion ()
 Get libhelper library version string.
 
template<std::invocable F>
static auto makeScopeGuard (F &&fn) noexcept
 Make scope guard with input function.
 
template<typename... Args>
requires (sizeof...(Args) >= 2)
auto openFd (Args &&...args) noexcept
 Open file (creates file descriptor).
 
template<typename... Args>
requires (sizeof...(Args) >= 2)
auto openFp (Args &&...args) noexcept
 Open file (creates file pointer).
 
template<typename... Args>
requires (sizeof...(Args) >= 1)
auto openDir (Args &&...args) noexcept
 Open directory.
 

Detailed Description

Main namespace of libhelper library.

Function Documentation

◆ convertTo() [1/2]

template<uint64_t size>
int Helper::convertTo ( const sizeCastTypes type)

Convert input size to input multiple.

Template Parameters
sizeSize.
Parameters
typeCast type.

◆ convertTo() [2/2]

template<typename Ret = int, typename SizeType = uint64_t>
requires std::is_integral_v<Ret> && std::is_integral_v<SizeType>
Ret Helper::convertTo ( SizeType  size,
sizeCastTypes  type 
)

Convert input size to input multiple.

Template Parameters
RetReturn type.
SizeTypeInput size type
Parameters
sizeSize.
typeCast type.

◆ copyFile()

template<typename PathType >
bool Helper::copyFile ( PathType &&  file,
PathType &&  dest 
)

Copy file to destination.

Parameters
fileFile path.
destDestination.

◆ currentDate()

std::string Helper::currentDate ( )

Get current date as string (format: YYYY-MM-DD).

Return values
Empty StringAn error occurred.

◆ currentTime()

std::string Helper::currentTime ( )

Get current time as string (format: HH:MM:SS).

Return values
Empty StringAn error occurred.

◆ currentWorkingDirectory()

std::string Helper::currentWorkingDirectory ( )

Get current working directory as string.

Return values
Empty StringAn error occurred.

◆ directoryIsExists()

template<typename PathType >
bool Helper::directoryIsExists ( PathType &&  path)

Checks whether the directory exists.

Parameters
pathDirectory path.

◆ fileIsExists()

template<typename PathType >
bool Helper::fileIsExists ( PathType &&  file)

Checks whether the file exists.

Parameters
fileFile path.

◆ fileSize()

template<typename ReturnType = int64_t>
requires std::is_integral_v<ReturnType>
ReturnType Helper::fileSize ( const std::filesystem::path file)

Get file size.

Template Parameters
ReturnTypeReturn type (default is int64_t ).
Parameters
fileFile path.

◆ isExists()

template<typename PathType >
bool Helper::isExists ( PathType &&  entry)

Checks whether the file/directory exists.

Parameters
entryFile/directory path.

◆ isHardLink()

template<typename PathType >
bool Helper::isHardLink ( PathType &&  entry)

Checks if the entry is a hard link.

Parameters
entryFile/directory path.

◆ isLink()

template<typename PathType >
bool Helper::isLink ( PathType &&  entry)

Checks if the entry is a symbolic link.

Parameters
entryFile/directory path.

◆ isSymbolicLink()

template<typename PathType >
bool Helper::isSymbolicLink ( PathType &&  entry)

Checks if the entry is a symbolic link.

Parameters
entryFİle/directory path.

◆ linkIsExists()

template<typename PathType >
bool Helper::linkIsExists ( PathType &&  entry)

Checks whether the link (symbolic or hard) exists.

Parameters
entryFile/directory path.

◆ makeScopeGuard()

template<std::invocable F>
static auto Helper::makeScopeGuard ( F &&  fn)
staticnoexcept

Make scope guard with input function.

Template Parameters
FFunction reference.
Parameters
fnFunction.
Returns
Helper::ScopeGuard

◆ readFile()

template<typename PathType , typename StringType = std::string>
std::optional< ConstIfCharPointer_t< StringType > > Helper::readFile ( PathType &&  file)

Reads file content into string.

On success, returns file content. On error, returns std::nullopt.

Template Parameters
StringTypeString type (default is std::string ).
Parameters
fileFile path.
Return values
std::nulloptError occurred.
StringTypeFile content.

◆ sha256Compare()

bool Helper::sha256Compare ( const std::filesystem::path file1,
const std::filesystem::path file2 
)

Compare SHA-256 values of files.

Parameters
file1First file path.
file2Second file path.
Exceptions
Helper::Error

◆ sha256Of()

std::optional< std::string > Helper::sha256Of ( const std::filesystem::path path)

Get SHA-256 of file.

Parameters
pathFile path.
Exceptions
Helper::Error

◆ writeFile()

template<typename PathType , typename StringType = std::string>
bool Helper::writeFile ( PathType &&  file,
StringType &&  text 
)

Writes given text into file. If file does not exist, it is automatically created.

Template Parameters
StringTypeString type (default is std::string ).
Parameters
fileFile path.
textText.