本文整理汇总了C++中ZipEntry::getName方法的典型用法代码示例。如果您正苦于以下问题:C++ ZipEntry::getName方法的具体用法?C++ ZipEntry::getName怎么用?C++ ZipEntry::getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipEntry
的用法示例。
在下文中一共展示了ZipEntry::getName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deleteEntry
int ZipArchive::deleteEntry(const ZipEntry& entry) const {
if (!isOpen()) { return LIBZIPPP_ERROR_NOT_OPEN; }
if (entry.zipFile!=this) { return LIBZIPPP_ERROR_INVALID_ENTRY; }
if (mode==READ_ONLY) { return LIBZIPPP_ERROR_NOT_ALLOWED; } //deletion not allowed
if (entry.isFile()) {
int result = zip_delete(zipHandle, entry.getIndex());
if (result==0) { return 1; }
return LIBZIPPP_ERROR_UNKNOWN; //unable to delete the entry
} else {
int counter = 0;
vector<ZipEntry> allEntries = getEntries();
vector<ZipEntry>::const_iterator eit;
for(eit=allEntries.begin() ; eit!=allEntries.end() ; ++eit) {
ZipEntry ze = *eit;
int startPosition = ze.getName().find(entry.getName());
if (startPosition==0) {
int result = zip_delete(zipHandle, ze.getIndex());
if (result==0) { ++counter; }
else { return LIBZIPPP_ERROR_UNKNOWN; } //unable to remove the current entry
}
}
return counter;
}
}
示例2: renameEntry
int ZipArchive::renameEntry(const ZipEntry& entry, const string& newName) const {
if (!isOpen()) { return LIBZIPPP_ERROR_NOT_OPEN; }
if (entry.zipFile!=this) { return LIBZIPPP_ERROR_INVALID_ENTRY; }
if (mode==READ_ONLY) { return LIBZIPPP_ERROR_NOT_ALLOWED; } //renaming not allowed
if (newName.length()==0) { return LIBZIPPP_ERROR_INVALID_PARAMETER; }
if (newName==entry.getName()) { return LIBZIPPP_ERROR_INVALID_PARAMETER; }
if (entry.isFile()) {
if (ENTRY_IS_DIRECTORY(newName)) { return LIBZIPPP_ERROR_INVALID_PARAMETER; } //invalid new name
int lastSlash = newName.rfind(ENTRY_PATH_SEPARATOR);
if (lastSlash!=1) {
bool dadded = addEntry(newName.substr(0, lastSlash+1));
if (!dadded) { return LIBZIPPP_ERROR_UNKNOWN; } //the hierarchy hasn't been created
}
int result = zip_file_rename(zipHandle, entry.getIndex(), newName.c_str(), ZIP_FL_ENC_GUESS);
if (result==0) { return 1; }
return LIBZIPPP_ERROR_UNKNOWN; //renaming was not possible (entry already exists ?)
} else {
if (!ENTRY_IS_DIRECTORY(newName)) { return LIBZIPPP_ERROR_INVALID_PARAMETER; } //invalid new name
int parentSlash = newName.rfind(ENTRY_PATH_SEPARATOR, newName.length()-2);
if (parentSlash!=-1) { //updates the dir hierarchy
string parent = newName.substr(0, parentSlash+1);
bool dadded = addEntry(parent);
if (!dadded) { return LIBZIPPP_ERROR_UNKNOWN; }
}
int counter = 0;
string originalName = entry.getName();
vector<ZipEntry> allEntries = getEntries();
vector<ZipEntry>::const_iterator eit;
for(eit=allEntries.begin() ; eit!=allEntries.end() ; ++eit) {
ZipEntry ze = *eit;
string currentName = ze.getName();
int startPosition = currentName.find(originalName);
if (startPosition==0) {
if (currentName == originalName) {
int result = zip_file_rename(zipHandle, entry.getIndex(), newName.c_str(), ZIP_FL_ENC_GUESS);
if (result==0) { ++counter; }
else { return LIBZIPPP_ERROR_UNKNOWN; } //unable to rename the folder
} else {
string targetName = currentName.replace(0, originalName.length(), newName);
int result = zip_file_rename(zipHandle, ze.getIndex(), targetName.c_str(), ZIP_FL_ENC_GUESS);
if (result==0) { ++counter; }
else { return LIBZIPPP_ERROR_UNKNOWN; } //unable to rename a sub-entry
}
} else {
//file not affected by the renaming
}
}
/*
* Special case for moving a directory a/x to a/x/y to avoid to lose
* the a/x path in the archive.
*/
bool newNameIsInsideCurrent = (newName.find(entry.getName())==0);
if (newNameIsInsideCurrent) {
bool dadded = addEntry(newName);
if (!dadded) { return LIBZIPPP_ERROR_UNKNOWN; }
}
return counter;
}
}