13 File(const TCHAR *szName, const TCHAR *szExtension) {
14 m_hFile = INVALID_HANDLE_VALUE;
15 Open(szName, szExtension);
22 void Open(const TCHAR *szName, const TCHAR *szExtension) {
28 _sntprintf(szFileName, MAX_PATH, TEXT("%s.%u.%s"), szName, dwCounter, szExtension);
30 _sntprintf(szFileName, MAX_PATH, TEXT("%s.%s"), szName, szExtension);
32 m_hFile = CreateFile(szFileName,
37 FILE_ATTRIBUTE_NORMAL,
40 } while(m_hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS);
46 m_hFile = CreateFile(szFileName,
51 FILE_ATTRIBUTE_NORMAL,
56 if(m_hFile != INVALID_HANDLE_VALUE) {
58 m_hFile = INVALID_HANDLE_VALUE;
62 void Write(const char *szText) {
63 if(m_hFile == INVALID_HANDLE_VALUE)
66 DWORD dwBytesToWrite = (DWORD)strlen(szText);
67 DWORD dwBytesWritten = 0;
69 while (dwBytesWritten < dwBytesToWrite) {
70 OVERLAPPED overlapped;
71 memset(&overlapped, 0, sizeof(OVERLAPPED));
73 /* Write to end of file */
74 overlapped.Offset = 0xffffffff;
75 overlapped.OffsetHigh = 0xffffffff;
78 szText + dwBytesWritten,
79 dwBytesToWrite - dwBytesWritten,
81 &overlapped) == FALSE) {
83 Open(TEXT("extra"), TEXT("xml"));
91 TCHAR szFileName[MAX_PATH];
95 class Log : public File
98 Log(const TCHAR *szName) : File(szName, TEXT("xml")) {
99 Write("<?xml version='1.0' encoding='UTF-8'?>");
101 Write("<?xml-stylesheet type='text/xsl' href='d3dtrace.xsl'?>");
116 void Tag(const char *name) {
122 void BeginTag(const char *name) {
128 void BeginTag(const char *name,
129 const char *attr1, const char *value1) {
139 void BeginTag(const char *name,
140 const char *attr1, const char *value1,
141 const char *attr2, const char *value2) {
155 void EndTag(const char *name) {
161 void Text(const char *text) {
165 void TextF(const char *format, ...) {
168 va_start(ap, format);
169 vsnprintf(szBuffer, sizeof(szBuffer), format, ap);
174 void BeginCall(const char *function) {
176 BeginTag("call", "name", function);
186 void BeginParam(const char *name, const char *type) {
188 BeginTag("param", "name", name, "type", type);
191 void EndParam(void) {
196 void BeginReturn(const char *type) {
198 BeginTag("return", "type", type);
201 void EndReturn(void) {
207 void Escape(const char *s) {
217 #endif /* _LOG_HPP_ */