CFx SDK Documentation  2022 SP0
Functions
ZipUtils Namespace Reference

Functions

OdAnsiString OdStringToUtf8 (const OdString &sUnicode)
 
OdString formatPath (const OdString &path)
 
OdString formatDir (const OdString &dir)
 
bool containsDir (const OdString &dir)
 
bool isDir (const OdString &dir)
 
OdString getFileExtension (const OdString &path)
 
OdString getFile (const OdString &path)
 
OdString getDir (const OdString &path)
 
int createFile (const OdString &path, const char *data, unsigned int size)
 
int copyFile (const OdString &existingFileName, const OdString &newFileName)
 
int removeFile (const OdString &path)
 
bool dirExists (const OdString &dir)
 
int createDir (const OdString &dir)
 
int removeEmptyDir (const OdString &dir)
 
int removeDir (const OdString &dir)
 
OdStringArray getFileList (const OdString &dir)
 
OdStringArray getDirList (const OdString &dir)
 
uintmax_t getProcessId ()
 
OdString getUniqueDirName ()
 
OdResult unzipFile (const OdString &filePath, const OdString &targetDir, bool overwriteTargetDir=true)
 
OdResult zipToFile (const OdString &targetFile, const OdString &filesDir, bool overwriteTargetFile=true)
 

Detailed Description

Contains declarations related to working with Zip files content.

Function Documentation

◆ containsDir()

bool ZipUtils::containsDir ( const OdString dir)

Checks if string contains path to directory.

Parameters
dir[in] A string containing path.
Returns
Returns true if string contains path to directory; otherwise the method returns false.

◆ copyFile()

int ZipUtils::copyFile ( const OdString existingFileName,
const OdString newFileName 
)

Copies existing file to new location under specified name.

Parameters
existingFileName[in] A string containing path to exsiting file.
newFileName[in] A string containing path to new file.
Returns
Returns 0 if file was successfully copied; otherwise, the method returns an appropriate error.

◆ createDir()

int ZipUtils::createDir ( const OdString dir)

Creates empty directory.

Parameters
dir[in] A string containing path to new directory.
Returns
Returns 0 if directory was successfully created; otherwise, the method returns an appropriate error.

◆ createFile()

int ZipUtils::createFile ( const OdString path,
const char *  data,
unsigned int  size 
)

Creates file.

Parameters
path[in] A string containing path to file.
data[in] A pointer to buffer containing file data.
size[in] Length of the buffer containing file data.
Returns
Returns 0 if file was successfully created; otherwise, the method returns an appropriate error.

◆ dirExists()

bool ZipUtils::dirExists ( const OdString dir)

Checks if string is path to existing directory.

Parameters
dir[in] A string containing path.
Returns
Returns true if string is path to existing directory; otherwise the method returns false.

◆ formatDir()

OdString ZipUtils::formatDir ( const OdString dir)

Formats path to directory to conform current platform.

Parameters
dir[in] A string containing path to directory.
Returns
Returns string containing formatted path.
Remarks
The function ensures that there is separator on the end of the path.

◆ formatPath()

OdString ZipUtils::formatPath ( const OdString path)

Formats path to file to conform current platform.

Parameters
path[in] A string containing path to file.
Returns
Returns string containing formatted path.

◆ getDir()

OdString ZipUtils::getDir ( const OdString path)

Selects directory part of the path.

Parameters
path[in] A string containing path to the directory.
Returns
Returns string containing path the directory.

◆ getDirList()

OdStringArray ZipUtils::getDirList ( const OdString dir)

Creates list of all directories in specified directory.

Parameters
dir[in] A string containing path to directory.
Returns
Returns list of directories.

◆ getFile()

OdString ZipUtils::getFile ( const OdString path)

Selects file part of the path.

Parameters
path[in] A string containing path to the file.
Returns
Returns string containing file name.

◆ getFileExtension()

OdString ZipUtils::getFileExtension ( const OdString path)

Selects file extension part of the path.

Parameters
path[in] A string containing path to the file.
Returns
Returns string containing file extension.

◆ getFileList()

OdStringArray ZipUtils::getFileList ( const OdString dir)

Creates list of all files in specified directory.

Parameters
dir[in] A string containing path to directory.
Returns
Returns list of files.

◆ getProcessId()

uintmax_t ZipUtils::getProcessId ( )

Returns identifier of current process.

Returns
Returns id of process.

◆ getUniqueDirName()

OdString ZipUtils::getUniqueDirName ( )

Returns unique name for current process and time.

Returns
Returns unique name.

◆ isDir()

bool ZipUtils::isDir ( const OdString dir)

Checks if string is path to directory.

Parameters
dir[in] A string containing path.
Returns
Returns true if string is path to directory; otherwise the method returns false.

◆ OdStringToUtf8()

OdAnsiString ZipUtils::OdStringToUtf8 ( const OdString sUnicode)

Converts unicode string to UTF-8.

Parameters
sUnicode[in] A string in unicode format.
Returns
Returns string in UTF-8 format.

◆ removeDir()

int ZipUtils::removeDir ( const OdString dir)

Removes directory.

Parameters
dir[in] A string containing path to new directory.
Returns
Returns 0 if directory was successfully removed; otherwise, the method returns an appropriate error.
Remarks
The function removes all files from directory and recursively removes all subdirectories.

◆ removeEmptyDir()

int ZipUtils::removeEmptyDir ( const OdString dir)

Removes empty directory.

Parameters
value[in] A string containing path to new directory.
Returns
Returns 0 if directory was successfully removed; otherwise, the method returns an appropriate error.

◆ removeFile()

int ZipUtils::removeFile ( const OdString path)

Removes file.

Parameters
path[in] A string containing path to file.
Returns
Returns 0 if file was successfully removed; otherwise, the method returns an appropriate error.

◆ unzipFile()

OdResult ZipUtils::unzipFile ( const OdString filePath,
const OdString targetDir,
bool  overwriteTargetDir = true 
)

Unzips file to directory.

Parameters
filePath[in] A string containing path to the zip file.
targetDir[in] A string containing name of the target directory.
overwriteTargetDir[in] Return error if false and target directory is not empty; otherwise, overwrite target directory.
Returns
Returns appropriate error code.

◆ zipToFile()

OdResult ZipUtils::zipToFile ( const OdString targetFile,
const OdString filesDir,
bool  overwriteTargetFile = true 
)

Zips directory to file.

Parameters
targetFile[in] A string containing path to the target zip file.
filesDir[in] A string containing name of the source directory.
overwriteTargetFile[in] Return error if false and target file exists; otherwise, overwrite target file.
Returns
Returns appropriate error code.