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 "dxdiag_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag
);
32 struct command_line_info
34 WCHAR outfile
[MAX_PATH
];
35 enum output_type output_type
;
39 static void usage(void)
41 WCHAR title
[MAX_STRING_LEN
];
42 WCHAR usage
[MAX_STRING_LEN
];
44 LoadStringW(hInstance
, STRING_DXDIAG_TOOL
, title
, ARRAY_SIZE(title
));
45 LoadStringW(hInstance
, STRING_USAGE
, usage
, ARRAY_SIZE(usage
));
47 MessageBoxW(NULL
, usage
, title
, MB_OK
| MB_ICONWARNING
);
52 static BOOL
process_file_name(const WCHAR
*cmdline
, enum output_type output_type
, WCHAR
*filename
, size_t filename_len
)
57 /* Skip any intervening spaces. */
58 while (*cmdline
== ' ')
61 /* Ignore filename quoting, if any. */
62 if (*cmdline
== '"' && (endptr
= wcsrchr(cmdline
, '"')))
64 /* Reject a string with only one quote. */
65 if (cmdline
== endptr
)
71 endptr
= cmdline
+ lstrlenW(cmdline
);
73 len
= endptr
- cmdline
;
74 if (len
== 0 || len
>= filename_len
)
77 memcpy(filename
, cmdline
, len
* sizeof(WCHAR
));
80 /* Append an extension appropriate for the output type if the filename does not have one. */
81 if (!wcsrchr(filename
, '.'))
83 const WCHAR
*filename_ext
= get_output_extension(output_type
);
85 if (len
+ lstrlenW(filename_ext
) >= filename_len
)
88 lstrcatW(filename
, filename_ext
);
95 Process options [/WHQL:ON|OFF][/X outfile|/T outfile]
96 Returns TRUE if options were present, FALSE otherwise
97 Only one of /X and /T is allowed, /WHQL must come before /X and /T,
98 and the rest of the command line after /X or /T is interpreted as a
99 filename. If a non-option portion of the command line is encountered,
100 dxdiag assumes that the string is a filename for the /T option.
102 Native does not interpret quotes, but quotes are parsed here because of how
103 Wine handles the command line.
106 static BOOL
process_command_line(const WCHAR
*cmdline
, struct command_line_info
*info
)
108 info
->whql_check
= FALSE
;
109 info
->output_type
= OUTPUT_NONE
;
113 /* Skip whitespace before arg */
114 while (*cmdline
== ' ')
117 /* If no option is specified, treat the command line as a filename. */
118 if (*cmdline
!= '-' && *cmdline
!= '/')
120 info
->output_type
= OUTPUT_TEXT
;
121 return process_file_name(cmdline
, OUTPUT_TEXT
, info
->outfile
,
122 ARRAY_SIZE(info
->outfile
));
131 info
->output_type
= OUTPUT_TEXT
;
132 return process_file_name(cmdline
+ 1, OUTPUT_TEXT
, info
->outfile
,
133 ARRAY_SIZE(info
->outfile
));
136 info
->output_type
= OUTPUT_XML
;
137 return process_file_name(cmdline
+ 1, OUTPUT_XML
, info
->outfile
,
138 ARRAY_SIZE(info
->outfile
));
141 if (wcsnicmp(cmdline
, L
"whql:", 5))
146 if (!wcsnicmp(cmdline
, L
"off", 3))
148 info
->whql_check
= FALSE
;
151 else if (!wcsnicmp(cmdline
, L
"on", 2))
153 info
->whql_check
= TRUE
;
163 if (wcsnicmp(cmdline
, L
"dontskip", 8))
178 int WINAPI
wWinMain(HINSTANCE hInst
, HINSTANCE hPrevInst
, LPWSTR cmdline
, int cmdshow
)
180 struct command_line_info info
;
181 struct dxdiag_information
*dxdiag_info
;
185 if (!process_command_line(cmdline
, &info
))
188 WINE_TRACE("WHQL check: %s\n", info
.whql_check
? "TRUE" : "FALSE");
189 WINE_TRACE("Output type: %d\n", info
.output_type
);
190 if (info
.output_type
!= OUTPUT_NONE
)
191 WINE_TRACE("Output filename: %s\n", debugstr_output_type(info
.output_type
));
195 dxdiag_info
= collect_dxdiag_information(info
.whql_check
);
198 WINE_ERR("DxDiag information collection failed\n");
203 if (info
.output_type
!= OUTPUT_NONE
)
204 output_dxdiag_information(dxdiag_info
, info
.outfile
, info
.output_type
);
206 WINE_FIXME("Information dialog is not implemented\n");
208 free_dxdiag_information(dxdiag_info
);