ole2disp.dll16: Implement SafeArrayGet[UBound|LBound].
[wine.git] / programs / dxdiag / main.c
blobd7d430b57016e76d42618b4ca4403e33785b8126
1 /*
2 * DxDiag Implementation
4 * Copyright 2009 Austin English
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.
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.
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
21 #define WIN32_LEAN_AND_MEAN
22 #include <windows.h>
23 #include <dxdiag.h>
25 #include "wine/debug.h"
26 #include "wine/unicode.h"
28 #include "dxdiag_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
32 HINSTANCE hInstance;
34 struct command_line_info
36 WCHAR outfile[MAX_PATH];
37 enum output_type output_type;
38 BOOL whql_check;
41 static void usage(void)
43 WCHAR title[MAX_STRING_LEN];
44 WCHAR usage[MAX_STRING_LEN];
46 LoadStringW(hInstance, STRING_DXDIAG_TOOL, title, sizeof(title)/sizeof(WCHAR));
47 LoadStringW(hInstance, STRING_USAGE, usage, sizeof(usage)/sizeof(WCHAR));
49 MessageBoxW(NULL, usage, title, MB_OK | MB_ICONWARNING);
51 ExitProcess(0);
54 static BOOL process_file_name(const WCHAR *cmdline, enum output_type output_type, WCHAR *filename, size_t filename_len)
56 const WCHAR *endptr;
57 size_t len;
59 /* Skip any intervening spaces. */
60 while (*cmdline == ' ')
61 cmdline++;
63 /* Ignore filename quoting, if any. */
64 if (*cmdline == '"' && (endptr = strrchrW(cmdline, '"')))
66 /* Reject a string with only one quote. */
67 if (cmdline == endptr)
68 return FALSE;
70 cmdline++;
72 else
73 endptr = cmdline + strlenW(cmdline);
75 len = endptr - cmdline;
76 if (len == 0 || len >= filename_len)
77 return FALSE;
79 memcpy(filename, cmdline, len * sizeof(WCHAR));
80 filename[len] = '\0';
82 /* Append an extension appropriate for the output type if the filename does not have one. */
83 if (!strrchrW(filename, '.'))
85 const WCHAR *filename_ext = get_output_extension(output_type);
87 if (len + strlenW(filename_ext) >= filename_len)
88 return FALSE;
90 strcatW(filename, filename_ext);
93 return TRUE;
97 Process options [/WHQL:ON|OFF][/X outfile|/T outfile]
98 Returns TRUE if options were present, FALSE otherwise
99 Only one of /X and /T is allowed, /WHQL must come before /X and /T,
100 and the rest of the command line after /X or /T is interpreted as a
101 filename. If a non-option portion of the command line is encountered,
102 dxdiag assumes that the string is a filename for the /T option.
104 Native does not interpret quotes, but quotes are parsed here because of how
105 Wine handles the command line.
108 static BOOL process_command_line(const WCHAR *cmdline, struct command_line_info *info)
110 static const WCHAR whql_colonW[] = {'w','h','q','l',':',0};
111 static const WCHAR offW[] = {'o','f','f',0};
112 static const WCHAR onW[] = {'o','n',0};
113 static const WCHAR dontskipW[] = {'d','o','n','t','s','k','i','p',0};
115 info->whql_check = FALSE;
116 info->output_type = OUTPUT_NONE;
118 while (*cmdline)
120 /* Skip whitespace before arg */
121 while (*cmdline == ' ')
122 cmdline++;
124 /* If no option is specified, treat the command line as a filename. */
125 if (*cmdline != '-' && *cmdline != '/')
127 info->output_type = OUTPUT_TEXT;
128 return process_file_name(cmdline, OUTPUT_TEXT, info->outfile,
129 sizeof(info->outfile)/sizeof(WCHAR));
132 cmdline++;
134 switch (*cmdline)
136 case 'T':
137 case 't':
138 info->output_type = OUTPUT_TEXT;
139 return process_file_name(cmdline + 1, OUTPUT_TEXT, info->outfile,
140 sizeof(info->outfile)/sizeof(WCHAR));
141 case 'X':
142 case 'x':
143 info->output_type = OUTPUT_XML;
144 return process_file_name(cmdline + 1, OUTPUT_XML, info->outfile,
145 sizeof(info->outfile)/sizeof(WCHAR));
146 case 'W':
147 case 'w':
148 if (strncmpiW(cmdline, whql_colonW, 5))
149 return FALSE;
151 cmdline += 5;
153 if (!strncmpiW(cmdline, offW, 3))
155 info->whql_check = FALSE;
156 cmdline += 2;
158 else if (!strncmpiW(cmdline, onW, 2))
160 info->whql_check = TRUE;
161 cmdline++;
163 else
164 return FALSE;
166 break;
168 case 'd':
169 case 'D':
170 if (strncmpiW(cmdline, dontskipW, 8))
171 return FALSE;
172 cmdline += 8;
173 break;
175 default:
176 return FALSE;
179 cmdline++;
182 return TRUE;
185 int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow)
187 struct command_line_info info;
188 struct dxdiag_information *dxdiag_info;
190 hInstance = hInst;
192 if (!process_command_line(cmdline, &info))
193 usage();
195 WINE_TRACE("WHQL check: %s\n", info.whql_check ? "TRUE" : "FALSE");
196 WINE_TRACE("Output type: %d\n", info.output_type);
197 if (info.output_type != OUTPUT_NONE)
198 WINE_TRACE("Output filename: %s\n", debugstr_output_type(info.output_type));
200 CoInitialize(NULL);
202 dxdiag_info = collect_dxdiag_information(info.whql_check);
203 if (!dxdiag_info)
205 WINE_ERR("DxDiag information collection failed\n");
206 CoUninitialize();
207 return 1;
210 if (info.output_type != OUTPUT_NONE)
211 output_dxdiag_information(dxdiag_info, info.outfile, info.output_type);
212 else
213 WINE_FIXME("Information dialog is not implemented\n");
215 free_dxdiag_information(dxdiag_info);
217 CoUninitialize();
218 return 0;