📄 ziparchive.h
字号:
how the files are sorted in CZipCentralDir::m_findarray (you can use it
in your own program if you need to display the sorted list and do not want
to duplicate data)
\param iFindFastIndex
index in CZipCentralDir::m_findarray (not necessary the same as the one you'd
pass to #GetFileInfo); the number of items in this array is the same
as the number of files in the archive (you can retrieve it with
#GetCount)
\return
index of the file in central directory (now you can call #GetFileInfo to get
the information); if the value is \c -1 then you have not called
#EnableFindFast before or the archive is closed or the \e iFindFastIndex
is out of range)
*/
int GetFindFastIndex(int iFindFastIndex) const
{
if (IsClosed())
{
TRACE(_T("CZipArchive::GetFindFastIndex: ZipArchive not yet opened.\n"));
return -1;
}
return m_centralDir.GetFindFastIndex(iFindFastIndex);
}
/**
Set a temporary path used when compressing files and #zipsmCheckForEff
is specified as an argument in #AddNewFile and the disk spanning archive
is in creation.
\param lpszPath set it to NULL to clear the temporary path and let the
library figure it out (it uses the system temporary directory if possible)
\param bForce if \e lpszPath is not \c NULL and this parameter set to \c true
the directory is created if it doesn't exists (if the given directory
does not exists , the temporary file will not be created)
\see AddNewFile
\see Smartness
\see GetTempPath
*/
void SetTempPath(LPCTSTR lpszPath = NULL, bool bForce = true);
/**
enum values used in #PredictFileNameInZip
*/
enum Predict
{
prDir, ///< if an argument is a directory, add a separator at the end
prFile, ///< treat the argument as a common file
prAuto ///< treat the argument as a directory only if it has a path separator at the end
};
/**
Given the file path in the form it would be passed to #AddNewFile
as \e lpszFilePath argument, the function returns the file name
as it would be stored in the archive. <BR>
The function takes into account the root path set with #SetRootPath. You can use this function
to eliminate duplicates before adding a list of files.<BR>
\param lpszFilePath
the file path as it would be passed to #AddNewFile function
\param bFullPath
the same as \e bFullPath in #AddNewFile
\param iWhat
one of #Predict values to treat \e lpszFilePath correctly
\param bExactly
if \c true, return the filename exactly as it would look inside the archive i.e. convert slash to backslash, and perform ANSI->OEM conversion;
otherwise return the filename with the path separators that are used by default in the system
\return a modified file path
*/
CZipString PredictFileNameInZip(LPCTSTR lpszFilePath, bool bFullPath, int iWhat = prAuto, bool bExactly = false)const ;
/**
Check if the filename will be duplicted in the archive, if added to the archive in the given form
\param bFileNameOnly
if \c true, assume that the filename is duplicated if only the filename (no path) is the same (\e bFullPath is ignored), otherwise the whole filename with path is taken into account.
\b Default: \c false
The rest of the parameters have the same meaning as in #PredictFileNameInZip.
\return the zero-based index of the file in the archive that the filename would be duplicated, or -1, if the filename is unique
*/
int WillBeDuplicated(LPCTSTR lpszFilePath, bool bFullPath, bool bFileNameOnly = false, int iWhat = prAuto);
/**
Predict the full filename with path after extraction. The parameters (except for the first) are in the form you'd pass
to the <CODE> #ExtractFile(WORD , LPCTSTR , bool , LPCTSTR , DWORD ) </CODE> function. The function takes into account the root path set with #SetRootPath.
\param lpszFileNameInZip
the filename of the file inside the archive (may be \c NULL if lpszNewName is not \c NULL)
\param lpszPath
\param bFullPath
\param lpszNewName
\return a predicted file path
*/
CZipString PredictExtractedFileName(LPCTSTR lpszFileNameInZip, LPCTSTR lpszPath, bool bFullPath, LPCTSTR lpszNewName = NULL)const ;
/**
Return the current value of #m_szTempPath
\return CZipString
*/
CZipString GetTempPath()const
{
return m_szTempPath;
}
/**
Function used in conjunction with #m_szRootPath to trim paths in #AddNewFile and #ExtractFile
\param zpc
\see SetRootPath
*/
CZipString TrimRootPath(CZipPathComponent& zpc)const ;
/**
Remove \e lpszBeginning from the beginning of the \e szPath. Both argument are
considered to be paths so they matches up to the path separator.
\param lpszBeginning
\param szPath
\param pCompareFunction (see: #m_pZipCompare)
\return \c true if the path beginning was removed
*/
static bool RemovePathBeginning(LPCTSTR lpszBeginning, CZipString& szPath, ZIPSTRINGCOMPARE pCompareFunction);
/**
Set the default archive case-sensitivity. Affects the following functions:
- #FindFile
- #FindMatches
- #EnableFindFast
- #TrimRootPath
- #DeleteFiles
\param bCaseSensitive
the default CZipArchive case-sensitivity depends on the system and is set
as follows:
- on Windows: \c false <BR>
- on Linux: \c true
\note Set it before using one of the functions above or leave it as it is by default;
*/
void SetCaseSensitivity(bool bCaseSensitive)
{
m_bCaseSensitive = bCaseSensitive;
m_pZipCompare = GetCZipStrCompFunc(bCaseSensitive);
}
/**
Return the central directory information.
\see GetCentralDirSize
*/
void GetCentralDirInfo(CZipCentralDir::Info& info)const;
/**
Get the central directory size.
\see CZipCentralDir::GetSize
\see GetCentralDirInfo
*/
DWORD GetCentralDirSize(bool bWhole = true) const
{
return m_centralDir.GetSize(bWhole);
}
/**
return \c true if the archive cannot be modified, because it is an existing disk spanning archive
or it was opened with #zipOpenReadOnly
*/
bool IsReadOnly(){return m_storage.IsReadOnly();}
/**
If you set \e bIgnore to \c true, CRC is not checked for the files being tested or extracted.
This method is useful when working with Java <sup><small>TM</small></sup> Archives (jar).
The CRC is checked by default. You can use this function on an opened or closed archive.
*/
void SetIgnoreCRC(bool bIgnore = true){m_bIgnoreCRC = bIgnore;}
/**
A class used in wildcard pattern matching.
This class is based on code by J. Kercheval, created 01/05/1991
and available as a public domain at http://www.snippets.org.
*/
class ZIP_API CWildcard
{
public:
enum Match
{
matchNone, ///< for internal use
matchValid, ///< valid match
matchEnd, ///< premature end of pattern string
matchAbort, ///< premature end of text string
matchRange, ///< match failure on [..] construct
matchLiteral, ///< match failure on literal match
matchPattern ///< bad pattern
};
enum Pattern
{
patternEmpty = -4, ///< [..] construct is empty
patternClose, ///< no end bracket in [..] construct
patternRange, ///< malformed range in [..] construct
patternEsc, ///< literal escape at end of pattern
patternValid, ///< valid pattern
};
/**
Match the pattern against the string \e lpszText
A match means the entire string \e lpszText is used up in matching.
\param lpszText
the string to match against
\param iRetCode
if not \c NULL, set to one of #Match values indicating the return code
\return \c true if \e lpszText matches the pattern.
\see SetPattern
*/
bool IsMatch(LPCTSTR lpszText, int* iRetCode = NULL);
/**
\param lpszPattern
\return \c true if \e lpszPattern has any special wildcard characters.
*/
static bool IsPattern(LPCTSTR lpszPattern);
/**
Test the pattern for validity.
\param lpszPattern
the pattern to test
\param iErrorType
if not \c NULL, set to one of #Pattern values indicating the return code
\return \c true if \e lpszPattern is a well formed regular expression according
to the CWildcard class syntax (see #SetPattern)
*/
static bool IsPatternValid(LPCTSTR lpszPattern, int* iErrorType = NULL);
/**
Match the pattern \e lpszPattern against the string \e lpszText
A match means the entire string \e lpszText is used up in matching.
\param lpszPattern
see #SetPattern
\param lpszText
the string to match against
\return
one of #Match values
*/
static int Match(LPCTSTR lpszPattern, LPCTSTR lpszText);
CWildcard(){}
/**
Initialize the pattern.
\see SetPattern
*/
CWildcard(LPCTSTR lpszPattern, bool bCaseSensitive)
{
SetPattern(lpszPattern, bCaseSensitive);
}
virtual ~CWildcard(){}
/**
Set the pattern to \e lpszPattern.
\param lpszPattern
In the pattern string:
- * matches any sequence of characters(zero or more)
- ? matches any character
- [SET] matches any character in the specified set,
- [!SET] or[^SET] matches any character not in the specified set.
A set is composed of characters or ranges; a range looks like
character hyphen character(as in 0 - 9 or A - Z).[0 - 9a - zA - Z_] is the
minimal set of characters allowed in the[..] pattern construct.
Other characters are allowed(ie. 8 bit characters) if your system
will support them.
\note To suppress the special syntactic significance of any of []*?!^-\,
and match the character exactly, precede it with a \
*/
void SetPattern(LPCTSTR lpszPattern, bool bCaseSensitive)
{
m_szPattern = lpszPattern;
m_bCaseSensitive=bCaseSensitive;
if (!bCaseSensitive)
m_szPattern.MakeLower();
}
operator LPCTSTR()
{
return (LPCTSTR)m_szPattern;
}
protected:
bool m_bCaseSensitive;
static int MatchAfterStar(LPCTSTR p , LPCTSTR t);
CZipString m_szPattern;
};
/**
This function finds the indexes of the files, which filenames match the specified pattern and stores
these indexes in the array. The indexes can be used then e.g. in deleting (CZipArchive::DeleteFiles) or
extracting files (CZipArchive::ExtractFile).
\param lpszPattern
the pattern to match (see CWildcard::SetPattern on how to build the pattern). The case-sensitivity of the pattern
is set to the global archive case-sensitivity (set with #SetCaseSensitivity)
\param ar
the array which will contain the indexes of the files which filenames match the pattern; the contents of the array are NOT clearead, but the
indexes are appended to it
\param bFullPath <BR>
- if \c true, match the filename with path (if present) of the file (if the file is a directory, end it with the path separator or use a pattern that will recognize it)
- otherwise match only the name of the file (if the file is a directory, do not end it with the path separator)
*/
void FindMatches(LPCTSTR lpszPattern, CZipWordArray& ar, bool bFullPath = true)const;
/**
Change th
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -