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
25 #include "wine/debug.h"
26 #include "wine/unicode.h"
28 #include "dxdiag_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
34 struct command_line_info
36 WCHAR outfile[MAX_PATH];
37 enum output_type output_type;
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);
54 static BOOL process_file_name(const WCHAR *cmdline, enum output_type output_type, WCHAR *filename, size_t filename_len)
59 /* Skip any intervening spaces. */
60 while (*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)
73 endptr = cmdline + strlenW(cmdline);
75 len = endptr - cmdline;
76 if (len == 0 || len >= filename_len)
79 memcpy(filename, cmdline, len * sizeof(WCHAR));
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)
90 strcatW(filename, filename_ext);
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};
114 info->whql_check = FALSE;
115 info->output_type = OUTPUT_NONE;
119 /* Skip whitespace before arg */
120 while (*cmdline == ' ')
123 /* If no option is specified, treat the command line as a filename. */
124 if (*cmdline != '-' && *cmdline != '/')
126 info->output_type = OUTPUT_TEXT;
127 return process_file_name(cmdline, OUTPUT_TEXT, info->outfile,
128 sizeof(info->outfile)/sizeof(WCHAR));
137 info->output_type = OUTPUT_TEXT;
138 return process_file_name(cmdline + 1, OUTPUT_TEXT, info->outfile,
139 sizeof(info->outfile)/sizeof(WCHAR));
142 info->output_type = OUTPUT_XML;
143 return process_file_name(cmdline + 1, OUTPUT_XML, info->outfile,
144 sizeof(info->outfile)/sizeof(WCHAR));
147 if (strncmpiW(cmdline, whql_colonW, 5))
152 if (!strncmpiW(cmdline, offW, 3))
154 info->whql_check = FALSE;
157 else if (!strncmpiW(cmdline, onW, 2))
159 info->whql_check = TRUE;
176 int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow)
178 struct command_line_info info;
179 struct dxdiag_information *dxdiag_info;
183 if (!process_command_line(cmdline, &info))
186 WINE_TRACE("WHQL check: %s\n", info.whql_check ? "TRUE" : "FALSE");
187 WINE_TRACE("Output type: %d\n", info.output_type);
188 if (info.output_type != OUTPUT_NONE)
189 WINE_TRACE("Output filename: %s\n", debugstr_output_type(info.output_type));
193 dxdiag_info = collect_dxdiag_information(info.whql_check);
196 WINE_ERR("DxDiag information collection failed\n");
201 if (info.output_type != OUTPUT_NONE)
202 output_dxdiag_information(dxdiag_info, info.outfile, info.output_type);
204 WINE_FIXME("Information dialog is not implemented\n");
206 free_dxdiag_information(dxdiag_info);