Populate the hzFileset instance from a import file
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzFileset::Import | (const char*,) |
Declared in file: hzDirectory.h
Defined in file : hzDirectory.cpp
Function Logic:
Function body:
hzEcode hzFileset::Import (const char* filepath)
{
// Populate the hzFileset instance from a import file
//
// Arguments: 1) filepath The import file
//
// Returns: E_ARGUMENT If the import filename is not supplied
// E_OPENFAIL If the import file cannot be opened
// E_READFAIL If the import file cannot be read
// E_OK If the import was successful
_hzfunc("hzFileset::Import()") ;
std::ifstream is ; // File input stream
hzDirent* pDX ; // New directory
hzDirent* pFX ; // New file
char* i ; // Buffer iterator
hzString newname ; // New dir/file name
uint32_t nLine ; // Line number
uint32_t nInode ; // Inode (used in copy protection etc)
uint32_t nSize ; // File size
uint32_t nCtime ; // File create date
uint32_t nMtime ; // File modified date
uint32_t nMode ; // File mode
uint32_t nOwner ; // UNIX owner id
uint32_t nGroup ; // UNIX group id
bool bOk ; // Format OK
hzEcode rc ; // Return code
char cvLine[512];// Line buffer
// Check filepath
if (!filepath || !filepath[0])
return E_ARGUMENT ;
// Open for reading
is.open(filepath) ;
if (is.fail())
return E_OPENFAIL ;
// Read in line by line
for (nLine = 1;; nLine++)
{
is.getline(cvLine, 512);
if (!is.gcount())
break ;
i = cvLine ;
if (i[0]== ''#'')
continue ;
// These apply to both dirs and files
bOk = IsPosint(nInode, i + 2);
if (bOk) bOk = IsHexnum(nMode, i + 13);
if (bOk) bOk = IsPosint(nSize, i + 22);
if (bOk) bOk = IsPosint(nCtime, i + 33);
if (bOk) bOk = IsPosint(nMtime, i + 44);
if (bOk) bOk = IsPosint(nOwner, i + 55);
if (bOk) bOk = IsPosint(nGroup, i + 61);
if (!bOk)
{
is.close() ;
return hzerr(E_CORRUPT, "Line %d of %s is malformed", nLine, filepath) ;
}
newname = i + 67;
if (i[0]== ''D'')
{
// Directory entry
pDX = new hzDirent() ;
pDX->InitNorm(0,newname, nInode, nSize, nCtime, nMtime, nMode, nOwner, nGroup, 0);
m_dirs.Insert(pDX->Path(), pDX) ;
continue ;
}
if (i[0]== ''F'')
{
// File entry
pFX = new hzDirent() ;
pFX->InitNorm(pDX->strName(), newname, nInode, nSize, nCtime, nMtime, nMode, nOwner, nGroup, 0);
m_nBytes += pFX->Size() ;
m_file.Insert(pFX->Path(), pFX) ;
}
}
is.close() ;
return E_OK ;
}