msi: Move the file sequence check out of ready_media_info to avoid an unnecessary...
[wine] / dlls / dxerr9 / dxerr9.c
1 /*
2  * DirectX 9 error routines
3  *
4  * Copyright 2004 Robert Reif
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winnls.h"
29
30 #include "mmsystem.h"
31 #include "dmerror.h"
32 #include "ddraw.h"
33 #include "dinput.h"
34 #include "vfwmsgs.h"
35 #include "mmstream.h"
36 #include "dplay8.h"
37 #include "dxfile.h"
38 #include "d3d9.h"
39 #include "dsound.h"
40
41 #include "dxerr9.h"
42
43 #include "wine/debug.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(dxerr);
46
47 typedef struct {
48     HRESULT      hr;
49     const CHAR*  resultA;
50     const WCHAR* resultW;
51     const CHAR*  descriptionA;
52     const WCHAR* descriptionW;
53 } error_info;
54
55 #include "errors.h"
56
57 const char * WINAPI DXGetErrorString9A(HRESULT hr)
58 {
59     unsigned int i, j, k = 0;
60     TRACE("(0x%08x)\n", hr);
61
62     for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
63         j = k + (i / 2);
64         if (hr == info[j].hr)
65             return info[j].resultA;
66         if ((unsigned int)hr > (unsigned int)info[j].hr) {
67             k = j + 1;
68             i--;
69         }
70     }
71
72     return "Unknown";
73 }
74
75 const WCHAR * WINAPI DXGetErrorString9W(HRESULT hr)
76 {
77     static const WCHAR unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', 0 };
78     unsigned int i, j, k = 0;
79     TRACE("(0x%08x)\n", hr);
80
81     for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
82         j = k + (i / 2);
83         if (hr == info[j].hr)
84             return info[j].resultW;
85         if ((unsigned int)hr > (unsigned int)info[j].hr) {
86             k = j + 1;
87             i--;
88         }
89     }
90
91     return unknown;
92 }
93
94 const char * WINAPI DXGetErrorDescription9A(HRESULT hr)
95 {
96     unsigned int i, j, k = 0;
97     TRACE("(0x%08x)\n", hr);
98
99     for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
100         j = k + (i / 2);
101         if (hr == info[j].hr)
102             return info[j].descriptionA;
103         if ((unsigned int)hr > (unsigned int)info[j].hr) {
104             k = j + 1;
105             i--;
106         }
107     }
108
109     return "n/a";
110 }
111
112 const WCHAR * WINAPI DXGetErrorDescription9W(HRESULT hr)
113 {
114     static const WCHAR na[] = { 'n', '/', 'a', 0 };
115     unsigned int i, j, k = 0;
116     TRACE("(0x%08x)\n", hr);
117
118     for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
119         j = k + (i / 2);
120         if (hr == info[j].hr)
121             return info[j].descriptionW;
122         if ((unsigned int)hr > (unsigned int)info[j].hr) {
123             k = j + 1;
124             i--;
125         }
126     }
127
128     return na;
129 }
130
131 HRESULT WINAPI DXTraceA(const char* strFile, DWORD dwLine, HRESULT hr, const char*  strMsg, BOOL bPopMsgBox)
132 {
133     char msg[1024];
134     TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
135
136     if (bPopMsgBox) {
137         snprintf(msg, sizeof(msg), "File: %s\nLine: %d\nError Code: %s (0x%08x)\nCalling: %s",
138             strFile, dwLine, DXGetErrorString9A(hr), hr, strMsg);
139         MessageBoxA(0, msg, "Unexpected error encountered", MB_OK|MB_ICONERROR);
140     } else {
141         snprintf(msg, sizeof(msg), "%s(%d): %s (hr=%s (0x%08x))", strFile,
142             dwLine, strMsg, DXGetErrorString9A(hr), hr);
143         OutputDebugStringA(msg);
144     }
145
146     return hr;
147 }
148
149 HRESULT WINAPI DXTraceW(const char* strFile, DWORD dwLine, HRESULT hr, const WCHAR* strMsg, BOOL bPopMsgBox)
150 {
151     WCHAR msg[1024];
152     TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
153
154     if (bPopMsgBox) {
155         static const WCHAR format[] = { 'F','i','l','e',':',' ','%','s','\\','n','L','i','n',
156             'e',':',' ','%','l','d','\\','n','E','r','r','o','r',' ','C','o',
157             'd','e',':',' ','%','s',' ','(','0','x','%','0','8','l','x',')',
158             '\\','n','C','a','l','l','i','n','g',':',' ','%','s',0 };
159         static const WCHAR caption[] = { 'U','n','e','x','p','e','c','t','e','d',' ','e','r',
160             'r','o','r',' ','e','n','c','o','u','n','t','e','r','e','d',0 };
161         /* FIXME: should use wsnprintf */
162         wsprintfW(msg, format, strFile, dwLine,
163                   DXGetErrorString9W(hr), hr, strMsg);
164         MessageBoxW(0, msg, caption, MB_OK|MB_ICONERROR);
165     } else {
166         static const WCHAR format[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
167             'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
168             0 };
169         /* FIXME: should use wsnprintf */
170         wsprintfW(msg, format, strFile, dwLine, strMsg,
171                   DXGetErrorString9W(hr), hr);
172         OutputDebugStringW(msg);
173     }
174
175     return hr;
176 }