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
26 #include "wine/debug.h"
27 #include "dxdiag_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag
);
33 struct command_line_info
35 WCHAR outfile
[MAX_PATH
];
36 enum output_type output_type
;
40 static void usage(void)
42 WCHAR title
[MAX_STRING_LEN
];
43 WCHAR usage
[MAX_STRING_LEN
];
45 LoadStringW(hInstance
, STRING_DXDIAG_TOOL
, title
, ARRAY_SIZE(title
));
46 LoadStringW(hInstance
, STRING_USAGE
, usage
, ARRAY_SIZE(usage
));
48 MessageBoxW(NULL
, usage
, title
, MB_OK
| MB_ICONWARNING
);
53 static BOOL
process_file_name(const WCHAR
*cmdline
, enum output_type output_type
, WCHAR
*filename
, size_t filename_len
)
58 /* Skip any intervening spaces. */
59 while (*cmdline
== ' ')
62 /* Ignore filename quoting, if any. */
63 if (*cmdline
== '"' && (endptr
= wcsrchr(cmdline
, '"')))
65 /* Reject a string with only one quote. */
66 if (cmdline
== endptr
)
72 endptr
= cmdline
+ lstrlenW(cmdline
);
74 len
= endptr
- cmdline
;
75 if (len
== 0 || len
>= filename_len
)
78 memcpy(filename
, cmdline
, len
* sizeof(WCHAR
));
81 /* Append an extension appropriate for the output type if the filename does not have one. */
82 if (!wcsrchr(filename
, '.'))
84 const WCHAR
*filename_ext
= get_output_extension(output_type
);
86 if (len
+ lstrlenW(filename_ext
) >= filename_len
)
89 lstrcatW(filename
, filename_ext
);
96 Process options [/WHQL:ON|OFF][/X outfile|/T outfile]
97 Returns TRUE if options were present, FALSE otherwise
98 Only one of /X and /T is allowed, /WHQL must come before /X and /T,
99 and the rest of the command line after /X or /T is interpreted as a
100 filename. If a non-option portion of the command line is encountered,
101 dxdiag assumes that the string is a filename for the /T option.
103 Native does not interpret quotes, but quotes are parsed here because of how
104 Wine handles the command line.
107 static BOOL
process_command_line(const WCHAR
*cmdline
, struct command_line_info
*info
)
109 info
->whql_check
= FALSE
;
110 info
->output_type
= OUTPUT_NONE
;
114 /* Skip whitespace before arg */
115 while (*cmdline
== ' ')
118 /* If no option is specified, treat the command line as a filename. */
119 if (*cmdline
!= '-' && *cmdline
!= '/')
121 info
->output_type
= OUTPUT_TEXT
;
122 return process_file_name(cmdline
, OUTPUT_TEXT
, info
->outfile
,
123 ARRAY_SIZE(info
->outfile
));
132 info
->output_type
= OUTPUT_TEXT
;
133 return process_file_name(cmdline
+ 1, OUTPUT_TEXT
, info
->outfile
,
134 ARRAY_SIZE(info
->outfile
));
137 info
->output_type
= OUTPUT_XML
;
138 return process_file_name(cmdline
+ 1, OUTPUT_XML
, info
->outfile
,
139 ARRAY_SIZE(info
->outfile
));
142 if (wcsnicmp(cmdline
, L
"whql:", 5))
147 if (!wcsnicmp(cmdline
, L
"off", 3))
149 info
->whql_check
= FALSE
;
152 else if (!wcsnicmp(cmdline
, L
"on", 2))
154 info
->whql_check
= TRUE
;
164 if (wcsnicmp(cmdline
, L
"dontskip", 8))
179 int WINAPI
wWinMain(HINSTANCE hInst
, HINSTANCE hPrevInst
, LPWSTR cmdline
, int cmdshow
)
181 struct command_line_info info
;
182 struct dxdiag_information
*dxdiag_info
;
184 InitCommonControls();
188 if (!process_command_line(cmdline
, &info
))
191 WINE_TRACE("WHQL check: %s\n", info
.whql_check
? "TRUE" : "FALSE");
192 WINE_TRACE("Output type: %d\n", info
.output_type
);
193 if (info
.output_type
!= OUTPUT_NONE
)
194 WINE_TRACE("Output filename: %s\n", debugstr_output_type(info
.output_type
));
198 dxdiag_info
= collect_dxdiag_information(info
.whql_check
);
201 WINE_ERR("DxDiag information collection failed\n");
206 if (info
.output_type
!= OUTPUT_NONE
)
207 output_dxdiag_information(dxdiag_info
, info
.outfile
, info
.output_type
);
209 WINE_FIXME("Information dialog is not implemented\n");
211 free_dxdiag_information(dxdiag_info
);