Versie 3.11: Zip.FileToHexStream toegevoegd
svn path=/Slnkdwf/trunk/; revision=20064
This commit is contained in:
@@ -300,6 +300,7 @@ interface IZip : IDispatch{
|
||||
[id(6), helpstring("method ZipFromStream")] HRESULT ZipFromStream([in] BSTR filepath, [in] VARIANT pVal, [in, defaultvalue(L"")] BSTR Password);
|
||||
[id(7), helpstring("method EncryptFromString")] HRESULT EncryptFromString([in] BSTR filepath, [in] BSTR data);
|
||||
[id(8), helpstring("method Close")] HRESULT Close(void);
|
||||
[id(9), helpstring("method FileToHexStream")] HRESULT FileToHexStream([in] BSTR filepath, [in] VARIANT pStream);
|
||||
};
|
||||
[
|
||||
object,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Zorg dat versies alfabetisch altijd op elkaar volgen!
|
||||
#define SLNK_MAJOR_VERSION 3
|
||||
#define SLNK_MINOR_VERSION 10
|
||||
#define SLNK_MINOR_VERSION 11
|
||||
#define SLNK_BUILD_VERSION 0
|
||||
|
||||
// Define resource strings
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Zip.h"
|
||||
#include "atlfile.h"
|
||||
|
||||
#define DATA_BUFFER_BYTES 4096
|
||||
|
||||
@@ -11,7 +12,7 @@
|
||||
|
||||
STDMETHODIMP CZip::InterfaceSupportsErrorInfo(REFIID riid)
|
||||
{
|
||||
static const IID* arr[] =
|
||||
static const IID* arr[] =
|
||||
{
|
||||
&IID_IZip
|
||||
};
|
||||
@@ -106,9 +107,9 @@ STDMETHODIMP CZip::UnzipToStream(VARIANT pStream, BSTR filepath, BSTR Password/*
|
||||
_DWFCORE_THROW( DWFMemoryException, L"No memory for data buffer" );
|
||||
}
|
||||
|
||||
DWFCore::DWFInputStream* pUnzipStream =
|
||||
DWFCore::DWFInputStream* pUnzipStream =
|
||||
m_pZipFile->unzip((LPCSTR)CString(filepath),(LPCSTR)CString(Password));
|
||||
|
||||
|
||||
while (pUnzipStream->available() > 0)
|
||||
{
|
||||
size_t nBytes;
|
||||
@@ -175,7 +176,7 @@ STDMETHODIMP CZip::ZipFromStream(BSTR filepath, VARIANT pStream, BSTR Password)
|
||||
{
|
||||
_DWFCORE_THROW( DWFMemoryException, L"No memory for data buffer" );
|
||||
}
|
||||
|
||||
|
||||
ULONG cbRead;
|
||||
do
|
||||
{
|
||||
@@ -239,3 +240,66 @@ STDMETHODIMP CZip::Close(void)
|
||||
m_pZipFile = NULL;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// Schrijft een file hex-encoded naar de stream
|
||||
// Stream moet al open zijn.
|
||||
STDMETHODIMP CZip::FileToHexStream(BSTR filepath, VARIANT pStream)
|
||||
{
|
||||
CComQIPtr<IStream> pIStream;
|
||||
|
||||
if (pStream.vt!=VT_ERROR)
|
||||
{
|
||||
VARIANT *var2 = &pStream;
|
||||
if (var2->vt==(VT_VARIANT|VT_BYREF)) // ByRef vanuit VBScript
|
||||
var2 = (VARIANT *)var2->pvarVal;
|
||||
|
||||
if (var2->vt==VT_DISPATCH)
|
||||
pIStream = var2->pdispVal;
|
||||
else if (var2->vt==(VT_DISPATCH|VT_BYREF)) // ByRef vanuit VB
|
||||
pIStream = *(var2->ppdispVal);
|
||||
|
||||
if (!pIStream)
|
||||
return E_INVALIDARG;
|
||||
|
||||
try
|
||||
{
|
||||
CAtlFile f;
|
||||
if (f.Create(CString(filepath), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING) != S_OK)
|
||||
return myAtlReportError (GetObjectCLSID(), "\nCZip::FileToHexStream('%ls')", filepath);
|
||||
|
||||
unsigned char* pDataBuffer = DWFCORE_ALLOC_MEMORY( unsigned char, DATA_BUFFER_BYTES );
|
||||
if (pDataBuffer == NULL)
|
||||
{
|
||||
_DWFCORE_THROW( DWFMemoryException, L"No memory for data buffer" );
|
||||
}
|
||||
|
||||
char const hex_chars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
DWORD cbRead;
|
||||
do
|
||||
{
|
||||
f.Read((void*)pDataBuffer, DATA_BUFFER_BYTES, cbRead);
|
||||
for (DWORD i = 0; i < cbRead; i++)
|
||||
{
|
||||
char const byte = pDataBuffer[i];
|
||||
|
||||
ULONG cbWritten;
|
||||
char hex[2];
|
||||
hex[0] = hex_chars[ ( byte & 0xF0 ) >> 4 ];
|
||||
hex[1] = hex_chars[ ( byte & 0x0F ) >> 0 ];
|
||||
pIStream->Write(hex, 2, &cbWritten);
|
||||
}
|
||||
}
|
||||
while (cbRead == DATA_BUFFER_BYTES);
|
||||
f.Close();
|
||||
|
||||
DWFCORE_FREE_MEMORY( pDataBuffer )
|
||||
}
|
||||
catch (DWFException& ex)
|
||||
{
|
||||
CString err;
|
||||
err.Format("%ls\n%ls\n%s\n%ls(%d)",ex.type(),ex.message(),ex.function(),ex.file(),ex.line());
|
||||
return myAtlReportError (GetObjectCLSID(), "\nCZip::ZipFromString('%ls')\n%s", filepath, err);
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ public:
|
||||
STDMETHOD(ZipFromStream)(BSTR filepath, VARIANT pStream, BSTR Password);
|
||||
STDMETHOD(EncryptFromString)(BSTR filepath, BSTR data);
|
||||
STDMETHOD(Close)(void);
|
||||
STDMETHOD(FileToHexStream)(BSTR filepath, VARIANT pStream);
|
||||
};
|
||||
|
||||
OBJECT_ENTRY_AUTO(__uuidof(Zip), CZip)
|
||||
|
||||
Reference in New Issue
Block a user