msi: Set the install context based on the ALLUSERS property.
[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 "config.h"
22 #include "wine/port.h"
23
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31
32 #include "mmsystem.h"
33 #include "dmerror.h"
34 #include "ddraw.h"
35 #include "dinput.h"
36 #include "vfwmsgs.h"
37 #include "mmstream.h"
38 #include "dplay8.h"
39 #include "dxfile.h"
40 #include "d3d9.h"
41 #include "dsound.h"
42
43 #include "dxerr9.h"
44
45 #include "wine/debug.h"
46
47 WINE_DEFAULT_DEBUG_CHANNEL(dxerr);
48
49 typedef struct {
50     HRESULT      hr;
51     const CHAR*  resultA;
52     const WCHAR* resultW;
53     const CHAR*  descriptionA;
54     const WCHAR* descriptionW;
55 } error_info;
56
57 #include "errors.h"
58
59 const char * WINAPI DXGetErrorString9A(HRESULT hr)
60 {
61     unsigned int i, j, k = 0;
62     TRACE("(0x%08x)\n", hr);
63
64     for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
65         j = k + (i / 2);
66         if (hr == info[j].hr)
67             return info[j].resultA;
68         if ((unsigned int)hr > (unsigned int)info[j].hr) {
69             k = j + 1;
70             i--;
71         }
72     }
73
74     return "Unknown";
75 }
76
77 const WCHAR * WINAPI DXGetErrorString9W(HRESULT hr)
78 {
79     static const WCHAR unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', 0 };
80     unsigned int i, j, k = 0;
81     TRACE("(0x%08x)\n", hr);
82
83     for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
84         j = k + (i / 2);
85         if (hr == info[j].hr)
86             return info[j].resultW;
87         if ((unsigned int)hr > (unsigned int)info[j].hr) {
88             k = j + 1;
89             i--;
90         }
91     }
92
93     return unknown;
94 }
95
96 const char * WINAPI DXGetErrorDescription9A(HRESULT hr)
97 {
98     unsigned int i, j, k = 0;
99     TRACE("(0x%08x)\n", hr);
100
101     for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
102         j = k + (i / 2);
103         if (hr == info[j].hr)
104             return info[j].descriptionA;
105         if ((unsigned int)hr > (unsigned int)info[j].hr) {
106             k = j + 1;
107             i--;
108         }
109     }
110
111     return "n/a";
112 }
113
114 const WCHAR * WINAPI DXGetErrorDescription9W(HRESULT hr)
115 {
116     static const WCHAR na[] = { 'n', '/', 'a', 0 };
117     unsigned int i, j, k = 0;
118     TRACE("(0x%08x)\n", hr);
119
120     for (i = sizeof(info)/sizeof(info[0]); i != 0; i /= 2) {
121         j = k + (i / 2);
122         if (hr == info[j].hr)
123             return info[j].descriptionW;
124         if ((unsigned int)hr > (unsigned int)info[j].hr) {
125             k = j + 1;
126             i--;
127         }
128     }
129
130     return na;
131 }
132
133 HRESULT WINAPI DXTraceA(const char* strFile, DWORD dwLine, HRESULT hr, const char*  strMsg, BOOL bPopMsgBox)
134 {
135     char msg[1024];
136     TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
137
138     if (bPopMsgBox) {
139         snprintf(msg, sizeof(msg), "File: %s\nLine: %d\nError Code: %s (0x%08x)\nCalling: %s",
140             strFile, dwLine, DXGetErrorString9A(hr), hr, strMsg);
141         MessageBoxA(0, msg, "Unexpected error encountered", MB_OK|MB_ICONERROR);
142     } else {
143         snprintf(msg, sizeof(msg), "%s(%d): %s (hr=%s (0x%08x))", strFile,
144             dwLine, strMsg, DXGetErrorString9A(hr), hr);
145         OutputDebugStringA(msg);
146     }
147
148     return hr;
149 }
150
151 HRESULT WINAPI DXTraceW(const char* strFile, DWORD dwLine, HRESULT hr, const WCHAR* strMsg, BOOL bPopMsgBox)
152 {
153     WCHAR msg[1024];
154     TRACE("(%p,%d,0x%08x,%p,%d)\n", strFile, dwLine, hr, strMsg, bPopMsgBox);
155
156     if (bPopMsgBox) {
157         static const WCHAR format[] = { 'F','i','l','e',':',' ','%','s','\\','n','L','i','n',
158             'e',':',' ','%','l','d','\\','n','E','r','r','o','r',' ','C','o',
159             'd','e',':',' ','%','s',' ','(','0','x','%','0','8','l','x',')',
160             '\\','n','C','a','l','l','i','n','g',':',' ','%','s',0 };
161         static const WCHAR caption[] = { 'U','n','e','x','p','e','c','t','e','d',' ','e','r',
162             'r','o','r',' ','e','n','c','o','u','n','t','e','r','e','d',0 };
163         /* FIXME: should use wsnprintf */
164         wsprintfW(msg, format, strFile, dwLine,
165                   DXGetErrorString9W(hr), hr, strMsg);
166         MessageBoxW(0, msg, caption, MB_OK|MB_ICONERROR);
167     } else {
168         static const WCHAR format[] = { '%','s','(','%','l','d',')',':',' ','%','s',' ','(',
169             'h','r','=','%','s',' ','(','0','x','%','0','8','l','x',')',')',' ',
170             0 };
171         /* FIXME: should use wsnprintf */
172         wsprintfW(msg, format, strFile, dwLine, strMsg,
173                   DXGetErrorString9W(hr), hr);
174         OutputDebugStringW(msg);
175     }
176
177     return hr;
178 }