Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

266 lines
7.0 KiB

  1. #include "stdafx.h"
  2. #include <iadmw.h>
  3. #include <inetcom.h>
  4. #include <logtype.h>
  5. #include <ilogobj.hxx>
  6. #include "wrapmb.h"
  7. #include "logui.h"
  8. #include "uiextnd.h"
  9. #include "LogGenPg.h"
  10. #include "LogExtPg.h"
  11. #include "LogAdvPg.h"
  12. #include "logtools.h"
  13. //#include <inetprop.h>
  14. #define OLE_NAME _T("Extended_Logging_UI")
  15. static const DWORD BASED_CODE _dwOleMisc =
  16. OLEMISC_INSIDEOUT |
  17. OLEMISC_CANTLINKINSIDE;
  18. extern HINSTANCE g_hInstance;
  19. //====================== the required methods
  20. //---------------------------------------------------------------
  21. CFacExtndLogUI::CFacExtndLogUI() :
  22. COleObjectFactory( CLSID_EXTLOGUI, RUNTIME_CLASS(CExtndCreator), TRUE, OLE_NAME )
  23. {
  24. }
  25. //---------------------------------------------------------------
  26. static const LPCTSTR rglpszServerRegister[] =
  27. {
  28. _T("%2\\CLSID\0") _T("%1"),
  29. _T("%2\\NotInsertable\0") _T(""),
  30. _T("%2\\protocol\\StdFileEditing\\verb\\0\0") _T("&Edit"),
  31. _T("CLSID\\%1\0") _T("%5"),
  32. _T("CLSID\\%1\\Verb\\0\0") _T("&Edit,0,2"),
  33. _T("CLSID\\%1\\NotInsertable\0") _T(""),
  34. _T("CLSID\\%1\\AuxUserType\\2\0") _T("%4"),
  35. _T("CLSID\\%1\\AuxUserType\\3\0") _T("%6"),
  36. _T("CLSID\\%1\\MiscStatus\0") _T("32"),
  37. NULL
  38. };
  39. static const LPCTSTR rglpszServerOverwriteDLL[] =
  40. {
  41. _T("%2\\CLSID\0") _T("%1"),
  42. _T("%2\\protocol\\StdFileEditing\\server\0") _T("%3"),
  43. _T("CLSID\\%1\\ProgID\0") _T("%2"),
  44. _T("CLSID\\%1\\InProcServer32\0") _T("%3"),
  45. _T("CLSID\\%1\\DefaultIcon\0") _T("%3,%7"),
  46. NULL
  47. };
  48. BOOL CFacExtndLogUI::UpdateRegistry( BOOL bRegister )
  49. {
  50. if (bRegister)
  51. /*
  52. return AfxOleRegisterControlClass(
  53. AfxGetInstanceHandle(),
  54. CLSID_EXTLOGUI,
  55. OLE_NAME,
  56. 0,
  57. 0,
  58. afxRegApartmentThreading,
  59. _dwOleMisc,
  60. _tlid,
  61. _wVerMajor,
  62. _wVerMinor);
  63. */
  64. if (AfxOleRegisterServerClass(
  65. CLSID_EXTLOGUI,
  66. OLE_NAME,
  67. _T("LogUI extnd"),
  68. _T("LogUI extnd"),
  69. OAT_SERVER,
  70. (LPCTSTR *)rglpszServerRegister,
  71. (LPCTSTR *)rglpszServerOverwriteDLL
  72. )
  73. )
  74. {
  75. return FSetObjectApartmentModel( CLSID_EXTLOGUI );
  76. }
  77. else
  78. return AfxOleUnregisterClass(m_clsid, OLE_NAME);
  79. return FALSE;
  80. }
  81. //---------------------------------------------------------------
  82. IMPLEMENT_DYNCREATE(CExtndCreator, CCmdTarget)
  83. LPUNKNOWN CExtndCreator::GetInterfaceHook(const void* piid)
  84. {
  85. return new CImpExtndLogUI;
  86. }
  87. //====================== the action
  88. //---------------------------------------------------------------
  89. CImpExtndLogUI::CImpExtndLogUI():
  90. m_dwRefCount(0)
  91. {
  92. // guid = IID_LOGGINGUI;
  93. AfxOleLockApp();
  94. }
  95. //---------------------------------------------------------------
  96. CImpExtndLogUI::~CImpExtndLogUI()
  97. {
  98. AfxOleUnlockApp();
  99. }
  100. //---------------------------------------------------------------
  101. HRESULT CImpExtndLogUI::OnProperties( IN OLECHAR* pocMachineName, IN OLECHAR* pocMetabasePath )
  102. {
  103. // AFX_MANAGE_STATE(_afxModuleAddrThis);
  104. AFX_MANAGE_STATE(::AfxGetStaticModuleState());
  105. // prepare the metabase wrapper
  106. IMSAdminBase * pMB;
  107. if ( !FInitMetabaseWrapperEx( pocMachineName, &pMB ) )
  108. return 0xFFFFFFFF;
  109. // specify the resources to use
  110. HINSTANCE hOldRes = AfxGetResourceHandle();
  111. AfxSetResourceHandle( g_hInstance );
  112. // prepare the help
  113. ((CLoguiApp*)AfxGetApp())->PrepHelp( pocMetabasePath );
  114. // Things could (potentially maybe) throw here, so better protect it.
  115. try
  116. {
  117. // declare the property sheet
  118. CPropertySheet propsheet( IDS_SHEET_EXTND_TITLE );
  119. // declare the property pages
  120. CLogGeneral pageLogGeneral;
  121. CLogAdvanced pageLogAdvanced;
  122. CLogExtended pageLogExtended;
  123. // prepare the common pages
  124. pageLogGeneral.m_pMB = pMB;
  125. pageLogGeneral.m_szMeta = pocMetabasePath;
  126. pageLogGeneral.m_szServer = pocMachineName;
  127. pageLogGeneral.szPrefix.LoadString( IDS_LOG_EXTND_PREFIX );
  128. pageLogGeneral.szSizePrefix.LoadString( IDS_LOG_SIZE_EXTND_PREFIX );
  129. // make the use local time checkbox visible
  130. pageLogGeneral.m_fShowLocalTimeCheckBox = TRUE;
  131. // set the local flag
  132. pageLogGeneral.m_fLocalMachine = FIsLocalMachine( pocMachineName );
  133. // add the pages to the sheet and run
  134. propsheet.AddPage( &pageLogGeneral );
  135. // turn on help
  136. propsheet.m_psh.dwFlags |= PSH_HASHELP;
  137. pageLogGeneral.m_psp.dwFlags |= PSP_HASHELP;
  138. //
  139. // Extract the service name from the metabase path
  140. //
  141. // For /LM/W3SVC/1 scenario
  142. CString m_szServiceName(pocMetabasePath+3);
  143. m_szServiceName = m_szServiceName.Left( m_szServiceName.ReverseFind('/'));
  144. // For /LM/W3SVC scenario
  145. if (m_szServiceName.IsEmpty())
  146. {
  147. m_szServiceName = pocMetabasePath+3;
  148. }
  149. DWORD version;
  150. BOOL res;
  151. {
  152. CComAuthInfo auth(pocMachineName);
  153. CMetabasePath path(TRUE, m_szServiceName, SZ_MBN_INFO);
  154. CMetaKey mk(&auth, path);
  155. mk.QueryValue(MD_SERVER_VERSION_MAJOR, version);
  156. res = mk.Succeeded();
  157. }
  158. if (res && (version > 4))
  159. {
  160. pageLogAdvanced.m_pMB = pMB;
  161. pageLogAdvanced.m_szMeta = pocMetabasePath;
  162. pageLogAdvanced.m_szServer = pocMachineName;
  163. pageLogAdvanced.m_szServiceName = m_szServiceName;
  164. // add the pages to the sheet and run
  165. propsheet.AddPage( &pageLogAdvanced );
  166. // turn on help
  167. pageLogAdvanced.m_psp.dwFlags |= PSP_HASHELP;
  168. }
  169. else
  170. {
  171. pageLogExtended.m_pMB = pMB;
  172. pageLogExtended.m_szMeta = pocMetabasePath;
  173. pageLogExtended.m_szServer = pocMachineName;
  174. // add the pages to the sheet and run
  175. propsheet.AddPage( &pageLogExtended );
  176. // turn on help
  177. pageLogExtended.m_psp.dwFlags |= PSP_HASHELP;
  178. }
  179. propsheet.DoModal();
  180. }
  181. catch ( CException e )
  182. {
  183. }
  184. // close the metabase wrappings
  185. FCloseMetabaseWrapperEx(&pMB);
  186. // restore the resources
  187. AfxSetResourceHandle( hOldRes );
  188. return NO_ERROR;
  189. }
  190. //====================== the required methods
  191. //---------------------------------------------------------------
  192. HRESULT CImpExtndLogUI::QueryInterface(REFIID riid, void **ppObject)
  193. {
  194. if (riid==IID_IUnknown || riid==IID_LOGGINGUI || riid==CLSID_EXTLOGUI)
  195. {
  196. *ppObject = (ILogUIPlugin*) this;
  197. }
  198. else
  199. {
  200. return E_NOINTERFACE;
  201. }
  202. AddRef();
  203. return NO_ERROR;
  204. }
  205. //---------------------------------------------------------------
  206. ULONG CImpExtndLogUI::AddRef()
  207. {
  208. DWORD dwRefCount;
  209. dwRefCount = InterlockedIncrement((long *)&m_dwRefCount);
  210. return dwRefCount;
  211. }
  212. //---------------------------------------------------------------
  213. ULONG CImpExtndLogUI::Release()
  214. {
  215. DWORD dwRefCount;
  216. dwRefCount = InterlockedDecrement((long *)&m_dwRefCount);
  217. if (dwRefCount == 0) {
  218. delete this;
  219. }
  220. return dwRefCount;
  221. }