GME
13
|
00001 00002 #ifndef MGA_MGADUMPER_H 00003 #define MGA_MGADUMPER_H 00004 00005 #include <fstream> //fstream.h 00006 #include "resource.h" 00007 #include "CommonVersionInfo.h" 00008 #include "Transcoder.h" 00009 #include "helper.h" 00010 #include "MgaUtil.h" 00011 00012 class GmeEqual 00013 { 00014 public: 00015 GmeEqual( CComObjPtr<IMgaObject>); 00016 GmeEqual( CComObjPtr<IMgaFCO>); 00017 GmeEqual( CComObjPtr<IMgaFolder>); 00018 GmeEqual( CComObjPtr<IMgaModel>); 00019 00020 bool operator() ( CComObjPtr<IMgaObject>& ); 00021 bool operator() ( CComObjPtr<IMgaFCO>& ); 00022 bool operator() ( CComObjPtr<IMgaFolder>& ); 00023 bool operator() ( CComObjPtr<IMgaModel>& ); 00024 private: 00025 CComObjPtr<IMgaObject> m_objToFind; 00026 CComObjPtr<IMgaFCO> m_fcoToFind; 00027 CComObjPtr<IMgaFolder> m_folderToFind; 00028 CComObjPtr<IMgaModel> m_modelToFind; 00029 int m_which; // which variable is set 00030 }; 00031 00032 00033 00034 // --------------------------- CMgaDumper 00035 00036 class ATL_NO_VTABLE CMgaDumper : 00037 public CComObjectRootEx<CComSingleThreadModel>, 00038 public CComCoClass<CMgaDumper, &__uuidof(MgaDumper)>, 00039 public ISupportErrorInfoImpl2<&__uuidof(IMgaDumper), &_uuidof(IMgaDumper2)>, 00040 public IDispatchImpl<IMgaDumper2, &__uuidof(IMgaDumper2), &__uuidof(__MGAParserLib), 1, 1>, 00041 public IGMEVersionInfoImpl 00042 { 00043 public: 00044 CMgaDumper() 00045 : dumpversion( 1) 00046 , m_closureDump( false) 00047 , m_strictDump( true) 00048 , m_dumpRelids( true) 00049 , m_dumpLibraryStubs(false) 00050 , m_dumpGuids( false) 00051 { } 00052 00053 DECLARE_REGISTRY_RESOURCEID(IDR_MGADUMPER) 00054 BEGIN_COM_MAP(CMgaDumper) 00055 COM_INTERFACE_ENTRY2(IMgaDumper, IMgaDumper2) 00056 COM_INTERFACE_ENTRY2(IDispatch, IMgaDumper2) 00057 COM_INTERFACE_ENTRY(IMgaDumper2) 00058 COM_INTERFACE_ENTRY(ISupportErrorInfo) 00059 COM_INTERFACE_ENTRY_IID(__uuidof(IGMEVersionInfo), IGMEVersionInfoImpl) 00060 END_COM_MAP() 00061 00062 // ------- Methods 00063 00064 public: 00065 void InitDump(IMgaProject *p, BSTR xmlfile, BSTR encoding); 00066 void DoneDump(bool abort); 00067 00068 STDMETHOD(DumpProject)(IMgaProject *p, BSTR xmlfile); 00069 STDMETHOD(DumpProject2)(IMgaProject *p, BSTR xmlfile, ULONGLONG hwndParent); 00070 STDMETHOD(DumpFCOs)(IMgaProject *proj, IMgaFCOs *p, IMgaFolders *f, IMgaRegNodes *r, BSTR xmlfile); 00071 STDMETHOD(DumpFCOs2)(IMgaProject *proj, IMgaFCOs *p, IMgaFolders *f, IMgaRegNodes *r, BSTR xmlfile, ULONGLONG hwndParent); 00072 STDMETHOD(DumpClos)( IMgaFCOs *sel_fco, IMgaFolders *sel_fold, BSTR xmlfile, int lib_stub); 00073 STDMETHOD(DumpClosR)( IMgaFCOs *sel_fco, IMgaFolders *sel_fold, BSTR xmlfile, IMgaFCOs *top_fco, IMgaFolders *top_fold, int options, BSTR abspath, BSTR acceptingkinds); 00074 STDMETHOD(put_FormatVersion)(long p) { dumpversion = p; return S_OK; } 00075 00076 // ------- Low level stuff 00077 void Indent(int i); 00078 void StartElem(const TCHAR *name); 00079 void Attr(const TCHAR *name, const TCHAR *value); 00080 void Attr(const TCHAR *name, const TCHAR *value, int len); 00081 static bool HasMarkup(const TCHAR *value, int len); 00082 void Data(const TCHAR *value, int len); 00083 void EndElem(); 00084 00085 void Attr(const TCHAR *name, std::tstring &value) 00086 { 00087 Attr(name, value.data(), value.length()); 00088 } 00089 00090 void Attr(const TCHAR *name, const CComBstrObj &value) 00091 { 00092 std::tstring t; 00093 CopyTo(value, t); 00094 Attr(name, t); 00095 } 00096 00097 void Data(std::tstring &value) 00098 { 00099 Data(value.data(), value.length()); 00100 } 00101 00102 void Data(const CComBstrObj &value) 00103 { 00104 std::tstring t; 00105 if (value.p != NULL) 00106 CopyTo(value, t); 00107 Data(t); 00108 } 00109 00110 template<class INTERFACE, class FUNC_INTERFACE> 00111 void Attr(const TCHAR *name, INTERFACE p, HRESULT (__stdcall FUNC_INTERFACE::*func)(BSTR *)) 00112 { 00113 FUNC_INTERFACE *q = p; 00114 ASSERT( q != NULL ); 00115 00116 CComBstrObj value; 00117 COMTHROW( (q->*func)(PutOut(value)) ); 00118 00119 Attr(name, value); 00120 } 00121 00122 template<class INTERFACE, class FUNC_INTERFACE> 00123 void LAttr(const TCHAR *name, INTERFACE p, HRESULT (__stdcall FUNC_INTERFACE::*func)(long *)) 00124 { 00125 FUNC_INTERFACE *q = p; 00126 ASSERT( q != NULL ); 00127 00128 long value; 00129 COMTHROW( (q->*func)(&value) ); 00130 00131 TCHAR buf[16] = _T("0x"); 00132 _ltot(value,buf+2, 16); 00133 00134 Attr(name, buf); 00135 } 00136 00137 template<class INTERFACE, class FUNC_INTERFACE> 00138 void Data(INTERFACE p, HRESULT (__stdcall FUNC_INTERFACE::*func)(BSTR *)) 00139 { 00140 FUNC_INTERFACE *q = p; 00141 ASSERT( q != NULL ); 00142 00143 CComBstrObj value; 00144 COMTHROW( (q->*func)(&value.p) ); 00145 //ASSERT(value.p); 00146 //if (value.p == 0) 00147 // DebugBreak(); 00148 00149 Data(value); 00150 } 00151 00152 template<class INTERFACE, class FUNC_INTERFACE, class COLLECTION> 00153 void Dump(INTERFACE p, HRESULT (__stdcall FUNC_INTERFACE::*func)(COLLECTION **q)) 00154 { 00155 FUNC_INTERFACE *q = p; 00156 ASSERT( q != NULL ); 00157 00158 typedef TYPENAME_COLL2ELEM(COLLECTION) element_type; 00159 00160 CComObjPtrVector<element_type> v; 00161 COMTHROW( (q->*func)(PutOut(v)) ); 00162 00163 Sort(&v); 00164 00165 CComObjPtrVector<element_type>::iterator i = v.begin(); 00166 CComObjPtrVector<element_type>::iterator e = v.end(); 00167 while( i != e ) 00168 { 00169 if ( CheckInClosure( *i)) // by ZolMol 00170 Dump(*i); 00171 00172 ++i; 00173 } 00174 } 00175 00176 bool CheckInClosure( CComObjPtr<IMgaFCO>); 00177 bool CheckInClosure( CComObjPtr<IMgaFolder>); 00178 bool CheckInClosure( CComObjPtr<IMgaAttribute>); 00179 bool CheckInClosure( CComObjPtr<IMgaConnPoint>); 00180 00181 00182 // ------- Dumpers 00183 00184 public: 00185 00186 void Dump(IMgaProject *project); 00187 void Dump(IMgaFolder *folder); 00188 void Dump(IMgaRegNode *regnode); 00189 void Dump(IMgaObject *obj); 00190 void Dump(IMgaModel *model); 00191 void Dump(IMgaConstraint *constraint); 00192 void Dump(IMgaAttribute *attribute); 00193 void Dump(IMgaAtom *atom); 00194 void Dump(IMgaReference *reference); 00195 void Dump(IMgaConnection *connection); 00196 void Dump(IMgaSet *set); 00197 void Dump(IMgaConnPoint *connpoint); 00198 00199 void DumpFCO(IMgaFCO *fco, bool dump_attrs = true, 00200 bool dump_name = true, bool dump_elems = true); 00201 void DumpConstraints(IMgaObject *object); 00202 void DumpIDRefs(const TCHAR *name, CComObjPtrVector<IMgaFCO> &fcos); 00203 std::tstring DumpGUIDRefs( CComObjPtrVector<IMgaFCO>& fcos); 00204 std::tstring DumpMixedGUIDRefs( CComObjPtrVector<IMgaFCO>& fcos); 00205 void DumpConnDetails(CComObjPtr<IMgaConnection> connection); 00206 00207 // ------- Sorters 00208 00209 public: 00210 void Sort(CComObjPtrVector<IMgaRegNode> *v); 00211 void Sort(CComObjPtrVector<IMgaAttribute> *v); 00212 void Sort(CComObjPtrVector<IMgaConnPoint> *v); 00213 void Sort(CComObjPtrVector<IMgaFolder> *v); 00214 void Sort(CComObjPtrVector<IMgaFCO> *v); 00215 00216 00217 // ------- Attributes 00218 00219 public: 00220 Transcoder ofs; 00221 00222 struct elem 00223 { 00224 std::tstring name; 00225 bool inbody; 00226 bool indata; 00227 }; 00228 00229 std::vector<elem> elems; 00230 00231 long fco_count; 00232 int dumpversion;// >=1 means new xme format, ==2 means do not dump relids 00233 bool m_dumpGuids; 00234 00235 bool m_closureDump; 00236 bool m_dumpRelids; 00237 bool m_strictDump; // if true then containers dump their children only if the child is present in the closure collection 00238 bool m_dumpLibraryStubs; // if true the libreferred attribute is dumped 00239 00240 inline bool isInLibrary( IMgaObject * obj) 00241 { 00242 VARIANT_BOOL vbLibrary; 00243 COMTHROW( obj->get_IsLibObject( &vbLibrary ) ); 00244 return ( vbLibrary ) ? true : false; 00245 } 00246 00247 CComObjPtr<IMgaProject> project; 00248 CComObjPtr<IMgaTerritory> territory; 00249 00250 CComObjPtrVector<IMgaFCO> m_selFcos; // selected objects for dump or closure 00251 CComObjPtrVector<IMgaFolder> m_selFolders; 00252 CComObjPtrVector<IMgaRegNode> m_selRegNodes; 00253 void removeInnerObjs(); 00254 00255 void putInTerritory( CComObjPtrVector<IMgaFCO>&); 00256 void putInTerritory( CComObjPtrVector<IMgaFolder>&); 00257 00258 //std::tstring m_curTopPath; // used for the 'closurename' calc 00259 std::tstring m_currAbsPath;//? it is needed any more? 00260 //std::tstring m_currParAbsPath; // used for 'closurepath' calc 00261 bool m_v2; 00262 CComPtr<IMgaProgressDlg> m_progress; 00263 00264 }; 00265 00266 #endif //__MGADUMPER_H_