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 static const WCHAR whql_colonW
[] = {'w','h','q','l',':',0};
109 static const WCHAR offW
[] = {'o','f','f',0};
110 static const WCHAR onW
[] = {'o','n',0};
111 static const WCHAR dontskipW
[] = {'d','o','n','t','s','k','i','p',0};
113 info
->whql_check
= FALSE
;
114 info
->output_type
= OUTPUT_NONE
;
118 /* Skip whitespace before arg */
119 while (*cmdline
== ' ')
122 /* If no option is specified, treat the command line as a filename. */
123 if (*cmdline
!= '-' && *cmdline
!= '/')
125 info
->output_type
= OUTPUT_TEXT
;
126 return process_file_name(cmdline
, OUTPUT_TEXT
, info
->outfile
,
127 ARRAY_SIZE(info
->outfile
));
136 info
->output_type
= OUTPUT_TEXT
;
137 return process_file_name(cmdline
+ 1, OUTPUT_TEXT
, info
->outfile
,
138 ARRAY_SIZE(info
->outfile
));
141 info
->output_type
= OUTPUT_XML
;
142 return process_file_name(cmdline
+ 1, OUTPUT_XML
, info
->outfile
,
143 ARRAY_SIZE(info
->outfile
));
146 if (wcsnicmp(cmdline
, whql_colonW
, 5))
151 if (!wcsnicmp(cmdline
, offW
, 3))
153 info
->whql_check
= FALSE
;
156 else if (!wcsnicmp(cmdline
, onW
, 2))
158 info
->whql_check
= TRUE
;
168 if (wcsnicmp(cmdline
, dontskipW
, 8))
183 int WINAPI
wWinMain(HINSTANCE hInst
, HINSTANCE hPrevInst
, LPWSTR cmdline
, int cmdshow
)
185 struct command_line_info info
;
186 struct dxdiag_information
*dxdiag_info
;
190 if (!process_command_line(cmdline
, &info
))
193 WINE_TRACE("WHQL check: %s\n", info
.whql_check
? "TRUE" : "FALSE");
194 WINE_TRACE("Output type: %d\n", info
.output_type
);
195 if (info
.output_type
!= OUTPUT_NONE
)
196 WINE_TRACE("Output filename: %s\n", debugstr_output_type(info
.output_type
));
200 dxdiag_info
= collect_dxdiag_information(info
.whql_check
);
203 WINE_ERR("DxDiag information collection failed\n");
208 if (info
.output_type
!= OUTPUT_NONE
)
209 output_dxdiag_information(dxdiag_info
, info
.outfile
, info
.output_type
);
211 WINE_FIXME("Information dialog is not implemented\n");
213 free_dxdiag_information(dxdiag_info
);