/[pcsx2_0.9.7]/trunk/plugins/zzogl-pg/opengl/ZZLog.cpp
ViewVC logotype

Annotation of /trunk/plugins/zzogl-pg/opengl/ZZLog.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (hide annotations) (download)
Tue Sep 7 11:08:22 2010 UTC (9 years, 10 months ago) by william
File size: 4978 byte(s)
Auto Commited Import of: pcsx2-0.9.7-r3738-debug in ./trunk
1 william 62 /* ZZ Open GL graphics plugin
2     * Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
3     * Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
4     *
5     * This program is free software; you can redistribute it and/or modify
6     * it under the terms of the GNU General Public License as published by
7     * the Free Software Foundation; either version 2 of the License, or
8     * (at your option) any later version.
9     *
10     * This program is distributed in the hope that it will be useful,
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     * GNU General Public License for more details.
14     *
15     * You should have received a copy of the GNU General Public License
16     * along with this program; if not, write to the Free Software
17     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18     */
19    
20     #include <stdio.h>
21     #include "ZZLog.h"
22    
23     extern GSconf conf;
24    
25     namespace ZZLog
26     {
27     std::string s_strLogPath("logs/");
28     FILE *gsLog;
29    
30     bool IsLogging()
31     {
32     // gsLog can be null if the config dialog is used prior to Pcsx2 starting an emulation session.
33     // (GSinit won't have been called then)
34     return (gsLog != NULL && conf.log);
35     }
36    
37     bool Open()
38     {
39     bool result = true;
40     const std::string LogFile(s_strLogPath + "GSzzogl.log");
41    
42     gsLog = fopen(LogFile.c_str(), "w");
43     if (gsLog != NULL)
44     setvbuf(gsLog, NULL, _IONBF, 0);
45     else
46     {
47     SysMessage("Can't create log file %s\n", LogFile.c_str());
48     result = false;
49     }
50    
51     return result;
52     }
53    
54     void Close()
55     {
56     if (gsLog != NULL) {
57     fclose(gsLog);
58     gsLog = NULL;
59     }
60     }
61    
62     void SetDir(const char* dir)
63     {
64     // Get the path to the log directory.
65     s_strLogPath = (dir==NULL) ? "logs/" : dir;
66    
67     // Reload the log file after updated the path
68     Close();
69     Open();
70     }
71    
72     void WriteToScreen(const char* pstr, u32 ms)
73     {
74     ZeroGS::AddMessage(pstr, ms);
75     }
76    
77     void _Message(const char *str)
78     {
79     SysMessage(str);
80     }
81    
82     void _Log(const char *str)
83     {
84     if (IsLogging()) fprintf(gsLog, str);
85     }
86    
87     void _WriteToConsole(const char *str)
88     {
89     fprintf(stderr,"ZZogl-PG: %s", str);
90     }
91    
92     void _Print(const char *str)
93     {
94     fprintf(stderr,"ZZogl-PG: %s", str);
95    
96     if (IsLogging()) fprintf(gsLog, str);
97     }
98    
99     void Message(const char *fmt, ...)
100     {
101     va_list list;
102     char tmp[512];
103    
104     va_start(list, fmt);
105     vsprintf(tmp, fmt, list);
106     va_end(list);
107    
108     SysMessage(tmp);
109     }
110    
111     void Log(const char *fmt, ...)
112     {
113     va_list list;
114    
115     va_start(list, fmt);
116    
117     if (IsLogging()) vfprintf(gsLog, fmt, list);
118    
119     va_end(list);
120     }
121    
122     void WriteToConsole(const char *fmt, ...)
123     {
124     va_list list;
125    
126     va_start(list, fmt);
127    
128     fprintf(stderr, "ZZogl-PG: ");
129     vfprintf(stderr, fmt, list);
130     va_end(list);
131     }
132    
133     void Print(const char *fmt, ...)
134     {
135     va_list list;
136    
137     va_start(list, fmt);
138    
139     if (IsLogging()) vfprintf(gsLog, fmt, list);
140    
141     fprintf(stderr, "ZZogl-PG: ");
142     vfprintf(stderr, fmt, list);
143    
144     va_end(list);
145     }
146    
147    
148     void WriteLn(const char *fmt, ...)
149     {
150     va_list list;
151    
152     va_start(list, fmt);
153    
154     if (IsLogging()) vfprintf(gsLog, fmt, list);
155    
156     fprintf(stderr, "ZZogl-PG: ");
157     vfprintf(stderr, fmt, list);
158     va_end(list);
159     fprintf(stderr,"\n");
160     }
161    
162     void Greg_Log(const char *fmt, ...)
163     {
164     #if defined(WRITE_GREG_LOGS)
165     va_list list;
166     char tmp[512];
167    
168     va_start(list, fmt);
169    
170     fprintf(gsLog, "GRegs: ");
171     //fprintf(stderr,"GRegs: ");
172     if (IsLogging()) vfprintf(gsLog, fmt, list);
173     //vfprintf(stderr, fmt, list);
174    
175     va_end(list);
176    
177     if (IsLogging()) fprintf(gsLog, "\n");
178     //fprintf(stderr,"\n");
179     #endif
180     }
181    
182     void Prim_Log(const char *fmt, ...)
183     {
184     #if defined(ZEROGS_DEVBUILD) && defined(WRITE_PRIM_LOGS)
185     va_list list;
186     char tmp[512];
187    
188     va_start(list, fmt);
189    
190     if (conf.log /*& 0x00000010*/)
191     {
192     if (IsLogging()) vfprintf(gsLog, fmt, list);
193    
194     fprintf(stderr, "ZZogl-PG(PRIM): ");
195     vfprintf(stderr, fmt, list);
196    
197     vprintf(fmt, list);
198     }
199    
200     va_end(list);
201     fprintf(stderr,"\n");
202    
203     #endif
204     }
205    
206     void GS_Log(const char *fmt, ...)
207     {
208     #ifdef ZEROGS_DEVBUILD
209     va_list list;
210    
211     va_start(list, fmt);
212    
213     if (IsLogging())
214     {
215     vfprintf(gsLog, fmt, list);
216     fprintf(gsLog, "\n");
217     }
218    
219     fprintf(stderr, "ZZogl-PG: ");
220     vfprintf(stderr, fmt, list);
221     fprintf(stderr, "\n");
222    
223     va_end(list);
224     #endif
225     }
226    
227     void Warn_Log(const char *fmt, ...)
228     {
229     #ifdef ZEROGS_DEVBUILD
230     va_list list;
231    
232     va_start(list, fmt);
233    
234     if (IsLogging())
235     {
236     vfprintf(gsLog, fmt, list);
237     fprintf(gsLog, "\n");
238     }
239    
240     fprintf(stderr, "ZZogl-PG: ");
241     vfprintf(stderr, fmt, list);
242     fprintf(stderr, "\n");
243    
244     va_end(list);
245     #endif
246     }
247    
248     void Debug_Log(const char *fmt, ...)
249     {
250     #if _DEBUG
251     va_list list;
252    
253     va_start(list, fmt);
254    
255     if (IsLogging())
256     {
257     vfprintf(gsLog, fmt, list);
258     fprintf(gsLog, "\n");
259     }
260    
261     fprintf(stderr, "ZZogl-PG: ");
262     vfprintf(stderr, fmt, list);
263     fprintf(stderr, "\n");
264    
265     va_end(list);
266     #endif
267     }
268    
269     void Error_Log(const char *fmt, ...)
270     {
271     va_list list;
272    
273     va_start(list, fmt);
274    
275     if (IsLogging())
276     {
277     vfprintf(gsLog, fmt, list);
278     fprintf(gsLog, "\n");
279     }
280    
281     fprintf(stderr, "ZZogl-PG: ");
282     vfprintf(stderr, fmt, list);
283     fprintf(stderr, "\n");
284    
285     va_end(list);
286     }
287     };

  ViewVC Help
Powered by ViewVC 1.1.22