From eab47d4b85a8ba2a17fd8a107ceff0a823e35e49 Mon Sep 17 00:00:00 2001 From: opencollada-sebastian Date: Fri, 6 Nov 2009 15:42:27 +0000 Subject: [PATCH] add G3DWarehouseBrowser --- G3DWarehouseBrowser/G3DWarehouseBrowser.sln | 26 ++ G3DWarehouseBrowser/include/G3DBrowser.h | 65 +++ .../include/G3DDocHostUiHandler.h | 106 +++++ G3DWarehouseBrowser/include/G3DDownloadFile.h | 40 ++ .../include/G3DDownloadStatusCallback.h | 51 +++ G3DWarehouseBrowser/include/G3DFileUnzipper.h | 60 +++ .../include/G3DOleClientSite.h | 58 +++ .../include/G3DOleInPlaceFrame.h | 67 +++ .../include/G3DOleInPlaceSite.h | 102 +++++ .../include/G3DPrerequisites.h | 25 ++ .../include/G3DStableHeaders.h | 37 ++ .../scripts/G3DWarehouseBrowser.vcproj | 396 ++++++++++++++++++ G3DWarehouseBrowser/src/G3DBrowser.cpp | 315 ++++++++++++++ .../src/G3DDocHostUiHandler.cpp | 133 ++++++ .../src/G3DDownloadStatusCallback.cpp | 40 ++ G3DWarehouseBrowser/src/G3DFileUnzipper.cpp | 141 +++++++ G3DWarehouseBrowser/src/G3DOleClientSite.cpp | 53 +++ G3DWarehouseBrowser/src/G3DOleInPlaceSite.cpp | 32 ++ .../src/G3DPrecompiledHeaders.cpp | 11 + 19 files changed, 1758 insertions(+) create mode 100644 G3DWarehouseBrowser/G3DWarehouseBrowser.sln create mode 100644 G3DWarehouseBrowser/include/G3DBrowser.h create mode 100644 G3DWarehouseBrowser/include/G3DDocHostUiHandler.h create mode 100644 G3DWarehouseBrowser/include/G3DDownloadFile.h create mode 100644 G3DWarehouseBrowser/include/G3DDownloadStatusCallback.h create mode 100644 G3DWarehouseBrowser/include/G3DFileUnzipper.h create mode 100644 G3DWarehouseBrowser/include/G3DOleClientSite.h create mode 100644 G3DWarehouseBrowser/include/G3DOleInPlaceFrame.h create mode 100644 G3DWarehouseBrowser/include/G3DOleInPlaceSite.h create mode 100644 G3DWarehouseBrowser/include/G3DPrerequisites.h create mode 100644 G3DWarehouseBrowser/include/G3DStableHeaders.h create mode 100644 G3DWarehouseBrowser/scripts/G3DWarehouseBrowser.vcproj create mode 100644 G3DWarehouseBrowser/src/G3DBrowser.cpp create mode 100644 G3DWarehouseBrowser/src/G3DDocHostUiHandler.cpp create mode 100644 G3DWarehouseBrowser/src/G3DDownloadStatusCallback.cpp create mode 100644 G3DWarehouseBrowser/src/G3DFileUnzipper.cpp create mode 100644 G3DWarehouseBrowser/src/G3DOleClientSite.cpp create mode 100644 G3DWarehouseBrowser/src/G3DOleInPlaceSite.cpp create mode 100644 G3DWarehouseBrowser/src/G3DPrecompiledHeaders.cpp diff --git a/G3DWarehouseBrowser/G3DWarehouseBrowser.sln b/G3DWarehouseBrowser/G3DWarehouseBrowser.sln new file mode 100644 index 000000000..c74d90a5d --- /dev/null +++ b/G3DWarehouseBrowser/G3DWarehouseBrowser.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "G3DWarehouseBrowser", "scripts\G3DWarehouseBrowser.vcproj", "{81F6BA2E-BB3A-4D67-AC12-A112946EB832}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {81F6BA2E-BB3A-4D67-AC12-A112946EB832}.Debug|Win32.ActiveCfg = Debug|Win32 + {81F6BA2E-BB3A-4D67-AC12-A112946EB832}.Debug|Win32.Build.0 = Debug|Win32 + {81F6BA2E-BB3A-4D67-AC12-A112946EB832}.Debug|x64.ActiveCfg = Debug|x64 + {81F6BA2E-BB3A-4D67-AC12-A112946EB832}.Debug|x64.Build.0 = Debug|x64 + {81F6BA2E-BB3A-4D67-AC12-A112946EB832}.Release|Win32.ActiveCfg = Release|Win32 + {81F6BA2E-BB3A-4D67-AC12-A112946EB832}.Release|Win32.Build.0 = Release|Win32 + {81F6BA2E-BB3A-4D67-AC12-A112946EB832}.Release|x64.ActiveCfg = Release|x64 + {81F6BA2E-BB3A-4D67-AC12-A112946EB832}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/G3DWarehouseBrowser/include/G3DBrowser.h b/G3DWarehouseBrowser/include/G3DBrowser.h new file mode 100644 index 000000000..f13dacc74 --- /dev/null +++ b/G3DWarehouseBrowser/include/G3DBrowser.h @@ -0,0 +1,65 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef __G3D_BROWSER_H__ +#define __G3D_BROWSER_H__ + +#include "G3DPrerequisites.h" +#include +#include + +#include "G3DOleInPlaceFrame.h" +#include "G3DOleInPlaceSite.h" +#include "G3DDocHostUiHandler.h" +#include "G3DOleClientSite.h" + +#include + + +namespace G3D +{ + + class Browser + { + private: + static Browser* msSingleton; + WideString mFilePath; + + private: + HWND mMainWindow; + HWND hwndProgress; + IOleObject* mBrowserObject; + IWebBrowser2* mWebBrowser; + OleInPlaceFrame* inPlaceFrame; + OleInPlaceSite* inPlaceSite; + DocHostUiHandler* docHostUiHandler; + OleClientSite* clientSite; + + public: + static Browser& getSingleton(); + static Browser* getSingletonPtr(); + + private: + static LRESULT CALLBACK windowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + static LRESULT CALLBACK browserWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + + public: + Browser(); + virtual ~Browser(); + + WideString openBrowser(HINSTANCE hInstance, const WideString& filePath, HWND parentWindow); + void closeBrowser(){DestroyWindow(mMainWindow);} + + private: + void setBrowserObject(IOleObject* browserObj); + void setWebBrowser(IWebBrowser2* webBrowser); + }; +} +#endif // __G3DBROWSER_H__ diff --git a/G3DWarehouseBrowser/include/G3DDocHostUiHandler.h b/G3DWarehouseBrowser/include/G3DDocHostUiHandler.h new file mode 100644 index 000000000..cca81b412 --- /dev/null +++ b/G3DWarehouseBrowser/include/G3DDocHostUiHandler.h @@ -0,0 +1,106 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef __G3D_DOC_HOST_UI_HANDLER_H__ +#define __G3D_DOC_HOST_UI_HANDLER_H__ + +#include "G3DPrerequisites.h" +#include +#include +#include +#include + +namespace G3D +{ + static const wchar_t* URL_START_STRING = L"skp:getSkp@"; + static const wchar_t* FILE_PATH = L"C:\\Temp\\test.zip"; + + class DocHostUiHandler : public IDocHostUIHandler { + + private: + IOleClientSite* mClientSite; + HWND mHwndProgress; + WideString& mFilePath; + + public: + DocHostUiHandler(HWND hwndProgress, WideString& filePath) + : mHwndProgress(hwndProgress) + , mFilePath(filePath) + , mClientSite(0) {}; + virtual ~DocHostUiHandler() { mClientSite->Release(); } + void setClientSite(IOleClientSite*); + HRESULT cancelNavigation(OLECHAR __RPC_FAR* __RPC_FAR* ppchURLOut); + + public: // IDocHostUIHandler interface + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID FAR* ppvObj) { + if (mClientSite) { + return mClientSite->QueryInterface(riid, ppvObj); + } + return E_NOINTERFACE; + } + + ULONG STDMETHODCALLTYPE AddRef() { return 1; } + + ULONG STDMETHODCALLTYPE Release() { return 1; } + + HRESULT STDMETHODCALLTYPE ShowContextMenu( + DWORD dwID, + POINT __RPC_FAR *ppt, + IUnknown __RPC_FAR *pcmdtReserved, + IDispatch __RPC_FAR *pdispReserved){ return S_OK; } + + HRESULT STDMETHODCALLTYPE ShowUI( + DWORD dwID, + IOleInPlaceActiveObject __RPC_FAR *pActiveObject, + IOleCommandTarget __RPC_FAR *pCommandTarget, + IOleInPlaceFrame __RPC_FAR *pFrame, + IOleInPlaceUIWindow __RPC_FAR *pDoc) { return S_OK; } + + HRESULT STDMETHODCALLTYPE GetHostInfo(DOCHOSTUIINFO __RPC_FAR *pInfo); + + HRESULT STDMETHODCALLTYPE HideUI() { return S_OK; } + + HRESULT STDMETHODCALLTYPE UpdateUI() { return S_OK; } + + HRESULT STDMETHODCALLTYPE EnableModeless(BOOL fEnable) { return S_FALSE; } + + HRESULT STDMETHODCALLTYPE OnDocWindowActivate(BOOL fActivate) { return S_OK; } + + HRESULT STDMETHODCALLTYPE OnFrameWindowActivate(BOOL fActivate) { return S_OK; } + + HRESULT STDMETHODCALLTYPE ResizeBorder(LPCRECT prcBorder, IOleInPlaceUIWindow __RPC_FAR *pUIWindow, BOOL fRameWindow) { return S_OK; } + + HRESULT STDMETHODCALLTYPE TranslateAccelerator(LPMSG lpMsg, const GUID __RPC_FAR *pguidCmdGroup, DWORD nCmdID) + { + pguidCmdGroup = 0; + return S_FALSE; + } + + HRESULT STDMETHODCALLTYPE GetOptionKeyPath(LPOLESTR __RPC_FAR *pchKey, DWORD dw) { return S_FALSE; } + + HRESULT STDMETHODCALLTYPE GetDropTarget(IDropTarget __RPC_FAR *pDropTarget, IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget) + { return S_FALSE; } + + HRESULT STDMETHODCALLTYPE GetExternal(IDispatch __RPC_FAR *__RPC_FAR *ppDispatch){ + *ppDispatch = 0; + return S_FALSE; + } + + HRESULT STDMETHODCALLTYPE TranslateUrl(DWORD dwTranslate, OLECHAR __RPC_FAR *pchURLIn, OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut); + + HRESULT STDMETHODCALLTYPE FilterDataObject(IDataObject __RPC_FAR *pDO, IDataObject __RPC_FAR *__RPC_FAR *ppDORet) { + + NOTIMPLEMENTED; + //*ppDORet = 0; + //return S_FALSE; + } + }; +} +#endif // __G3D_DOC_HOST_UI_HANDLER_H__ \ No newline at end of file diff --git a/G3DWarehouseBrowser/include/G3DDownloadFile.h b/G3DWarehouseBrowser/include/G3DDownloadFile.h new file mode 100644 index 000000000..fe1d10dff --- /dev/null +++ b/G3DWarehouseBrowser/include/G3DDownloadFile.h @@ -0,0 +1,40 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef __G3D_DOWNLOAD_FILE_H__ +#define __G3D_DOWNLOAD_FILE_H__ + +#include "G3DPrerequisites.h" +#include +#pragma comment(lib,"urlmon") // link against urlmon.lib + +#include "G3DDownloadStatusCallback.h" + +class DownloadFile +{ +public: + void getFile( const wchar_t* url, const wchar_t* fileName, HWND hwndProgress ) + { + // initialize COM + if ( FAILED( CoInitialize(NULL) ) ) { + return; + } + + DownloadStatusCallback callback(hwndProgress); + HRESULT hResult = URLDownloadToFile( + NULL, url, fileName, 0, &callback ); + + CoUninitialize(); + if ( FAILED(hResult) ) { + return; + } + } +}; +#endif // __G3D_DOWNLOAD_FILE_H__ diff --git a/G3DWarehouseBrowser/include/G3DDownloadStatusCallback.h b/G3DWarehouseBrowser/include/G3DDownloadStatusCallback.h new file mode 100644 index 000000000..ed6e912aa --- /dev/null +++ b/G3DWarehouseBrowser/include/G3DDownloadStatusCallback.h @@ -0,0 +1,51 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef __G3D_DOWNLOAD_STATUS_CALLBACK_H__ +#define __G3D_DOWNLOAD_STATUS_CALLBACK_H__ + +class DownloadStatusCallback : public IBindStatusCallback +{ +private: + HWND hwndProgress; + double stepFactor; + +public: + DownloadStatusCallback(HWND hwndProgress):hwndProgress(hwndProgress){}; + virtual ~DownloadStatusCallback(){}; + + // IBindStatusCallback methods. Note that the only method called by IE + // is OnProgress() + STDMETHOD(OnStartBinding)(DWORD dwReserved, IBinding __RPC_FAR *pib) { return E_NOTIMPL; } + + STDMETHOD(GetPriority)( LONG __RPC_FAR *pnPriority ) { return E_NOTIMPL; } + + STDMETHOD(OnLowResource)( DWORD reserved ) { return E_NOTIMPL; } + + STDMETHOD(OnProgress)( ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR wszStatusText); + + STDMETHOD(OnStopBinding)( HRESULT hresult, LPCWSTR szError) { return E_NOTIMPL; } + + STDMETHOD(GetBindInfo)( DWORD __RPC_FAR *grfBINDF, BINDINFO __RPC_FAR *pbindinfo) { return E_NOTIMPL; } + + STDMETHOD(OnDataAvailable)( DWORD grfBSCF, DWORD dwSize, FORMATETC __RPC_FAR *pformatetc, STGMEDIUM __RPC_FAR *pstgmed) + { return E_NOTIMPL; } + + STDMETHOD(OnObjectAvailable)( REFIID riid, IUnknown __RPC_FAR *punk) { return E_NOTIMPL; } + + + + STDMETHOD_(ULONG,AddRef)() { return 0; } + STDMETHOD_(ULONG,Release)() { return 0; } + STDMETHOD(QueryInterface)( REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject) { return E_NOTIMPL; } +}; + + +#endif // __G3D_DOWNLOAD_STATUS_CALLBACK_H__ diff --git a/G3DWarehouseBrowser/include/G3DFileUnzipper.h b/G3DWarehouseBrowser/include/G3DFileUnzipper.h new file mode 100644 index 000000000..95cc41d0f --- /dev/null +++ b/G3DWarehouseBrowser/include/G3DFileUnzipper.h @@ -0,0 +1,60 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef ___G3D_FILEUNZIPPER_H__ +#define ___G3D_FILEUNZIPPER_H__ + +#include "G3DPrerequisites.h" +#include + + +namespace G3D +{ + /** Extracts the model (model.dae) and all the images of a zip file, downloaded from the + google 3d Warehouse.*/ + class FileUnzipper + { + private: + String mLastErrorString; + + String mDAEFilePath; + + /** True, if unzipping succeeded.*/ + bool mSucceeded; + + public: + /** Constructor. Extracts the model and the images contained in @a zipFile into the + directory @a extractPath. @a extractPath must exist.*/ + FileUnzipper( const String& zipFile, const String& extractPath ); + virtual ~FileUnzipper(); + + /** Returns the path to the model.dae file.*/ + String getDAEFilePath() const { return mDAEFilePath; }; + + /** True, if unzipping succeeded.*/ + bool getSucceeded() const { return mSucceeded; } + + /** Returns the error string of the last error that occurred.*/ + const String& getLastErrorString() const { return mLastErrorString; } + + + // private function declarations + private: + /** Disable default copy ctor. */ + FileUnzipper( const FileUnzipper& pre ); + /** Disable default assignment operator. */ + const FileUnzipper& operator= ( const FileUnzipper& pre ); + + bool unzipFile( const String& zipFile, const String& extractPath ); + + }; +} // namespace + +#endif // ___G3D_FILEUNZIPPER_H__ diff --git a/G3DWarehouseBrowser/include/G3DOleClientSite.h b/G3DWarehouseBrowser/include/G3DOleClientSite.h new file mode 100644 index 000000000..2003f4b21 --- /dev/null +++ b/G3DWarehouseBrowser/include/G3DOleClientSite.h @@ -0,0 +1,58 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef __G3D_OLE_CLIENT_SITE_H__ +#define __G3D_OLE_CLIENT_SITE_H__ + +#include "G3DPrerequisites.h" +#include +#include +#include +#include + +namespace G3D +{ + class OleInPlaceSite; + class DocHostUiHandler; + + class OleClientSite : public IOleClientSite { + + private: + OleInPlaceSite* mInPlace; + DocHostUiHandler* mDocHostUiHandler; + + public: + OleClientSite ( OleInPlaceSite* inPlace, DocHostUiHandler* docHostUiHandler); + virtual ~OleClientSite(); + + public: // IOleClientSite interface + HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void ** ppvObject); + + ULONG STDMETHODCALLTYPE AddRef() { return(1); } + + ULONG STDMETHODCALLTYPE Release() { return(1); } + + HRESULT STDMETHODCALLTYPE SaveObject() { NOTIMPLEMENTED; } + + HRESULT STDMETHODCALLTYPE GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk) { NOTIMPLEMENTED; } + + HRESULT STDMETHODCALLTYPE GetContainer( LPOLECONTAINER FAR* ppContainer) { + *ppContainer = 0; + return(E_NOINTERFACE); + } + + HRESULT STDMETHODCALLTYPE ShowObject() { return(NOERROR); } + + HRESULT STDMETHODCALLTYPE OnShowWindow( BOOL fShow) { NOTIMPLEMENTED; } + + HRESULT STDMETHODCALLTYPE RequestNewObjectLayout() { NOTIMPLEMENTED; } + }; +} +#endif // __G3D_OLE_CLIENT_SITE_H__ \ No newline at end of file diff --git a/G3DWarehouseBrowser/include/G3DOleInPlaceFrame.h b/G3DWarehouseBrowser/include/G3DOleInPlaceFrame.h new file mode 100644 index 000000000..c9ecf0bdd --- /dev/null +++ b/G3DWarehouseBrowser/include/G3DOleInPlaceFrame.h @@ -0,0 +1,67 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef __G3D_OLE_IN_PLACE_FRAME_H__ +#define __G3D_OLE_IN_PLACE_FRAME_H__ + +#include "G3DPrerequisites.h" +#define NOTIMPLEMENTED assert(0); return(E_NOTIMPL) + +namespace G3D +{ + class OleInPlaceFrame : public IOleInPlaceFrame + { + private: + HWND mHwnd; + + public: + OleInPlaceFrame(HWND hwnd):mHwnd(hwnd){} + virtual ~OleInPlaceFrame(){mHwnd = 0;} + + public: // IOleInPlaceFrame interface + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID FAR* ppvObj) { + NOTIMPLEMENTED; + } + + ULONG STDMETHODCALLTYPE AddRef() { return 1; } + + ULONG STDMETHODCALLTYPE Release() { return 1; } + + HRESULT STDMETHODCALLTYPE GetWindow( HWND FAR* lphwnd) { + *lphwnd = mHwnd; + return S_OK; + } + + HRESULT STDMETHODCALLTYPE ContextSensitiveHelp( BOOL fEnterMode) { NOTIMPLEMENTED; } + + HRESULT STDMETHODCALLTYPE GetBorder( LPRECT lprectBorder) { NOTIMPLEMENTED; } + + HRESULT STDMETHODCALLTYPE RequestBorderSpace( LPCBORDERWIDTHS pborderwidths) { NOTIMPLEMENTED; } + + HRESULT STDMETHODCALLTYPE SetBorderSpace( LPCBORDERWIDTHS pborderwidths) { NOTIMPLEMENTED; } + + HRESULT STDMETHODCALLTYPE SetActiveObject( IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName) { return S_OK; } + + HRESULT STDMETHODCALLTYPE InsertMenus( HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths) { NOTIMPLEMENTED; } + + HRESULT STDMETHODCALLTYPE SetMenu( HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject) { return S_OK; } + + HRESULT STDMETHODCALLTYPE RemoveMenus( HMENU hmenuShared) { NOTIMPLEMENTED; } + + HRESULT STDMETHODCALLTYPE SetStatusText( LPCOLESTR pszStatusText) { return S_OK; } + + HRESULT STDMETHODCALLTYPE EnableModeless( BOOL fEnable) { return S_FALSE; } + + HRESULT STDMETHODCALLTYPE TranslateAccelerator( LPMSG lpmsg, WORD wID) { + NOTIMPLEMENTED; + } + }; +} +#endif // __G3D_OLE_IN_PLACE_FRAME_H__ \ No newline at end of file diff --git a/G3DWarehouseBrowser/include/G3DOleInPlaceSite.h b/G3DWarehouseBrowser/include/G3DOleInPlaceSite.h new file mode 100644 index 000000000..1a77c8247 --- /dev/null +++ b/G3DWarehouseBrowser/include/G3DOleInPlaceSite.h @@ -0,0 +1,102 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef __G3D_OLE_IN_PLACE_SITE_H__ +#define __G3D_OLE_IN_PLACE_SITE_H__ + +#include "G3DPrerequisites.h" +#include "G3DOleClientSite.h" +#include "G3DOleInPlaceFrame.h" + +#include + +namespace G3D +{ + class OleInPlaceSite : public IOleInPlaceSite { + private: + OleClientSite* mClientSite; + OleInPlaceFrame* mInPlaceFrame; + IOleObject* mBrowserObject; + HWND mHwnd; + + public: + OleInPlaceSite(IOleObject* browserObject, OleInPlaceFrame* inPlaceFrame, HWND h); + virtual ~OleInPlaceSite(){ + mClientSite -> Release(); +// mInPlaceFrame -> Release(); + mBrowserObject -> Release(); + mHwnd = 0; + } + void setBrowserObject(IOleObject* o); + + void setClientSite(OleClientSite* o) {mClientSite=o;} + + public: // IOleInPlaceSite interface + HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, LPVOID FAR* ppvObj); + + ULONG STDMETHODCALLTYPE AddRef() { + return(1); + } + + ULONG STDMETHODCALLTYPE Release() { + return(1); + } + + HRESULT STDMETHODCALLTYPE GetWindow( HWND FAR* lphwnd) { + *lphwnd = mHwnd; + return(S_OK); + } + + HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode) { + NOTIMPLEMENTED; + } + + HRESULT STDMETHODCALLTYPE CanInPlaceActivate() { + return S_OK; + } + + HRESULT STDMETHODCALLTYPE OnInPlaceActivate() { + return S_OK; + } + + HRESULT STDMETHODCALLTYPE OnUIActivate() { return(S_OK); } + + HRESULT STDMETHODCALLTYPE GetWindowContext( LPOLEINPLACEFRAME FAR* lplpFrame, LPOLEINPLACEUIWINDOW FAR* lplpDoc, LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo) { + *lplpFrame = mInPlaceFrame; + *lplpDoc = 0; + + lpFrameInfo->fMDIApp = FALSE; + lpFrameInfo->hwndFrame = mHwnd; + lpFrameInfo->haccel = 0; + lpFrameInfo->cAccelEntries = 0; + + return S_OK; + } + + HRESULT STDMETHODCALLTYPE Scroll(SIZE scrollExtent) { NOTIMPLEMENTED; } + + HRESULT STDMETHODCALLTYPE OnUIDeactivate( BOOL fUndoable) { return S_OK; } + + HRESULT STDMETHODCALLTYPE OnInPlaceDeactivate() { return S_OK; } + + HRESULT STDMETHODCALLTYPE DiscardUndoState() { NOTIMPLEMENTED; } + + HRESULT STDMETHODCALLTYPE DeactivateAndUndo() { NOTIMPLEMENTED; } + + HRESULT STDMETHODCALLTYPE OnPosRectChange( LPCRECT lprcPosRect) { + IOleInPlaceObject *inplace; + if (!mBrowserObject->QueryInterface(IID_IOleInPlaceObject, (void**)&inplace)) { + inplace->SetObjectRects(lprcPosRect, lprcPosRect); + } + return(S_OK); + } + }; +} +#endif // __G3D_OLE_IN_PLACE_SITE_H__ diff --git a/G3DWarehouseBrowser/include/G3DPrerequisites.h b/G3DWarehouseBrowser/include/G3DPrerequisites.h new file mode 100644 index 000000000..bbd1ab78d --- /dev/null +++ b/G3DWarehouseBrowser/include/G3DPrerequisites.h @@ -0,0 +1,25 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef __G3D__PREREQUISITES_H__ +#define __G3D__PREREQUISITES_H__ + +#include + + +namespace G3D +{ + typedef std::string String; + typedef std::wstring WideString; +} + + + +#endif //__G3D__PREREQUISITES_H__ diff --git a/G3DWarehouseBrowser/include/G3DStableHeaders.h b/G3DWarehouseBrowser/include/G3DStableHeaders.h new file mode 100644 index 000000000..1b4b4fc98 --- /dev/null +++ b/G3DWarehouseBrowser/include/G3DStableHeaders.h @@ -0,0 +1,37 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#ifndef __G3D_STABLE_HEADERS_H__ +#define __G3D_STABLE_HEADERS_H__ + +#include "G3DPrerequisites.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +//zzip +#include "zzip/zzip.h" + + +//stl +#include +#include + + +#define NOTIMPLEMENTED assert(0); return(E_NOTIMPL) + +#endif //__G3D_STABLE_HEADERS_H__ \ No newline at end of file diff --git a/G3DWarehouseBrowser/scripts/G3DWarehouseBrowser.vcproj b/G3DWarehouseBrowser/scripts/G3DWarehouseBrowser.vcproj new file mode 100644 index 000000000..f579fa6e4 --- /dev/null +++ b/G3DWarehouseBrowser/scripts/G3DWarehouseBrowser.vcproj @@ -0,0 +1,396 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/G3DWarehouseBrowser/src/G3DBrowser.cpp b/G3DWarehouseBrowser/src/G3DBrowser.cpp new file mode 100644 index 000000000..2a01977a4 --- /dev/null +++ b/G3DWarehouseBrowser/src/G3DBrowser.cpp @@ -0,0 +1,315 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#include "G3DStableHeaders.h" +#include "G3DBrowser.h" +#include "G3DOleInPlaceFrame.h" +#include "G3DOleInPlaceSite.h" +#include "G3DOleClientSite.h" +#include "G3DDocHostUiHandler.h" + +#include +#include +#include + +namespace G3D +{ + static const wchar_t* CLASS_NAME = L"Browser Example"; + static const wchar_t* BROWSER_CLASS_NAME = L"Browser Object"; + static const wchar_t* WINDOW_TITLE = L"G3D Warehouse Collada Browser"; + static const wchar_t* HOST_NAME =L"Host Name"; + static const LPTSTR HOME = L"http://sketchup.google.com/3dwarehouse/?ctyp=sxample&cv=su_6&rtyppref=s6&hl=en "; + + + //--------------------------------------------------------------------- + Browser* Browser::msSingleton = 0; + //--------------------------------------------------------------------- + Browser& Browser::getSingleton() + { + assert(msSingleton); + return *msSingleton; + } + //--------------------------------------------------------------------- + Browser* Browser::getSingletonPtr() + { + return msSingleton; + } + //--------------------------------------------------------------------- + Browser::Browser() + : mMainWindow(0) + , mWebBrowser(0) + , mBrowserObject(0) + , inPlaceFrame(0) + , inPlaceSite(0) + , docHostUiHandler(0) + , clientSite(0) + { + assert(msSingleton == 0); + msSingleton = this; + } + //--------------------------------------------------------------------- + Browser::~Browser() + { + delete inPlaceFrame; + delete inPlaceSite; + delete docHostUiHandler; + delete clientSite; + if ( mWebBrowser ) + { + mWebBrowser->Release(); + } + if ( mBrowserObject ) + { + mBrowserObject->Release(); + } + msSingleton = 0; + } + //--------------------------------------------------------------------- + WideString Browser::openBrowser(HINSTANCE hInstance, const WideString& filePath, HWND parentWindow = HWND_DESKTOP ){ + MSG msg; + HRESULT result = OleInitialize(NULL); + + mFilePath = filePath; + + if(SUCCEEDED(result)) + { + WNDCLASSEX wc; + // Register the class of our Main window. + ZeroMemory(&wc, sizeof(WNDCLASSEX)); + wc.cbSize = sizeof(WNDCLASSEX); + wc.hInstance = hInstance; + wc.lpfnWndProc = windowProc; + wc.lpszClassName = CLASS_NAME; + wc.style = CS_CLASSDC|CS_HREDRAW|CS_VREDRAW|CS_PARENTDC|CS_BYTEALIGNCLIENT|CS_DBLCLKS; + RegisterClassEx(&wc); + + // Register the class of our window to host the browser. + wc.lpfnWndProc = browserWindowProc; + wc.lpszClassName = BROWSER_CLASS_NAME; + wc.style = CS_HREDRAW|CS_VREDRAW; + RegisterClassEx(&wc); + + // Create a Main window. + mMainWindow = CreateWindowEx(0, CLASS_NAME, WINDOW_TITLE, + WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, parentWindow, NULL, hInstance, 0); + if (mMainWindow) + { + // Create a "Back" button. + msg.hwnd = CreateWindow(L"Button", L"Back", + WS_TABSTOP|BS_PUSHBUTTON|BS_TEXT|WS_CHILD|BS_VCENTER|WS_VISIBLE, + 6, 6, // X, Y position + 70, 26, // Width, Height + mMainWindow, + (HMENU)1001, hInstance, 0); + + // Create a "Forward" button. + msg.hwnd = CreateWindow(L"Button", L"Forward", + WS_TABSTOP|BS_PUSHBUTTON|BS_TEXT|WS_CHILD|BS_VCENTER|WS_VISIBLE, + 6 + 70 + 10, 6, // X, Y position + 70, 26, // Width, Height + mMainWindow, + (HMENU)1002, hInstance, 0); + + // Create a "Home" button. + msg.hwnd = CreateWindow(L"Button", L"Home", + WS_TABSTOP|BS_PUSHBUTTON|BS_TEXT|WS_CHILD|BS_VCENTER|WS_VISIBLE, + 6 + 2*70 + 2*10 , 6, // X, Y position + 70, 26, // Width, Height + mMainWindow, + (HMENU)1003, hInstance, 0); + + // Create a Progress bar + InitCommonControls(); + hwndProgress = CreateWindowEx(0, PROGRESS_CLASS, + L"", WS_CHILD | PBS_SMOOTH//| WS_VISIBLE + ,6 + 3*70 + 3*10 , 10, + 300, 18, + mMainWindow, NULL, + hInstance, NULL); + + // Create a child window to host the browser object. + if ((msg.hwnd = CreateWindowEx(0, BROWSER_CLASS_NAME, 0, WS_CHILD|WS_VISIBLE, + 0, 40, 0, 0, + mMainWindow, (HMENU)1000, hInstance, 0))) + { + // Show the Main window. + ShowWindow(mMainWindow, 1); + UpdateWindow(mMainWindow); + + VARIANT myURL; + VariantInit(&myURL); + myURL.vt = VT_BSTR; + myURL.bstrVal = SysAllocString(HOME); + mWebBrowser->Navigate(myURL.bstrVal,0, 0, 0, 0); + VariantClear(&myURL); + + // Do a message loop until WM_QUIT. + while (GetMessage(&msg, 0, 0, 0) == 1) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + else + { + MessageBox(mMainWindow, L"Can't create browser child window!", L"ERROR", MB_OK); + } + DestroyWindow(mMainWindow); + } + DestroyWindow(mMainWindow); + OleUninitialize(); + } + + if ( mFilePath == filePath ) + { + return WideString(); + } + else + { + return mFilePath; + } + } + //--------------------------------------------------------------------- + LRESULT CALLBACK Browser::windowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ + Browser* _this = Browser::getSingletonPtr(); + switch (uMsg) + { + case WM_CLOSE: + { + DestroyWindow(hwnd); + return(1); + } + + case WM_DESTROY: + { + // Post the WM_QUIT message to quit the message loop in WinMain() + PostQuitMessage(0); + return(1); + } + + case WM_SIZE: + { + // Resize the browser child window, leaving room for our buttons. + MoveWindow(GetDlgItem(hwnd, 1000), 0, 40, LOWORD(lParam), HIWORD(lParam) - 40, TRUE); + return(0); + } + case WM_ERASEBKGND: + { + HBRUSH hBrush; + HGDIOBJ orig; + RECT rec; + // Erase the background behind the buttons. Note: The browser object takes care + // of completely redrawing its area, so we don't need to erase there. + hBrush = (HBRUSH)GetStockObject(LTGRAY_BRUSH); + GetClientRect(hwnd, &rec); + orig = SelectObject((HDC)wParam, hBrush); + Rectangle((HDC)wParam, 0, 0, rec.right, 40); + SelectObject((HDC)wParam, orig); + return(TRUE); + } + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case 1001: + { + _this->mWebBrowser->GoBack(); + break; + } + case 1002: + { + _this->mWebBrowser->GoForward(); + break; + } + case 1003: + { + //mWebBrowser->GoHome(); + VARIANT myURL; + VariantInit(&myURL); + myURL.vt = VT_BSTR; + myURL.bstrVal = SysAllocString(HOME); + _this->mWebBrowser->Navigate(myURL.bstrVal,0, 0, 0, 0); + VariantClear(&myURL); + break; + } + } + break; + } + } + return(DefWindowProc(hwnd, uMsg, wParam, lParam)); + } + //--------------------------------------------------------------------- + LRESULT CALLBACK Browser::browserWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ + Browser* _this = Browser::getSingletonPtr(); + switch (uMsg) + { + case WM_SIZE: + { + _this->mWebBrowser->put_Width(LOWORD(lParam)); + _this->mWebBrowser->put_Height(HIWORD(lParam)); + return(0); + } + case WM_CREATE: + { + IClassFactory* pClassFactory = 0; + HRESULT result = CoGetClassObject(CLSID_WebBrowser, 3, NULL, IID_IClassFactory, (void **)&pClassFactory); + if(SUCCEEDED(result)) + { + IOleObject* browserObject = 0; + result = pClassFactory->CreateInstance(0, IID_IOleObject, (void**)&browserObject); + if(SUCCEEDED(result)) + { + _this->setBrowserObject(browserObject); + _this->inPlaceFrame = new OleInPlaceFrame(_this->mMainWindow); + _this->inPlaceSite = new OleInPlaceSite(browserObject, _this->inPlaceFrame, hwnd); + _this->docHostUiHandler = new DocHostUiHandler(_this->hwndProgress, _this->mFilePath); + _this->clientSite = new OleClientSite(_this->inPlaceSite, _this->docHostUiHandler); + + RECT rect; + GetClientRect(hwnd, &rect); + + _this->mBrowserObject->SetClientSite(_this->clientSite); + _this->mBrowserObject->SetHostNames(HOST_NAME, 0); + + // Let browser object know that it is embedded in an OLE container. + if (!OleSetContainedObject(_this->mBrowserObject, TRUE)) + { + // Set the display area of our browser control the same as our window's size and actually put the browser object into our window. + if(!_this->mBrowserObject->DoVerb(OLEIVERB_SHOW, NULL, _this->clientSite, -1, hwnd, &rect)) + { + IWebBrowser2* webBrowser = 0; + result = _this->mBrowserObject->QueryInterface(IID_IWebBrowser2,(void**)&webBrowser); + if(SUCCEEDED(result)) + { + _this->setWebBrowser(webBrowser); + } + } + } + } + + } + pClassFactory->Release(); + // Success + return(0); + } + } + return(DefWindowProc(hwnd, uMsg, wParam, lParam)); + } + //--------------------------------------------------------------------- + void Browser::setBrowserObject( IOleObject* browserObj ) + { + mBrowserObject = browserObj; + } + //--------------------------------------------------------------------- + void Browser::setWebBrowser( IWebBrowser2* webBrowser ) + { + mWebBrowser = webBrowser; + } +} diff --git a/G3DWarehouseBrowser/src/G3DDocHostUiHandler.cpp b/G3DWarehouseBrowser/src/G3DDocHostUiHandler.cpp new file mode 100644 index 000000000..cdb6186d5 --- /dev/null +++ b/G3DWarehouseBrowser/src/G3DDocHostUiHandler.cpp @@ -0,0 +1,133 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#include "G3DStableHeaders.h" +#include "G3DDocHostUiHandler.h" +#include "G3DDownloadFile.h" +#include "G3DBrowser.h" + +#include +#include + + +namespace G3D +{ + //--------------------------------------------------------------------- + void DocHostUiHandler::setClientSite(IOleClientSite* o) { + mClientSite = o; + } + //--------------------------------------------------------------------- + HRESULT STDMETHODCALLTYPE DocHostUiHandler::TranslateUrl ( + DWORD dwTranslate, + OLECHAR __RPC_FAR* pchURLIn, + OLECHAR __RPC_FAR* __RPC_FAR* ppchURLOut) { + + OLECHAR* src = pchURLIn; + + // determine length of URL + while ( (*(src)++) ); + --src; + size_t len = src - pchURLIn; + size_t urlStartStringLen = wcslen(URL_START_STRING); + + if (len >= urlStartStringLen && !_wcsnicmp(pchURLIn, URL_START_STRING , urlStartStringLen)) + { + // modify URL + WideString inString ( pchURLIn ); + size_t fromPos = inString.find( L"rtyp=" ); + size_t lenPos = inString.find( L"&fn=" ); + inString.replace(fromPos,lenPos-fromPos, L"rtyp=zs" ); + inString = inString.substr(inString.find( L"http://" )); + + // get filename + fromPos = inString.find( L"&fn=" ) + 4; + lenPos = inString.find( L"&ctyp=" ); + WideString fileName = inString.substr(fromPos, lenPos-fromPos); + for ( UINT i = 0; i < fileName.length(); i++) + { + if (fileName[i] =='+') + { + fileName.replace(i,1,L"_"); + i++; + } + } + fileName.append(L".zip"); + + mFilePath.append(fileName.c_str()); + + DownloadFile test; + test.getFile(inString.c_str(), mFilePath.c_str(), mHwndProgress); + + + // close Browser + Browser::getSingletonPtr()->closeBrowser(); + + return cancelNavigation(ppchURLOut); + } + else if (len >= 4 && !_wcsnicmp(pchURLIn, L"skp:" , 4)) + { + MessageBox(0,L"This operation is not supported!", L"Error", MB_OK ); + return cancelNavigation(ppchURLOut); + } + + // do nothing + *ppchURLOut = 0; + return S_FALSE; + } + //--------------------------------------------------------------------- + HRESULT DocHostUiHandler::cancelNavigation(OLECHAR __RPC_FAR* __RPC_FAR* ppchURLOut) + { + OLECHAR* dest; + if ((dest = (OLECHAR *)CoTaskMemAlloc(2 << 1))) + { + *ppchURLOut = dest; + CopyMemory(dest, L" ", 2 << 1); + return S_OK; + } + *ppchURLOut = 0; + return S_FALSE; + } + + + //--------------------------------------------------------------------- + /* Be sure to use CoTaskMemAlloc to allocate strings for pchHostCss or pchHostNS. */ + HRESULT DocHostUiHandler::GetHostInfo(DOCHOSTUIINFO __RPC_FAR *pInfo) { + pInfo->cbSize = sizeof(DOCHOSTUIINFO); + + pInfo->dwFlags = + // DOCHOSTUIFLAG_DIALOG | + // DOCHOSTUIFLAG_DISABLE_HELP_MENU | + DOCHOSTUIFLAG_NO3DBORDER | /* No 3D Border */ + // DOCHOSTUIFLAG_SCROLL_NO | /* Hide Scrollbar */ + // DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE | + // DOCHOSTUIFLAG_OPENNEWWIN | + // DOCHOSTUIFLAG_DISABLE_OFFSCREEN | + // DOCHOSTUIFLAG_FLAT_SCROLLBAR | + // DOCHOSTUIFLAG_DIV_BLOCKDEFAULT | + // DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY | + // DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY | + // DOCHOSTUIFLAG_CODEPAGELINKEDFONTS | + // DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8 | + // DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | + // DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE | + // DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION | + // DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION | + // DOCHOSTUIFLAG_THEME | + // DOCHOSTUIFLAG_NOTHEME | + // DOCHOSTUIFLAG_NOPICS | + DOCHOSTUIFLAG_NO3DOUTERBORDER | + 0 ; + + // What happens if user double clicks? + pInfo->dwDoubleClick = DOCHOSTUIDBLCLK_DEFAULT; + + return S_OK ; + } +} \ No newline at end of file diff --git a/G3DWarehouseBrowser/src/G3DDownloadStatusCallback.cpp b/G3DWarehouseBrowser/src/G3DDownloadStatusCallback.cpp new file mode 100644 index 000000000..eededbee5 --- /dev/null +++ b/G3DWarehouseBrowser/src/G3DDownloadStatusCallback.cpp @@ -0,0 +1,40 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#include "G3DStableHeaders.h" +#include "G3DDownloadStatusCallback.h" +#include + + +//--------------------------------------------------------------------- +HRESULT STDMETHODCALLTYPE DownloadStatusCallback::OnProgress( ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR wszStatusText) +{ + if(ulStatusCode == BINDSTATUS_BEGINDOWNLOADDATA) + { + ShowWindow(hwndProgress, 1); + stepFactor = 1000. / ulProgressMax; + SendMessage(hwndProgress, PBM_SETRANGE, 0, MAKELPARAM (0, 1000)); + } + else if(ulStatusCode == BINDSTATUS_DOWNLOADINGDATA) + { + SendMessage(hwndProgress, PBM_SETPOS, (WPARAM)(ulProgress * stepFactor), 0); + } + else if(ulStatusCode == BINDSTATUS_ENDDOWNLOADDATA) + { + ShowWindow(hwndProgress, 0); + SendMessage(hwndProgress, PBM_SETRANGE, 0, MAKELPARAM (0, 0)); + SendMessage(hwndProgress, PBM_SETPOS, 0, 0); + } + + return S_OK; + +} + + diff --git a/G3DWarehouseBrowser/src/G3DFileUnzipper.cpp b/G3DWarehouseBrowser/src/G3DFileUnzipper.cpp new file mode 100644 index 000000000..2ba8062f0 --- /dev/null +++ b/G3DWarehouseBrowser/src/G3DFileUnzipper.cpp @@ -0,0 +1,141 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#define _CRT_SECURE_NO_WARNINGS + +#include "G3DStableHeaders.h" +#include "G3DFileUnzipper.h" + +#include +#include + +#include "zzip/zzip.h" + +#include "COLLADABUStringUtils.h" + + + +namespace G3D +{ + + const char IMAGES_DIRECTORY[] = "images"; + const char MODEL_PATH[] = "models/model.dae"; + const char MODEL_DIR[] = "models"; + + const String SLASH("/"); + const String BACKSLASH("\\"); + + + + String unzipFile_( ZZIP_DIR * dir, const ZZIP_DIRENT& d, const String& extractPath, String& errorString ) + { + ZZIP_FILE* input = zzip_file_open (dir, d.d_name, O_RDONLY); + if ( !input) + { + errorString = zzip_strerror_of(dir); + return String(); + } + String filePath(d.d_name); + COLLADABU::StringUtils::stringFindAndReplace(filePath, SLASH, BACKSLASH); + String extractedFilePath = extractPath + filePath; + FILE* outFile; + errno_t error = fopen_s( &outFile, extractedFilePath.c_str(), "wb" ); + if (error) + { + errorString = String("Could not open output file") + d.d_name; + perror(d.d_name); + zzip_file_close (input); + return String(); + } + + { + char buf[17]; zzip_ssize_t n; + /* read chunks of 16 bytes into buf */ + while (0 < (n = zzip_read (input, buf, 16))) + { + fwrite (buf, 1, n, outFile); + } + + if (n == -1) + perror (d.d_name); + } + fclose (outFile); + zzip_file_close (input); + + return extractedFilePath; + } + + + + //-------------------------------------------------------------------- + FileUnzipper::FileUnzipper( const String& zipFile, const String& extractPath ) + { + mSucceeded = unzipFile(zipFile, extractPath); + } + + //-------------------------------------------------------------------- + FileUnzipper::~FileUnzipper() + { + } + + //-------------------------------------------------------------------- + bool FileUnzipper::unzipFile( const String& zipFile, const String& extractPath ) + { + + ZZIP_DIR * dir; + ZZIP_DIRENT d; + zzip_error_t error; + + dir = zzip_dir_open(zipFile.c_str(), &error); + if (! dir) + { + mLastErrorString = zzip_strerror(error); + return false; + } + + /* read each dir entry and show one line of info per file */ + while (zzip_dir_read (dir, &d)) + { + + if ( strcmp(d.d_name, MODEL_PATH) == 0 ) + { + _mkdir( (extractPath+MODEL_DIR).c_str() ); + mDAEFilePath = unzipFile_(dir, d, extractPath, mLastErrorString); + continue; + } + + + String filePath(d.d_name); + size_t separatorPos = filePath.find_first_of('/'); + String filePathDir(filePath, 0, separatorPos); + + if ( filePathDir == IMAGES_DIRECTORY ) + { + _mkdir( (extractPath+IMAGES_DIRECTORY).c_str() ); + unzipFile_(dir, d, extractPath, mLastErrorString); + continue; + } + + } + return true; + } + + /* + bool FileUnzipper::unzipDirectory( ZZIP_DIR * dir, ZZIP_DIRENT d, const String& extractPath ) + { + + } + + */ + + + + +} \ No newline at end of file diff --git a/G3DWarehouseBrowser/src/G3DOleClientSite.cpp b/G3DWarehouseBrowser/src/G3DOleClientSite.cpp new file mode 100644 index 000000000..b19abe9ca --- /dev/null +++ b/G3DWarehouseBrowser/src/G3DOleClientSite.cpp @@ -0,0 +1,53 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#include "G3DStableHeaders.h" +#include "G3DOleClientSite.h" +#include "G3DOleInPlaceSite.h" +#include "G3DDocHostUiHandler.h" + +namespace G3D +{ + //--------------------------------------------------------------------- + OleClientSite::OleClientSite ( OleInPlaceSite* inPlace, DocHostUiHandler* docHostUiHandler) + : mInPlace(inPlace) + , mDocHostUiHandler(docHostUiHandler) + { + mInPlace->setClientSite(this); + mDocHostUiHandler->setClientSite(this); + } + //--------------------------------------------------------------------- + OleClientSite::~OleClientSite() + { + //mInPlace -> Release(); + //mDocHostUiHandler -> Release(); + } + //--------------------------------------------------------------------- + HRESULT OleClientSite::QueryInterface(REFIID riid, void ** ppvObject) { + if (!memcmp((const void*) &riid, (const void*)&IID_IUnknown, sizeof(GUID)) || + !memcmp((const void*) &riid, (const void*)&IID_IOleClientSite, sizeof(GUID))) { + + *ppvObject = this; + return S_OK; + } + else if (!memcmp((const void*)&riid, &IID_IOleInPlaceSite, sizeof(GUID))) { + *ppvObject = mInPlace; + return S_OK; + } + else if (!memcmp((const void*)&riid, &IID_IDocHostUIHandler, sizeof(GUID))) { + *ppvObject = mDocHostUiHandler; + return S_OK; + } + else { + *ppvObject = 0; + return E_NOINTERFACE; + } + } +} diff --git a/G3DWarehouseBrowser/src/G3DOleInPlaceSite.cpp b/G3DWarehouseBrowser/src/G3DOleInPlaceSite.cpp new file mode 100644 index 000000000..b3fd40d6d --- /dev/null +++ b/G3DWarehouseBrowser/src/G3DOleInPlaceSite.cpp @@ -0,0 +1,32 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#include "G3DStableHeaders.h" +#include "G3DOleInPlaceSite.h" + +namespace G3D +{ + //--------------------------------------------------------------------- + OleInPlaceSite::OleInPlaceSite(IOleObject* browserObject, OleInPlaceFrame* inPlaceFrame, HWND h) + : mClientSite(0) + , mInPlaceFrame(inPlaceFrame) + , mBrowserObject(browserObject) + , mHwnd(h) + { + } + //--------------------------------------------------------------------- + HRESULT OleInPlaceSite::QueryInterface( REFIID riid, LPVOID FAR* ppvObj) { + return mClientSite->QueryInterface(riid, ppvObj); + } + //--------------------------------------------------------------------- + void OleInPlaceSite::setBrowserObject(IOleObject* o) { + mBrowserObject = o; + } +} diff --git a/G3DWarehouseBrowser/src/G3DPrecompiledHeaders.cpp b/G3DWarehouseBrowser/src/G3DPrecompiledHeaders.cpp new file mode 100644 index 000000000..2ae555316 --- /dev/null +++ b/G3DWarehouseBrowser/src/G3DPrecompiledHeaders.cpp @@ -0,0 +1,11 @@ +/* + Copyright (c) 2009 NetAllied Systems GmbH + + This file is part of G3DWarehouseBrowser. + + Licensed under the MIT Open Source License, + for details please see LICENSE file or the website + http://www.opensource.org/licenses/mit-license.php +*/ + +#include "G3DStableHeaders.h" \ No newline at end of file