本文整理汇总了C++中UStringVector::Delete方法的典型用法代码示例。如果您正苦于以下问题:C++ UStringVector::Delete方法的具体用法?C++ UStringVector::Delete怎么用?C++ UStringVector::Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UStringVector
的用法示例。
在下文中一共展示了UStringVector::Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DecompressArchives
HRESULT DecompressArchives(
UStringVector &archivePaths, UStringVector &archivePathsFull,
const NWildcard::CCensorNode &wildcardCensor,
const CExtractOptions &optionsSpec,
IOpenCallbackUI *openCallback,
IExtractCallbackUI *extractCallback)
{
CExtractOptions options = optionsSpec;
for (int i = 0; i < archivePaths.Size(); i++)
{
const UString &archivePath = archivePaths[i];
NFile::NFind::CFileInfoW archiveFileInfo;
if (!NFile::NFind::FindFile(archivePath, archiveFileInfo))
throw "there is no such archive";
if (archiveFileInfo.IsDirectory())
throw "there is no such archive";
options.ArchiveFileInfo = archiveFileInfo;
RINOK(extractCallback->BeforeOpen(archivePath));
CArchiveLink archiveLink;
HRESULT result = MyOpenArchive(archivePath, archiveLink, openCallback);
RINOK(extractCallback->OpenResult(archivePath, result));
if (result != S_OK)
continue;
for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)
{
int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);
if (index >= 0 && index > i)
{
archivePaths.Delete(index);
archivePathsFull.Delete(index);
}
}
#ifndef _NO_CRYPTO
UString password;
RINOK(openCallback->GetPasswordIfAny(password));
if (!password.IsEmpty())
{
RINOK(extractCallback->SetPassword(password));
}
#endif
options.DefaultItemName = archiveLink.GetDefaultItemName();
RINOK(DecompressArchive(
archiveLink.GetArchive(), archiveLink.GetDefaultItemName(),
wildcardCensor, options, extractCallback));
}
return S_OK;
}
示例2: AddUniqueStringToHeadOfList
void AddUniqueStringToHeadOfList(UStringVector &list, const UString &s)
{
for (unsigned i = 0; i < list.Size();)
if (s.IsEqualTo_NoCase(list[i]))
list.Delete(i);
else
i++;
list.Insert(0, s);
}
示例3: AddItem
void CCensor::AddItem(bool include, const UString &path, bool recursive)
{
UStringVector pathParts;
SplitPathToParts(path, pathParts);
bool forFile = true;
if (pathParts.Back().IsEmpty())
{
forFile = false;
pathParts.DeleteBack();
}
const UString &front = pathParts.Front();
bool isAbs = false;
if (front.IsEmpty())
isAbs = true;
else if (front.Length() == 2 && front[1] == L':')
isAbs = true;
else
{
for (int i = 0; i < pathParts.Size(); i++)
{
const UString &part = pathParts[i];
if (part == L".." || part == L".")
{
isAbs = true;
break;
}
}
}
int numAbsParts = 0;
if (isAbs)
if (pathParts.Size() > 1)
numAbsParts = pathParts.Size() - 1;
else
numAbsParts = 1;
UString prefix;
for (int i = 0; i < numAbsParts; i++)
{
const UString &front = pathParts.Front();
if (DoesNameContainWildCard(front))
break;
prefix += front;
prefix += WCHAR_PATH_SEPARATOR;
pathParts.Delete(0);
}
int index = FindPrefix(prefix);
if (index < 0)
index = Pairs.Add(CPair(prefix));
CItem item;
item.PathParts = pathParts;
item.ForDir = true;
item.ForFile = forFile;
item.Recursive = recursive;
Pairs[index].Head.AddItem(include, item);
}
示例4: MakeCorrectPath
void MakeCorrectPath(UStringVector &pathParts)
{
for (int i = 0; i < pathParts.Size();)
{
UString &s = pathParts[i];
s = GetCorrectFileName(s);
if (s.IsEmpty())
pathParts.Delete(i);
else
i++;
}
}
示例5: MakeCorrectPath
void MakeCorrectPath(UStringVector &pathParts)
{
for (int i = 0; i < pathParts.Size();)
{
UString &s = pathParts[i];
s = GetCorrectFileName(s);
if (s.IsEmpty())
pathParts.Delete(i);
else
{
#ifdef _WIN32
if (!IsSupportedName(s))
s = (UString)L"_" + s;
#endif
i++;
}
}
}
示例6: DecompressArchives
HRESULT DecompressArchives(
CCodecs *codecs, const CIntVector &formatIndices,
UStringVector &archivePaths, UStringVector &archivePathsFull,
const NWildcard::CCensorNode &wildcardCensor,
const CExtractOptions &optionsSpec,
IOpenCallbackUI *openCallback,
IExtractCallbackUI *extractCallback,
UString &errorMessage,
CDecompressStat &stat)
{
stat.Clear();
CExtractOptions options = optionsSpec;
int i;
UInt64 totalPackSize = 0;
CRecordVector<UInt64> archiveSizes;
for (i = 0; i < archivePaths.Size(); i++)
{
const UString &archivePath = archivePaths[i];
NFile::NFind::CFileInfoW fi;
if (!NFile::NFind::FindFile(archivePath, fi))
throw "there is no such archive";
if (fi.IsDir())
throw "can't decompress folder";
archiveSizes.Add(fi.Size);
totalPackSize += fi.Size;
}
CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;
CMyComPtr<IArchiveExtractCallback> ec(extractCallbackSpec);
bool multi = (archivePaths.Size() > 1);
extractCallbackSpec->InitForMulti(multi, options.PathMode, options.OverwriteMode);
if (multi)
{
RINOK(extractCallback->SetTotal(totalPackSize));
}
for (i = 0; i < archivePaths.Size(); i++)
{
const UString &archivePath = archivePaths[i];
NFile::NFind::CFileInfoW fi;
if (!NFile::NFind::FindFile(archivePath, fi))
throw "there is no such archive";
if (fi.IsDir())
throw "there is no such archive";
options.ArchiveFileInfo = fi;
#ifndef _NO_CRYPTO
openCallback->Open_ClearPasswordWasAskedFlag();
#endif
RINOK(extractCallback->BeforeOpen(archivePath));
CArchiveLink archiveLink;
CIntVector formatIndices2 = formatIndices;
#ifndef _SFX
if (formatIndices.IsEmpty())
{
int pos = archivePath.ReverseFind(L'.');
if (pos >= 0)
{
UString s = archivePath.Mid(pos + 1);
int index = codecs->FindFormatForExtension(s);
if (index >= 0 && s == L"001")
{
s = archivePath.Left(pos);
pos = s.ReverseFind(L'.');
if (pos >= 0)
{
int index2 = codecs->FindFormatForExtension(s.Mid(pos + 1));
if (index2 >= 0 && s.CompareNoCase(L"rar") != 0)
{
formatIndices2.Add(index2);
formatIndices2.Add(index);
}
}
}
}
}
#endif
HRESULT result = MyOpenArchive(codecs, formatIndices2, archivePath, archiveLink, openCallback);
if (result == E_ABORT)
return result;
bool crypted = false;
#ifndef _NO_CRYPTO
crypted = openCallback->Open_WasPasswordAsked();
#endif
RINOK(extractCallback->OpenResult(archivePath, result, crypted));
if (result != S_OK)
continue;
for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)
{
int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);
if (index >= 0 && index > i)
{
archivePaths.Delete(index);
archivePathsFull.Delete(index);
totalPackSize -= archiveSizes[index];
//.........这里部分代码省略.........
示例7: ListArchives
HRESULT ListArchives(CCodecs *codecs, const CIntVector &formatIndices,
bool stdInMode,
UStringVector &arcPaths, UStringVector &arcPathsFull,
const NWildcard::CCensorNode &wildcardCensor,
bool enableHeaders, bool techMode,
#ifndef _NO_CRYPTO
bool &passwordEnabled, UString &password,
#endif
UInt64 &numErrors)
{
numErrors = 0;
CFieldPrinter fieldPrinter;
if (!techMode)
fieldPrinter.Init(kStandardFieldTable, sizeof(kStandardFieldTable) / sizeof(kStandardFieldTable[0]));
UInt64 numFiles2 = 0, numDirs2 = 0, totalPackSize2 = 0, totalUnPackSize2 = 0;
UInt64 *totalPackSizePointer2 = 0, *totalUnPackSizePointer2 = 0;
int numArcs = /* stdInMode ? 1 : */ arcPaths.Size();
for (int i = 0; i < numArcs; i++)
{
const UString &archiveName = arcPaths[i];
UInt64 arcPackSize = 0;
if (!stdInMode)
{
NFile::NFind::CFileInfoW fi;
if (!fi.Find(archiveName) || fi.IsDir())
{
g_StdOut << endl << "Error: " << archiveName << " is not file" << endl;
numErrors++;
continue;
}
arcPackSize = fi.Size;
}
CArchiveLink archiveLink;
COpenCallbackConsole openCallback;
openCallback.OutStream = &g_StdOut;
#ifndef _NO_CRYPTO
openCallback.PasswordIsDefined = passwordEnabled;
openCallback.Password = password;
#endif
HRESULT result = archiveLink.Open2(codecs, formatIndices, stdInMode, NULL, archiveName, &openCallback);
if (result != S_OK)
{
if (result == E_ABORT)
return result;
g_StdOut << endl << "Error: " << archiveName << ": ";
if (result == S_FALSE)
{
#ifndef _NO_CRYPTO
if (openCallback.Open_WasPasswordAsked())
g_StdOut << "Can not open encrypted archive. Wrong password?";
else
#endif
g_StdOut << "Can not open file as archive";
}
else if (result == E_OUTOFMEMORY)
g_StdOut << "Can't allocate required memory";
else
g_StdOut << NError::MyFormatMessage(result);
g_StdOut << endl;
numErrors++;
continue;
}
if (!stdInMode)
for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)
{
int index = arcPathsFull.FindInSorted(archiveLink.VolumePaths[v]);
if (index >= 0 && index > i)
{
arcPaths.Delete(index);
arcPathsFull.Delete(index);
numArcs = arcPaths.Size();
}
}
if (enableHeaders)
{
g_StdOut << endl << kListing << archiveName << endl << endl;
for (int i = 0; i < archiveLink.Arcs.Size(); i++)
{
const CArc &arc = archiveLink.Arcs[i];
g_StdOut << "--\n";
PrintPropPair(L"Path", arc.Path);
PrintPropPair(L"Type", codecs->Formats[arc.FormatIndex].Name);
if (!arc.ErrorMessage.IsEmpty())
PrintPropPair(L"Error", arc.ErrorMessage);
UInt32 numProps;
IInArchive *archive = arc.Archive;
if (archive->GetNumberOfArchiveProperties(&numProps) == S_OK)
{
for (UInt32 j = 0; j < numProps; j++)
//.........这里部分代码省略.........
示例8: Main2
int Main2(int argc,TCHAR **argv)
{
UStringVector commandStrings;
#ifdef _WIN32
NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);
#else
extern void mySplitCommandLineW(int numArguments,TCHAR **arguments,UStringVector &parts);
mySplitCommandLineW(argc,argv,commandStrings);
#endif
#ifndef UNDER_CE
if (commandStrings.Size() > 0)
commandStrings.Delete(0);
#endif
if (commandStrings.Size() == 0)
{
MessageBoxW(0, L"Specify command", L"7-Zip", 0);
return 0;
}
/*
{
CSysString resultPath;
NWindows::NFile::NDirectory::MyGetCurrentDirectory(resultPath);
::MessageBoxW(0, resultPath, L"7-Zip - curDir", 0);
}
*/
CArchiveCommandLineOptions options;
CArchiveCommandLineParser parser;
parser.Parse1(commandStrings, options);
parser.Parse2(options);
#if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)
if (options.LargePages)
NSecurity::EnableLockMemoryPrivilege();
#endif
CCodecs *codecs = new CCodecs;
CMyComPtr<IUnknown> compressCodecsInfo = codecs;
HRESULT result = codecs->Load();
if (result != S_OK)
throw CSystemException(result);
bool isExtractGroupCommand = options.Command.IsFromExtractGroup();
if (codecs->Formats.Size() == 0 &&
(isExtractGroupCommand ||
options.Command.IsFromUpdateGroup()))
throw kNoFormats;
CIntVector formatIndices;
if (!codecs->FindFormatForArchiveType(options.ArcType, formatIndices))
{
ErrorLangMessage(IDS_UNSUPPORTED_ARCHIVE_TYPE, 0x0200060D);
return NExitCode::kFatalError;
}
if (options.Command.CommandType == NCommandType::kBenchmark)
{
HRESULT res;
#ifdef EXTERNAL_CODECS
CObjectVector<CCodecInfoEx> externalCodecs;
res = LoadExternalCodecs(codecs, externalCodecs);
if (res != S_OK)
throw CSystemException(res);
#endif
res = Benchmark(
#ifdef EXTERNAL_CODECS
codecs, &externalCodecs,
#endif
options.NumThreads, options.DictionarySize);
if (res != S_OK)
throw CSystemException(res);
}
else if (isExtractGroupCommand)
{
CExtractCallbackImp *ecs = new CExtractCallbackImp;
CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;
#ifndef _NO_CRYPTO
ecs->PasswordIsDefined = options.PasswordEnabled;
ecs->Password = options.Password;
#endif
ecs->Init();
CExtractOptions eo;
eo.StdOutMode = options.StdOutMode;
eo.OutputDir = options.OutputDir;
eo.YesToAll = options.YesToAll;
eo.OverwriteMode = options.OverwriteMode;
eo.PathMode = options.Command.GetPathMode();
eo.TestMode = options.Command.IsTestMode();
eo.CalcCrc = options.CalcCrc;
#if !defined(_7ZIP_ST) && !defined(_SFX)
eo.Properties = options.ExtractProperties;
#endif
//.........这里部分代码省略.........
示例9: Main2
int Main2(
#ifndef _WIN32
int numArgs, char *args[]
#endif
)
{
#if defined(_WIN32) && !defined(UNDER_CE)
SetFileApisToOEM();
#endif
g_StdOut << kCopyrightString;
UStringVector commandStrings;
#ifdef _WIN32
NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);
#else
// GetArguments(numArgs, args, commandStrings);
mySplitCommandLine(numArgs,args,commandStrings);
#endif
#ifdef _WIN32
FString arcPath;
{
FString path;
NDLL::MyGetModuleFileName(path);
if (!MyGetFullPathName(path, arcPath))
{
g_StdOut << "GetFullPathName Error";
return NExitCode::kFatalError;
}
}
#else
// After mySplitCommandLine
showP7zipInfo(&g_StdOut);
UString arcPath = commandStrings.Front();
#endif
commandStrings.Delete(0);
NCommandLineParser::CParser parser(kNumSwitches);
try
{
parser.ParseStrings(kSwitchForms, commandStrings);
}
catch(...)
{
PrintHelpAndExit();
}
if (parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)
{
PrintHelp();
return 0;
}
const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
int numNonSwitchStrings = nonSwitchStrings.Size();
CArchiveCommand command;
if (numNonSwitchStrings == 0)
command.CommandType = NCommandType::kFullExtract;
else
{
if (numNonSwitchStrings > 1)
PrintHelpAndExit();
if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], command))
PrintHelpAndExit();
}
NRecursedType::EEnum recursedType;
recursedType = command.DefaultRecursedType();
NWildcard::CCensor wildcardCensor;
bool thereAreSwitchIncludeWildcards;
thereAreSwitchIncludeWildcards = false;
AddToCensorFromNonSwitchesStrings(wildcardCensor, nonSwitchStrings, recursedType,
thereAreSwitchIncludeWildcards);
bool yesToAll = parser[NKey::kYes].ThereIs;
// NExtractMode::EEnum extractMode;
// bool isExtractGroupCommand = command.IsFromExtractGroup(extractMode);
bool passwordEnabled = parser[NKey::kPassword].ThereIs;
UString password;
if (passwordEnabled)
password = parser[NKey::kPassword].PostStrings[0];
if (!NFind::DoesFileExist(arcPath))
throw kCantFindSFX;
FString outputDir;
//.........这里部分代码省略.........
示例10: if
int APIENTRY WinMain2()
{
UString password;
bool assumeYes = false;
bool outputFolderDefined = false;
UString outputFolder;
UStringVector commandStrings;
NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);
#ifndef UNDER_CE
if (commandStrings.Size() > 0)
commandStrings.Delete(0);
#endif
for (int i = 0; i < commandStrings.Size(); i++)
{
const UString &s = commandStrings[i];
if (s.CompareNoCase(L"-y") == 0)
assumeYes = true;
else if (s.Left(2).CompareNoCase(L"-o") == 0)
{
outputFolder = s.Mid(2);
NWindows::NFile::NName::NormalizeDirPathPrefix(outputFolder);
outputFolderDefined = !outputFolder.IsEmpty();
}
else if (s.Left(2).CompareNoCase(L"-p") == 0)
{
password = s.Mid(2);
}
}
UString path;
NWindows::NDLL::MyGetModuleFileName(g_hInstance, path);
UString fullPath;
int fileNamePartStartIndex;
if (!NWindows::NFile::NDirectory::MyGetFullPathName(path, fullPath, fileNamePartStartIndex))
{
ShowErrorMessage(L"Error 1329484");
return 1;
}
CCodecs *codecs = new CCodecs;
CMyComPtr<IUnknown> compressCodecsInfo = codecs;
HRESULT result = codecs->Load();
if (result != S_OK)
{
ErrorMessageForHRESULT(result);
return 1;
}
// COpenCallbackGUI openCallback;
// openCallback.PasswordIsDefined = !password.IsEmpty();
// openCallback.Password = password;
CExtractCallbackImp *ecs = new CExtractCallbackImp;
CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;
ecs->Init();
#ifndef _NO_CRYPTO
ecs->PasswordIsDefined = !password.IsEmpty();
ecs->Password = password;
#endif
CExtractOptions eo;
eo.OutputDir = outputFolderDefined ? outputFolder :
fullPath.Left(fileNamePartStartIndex);
eo.YesToAll = assumeYes;
eo.OverwriteMode = assumeYes ?
NExtract::NOverwriteMode::kWithoutPrompt :
NExtract::NOverwriteMode::kAskBefore;
eo.PathMode = NExtract::NPathMode::kFullPathnames;
eo.TestMode = false;
UStringVector v1, v2;
v1.Add(fullPath);
v2.Add(fullPath);
NWildcard::CCensorNode wildcardCensor;
wildcardCensor.AddItem(true, L"*", true, true, true);
bool messageWasDisplayed = false;
result = ExtractGUI(codecs, CIntVector(), v1, v2,
wildcardCensor, eo, (assumeYes ? false: true), messageWasDisplayed, ecs);
if (result == S_OK)
{
if (!ecs->IsOK())
return NExitCode::kFatalError;
return 0;
}
if (result == E_ABORT)
return NExitCode::kUserBreak;
if (!messageWasDisplayed)
{
if (result == S_FALSE)
ShowErrorMessage(L"Error in archive");
else
ErrorMessageForHRESULT(result);
}
//.........这里部分代码省略.........
示例11: if
int APIENTRY WinMain2()
{
// OleInitialize is required for ProgressBar in TaskBar.
#ifndef UNDER_CE
OleInitialize(NULL);
#endif
#ifndef UNDER_CE
g_ComCtl32Version = ::GetDllVersion(TEXT("comctl32.dll"));
g_LVN_ITEMACTIVATE_Support = (g_ComCtl32Version >= MAKELONG(71, 4));
#endif
UString password;
bool assumeYes = false;
bool outputFolderDefined = false;
FString outputFolder;
UStringVector commandStrings;
NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);
#ifndef UNDER_CE
if (commandStrings.Size() > 0)
commandStrings.Delete(0);
#endif
FOR_VECTOR (i, commandStrings)
{
const UString &s = commandStrings[i];
if (s.Len() > 1 && s[0] == '-')
{
wchar_t c = MyCharLower_Ascii(s[1]);
if (c == 'y')
{
assumeYes = true;
if (s.Len() != 2)
{
ShowErrorMessage(L"Bad command");
return 1;
}
}
else if (c == 'o')
{
outputFolder = us2fs(s.Ptr(2));
NName::NormalizeDirPathPrefix(outputFolder);
outputFolderDefined = !outputFolder.IsEmpty();
}
else if (c == 'p')
{
password = s.Ptr(2);
}
}
}
FString path;
NDLL::MyGetModuleFileName(path);
FString fullPath;
if (!MyGetFullPathName(path, fullPath))
{
ShowErrorMessage(L"Error 1329484");
return 1;
}
CCodecs *codecs = new CCodecs;
CMyComPtr<IUnknown> compressCodecsInfo = codecs;
HRESULT result = codecs->Load();
if (result != S_OK)
{
ErrorMessageForHRESULT(result);
return 1;
}
// COpenCallbackGUI openCallback;
// openCallback.PasswordIsDefined = !password.IsEmpty();
// openCallback.Password = password;
CExtractCallbackImp *ecs = new CExtractCallbackImp;
CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;
ecs->Init();
#ifndef _NO_CRYPTO
ecs->PasswordIsDefined = !password.IsEmpty();
ecs->Password = password;
#endif
CExtractOptions eo;
FString dirPrefix;
if (!GetOnlyDirPrefix(path, dirPrefix))
{
ShowErrorMessage(L"Error 1329485");
return 1;
}
eo.OutputDir = outputFolderDefined ? outputFolder : dirPrefix;
eo.YesToAll = assumeYes;
eo.OverwriteMode = assumeYes ?
NExtract::NOverwriteMode::kOverwrite :
NExtract::NOverwriteMode::kAsk;
eo.PathMode = NExtract::NPathMode::kFullPaths;
//.........这里部分代码省略.........
示例12: ListArchives
HRESULT ListArchives(
CCodecs *codecs,
UStringVector &archivePaths, UStringVector &archivePathsFull,
const NWildcard::CCensorNode &wildcardCensor,
bool enableHeaders, bool techMode, bool &passwordEnabled, UString &password, UInt64 &numErrors)
{
numErrors = 0;
CFieldPrinter fieldPrinter;
if (!techMode)
fieldPrinter.Init(kStandardFieldTable, sizeof(kStandardFieldTable) / sizeof(kStandardFieldTable[0]));
UInt64 numFiles2 = 0, numDirs2 = 0, totalPackSize2 = 0, totalUnPackSize2 = 0;
UInt64 *totalPackSizePointer2 = 0, *totalUnPackSizePointer2 = 0;
for (int i = 0; i < archivePaths.Size(); i++)
{
const UString &archiveName = archivePaths[i];
NFile::NFind::CFileInfoW archiveFileInfo;
if (!NFile::NFind::FindFile(archiveName, archiveFileInfo) || archiveFileInfo.IsDirectory())
{
g_StdOut << endl << "Error: " << archiveName << " is not archive" << endl;
numErrors++;
continue;
}
if (archiveFileInfo.IsDirectory())
{
g_StdOut << endl << "Error: " << archiveName << " is not file" << endl;
numErrors++;
continue;
}
CArchiveLink archiveLink;
COpenCallbackConsole openCallback;
openCallback.OutStream = &g_StdOut;
openCallback.PasswordIsDefined = passwordEnabled;
openCallback.Password = password;
HRESULT result = MyOpenArchive(codecs, archiveName, archiveLink, &openCallback);
if (result != S_OK)
{
g_StdOut << endl << "Error: " << archiveName << " is not supported archive" << endl;
numErrors++;
continue;
}
for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)
{
int index = archivePathsFull.FindInSorted(archiveLink.VolumePaths[v]);
if (index >= 0 && index > i)
{
archivePaths.Delete(index);
archivePathsFull.Delete(index);
}
}
IInArchive *archive = archiveLink.GetArchive();
const UString defaultItemName = archiveLink.GetDefaultItemName();
if (enableHeaders)
{
g_StdOut << endl << kListing << archiveName << endl << endl;
UInt32 numProps;
if (archive->GetNumberOfArchiveProperties(&numProps) == S_OK)
{
for (UInt32 i = 0; i < numProps; i++)
{
CMyComBSTR name;
PROPID propID;
VARTYPE vt;
if (archive->GetArchivePropertyInfo(i, &name, &propID, &vt) != S_OK)
continue;
NCOM::CPropVariant prop;
if (archive->GetArchiveProperty(propID, &prop) != S_OK)
continue;
UString s = ConvertPropertyToString(prop, propID);
if (!s.IsEmpty())
g_StdOut << GetPropName(propID, name) << " = " << s << endl;
}
}
if (techMode)
g_StdOut << "----------\n";
if (numProps > 0)
g_StdOut << endl;
}
if (enableHeaders && !techMode)
{
fieldPrinter.PrintTitle();
g_StdOut << endl;
fieldPrinter.PrintTitleLines();
g_StdOut << endl;
}
if (techMode)
{
RINOK(fieldPrinter.Init(archive));
}
UInt64 numFiles = 0, numDirs = 0, totalPackSize = 0, totalUnPackSize = 0;
UInt64 *totalPackSizePointer = 0, *totalUnPackSizePointer = 0;
//.........这里部分代码省略.........
示例13: ExplodeArchives
// Create a new 7z archive for each folder contained in the archive to be
// exploded.
HRESULT ExplodeArchives(CCodecs *codecs, const CIntVector &formatIndices,
bool stdInMode,
UStringVector &arcPaths, UStringVector &arcPathsFull,
UString& outputPath, UInt64 maxDepth, UInt64 &numErrors)
{
int numArcs = arcPaths.Size();
for (int i = 0; i < numArcs; i++)
{
UString archivePath = arcPaths[i];
/*UString outputPath = arcPaths[i];
outputPath.Replace(L'\\', L'/'); // linux and windows consistent
const UString archiveName = StripFile(outputPath);
outputPath.Empty();*/
archivePath.Replace(L'\\', L'/'); // linux, windows and archive consistent
outputPath.Replace(L'\\', L'/');
FixPathFormat(outputPath);
const UString archiveName = GetFileFromPath(archivePath);
g_StdOut << "Outputting into : " << outputPath << endl;
UInt64 arcPackSize = 0;
if (!stdInMode)
{
NFile::NFind::CFileInfoW fi;
if (!fi.Find(archivePath) || fi.IsDir())
{
SHOW_ERROR("is not a file.");
continue;
}
arcPackSize = fi.Size;
}
g_StdOut << endl << "Exploding : " << archivePath << endl << endl;
CArchiveLink archiveLink;
COpenCallbackConsole openCallback;
openCallback.OutStream = &g_StdOut;
#ifndef _NO_CRYPTO
openCallback.PasswordIsDefined = false;
#endif
HRESULT result = archiveLink.Open2(codecs, formatIndices, stdInMode, NULL, archivePath, &openCallback);
if (result != S_OK)
{
if (result == E_ABORT)
return result;
g_StdOut << endl << "Error: " << archivePath << ": ";
if (result == S_FALSE)
g_StdOut << "Can not open file as archive";
else if (result == E_OUTOFMEMORY)
g_StdOut << "Can't allocate required memory";
else
g_StdOut << NError::MyFormatMessage(result);
g_StdOut << endl;
numErrors++;
continue;
}
// remove other files names if multi-volume
if (!stdInMode) {
for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)
{
int index = arcPathsFull.FindInSorted(archiveLink.VolumePaths[v]);
if (index >= 0 && index > i)
{
arcPaths.Delete(index);
arcPathsFull.Delete(index);
numArcs = arcPaths.Size();
}
}
}
// don't support multi volume because i have to reopen the stream
if (archiveLink.VolumePaths.Size() != 1) {
SHOW_ERROR("Exploding multi-volume archives isn't supported.");
continue;
}
bool szArchive = true;
for (int x = 0; x < archiveLink.Arcs.Size(); x++)
{
const UString szName = L"7z";
const CArc &arc = archiveLink.Arcs[x];
if (codecs->Formats[arc.FormatIndex].Name != szName) {
szArchive = false;
break;
}
}
if (!szArchive) {
SHOW_ERROR("Only 7z archives can be exploded.");
continue;
}
//.........这里部分代码省略.........
示例14: Correct_FsPath
void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir)
{
unsigned i = 0;
if (absIsAllowed)
{
#if defined(_WIN32) && !defined(UNDER_CE)
bool isDrive = false;
#endif
if (parts[0].IsEmpty())
{
i = 1;
#if defined(_WIN32) && !defined(UNDER_CE)
if (parts.Size() > 1 && parts[1].IsEmpty())
{
i = 2;
if (parts.Size() > 2 && parts[2] == L"?")
{
i = 3;
if (parts.Size() > 3 && NWindows::NFile::NName::IsDrivePath2(parts[3]))
{
isDrive = true;
i = 4;
}
}
}
#endif
}
#if defined(_WIN32) && !defined(UNDER_CE)
else if (NWindows::NFile::NName::IsDrivePath2(parts[0]))
{
isDrive = true;
i = 1;
}
if (isDrive)
{
// we convert "c:name" to "c:\name", if absIsAllowed path.
UString &ds = parts[i - 1];
if (ds.Len() > 2)
{
parts.Insert(i, ds.Ptr(2));
ds.DeleteFrom(2);
}
}
#endif
}
for (; i < parts.Size();)
{
UString &s = parts[i];
Correct_PathPart(s);
if (s.IsEmpty())
{
if (isDir || i != parts.Size() - 1)
{
parts.Delete(i);
continue;
}
s = k_EmptyReplaceName;
}
else
{
#ifdef _WIN32
CorrectUnsupportedName(s);
#endif
}
i++;
}
if (!isDir)
{
if (parts.IsEmpty())
parts.Add((UString)k_EmptyReplaceName);
else
{
UString &s = parts.Back();
if (s.IsEmpty())
s = k_EmptyReplaceName;
}
}
}
示例15: Main2
int Main2(
#ifndef _WIN32
int numArguments, const char *arguments[]
#endif
)
{
#ifdef _WIN32
SetFileApisToOEM();
#endif
g_StdOut << kCopyrightString;
UStringVector commandStrings;
#ifdef _WIN32
NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);
#else
GetArguments(numArguments, arguments, commandStrings);
#endif
UString archiveName = commandStrings.Front();
commandStrings.Delete(0);
NCommandLineParser::CParser parser(kNumSwitches);
try
{
parser.ParseStrings(kSwitchForms, commandStrings);
}
catch(...)
{
PrintHelpAndExit();
}
if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)
{
PrintHelp();
return 0;
}
const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
int numNonSwitchStrings = nonSwitchStrings.Size();
CArchiveCommand command;
if (numNonSwitchStrings == 0)
command.CommandType = NCommandType::kFullExtract;
else
{
if (numNonSwitchStrings > 1)
PrintHelpAndExit();
if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], command))
PrintHelpAndExit();
}
NRecursedType::EEnum recursedType;
recursedType = command.DefaultRecursedType();
NWildcard::CCensor wildcardCensor;
bool thereAreSwitchIncludeWildCards;
thereAreSwitchIncludeWildCards = false;
AddToCensorFromNonSwitchesStrings(wildcardCensor, nonSwitchStrings, recursedType,
thereAreSwitchIncludeWildCards);
bool yesToAll = parser[NKey::kYes].ThereIs;
#ifdef _WIN32
if (archiveName.Right(kDefaultExtLength).CompareNoCase(kDefaultExt) != 0)
archiveName += kDefaultExt;
#endif
// NExtractMode::EEnum extractMode;
// bool isExtractGroupCommand = command.IsFromExtractGroup(extractMode);
bool passwordEnabled = parser[NKey::kPassword].ThereIs;
UString password;
if(passwordEnabled)
password = parser[NKey::kPassword].PostStrings[0];
NFind::CFileInfoW archiveFileInfo;
if (!NFind::FindFile(archiveName, archiveFileInfo))
throw kCantFindSFX;
if (archiveFileInfo.IsDir())
throw kCantFindSFX;
UString outputDir;
if(parser[NKey::kOutputDir].ThereIs)
{
outputDir = parser[NKey::kOutputDir].PostStrings[0];
NName::NormalizeDirPathPrefix(outputDir);
}
{
UStringVector v1, v2;
v1.Add(archiveName);
v2.Add(archiveName);
const NWildcard::CCensorNode &wildcardCensorHead =
wildcardCensor.Pairs.Front().Head;
//.........这里部分代码省略.........