summaryrefslogtreecommitdiff
path: root/shell/source/win32/shlxthandler/ooofilt/ooofilt.cxx
diff options
context:
space:
mode:
authorRelease Engineers <releng@openoffice.org>2009-08-10 06:05:55 +0000
committerRelease Engineers <releng@openoffice.org>2009-08-10 06:05:55 +0000
commit174c4ec63ebd420fe60c09ac7e4f17116ec557bc (patch)
tree1f0c5ea1af53d1c628ef3e8c275b4be0bbb8c9ad /shell/source/win32/shlxthandler/ooofilt/ooofilt.cxx
parent6cdf425050de733e5490717eeaa715d0b2738c61 (diff)
CWS-TOOLING: integrate CWS tkr23
2009-07-21 15:03:57 +0200 tkr r274199 : #i64277# open file only if needed and close immediately after use 2009-07-17 12:25:41 +0200 tkr r274087 : #i96743# patch minizip to provide stream operations 2009-07-17 12:21:13 +0200 tkr r274086 : #i96743# add new ifilter interface: IPersistStream
Diffstat (limited to 'shell/source/win32/shlxthandler/ooofilt/ooofilt.cxx')
-rw-r--r--shell/source/win32/shlxthandler/ooofilt/ooofilt.cxx212
1 files changed, 210 insertions, 2 deletions
diff --git a/shell/source/win32/shlxthandler/ooofilt/ooofilt.cxx b/shell/source/win32/shlxthandler/ooofilt/ooofilt.cxx
index 9d9ac04ee8..f907306e99 100644
--- a/shell/source/win32/shlxthandler/ooofilt/ooofilt.cxx
+++ b/shell/source/win32/shlxthandler/ooofilt/ooofilt.cxx
@@ -46,7 +46,7 @@
//--------------------------------------------------------------------------
#include "internal/contentreader.hxx"
#include "internal/metainforeader.hxx"
-#include "internal/utilities.hxx"
+//#include "internal/utilities.hxx"
#include "internal/registry.hxx"
#include "internal/fileextensions.hxx"
@@ -78,6 +78,8 @@
#include <ntquery.h>
#include "assert.h"
#include "ooofilt.hxx"
+#include <objidl.h>
+#include <stdio.h>
#include "propspec.hxx"
#ifdef __MINGW32__
#include <algorithm>
@@ -117,7 +119,9 @@ COooFilter::COooFilter() :
m_fEof(FALSE),
m_ChunkPosition(0),
m_cAttributes(0),
- m_pAttributes(0)
+ m_pAttributes(0),
+ m_pStream(NULL)
+
{
InterlockedIncrement( &g_lInstances );
}
@@ -172,6 +176,8 @@ SCODE STDMETHODCALLTYPE COooFilter::QueryInterface(
pUnkTemp = (IUnknown *)(IPersistFile *)this;
else if ( IID_IPersist == riid )
pUnkTemp = (IUnknown *)(IPersist *)(IPersistFile *)this;
+ else if (IID_IPersistStream == riid)
+ pUnkTemp = (IUnknown *)(IPersistStream *)this;
else if ( IID_IUnknown == riid )
pUnkTemp = (IUnknown *)(IPersist *)(IPersistFile *)this;
else
@@ -713,6 +719,101 @@ SCODE STDMETHODCALLTYPE COooFilter::SaveCompleted(LPCWSTR /*pszFileName*/)
// File is opened read-only, so "save" is always finished
return S_OK;
}
+
+//M-------------------------------------------------------------------------
+//
+// Method: COooFilter::Load (IPersistStream::Load)
+//
+// Summary: Initializes an object from the stream where it was previously saved
+//
+// Arguments: pStm
+// [in] Pointer to stream from which object should be loaded
+//
+//
+// Returns: S_OK
+// E_OUTOFMEMORY
+// E_FAIL
+//
+//
+//--------------------------------------------------------------------------
+SCODE STDMETHODCALLTYPE COooFilter::Load(IStream *pStm)
+{
+
+ // These next few lines work around the "Seek pointer" bug found on Vista.
+
+ char buf[20];
+ unsigned long count;
+ HRESULT hr;
+ ULARGE_INTEGER NewPosition;
+ LARGE_INTEGER Move;
+ Move.QuadPart = 0;
+ hr = pStm->Seek (Move, STREAM_SEEK_SET, &NewPosition);
+ hr = pStm->Read (buf, 20, &count);
+
+ zlib_filefunc_def z_filefunc;
+ fill_stream_filefunc (&z_filefunc);
+ z_filefunc.opaque = (void*)pStm;
+
+ m_pStream = pStm;
+
+ try
+ {
+ if (m_pMetaInfoReader)
+ delete m_pMetaInfoReader;
+ m_pMetaInfoReader = new CMetaInfoReader((void*)m_pStream, &z_filefunc);
+
+ if (m_pContentReader)
+ delete m_pContentReader;
+ m_pContentReader = new CContentReader((void*)m_pStream, m_pMetaInfoReader->getDefaultLocale(), &z_filefunc);
+ }
+ catch (const std::exception&)
+ {
+ return E_FAIL;
+ }
+ return S_OK;
+}
+
+//M-------------------------------------------------------------------------
+//
+// Method: COooFilter::GetSizeMax (IPersistStream::GetSizeMax)
+//
+// Summary: Returns the size in bytes of the stream neede to save the object.
+//
+// Arguments: pcbSize
+// [out] Pointer to a 64 bit unsigned int indicating the size needed
+//
+// Returns: E_NOTIMPL
+//
+//
+//--------------------------------------------------------------------------
+SCODE STDMETHODCALLTYPE COooFilter::GetSizeMax(ULARGE_INTEGER * /*pcbSize*/)
+{
+ //
+ return E_NOTIMPL;
+}
+
+//M-------------------------------------------------------------------------
+//
+// Method: COooFilter::Save (IPersistStream::Save)
+//
+// Summary: Save object to specified stream
+//
+// Arguments: pStm
+// [in] Pointer to stream
+//
+// fClearDirty
+// [in] Indicates whether to clear dirty flag
+//
+// Returns: E_NOTIMPL
+//
+//
+//--------------------------------------------------------------------------
+SCODE STDMETHODCALLTYPE COooFilter::Save(IStream * /*pStm*/, BOOL )
+{
+ //
+ return E_NOTIMPL;
+}
+
//M-------------------------------------------------------------------------
//
// Method: COooFilter::GetCurFile (IPersistFile::GetCurFile)
@@ -1142,8 +1243,18 @@ namespace /* private */
std::string ClsidEntry_Persist = CLSID_GUID_ENTRY;
SubstitutePlaceholder(ClsidEntry_Persist, GUID_PLACEHOLDER, ClsidToString(PersistentGuid));
+
if (!SetRegistryKey(HKEY_CLASSES_ROOT, ClsidEntry_Persist.c_str(), "", "OpenOffice.org Persistent Handler"))
return E_FAIL;
+
+ // Add missing entry
+ std::string ClsidEntry_Persist_Entry = CLSID_PERSIST_ENTRY;
+ SubstitutePlaceholder(ClsidEntry_Persist_Entry,
+ GUID_PLACEHOLDER,
+ ClsidToString(PersistentGuid));
+
+ if (!SetRegistryKey(HKEY_CLASSES_ROOT, ClsidEntry_Persist_Entry.c_str(), "", ClsidToString(PersistentGuid).c_str()));
+
std::string ClsidEntry_Persist_Addin = CLSID_GUID_PERSIST_ADDIN_ENTRY;
SubstitutePlaceholder(ClsidEntry_Persist_Addin,
@@ -1393,3 +1504,100 @@ STDAPI DllUnregisterServer()
*/
return S_OK;
}
+
+extern "C" {
+
+ // IStream callback
+ voidpf ZCALLBACK cb_sopen (voidpf opaque, const char* filename, int mode) {
+ return opaque;
+ }
+
+ uLong ZCALLBACK cb_sread (voidpf opaque, voidpf stream, void* buf, uLong size) {
+ unsigned long newsize;
+ HRESULT hr;
+
+ hr = ((IStream *)stream)->Read (buf, size, &newsize);
+ if (hr == S_OK){
+ return (unsigned long)newsize;
+ }
+ else {
+ return (uLong)0;
+ }
+ }
+
+ long ZCALLBACK cb_sseek (voidpf opaque, voidpf stream, uLong offset, int origin) {
+ // IStream::Seek parameters
+ HRESULT hr;
+ LARGE_INTEGER Move;
+ DWORD dwOrigin;
+ Move.QuadPart = (__int64)offset;
+
+ switch (origin) {
+ case SEEK_CUR:
+ dwOrigin = STREAM_SEEK_CUR;
+ break;
+ case SEEK_END:
+ dwOrigin = STREAM_SEEK_END;
+ break;
+ case SEEK_SET:
+ dwOrigin = STREAM_SEEK_SET;
+ break;
+ default:
+ return -1;
+ }
+
+ hr = ((IStream*)stream)->Seek (Move, dwOrigin, NULL);
+ if (hr == S_OK){
+ return 0;
+ }
+ else {
+ return -1;
+ }
+ }
+
+ long ZCALLBACK cb_stell (voidpf opaque, voidpf stream) {
+ // IStream::Seek parameters
+ HRESULT hr;
+ LARGE_INTEGER Move;
+ ULARGE_INTEGER NewPosition;
+ Move.QuadPart = 0;
+ NewPosition.QuadPart = 0;
+
+ hr = ((IStream*)stream)->Seek (Move, STREAM_SEEK_CUR, &NewPosition);
+ if (hr == S_OK){
+ return (long) NewPosition.QuadPart;
+ }
+ else {
+ return -1;
+ }
+ }
+
+ int ZCALLBACK cb_sclose (voidpf opaque, voidpf stream) {
+ return 0;
+ }
+
+ int ZCALLBACK cb_serror (voidpf opaque, voidpf stream) {
+ return 0; //RJK - for now
+ }
+
+ uLong ZCALLBACK cb_swrite (voidpf opaque, voidpf stream, const void* buf, uLong size) {
+ HRESULT hr;
+ unsigned long writecount;
+ hr = ((IStream*)stream)->Write (buf, size, &writecount);
+ if (hr == S_OK)
+ return (unsigned int)writecount;
+ else
+ return (uLong)0;
+ }
+
+ void fill_stream_filefunc (zlib_filefunc_def* pzlib_filefunc_def) {
+ pzlib_filefunc_def->zopen_file = cb_sopen;
+ pzlib_filefunc_def->zread_file = cb_sread;
+ pzlib_filefunc_def->zwrite_file = cb_swrite;
+ pzlib_filefunc_def->ztell_file = cb_stell;
+ pzlib_filefunc_def->zseek_file = cb_sseek;
+ pzlib_filefunc_def->zclose_file = cb_sclose;
+ pzlib_filefunc_def->zerror_file = cb_serror;
+ }
+}
+