1 /****************************************************************************
3 * Mesa 3-D graphics library
4 * Direct3D Driver Interface
6 * ========================================================================
8 * Copyright (C) 1991-2004 SciTech Software, Inc. All rights reserved.
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * SCITECH SOFTWARE INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
25 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * ======================================================================
31 * Environment: Windows 9x (Win32)
33 * Description: Logging functions.
35 ****************************************************************************/
41 #include "gld_driver.h"
43 // ***********************************************************************
45 static char ddlogbuf[256];
46 static FILE* fpDDLog = NULL; // Log file pointer
47 static char szDDLogName[_MAX_PATH] = {"gldirect.log"}; // Filename of the log
48 static DDLOG_loggingMethodType ddlogLoggingMethod = DDLOG_NONE; // Default to No Logging
49 static DDLOG_severityType ddlogDebugLevel;
50 static BOOL bUIWarning = FALSE; // MessageBox warning ?
52 // ***********************************************************************
55 DDLOG_loggingMethodType LoggingMethod,
56 DDLOG_severityType Severity)
58 if (fpDDLog != NULL) {
59 // Tried to re-open the log
60 ddlogMessage(DDLOG_WARN, "Tried to re-open the log file\n");
64 ddlogLoggingMethod = LoggingMethod;
65 ddlogDebugLevel = Severity;
67 if (ddlogLoggingMethod == DDLOG_NORMAL) {
68 fpDDLog = fopen(szDDLogName, "wt");
73 ddlogMessage(DDLOG_SYSTEM, "\n");
74 ddlogMessage(DDLOG_SYSTEM, "-> Logging Started\n");
77 // ***********************************************************************
81 // Determine whether the log is already closed
82 if (fpDDLog == NULL && ddlogLoggingMethod == DDLOG_NORMAL)
83 return; // Nothing to do.
85 ddlogMessage(DDLOG_SYSTEM, "<- Logging Ended\n");
87 if (ddlogLoggingMethod == DDLOG_NORMAL) {
93 // ***********************************************************************
96 DDLOG_severityType severity,
101 // Bail if logging is disabled
102 if (ddlogLoggingMethod == DDLOG_NONE)
105 if (ddlogLoggingMethod == DDLOG_CRASHPROOF)
106 fpDDLog = fopen(szDDLogName, "at");
111 if (severity >= ddlogDebugLevel) {
112 sprintf(buf, "DDLog: (%s) %s", ddlogSeverityMessages[severity], message);
113 fputs(buf, fpDDLog); // Write string to file
114 OutputDebugString(buf); // Echo to debugger
117 if (ddlogLoggingMethod == DDLOG_CRASHPROOF) {
118 fflush(fpDDLog); // Write info to disk
123 // Popup message box if critical error
124 if (bUIWarning && severity == DDLOG_CRITICAL) {
125 MessageBox(NULL, buf, "GLDirect", MB_OK | MB_ICONWARNING | MB_TASKMODAL);
129 // ***********************************************************************
131 // Write a string value to the log file
133 DDLOG_severityType severity,
139 _gldDriver.GetDXErrorString(hResult, &dxErrStr[0], sizeof(dxErrStr));
140 if (FAILED(hResult)) {
141 sprintf(ddlogbuf, "DDLog: %s %8x:[ %s ]\n", message, hResult, dxErrStr);
143 sprintf(ddlogbuf, "DDLog: %s\n", message);
145 if (FAILED(hResult)) {
146 sprintf(ddlogbuf, "DDLog: %s %8x:[ %s ]\n", message, hResult, DDErrorToString(hResult));
148 sprintf(ddlogbuf, "DDLog: %s\n", message);
150 ddlogMessage(severity, ddlogbuf);
153 // ***********************************************************************
156 DDLOG_severityType severity,
162 va_start(args, message);
163 vsprintf(ddlogbuf, message, args);
166 lstrcat(ddlogbuf, "\n");
168 ddlogMessage(severity, ddlogbuf);
171 // ***********************************************************************
173 void ddlogWarnOption(
176 bUIWarning = bWarnOption;
179 // ***********************************************************************
181 void ddlogPathOption(
184 char szPathName[_MAX_PATH];
186 strcpy(szPathName, szPath);
187 strcat(szPathName, "\\");
188 strcat(szPathName, szDDLogName);
189 strcpy(szDDLogName, szPathName);
192 // ***********************************************************************