本文整理汇总了C++中COutArchive::WriteDatabase方法的典型用法代码示例。如果您正苦于以下问题:C++ COutArchive::WriteDatabase方法的具体用法?C++ COutArchive::WriteDatabase怎么用?C++ COutArchive::WriteDatabase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类COutArchive
的用法示例。
在下文中一共展示了COutArchive::WriteDatabase方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteVolumeHeader
static HRESULT WriteVolumeHeader(COutArchive &archive, CFileItem &file, const CUpdateOptions &options)
{
CCoderInfo coder;
coder.NumInStreams = coder.NumOutStreams = 1;
coder.MethodID = k_Copy;
CFolder folder;
folder.Coders.Add(coder);
folder.PackStreams.Add(0);
CNum numUnPackStreams = 0;
if (file.UnPackSize != 0)
{
file.IsFileCRCDefined = true;
file.HasStream = true;
numUnPackStreams++;
}
else
{
throw 1;
file.IsFileCRCDefined = false;
file.HasStream = false;
}
folder.UnPackSizes.Add(file.UnPackSize);
CArchiveDatabase newDatabase;
newDatabase.Files.Add(file);
newDatabase.Folders.Add(folder);
newDatabase.NumUnPackStreamsVector.Add(numUnPackStreams);
newDatabase.PackSizes.Add(file.UnPackSize);
newDatabase.PackCRCsDefined.Add(false);
newDatabase.PackCRCs.Add(file.FileCRC);
return archive.WriteDatabase(newDatabase,
options.HeaderMethod,
false,
false);
}
示例2: UpdateItems
//.........这里部分代码省略.........
ui.Size = (UInt64)prop.uhVal.QuadPart;
if (ui.Size != 0 && ui.IsAnti)
return E_INVALIDARG;
}
updateItems.Add(ui);
}
CCompressionMethodMode methodMode, headerMethod;
RINOK(SetCompressionMethod(methodMode, headerMethod));
#ifdef COMPRESS_MT
methodMode.NumThreads = _numThreads;
headerMethod.NumThreads = 1;
#endif
CMyComPtr<ICryptoGetTextPassword2> getPassword2;
updateCallback->QueryInterface(IID_ICryptoGetTextPassword2, (void **)&getPassword2);
if (getPassword2)
{
CMyComBSTR password;
Int32 passwordIsDefined;
RINOK(getPassword2->CryptoGetTextPassword2(&passwordIsDefined, &password));
methodMode.PasswordIsDefined = IntToBool(passwordIsDefined);
if (methodMode.PasswordIsDefined)
methodMode.Password = password;
}
else
methodMode.PasswordIsDefined = false;
bool compressMainHeader = _compressHeaders; // check it
bool encryptHeaders = false;
if (methodMode.PasswordIsDefined)
{
if (_encryptHeadersSpecified)
encryptHeaders = _encryptHeaders;
#ifndef _NO_CRYPTO
else
encryptHeaders = _passwordIsDefined;
#endif
compressMainHeader = true;
if (encryptHeaders)
{
headerMethod.PasswordIsDefined = methodMode.PasswordIsDefined;
headerMethod.Password = methodMode.Password;
}
}
if (numItems < 2)
compressMainHeader = false;
CUpdateOptions options;
options.Method = &methodMode;
options.HeaderMethod = (_compressHeaders || encryptHeaders) ? &headerMethod : 0;
options.UseFilters = _level != 0 && _autoFilter;
options.MaxFilter = _level >= 8;
options.HeaderOptions.CompressMainHeader = compressMainHeader;
options.HeaderOptions.WriteCTime = WriteCTime;
options.HeaderOptions.WriteATime = WriteATime;
options.HeaderOptions.WriteMTime = WriteMTime;
options.NumSolidFiles = _numSolidFiles;
options.NumSolidBytes = _numSolidBytes;
options.SolidExtension = _solidExtension;
options.RemoveSfxBlock = _removeSfxBlock;
options.VolumeMode = _volumeMode;
COutArchive archive;
CArchiveDatabase newDatabase;
CMyComPtr<ICryptoGetTextPassword> getPassword;
updateCallback->QueryInterface(IID_ICryptoGetTextPassword, (void **)&getPassword);
HRESULT res = Update(
EXTERNAL_CODECS_VARS
#ifdef _7Z_VOL
volume ? volume->Stream: 0,
volume ? db : 0,
#else
_inStream,
db,
#endif
updateItems,
archive, newDatabase, outStream, updateCallback, options
#ifndef _NO_CRYPTO
, getPassword
#endif
);
RINOK(res);
updateItems.ClearAndFree();
return archive.WriteDatabase(EXTERNAL_CODECS_VARS
newDatabase, options.HeaderMethod, options.HeaderOptions);
COM_TRY_END
}
示例3: encoder
//.........这里部分代码省略.........
int startPackIndex = newDatabase.PackSizes.Size();
RINOK(encoder.Encode(
EXTERNAL_CODECS_LOC_VARS
solidInStream, NULL, &inSizeForReduce, folderItem,
archive.SeqStream, newDatabase.PackSizes, progress));
for (; startPackIndex < newDatabase.PackSizes.Size(); startPackIndex++)
lps->OutSize += newDatabase.PackSizes[startPackIndex];
lps->InSize += folderItem.GetUnPackSize();
// for()
// newDatabase.PackCRCsDefined.Add(false);
// newDatabase.PackCRCs.Add(0);
newDatabase.Folders.Add(folderItem);
CNum numUnPackStreams = 0;
for (int subIndex = 0; subIndex < numSubFiles; subIndex++)
{
const CUpdateItem &updateItem = updateItems[indices[i + subIndex]];
CFileItem file;
if (updateItem.NewProperties)
FromUpdateItemToFileItem(updateItem, file);
else
file = database->Files[updateItem.IndexInArchive];
if (file.IsAnti || file.IsDirectory)
return E_FAIL;
/*
CFileItem &file = newDatabase.Files[
startFileIndexInDatabase + i + subIndex];
*/
if (!inStreamSpec->Processed[subIndex])
{
continue;
// file.Name += L".locked";
}
file.FileCRC = inStreamSpec->CRCs[subIndex];
file.UnPackSize = inStreamSpec->Sizes[subIndex];
if (file.UnPackSize != 0)
{
file.IsFileCRCDefined = true;
file.HasStream = true;
numUnPackStreams++;
}
else
{
file.IsFileCRCDefined = false;
file.HasStream = false;
}
newDatabase.Files.Add(file);
}
// numUnPackStreams = 0 is very bad case for locked files
// v3.13 doesn't understand it.
newDatabase.NumUnPackStreamsVector.Add(numUnPackStreams);
i += numSubFiles;
}
}
{
/////////////////////////////////////////
// Write Empty Files & Folders
CRecordVector<int> emptyRefs;
for(i = 0; i < updateItems.Size(); i++)
{
const CUpdateItem &updateItem = updateItems[i];
if (updateItem.NewData)
{
if (updateItem.HasStream())
continue;
}
else
if (updateItem.IndexInArchive != -1)
if (database->Files[updateItem.IndexInArchive].HasStream)
continue;
emptyRefs.Add(i);
}
emptyRefs.Sort(CompareEmptyItems, (void *)&updateItems);
for(i = 0; i < emptyRefs.Size(); i++)
{
const CUpdateItem &updateItem = updateItems[emptyRefs[i]];
CFileItem file;
if (updateItem.NewProperties)
FromUpdateItemToFileItem(updateItem, file);
else
file = database->Files[updateItem.IndexInArchive];
newDatabase.Files.Add(file);
}
}
/*
if (newDatabase.Files.Size() != updateItems.Size())
return E_FAIL;
*/
return archive.WriteDatabase(EXTERNAL_CODECS_LOC_VARS
newDatabase, options.HeaderMethod, options.HeaderOptions);
}
示例4: ExplodeArchives
//.........这里部分代码省略.........
// Save each folder as a new 7z archive
for (int x = 0; x < exploded.Size(); x++) {
UString relativeFilePath; // relative to archive
UString fileName;
CArchiveDatabase& newDatabase = exploded[x].newDatabase;
szExplodeData& explodeData = exploded[x];
// each exploded archive will only have a single folder.
// no longer true. need to make sure the selected file
// is the highest in the dir tree. could make 7zhandler
// give us this info i guess.
if (newDatabase.Files.Size() > 0) {
relativeFilePath = newDatabase.Files[0].Name;
if (!newDatabase.Files[0].IsDir) {
fileName = GetFileFromPath(relativeFilePath);
StripFile(relativeFilePath);
}
}
//g_StdOut << "Relative path " << relativeFilePath << endl;
//g_StdOut << "Archive " << archivePath << endl;
UString folderOutPath = outputPath + relativeFilePath;
if (relativeFilePath.Length() != 0) {
bool b = NWindows::NFile::NDirectory::CreateComplexDirectory(folderOutPath);
if (!b) g_StdOut << "Couldn't create directory " << folderOutPath << endl;
//relativeFilePath.Insert(folderOutPath.Length(), L'/');
}
std::wstringstream sstream;
sstream << folderOutPath.GetBuffer();
if (newDatabase.Files.Size() == 1) // can use file names
sstream << fileName.GetBuffer();
else // use folder as name
sstream << archiveName.GetBuffer() << L"_folder_" << x;
sstream << ".7z";
g_StdOut << "Saving as '" << sstream.str().c_str() << "'" << endl;
COutFileStream* _outstream = new COutFileStream;
CMyComPtr<COutFileStream> outstream(_outstream);
outstream->Create(sstream.str().c_str(), true);
COutArchive out;
out.Create(outstream, false);
out.SkipPrefixArchiveHeader();
for (int folderIndex = 0; folderIndex < newDatabase.Folders.Size();
folderIndex++)
{
UInt64 folderLen = explodeData.folderSizes[folderIndex];
UInt64 folderStartPackPos = explodeData.folderPositions[folderIndex];
// write actual data
RINOK(WriteRange(inStream, out.SeqStream,
folderStartPackPos, folderLen, NULL));
}
CCompressionMethodMode method, headerMethod;
szHandler->SetCompressionMethod(method, headerMethod);
CHeaderOptions headerOptions;
headerOptions.CompressMainHeader = true;
out.WriteDatabase(newDatabase, &headerMethod, headerOptions);
out.Close();
/*#ifdef ENV_UNIX
// Create a symlink for each file in the folder.
// This makes it seem as though each file is individually accessible.
for (int fileIndex = 0; fileIndex < newDatabase.Files.Size(); fileIndex++) {
AString oldfile, newfile;
UString woldfile = sstream.str().c_str();
UString wnewfile = outputPath + relativeFilePath + newDatabase.Files[fileIndex].Name + L".7z";
ConvertUnicodeToUTF8(woldfile, oldfile);
ConvertUnicodeToUTF8(wnewfile, newfile);
const char* link_to = oldfile.GetBuffer();
const char* link_name = newfile.GetBuffer();
unlink(link_name);// should ask user
//g_StdOut << "Creating symlink to '" << link_to << "' called '" << link_name << "'" << endl;
int status = symlink(link_to, link_name);
if (status == -1) {
AString error = "Couldn't create symlink for '";
error += newfile;
error += "'";
SHOW_ERROR(error);
g_StdOut << "Error: " << errno << endl;
}
}
#endif*/
}
archiveLink.Close(); // not needed but oh well
}
return S_OK;
}