本文整理汇总了C++中CInFileStream::Open方法的典型用法代码示例。如果您正苦于以下问题:C++ CInFileStream::Open方法的具体用法?C++ CInFileStream::Open怎么用?C++ CInFileStream::Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CInFileStream
的用法示例。
在下文中一共展示了CInFileStream::Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LZMADecodeFile
bool LZMADecodeFile ( const char *fromFile, const char *toFile, CProgressInfo7Zip *progress )
{
CMyComPtr<ISequentialInStream> inStream;
CInFileStream *inStreamSpec = new CInFileStream;
inStream = inStreamSpec;
if ( !inStreamSpec->Open ( GetSystemString(fromFile) ) )
return false;
CMyComPtr<ISequentialOutStream> outStream;
COutFileStream *outStreamSpec = new COutFileStream;
outStream = outStreamSpec;
if ( !outStreamSpec->Create ( GetSystemString(toFile), true ) )
return false;
NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;
CMyComPtr<ICompressCoder> decoder = decoderSpec;
const UInt32 kPropertiesSize = 5;
Byte properties[kPropertiesSize];
UInt32 processedSize;
if ( ReadStream (inStream, properties, kPropertiesSize, &processedSize) != S_OK )
return false;
if ( processedSize != kPropertiesSize )
return false;
if ( decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK )
return false;
UInt64 fileSize = 0;
for (int i = 0; i < 8; i++)
{
Byte b;
if ( inStream->Read(&b, 1, &processedSize) != S_OK )
return false;
if ( processedSize != 1 )
return false;
fileSize |= ((UInt64)b) << (8 * i);
}
if ( progress )
{
progress->Init();
progress->ApprovedStart = 1 << 21;
progress->SetMax ( fileSize );
}
if ( decoder->Code(inStream, outStream, 0, &fileSize, progress) != S_OK )
// decoder error
return false;
return true;
}
示例2: ReOpenArchive
HRESULT ReOpenArchive(IInArchive *archive, const UString &fileName, IArchiveOpenCallback *openArchiveCallback)
{
CInFileStream *inStreamSpec = new CInFileStream;
CMyComPtr<IInStream> inStream(inStreamSpec);
inStreamSpec->Open(fileName);
return archive->Open(inStream, &kMaxCheckStartPosition, openArchiveCallback);
}
示例3: OpenStreamOrFile
HRESULT CArc::OpenStreamOrFile(
CCodecs *codecs,
int formatIndex,
bool stdInMode,
IInStream *stream,
IArchiveOpenCallback *callback)
{
CMyComPtr<IInStream> fileStream;
CMyComPtr<ISequentialInStream> seqStream;
if (stdInMode)
seqStream = new CStdInFileStream;
else if (!stream)
{
CInFileStream *fileStreamSpec = new CInFileStream;
fileStream = fileStreamSpec;
if (!fileStreamSpec->Open(Path))
return GetLastError();
stream = fileStream;
}
/*
if (callback)
{
UInt64 fileSize;
RINOK(stream->Seek(0, STREAM_SEEK_END, &fileSize));
RINOK(callback->SetTotal(NULL, &fileSize))
}
*/
return OpenStream(codecs, formatIndex, stream, seqStream, callback);
}
示例4: RINOK
STDMETHODIMP P7ZipArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)
{
RINOK(Finilize());
const CDirItem &dirItem = (*DirItems)[index];
GetStream2(dirItem.Name);
if (dirItem.isDir())
return S_OK;
{
CInFileStream *inStreamSpec = new CInFileStream;
CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);
UString path = DirPrefix + dirItem.FullPath;
if (!inStreamSpec->Open(path))
{
DWORD sysError = ::GetLastError();
FailedCodes.Add(sysError);
FailedFiles.Add(path);
// if (systemError == ERROR_SHARING_VIOLATION)
{
PrintNewLine();
PrintError("WARNING: can't open file");
// PrintString(NError::MyFormatMessageW(systemError));
return S_FALSE;
}
// return sysError;
}
*inStream = inStreamLoc.Detach();
}
return S_OK;
}
示例5: open_instream
int open_instream(const string infile,
CMyComPtr<ISequentialInStream> &inStream,
UInt64 &fileSize)
{
CInFileStream *inStreamSpec = new CInFileStream;
inStream = inStreamSpec;
if (!inStreamSpec->Open(infile.c_str()))
throw Exception("Cannot open input file " + infile);
inStreamSpec->File.GetLength(fileSize);
return inStreamSpec->File.GetHandle();
}
示例6: OpenArchive
HRESULT OpenArchive(
CCodecs *codecs,
const UString &filePath,
IInArchive **archiveResult,
int &formatIndex,
UString &defaultItemName,
IArchiveOpenCallback *openArchiveCallback)
{
CInFileStream *inStreamSpec = new CInFileStream;
CMyComPtr<IInStream> inStream(inStreamSpec);
if (!inStreamSpec->Open(filePath))
return GetLastError();
return OpenArchive(codecs, inStream, ExtractFileNameFromPath(filePath),
archiveResult, formatIndex,
defaultItemName, openArchiveCallback);
}
示例7: ReOpen
HRESULT CArchiveLink::ReOpen(CCodecs *codecs, const UString &filePath,
IArchiveOpenCallback *callback)
{
if (Arcs.Size() > 1)
return E_NOTIMPL;
if (Arcs.Size() == 0)
return Open2(codecs, CIntVector(), false, NULL, filePath, 0);
CMyComPtr<IArchiveOpenCallback> openCallbackNew;
SetCallback(filePath, NULL, callback, openCallbackNew);
CInFileStream *fileStreamSpec = new CInFileStream;
CMyComPtr<IInStream> stream(fileStreamSpec);
if (!fileStreamSpec->Open(filePath))
return GetLastError();
HRESULT res = GetArchive()->Open(stream, &kMaxCheckStartPosition, callback);
IsOpen = (res == S_OK);
return res;
}
示例8: aec
bool vms7zipArchive::Extract(LPCSTR pszArchive, LPCSTR pszOutFolder)
{
CInFileStream *fileSpec = new CInFileStream;
CMyComPtr <IInStream> spFile = fileSpec;
m_errExtract = AEE_GENERIC_ERROR;
if (false == fileSpec->Open(pszArchive))
return false;
CMyComPtr <IInArchive> spArc;
vms7zipFormatDLL dll;
if (false == Find7zipDLL (dll, pszArchive, true, spFile, spArc) &&
false == Find7zipDLL (dll, pszArchive, false, spFile, spArc))
return false;
m_errExtract = AEE_NO_ERROR;
char sz [MY_MAX_PATH];
fsGetFileName (pszArchive, sz);
vms7zipArchiveExtractCallback aec (spArc, pszOutFolder, m_pAC, sz);
HRESULT hr;
if (FAILED (hr=spArc->Extract (NULL, (UInt32)-1, 0, &aec))) {
spArc = NULL;
m_errExtract = aec.is_AbortedByUser () ? AEE_ABORTED_BY_USER : AEE_GENERIC_ERROR;
return false;
}
spArc = NULL;
if (*aec.get_FurtherExtractFile () != 0) {
bool b = Extract (aec.get_FurtherExtractFile (), pszOutFolder);
DeleteFile (aec.get_FurtherExtractFile ());
return b;
}
return true;
}
示例9: GetStream
STDMETHODIMP COpenArchiveCallback::GetStream(const wchar_t *name, IInStream **inStream)
{
COM_TRY_BEGIN
*inStream = NULL;
if (_subArchiveMode)
return S_FALSE;
FString fullPath;
if (!NFile::NName::GetFullPath(_folderPrefix, us2fs(name), fullPath))
return S_FALSE;
if (!_fileInfo.Find(fullPath))
return S_FALSE;
if (_fileInfo.IsDir())
return S_FALSE;
CInFileStream *inFile = new CInFileStream;
CMyComPtr<IInStream> inStreamTemp = inFile;
if (!inFile->Open(fullPath))
return ::GetLastError();
*inStream = inStreamTemp.Detach();
return S_OK;
COM_TRY_END
}
示例10: GetStream
STDMETHODIMP COpenArchiveCallback::GetStream(const wchar_t *name,
IInStream **inStream)
{
*inStream = NULL;
if (_subArchiveMode)
return S_FALSE;
NWindows::NFile::NFind::CFileInfoW fileInfo;
UString fullPath = _folderPrefix + name;
if (!NWindows::NFile::NFind::FindFile(fullPath, fileInfo))
return S_FALSE;
_fileInfo = fileInfo;
if (_fileInfo.IsDir())
return S_FALSE;
CInFileStream *inFile = new CInFileStream;
CMyComPtr<IInStream> inStreamTemp = inFile;
if (!inFile->Open(fullPath))
return ::GetLastError();
*inStream = inStreamTemp.Detach();
return S_OK;
}
示例11: OpenStreamOrFile
HRESULT CArc::OpenStreamOrFile(
CCodecs *codecs,
int formatIndex,
bool stdInMode,
IInStream *stream,
IArchiveOpenCallback *callback)
{
CMyComPtr<IInStream> fileStream;
CMyComPtr<ISequentialInStream> seqStream;
if (stdInMode)
seqStream = new CStdInFileStream;
else if (!stream)
{
CInFileStream *fileStreamSpec = new CInFileStream(true);
fileStream = fileStreamSpec;
if (!fileStreamSpec->Open(Path))
return GetLastError();
stream = fileStream;
}
return OpenStream(codecs, formatIndex, stream, seqStream, callback);
}
示例12: main2
//.........这里部分代码省略.........
numIterations = kNumDefaultItereations;
}
return LzmaBenchCon(stderr, numIterations, numThreads, dictionary);
}
if (numThreads == (UInt32)-1)
numThreads = 1;
bool encodeMode = false;
if (command.CompareNoCase(L"e") == 0)
encodeMode = true;
else if (command.CompareNoCase(L"d") == 0)
encodeMode = false;
else
IncorrectCommand();
bool stdInMode = parser[NKey::kStdIn].ThereIs;
bool stdOutMode = parser[NKey::kStdOut].ThereIs;
CMyComPtr<ISequentialInStream> inStream;
CInFileStream *inStreamSpec = 0;
if (stdInMode)
{
inStream = new CStdInFileStream;
MY_SET_BINARY_MODE(stdin);
}
else
{
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &inputName = nonSwitchStrings[paramIndex++];
inStreamSpec = new CInFileStream;
inStream = inStreamSpec;
if (!inStreamSpec->Open(GetSystemString(inputName)))
{
fprintf(stderr, "\nError: can not open input file %s\n",
(const char *)GetOemString(inputName));
return 1;
}
}
CMyComPtr<ISequentialOutStream> outStream;
COutFileStream *outStreamSpec = NULL;
if (stdOutMode)
{
outStream = new CStdOutFileStream;
MY_SET_BINARY_MODE(stdout);
}
else
{
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &outputName = nonSwitchStrings[paramIndex++];
outStreamSpec = new COutFileStream;
outStream = outStreamSpec;
if (!outStreamSpec->Create(GetSystemString(outputName), true))
{
fprintf(stderr, "\nError: can not open output file %s\n",
(const char *)GetOemString(outputName));
return 1;
}
}
if (parser[NKey::kFilter86].ThereIs)
{
// -f86 switch is for x86 filtered mode: BCJ + LZMA.
示例13: DoOperation
//.........这里部分代码省略.........
}
CObjectVector<CArcItem> arcItems;
if (GetArchive())
{
RINOK(ReadItems());
EnumerateArchiveItems(this, _proxyArchive->RootFolder, L"", arcItems);
}
CRecordVector<CUpdatePair2> updatePairs2;
{
CRecordVector<CUpdatePair> updatePairs;
GetUpdatePairInfoList(dirItems, arcItems, fileTimeType, updatePairs);
CAgUpCallbackImp upCallback(&arcItems, updateCallback100);
UpdateProduce(updatePairs, actionSet, updatePairs2, &upCallback);
}
UInt32 numFiles = 0;
for (i = 0; i < updatePairs2.Size(); i++)
if (updatePairs2[i].NewData)
numFiles++;
if (updateCallback100)
{
RINOK(updateCallback100->SetNumFiles(numFiles));
}
CUpdateCallbackAgent updateCallbackAgent;
updateCallbackAgent.SetCallback(updateCallback100);
CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;
CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec );
updateCallbackSpec->DirItems = &dirItems;
updateCallbackSpec->ArcItems = &arcItems;
updateCallbackSpec->UpdatePairs = &updatePairs2;
updateCallbackSpec->Archive = GetArchive();
updateCallbackSpec->Callback = &updateCallbackAgent;
COutFileStream *outStreamSpec = new COutFileStream;
CMyComPtr<IOutStream> outStream(outStreamSpec);
UString archiveName = newArchiveName;
{
UString resultPath;
int pos;
if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))
return E_FAIL;
NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));
}
if (!outStreamSpec->Create(archiveName, true))
{
// ShowLastErrorMessage();
return E_FAIL;
}
CMyComPtr<ISetProperties> setProperties;
if (outArchive->QueryInterface(IID_ISetProperties, (void **)&setProperties) == S_OK)
{
if (m_PropNames.Size() == 0)
{
RINOK(setProperties->SetProperties(0, 0, 0));
}
else
{
CRecordVector<const wchar_t *> names;
for(i = 0; i < m_PropNames.Size(); i++)
names.Add((const wchar_t *)m_PropNames[i]);
NWindows::NCOM::CPropVariant *propValues = new NWindows::NCOM::CPropVariant[m_PropValues.Size()];
try
{
for (int i = 0; i < m_PropValues.Size(); i++)
propValues[i] = m_PropValues[i];
RINOK(setProperties->SetProperties(&names.Front(), propValues, names.Size()));
}
catch(...)
{
delete []propValues;
return E_FAIL;
}
delete []propValues;
}
}
m_PropNames.Clear();
m_PropValues.Clear();
if (sfxModule != NULL)
{
CInFileStream *sfxStreamSpec = new CInFileStream;
CMyComPtr<IInStream> sfxStream(sfxStreamSpec);
if (!sfxStreamSpec->Open(sfxModule))
return E_FAIL;
// throw "Can't open sfx module";
RINOK(CopyBlock(sfxStream, outStream));
}
RINOK(outArchive->UpdateItems(outStream, updatePairs2.Size(),updateCallback));
return outStreamSpec->Close();
}
示例14: main2
int main2(int n, const char *args[])
{
if (strcmp(args[n - 1], "-notitle") == 0)
n--;
else {
fprintf(stderr,
"\nt5lzma 1.00 Copyright (C) 2004 H.Kawai\n"
" --- based : LZMA 4.03 Copyright (c) 1999-2004 Igor Pavlov 2004-06-18\n"
);
}
if (n == 1)
{
PrintHelp();
return 0;
}
if (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4)
{
fprintf(stderr, "Unsupported base types. Edit Common/Types.h and recompile");
return 1;
}
UStringVector commandStrings;
WriteArgumentsToStringList(n, args, commandStrings);
CParser parser(kNumSwitches);
try
{
parser.ParseStrings(kSwitchForms, commandStrings);
}
catch(...)
{
IncorrectCommand();
}
if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)
{
PrintHelp();
return 0;
}
const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
int paramIndex = 0;
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &command = nonSwitchStrings[paramIndex++];
if (command.CompareNoCase(L"b") == 0)
{
UInt32 dictionary = 1 << 21;
if(parser[NKey::kDictionary].ThereIs)
{
UInt32 dicLog;
if (!GetNumber(parser[NKey::kDictionary].PostStrings[0], dicLog))
IncorrectCommand();
dictionary = 1 << dicLog;
}
const UInt32 kNumDefaultItereations = 10;
UInt32 numIterations = kNumDefaultItereations;
{
if (paramIndex < nonSwitchStrings.Size())
if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))
numIterations = kNumDefaultItereations;
}
return LzmaBenchmark(numIterations, dictionary);
}
bool encodeMode;
if (command.CompareNoCase(L"e") == 0)
encodeMode = true;
else if (command.CompareNoCase(L"d") == 0)
encodeMode = false;
else
IncorrectCommand();
bool stdInMode = parser[NKey::kStdIn].ThereIs;
bool stdOutMode = parser[NKey::kStdOut].ThereIs;
CMyComPtr<ISequentialInStream> inStream;
CInFileStream *inStreamSpec = 0;
if (stdInMode)
{
inStream = new CStdInFileStream;
MY_SET_BINARY_MODE(stdin);
}
else
{
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &inputName = nonSwitchStrings[paramIndex++];
inStreamSpec = new CInFileStream;
inStream = inStreamSpec;
if (!inStreamSpec->Open(GetSystemString(inputName)))
{
fprintf(stderr, "\nError: can not open input file %s\n",
(const char *)GetOemString(inputName));
return 1;
}
}
//.........这里部分代码省略.........
示例15: LZMAEncodeFile
bool LZMAEncodeFile ( const char *fromFile, const char *toFile, CProgressInfo7Zip *progress )
{
bool eos = false;
CMyComPtr<ISequentialInStream> inStream;
CInFileStream *inStreamSpec = new CInFileStream;
inStream = inStreamSpec;
if ( !inStreamSpec->Open ( GetSystemString(fromFile) ) )
return false;
CMyComPtr<ISequentialOutStream> outStream;
COutFileStream *outStreamSpec = new COutFileStream;
outStream = outStreamSpec;
if ( !outStreamSpec->Create ( GetSystemString(toFile), true ) )
return false;
NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;
CMyComPtr<ICompressCoder> encoder = encoderSpec;
UInt32 dictionary = 1 << 21;
UInt32 posStateBits = 2;
UInt32 litContextBits = 3; // for normal files
// UInt32 litContextBits = 0; // for 32-bit data
UInt32 litPosBits = 0;
// UInt32 litPosBits = 2; // for 32-bit data
UInt32 algorithm = 2;
UInt32 numFastBytes = 128;
UInt32 matchFinderCycles = 16 + numFastBytes / 2;
bool matchFinderCyclesDefined = false;
//bool eos = parser[NKey::kEOS].ThereIs || stdInMode;
PROPID propIDs[] =
{
NCoderPropID::kDictionarySize,
NCoderPropID::kPosStateBits,
NCoderPropID::kLitContextBits,
NCoderPropID::kLitPosBits,
NCoderPropID::kAlgorithm,
NCoderPropID::kNumFastBytes,
NCoderPropID::kMatchFinder,
NCoderPropID::kEndMarker,
NCoderPropID::kMatchFinderCycles
};
const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);
UString mf = L"BT4";
PROPVARIANT properties[kNumPropsMax];
for (int p = 0; p < 6; p++)
properties[p].vt = VT_UI4;
properties[0].ulVal = UInt32(dictionary);
properties[1].ulVal = UInt32(posStateBits);
properties[2].ulVal = UInt32(litContextBits);
properties[3].ulVal = UInt32(litPosBits);
properties[4].ulVal = UInt32(algorithm);
properties[5].ulVal = UInt32(numFastBytes);
properties[8].vt = VT_UI4;
properties[8].ulVal = UInt32(matchFinderCycles);
properties[6].vt = VT_BSTR;
properties[6].bstrVal = (BSTR)(const wchar_t *)mf;
properties[7].vt = VT_BOOL;
properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;
int numProps = kNumPropsMax;
if (!matchFinderCyclesDefined)
numProps--;
if ( encoderSpec->SetCoderProperties(propIDs, properties, numProps) != S_OK )
return false;
encoderSpec->WriteCoderProperties(outStream);
UInt64 fileSize = 0;
if ( eos )
fileSize = (UInt64)(Int64)-1;
else
inStreamSpec->File.GetLength(fileSize);
for (int i = 0; i < 8; i++)
{
Byte b = Byte(fileSize >> (8 * i));
if (outStream->Write(&b, 1, 0) != S_OK)
return false;
}
if ( progress )
{
progress->Init();
progress->SetMax ( fileSize );
progress->ApprovedStart = 1 << 21;
progress->SetIn ( true );
}
HRESULT result = encoder->Code(inStream, outStream, 0, 0, progress );
if (result == E_OUTOFMEMORY)
//.........这里部分代码省略.........