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
, ARRAY_SIZE(title
));
47 LoadStringW(hInstance
, STRING_USAGE
, usage
, ARRAY_SIZE(usage
));
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};
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
;
120 /* Skip whitespace before arg */
121 while (*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 ARRAY_SIZE(info
->outfile
));
138 info
->output_type
= OUTPUT_TEXT
;
139 return process_file_name(cmdline
+ 1, OUTPUT_TEXT
, info
->outfile
,
140 ARRAY_SIZE(info
->outfile
));
143 info
->output_type
= OUTPUT_XML
;
144 return process_file_name(cmdline
+ 1, OUTPUT_XML
, info
->outfile
,
145 ARRAY_SIZE(info
->outfile
));
148 if (strncmpiW(cmdline
, whql_colonW
, 5))
153 if (!strncmpiW(cmdline
, offW
, 3))
155 info
->whql_check
= FALSE
;
158 else if (!strncmpiW(cmdline
, onW
, 2))
160 info
->whql_check
= TRUE
;
170 if (strncmpiW(cmdline
, dontskipW
, 8))
185 int WINAPI
wWinMain(HINSTANCE hInst
, HINSTANCE hPrevInst
, LPWSTR cmdline
, int cmdshow
)
187 struct command_line_info info
;
188 struct dxdiag_information
*dxdiag_info
;
192 if (!process_command_line(cmdline
, &info
))
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
));
202 dxdiag_info
= collect_dxdiag_information(info
.whql_check
);
205 WINE_ERR("DxDiag information collection failed\n");
210 if (info
.output_type
!= OUTPUT_NONE
)
211 output_dxdiag_information(dxdiag_info
, info
.outfile
, info
.output_type
);
213 WINE_FIXME("Information dialog is not implemented\n");
215 free_dxdiag_information(dxdiag_info
);