1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
|
// For licensing and usage information, read docs/winui_license.txt
// MASTER
//****************************************************************************
/***************************************************************************
mui_audit.c
Audit dialog
***************************************************************************/
// standard windows headers
#include <windows.h>
#include <windowsx.h>
// standard C headers
#include <tchar.h>
// MAME/MAMEUI headers
#include "winui.h"
#include "winutf8.h"
#include "audit.h"
#include "resource.h"
#include "mui_opts.h"
#include "mui_util.h"
#include "properties.h"
#include <richedit.h>
#ifdef _MSC_VER
#define vsnprintf _vsnprintf
#endif
/***************************************************************************
function prototypes
***************************************************************************/
static DWORD WINAPI AuditThreadProc(LPVOID hDlg);
static INT_PTR CALLBACK AuditWindowProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
static void ProcessNextRom(void);
static void ProcessNextSample(void);
static void CLIB_DECL DetailsPrintf(const char *fmt, ...) ATTR_PRINTF(1,2);
static const char * StatusString(int iStatus);
/***************************************************************************
Internal variables
***************************************************************************/
#define MAX_AUDITBOX_TEXT 0x7FFFFFFE
static volatile HWND hAudit;
static volatile int rom_index = 0;
static volatile int roms_correct = 0;
static volatile int roms_incorrect = 0;
static volatile int sample_index = 0;
static volatile int samples_correct = 0;
static volatile int samples_incorrect = 0;
static volatile BOOL bPaused = FALSE;
static volatile BOOL bCancel = FALSE;
static int m_choice = 0;
/***************************************************************************
External functions
***************************************************************************/
static int strcatprintf(std::string &str, const char *format, ...)
{
va_list ap;
va_start(ap, format);
int retVal = strcatvprintf(str, format, ap);
va_end(ap);
return retVal;
}
void AuditDialog(HWND hParent, int choice)
{
rom_index = 0;
roms_correct = -1; // ___empty must not be counted
roms_incorrect = 0;
sample_index = 0;
samples_correct = -1; // ___empty must not be counted
samples_incorrect = 0;
m_choice = choice;
//RS use Riched32.dll
HMODULE hModule = LoadLibrary(TEXT("Riched32.dll"));
if( hModule )
{
DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_AUDIT),hParent,AuditWindowProc);
FreeLibrary( hModule );
hModule = NULL;
}
else
MessageBox(GetMainWindow(),TEXT("Unable to Load Riched32.dll"),TEXT("Error"), MB_OK | MB_ICONERROR);
}
void InitGameAudit(int gameIndex)
{
rom_index = gameIndex;
}
const char * GetAuditString(int audit_result)
{
switch (audit_result)
{
case media_auditor::CORRECT :
case media_auditor::BEST_AVAILABLE :
case media_auditor::NONE_NEEDED :
return "Yes";
case media_auditor::NOTFOUND :
case media_auditor::INCORRECT :
return "No";
default:
printf("unknown audit value %i\n",audit_result);
}
return "?";
}
BOOL IsAuditResultKnown(int audit_result)
{
return TRUE;
}
BOOL IsAuditResultYes(int audit_result)
{
return audit_result == media_auditor::CORRECT
|| audit_result == media_auditor::BEST_AVAILABLE
|| audit_result == media_auditor::NONE_NEEDED;
}
BOOL IsAuditResultNo(int audit_result)
{
return audit_result == media_auditor::NOTFOUND
|| audit_result == media_auditor::INCORRECT;
}
/***************************************************************************
Internal functions
***************************************************************************/
// Verifies the ROM set while calling SetRomAuditResults
int MameUIVerifyRomSet(int game, bool choice)
{
driver_enumerator enumerator(MameUIGlobal(), driver_list::driver(game));
enumerator.next();
media_auditor auditor(enumerator);
media_auditor::summary summary = auditor.audit_media(AUDIT_VALIDATE_FAST);
std::string summary_string;
if (summary == media_auditor::NOTFOUND)
{
if (m_choice < 2)
strcatprintf(summary_string, "%s: Romset NOT FOUND\n", driver_list::driver(game).name);
}
else
if (choice)
{
auditor.winui_summarize(driver_list::driver(game).name, &summary_string); // audit all games
}
else
{
std::ostringstream whatever;
auditor.summarize(driver_list::driver(game).name, &whatever); // audit one game
summary_string = whatever.str();
}
// output the summary of the audit
DetailsPrintf("%s", summary_string.c_str());
SetRomAuditResults(game, summary);
return summary;
}
// Verifies the Sample set while calling SetSampleAuditResults
int MameUIVerifySampleSet(int game)
{
driver_enumerator enumerator(MameUIGlobal(), driver_list::driver(game));
enumerator.next();
media_auditor auditor(enumerator);
media_auditor::summary summary = auditor.audit_samples();
std::string summary_string;
if (summary == media_auditor::NOTFOUND)
strcatprintf(summary_string, "%s: Sampleset NOT FOUND\n", driver_list::driver(game).name);
else
{
std::ostringstream whatever;
auditor.summarize(driver_list::driver(game).name, &whatever);
summary_string = whatever.str();
}
// output the summary of the audit
DetailsPrintf("%s", summary_string.c_str());
SetSampleAuditResults(game, summary);
return summary;
}
static DWORD WINAPI AuditThreadProc(LPVOID hDlg)
{
char buffer[200];
while (!bCancel)
{
if (!bPaused)
{
if (rom_index != -1)
{
sprintf(buffer, "Checking Set %s - %s", driver_list::driver(rom_index).name, driver_list::driver(rom_index).type.fullname());
win_set_window_text_utf8((HWND)hDlg, buffer);
ProcessNextRom();
}
else
if (sample_index != -1)
{
sprintf(buffer, "Checking Set %s - %s", driver_list::driver(sample_index).name, driver_list::driver(sample_index).type.fullname());
win_set_window_text_utf8((HWND)hDlg, buffer);
ProcessNextSample();
}
else
{
win_set_window_text_utf8((HWND)hDlg, "File Audit");
EnableWindow(GetDlgItem((HWND)hDlg, IDPAUSE), FALSE);
ExitThread(1);
}
}
}
return 0;
}
static INT_PTR CALLBACK AuditWindowProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
static HANDLE hThread;
static DWORD dwThreadID = 0;
HWND hEdit;
switch (Msg)
{
case WM_INITDIALOG:
hAudit = hDlg;
//RS 20030613 Set Bkg of RichEdit Ctrl
hEdit = GetDlgItem(hAudit, IDC_AUDIT_DETAILS);
if (hEdit)
{
SendMessage( hEdit, EM_SETBKGNDCOLOR, FALSE, GetSysColor(COLOR_BTNFACE) );
// MSH - Set to max
SendMessage( hEdit, EM_SETLIMITTEXT, MAX_AUDITBOX_TEXT, 0 );
}
SendDlgItemMessage(hDlg, IDC_ROMS_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0, driver_list::total()));
SendDlgItemMessage(hDlg, IDC_SAMPLES_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0, driver_list::total()));
bPaused = false;
bCancel = false;
rom_index = 0;
hThread = CreateThread(NULL, 0, AuditThreadProc, hDlg, 0, &dwThreadID);
return 1;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDCANCEL:
bPaused = false;
if (hThread)
{
bCancel = true;
DWORD dwExitCode = 0;
if (GetExitCodeThread(hThread, &dwExitCode) && (dwExitCode == STILL_ACTIVE))
{
PostMessage(hDlg, WM_COMMAND, wParam, lParam);
return 1;
}
CloseHandle(hThread);
}
EndDialog(hDlg,0);
m_choice = 0;
break;
case IDPAUSE:
if (bPaused)
{
SendDlgItemMessage(hAudit, IDPAUSE, WM_SETTEXT, 0, (LPARAM)TEXT("Pause"));
bPaused = false;
}
else
{
SendDlgItemMessage(hAudit, IDPAUSE, WM_SETTEXT, 0, (LPARAM)TEXT("Continue"));
bPaused = true;
}
break;
}
return 1;
}
return 0;
}
/* Callback for the Audit property sheet */
INT_PTR CALLBACK GameAuditDialogProc(HWND hDlg,UINT Msg,WPARAM wParam,LPARAM lParam)
{
switch (Msg)
{
case WM_INITDIALOG:
FlushFileCaches();
hAudit = hDlg;
win_set_window_text_utf8(GetDlgItem(hDlg, IDC_PROP_TITLE), GameInfoTitle(OPTIONS_GAME, rom_index));
SetTimer(hDlg, 0, 1, NULL);
return 1;
case WM_TIMER:
KillTimer(hDlg, 0);
{
int iStatus;
LPCSTR lpStatus;
iStatus = MameUIVerifyRomSet(rom_index, 0);
lpStatus = DriverUsesRoms(rom_index) ? StatusString(iStatus) : "None required";
win_set_window_text_utf8(GetDlgItem(hDlg, IDC_PROP_ROMS), lpStatus);
if (DriverUsesSamples(rom_index))
{
iStatus = MameUIVerifySampleSet(rom_index);
lpStatus = StatusString(iStatus);
}
else
{
lpStatus = "None Required";
}
win_set_window_text_utf8(GetDlgItem(hDlg, IDC_PROP_SAMPLES), lpStatus);
}
ShowWindow(hDlg, SW_SHOW);
break;
}
return 0;
}
static void ProcessNextRom()
{
int retval = 0;
TCHAR buffer[200];
retval = MameUIVerifyRomSet(rom_index, 1);
switch (retval)
{
case media_auditor::BEST_AVAILABLE: /* correct, incorrect or separate count? */
case media_auditor::CORRECT:
case media_auditor::NONE_NEEDED:
roms_correct++;
_stprintf(buffer, TEXT("%i"), roms_correct);
SendDlgItemMessage(hAudit, IDC_ROMS_CORRECT, WM_SETTEXT, 0, (LPARAM)buffer);
_stprintf(buffer, TEXT("%i"), roms_correct + roms_incorrect);
SendDlgItemMessage(hAudit, IDC_ROMS_TOTAL, WM_SETTEXT, 0, (LPARAM)buffer);
break;
case media_auditor::NOTFOUND:
case media_auditor::INCORRECT:
roms_incorrect++;
_stprintf(buffer, TEXT("%i"), roms_incorrect);
SendDlgItemMessage(hAudit, IDC_ROMS_INCORRECT, WM_SETTEXT, 0, (LPARAM)buffer);
_stprintf(buffer, TEXT("%i"), roms_correct + roms_incorrect);
SendDlgItemMessage(hAudit, IDC_ROMS_TOTAL, WM_SETTEXT, 0, (LPARAM)buffer);
break;
}
rom_index++;
SendDlgItemMessage(hAudit, IDC_ROMS_PROGRESS, PBM_SETPOS, rom_index, 0);
if (rom_index == driver_list::total())
{
sample_index = 0;
rom_index = -1;
}
}
static void ProcessNextSample()
{
int retval = 0;
TCHAR buffer[200];
retval = MameUIVerifySampleSet(sample_index);
switch (retval)
{
case media_auditor::NOTFOUND:
case media_auditor::INCORRECT:
if (DriverUsesSamples(sample_index))
{
samples_incorrect++;
_stprintf(buffer, TEXT("%i"), samples_incorrect);
SendDlgItemMessage(hAudit, IDC_SAMPLES_INCORRECT, WM_SETTEXT, 0, (LPARAM)buffer);
_stprintf(buffer, TEXT("%i"), samples_correct + samples_incorrect);
SendDlgItemMessage(hAudit, IDC_SAMPLES_TOTAL, WM_SETTEXT, 0, (LPARAM)buffer);
break;
}
default:
if ((DriverUsesSamples(sample_index)) || (m_choice == 1))
{
samples_correct++;
_stprintf(buffer, TEXT("%i"), samples_correct);
SendDlgItemMessage(hAudit, IDC_SAMPLES_CORRECT, WM_SETTEXT, 0, (LPARAM)buffer);
_stprintf(buffer, TEXT("%i"), samples_correct + samples_incorrect);
SendDlgItemMessage(hAudit, IDC_SAMPLES_TOTAL, WM_SETTEXT, 0, (LPARAM)buffer);
break;
}
}
sample_index++;
SendDlgItemMessage(hAudit, IDC_SAMPLES_PROGRESS, PBM_SETPOS, sample_index, 0);
if (sample_index == driver_list::total())
{
DetailsPrintf("Audit complete.\n");
SendDlgItemMessage(hAudit, IDCANCEL, WM_SETTEXT, 0, (LPARAM)TEXT("Close"));
sample_index = -1;
}
}
static void CLIB_DECL DetailsPrintf(const char *fmt, ...)
{
//RS 20030613 Different Ids for Property Page and Dialog
// so see which one's currently instantiated
HWND hEdit = GetDlgItem(hAudit, IDC_AUDIT_DETAILS);
if (hEdit == NULL)
hEdit = GetDlgItem(hAudit, IDC_AUDIT_DETAILS_PROP);
if (hEdit == NULL)
{
// Auditing via F5 - no window to display the results
//printf("audit detailsprintf() can't find any audit control\n");
return;
}
va_list marker;
va_start(marker, fmt);
char buffer[8000];
vsprintf(buffer, fmt, marker);
va_end(marker);
TCHAR* t_s = ui_wstring_from_utf8(ConvertToWindowsNewlines(buffer));
if( !t_s || _tcscmp(TEXT(""), t_s) == 0)
return;
int textLength = Edit_GetTextLength(hEdit);
Edit_SetSel(hEdit, textLength, textLength);
SendMessage( hEdit, EM_REPLACESEL, false, (WPARAM)(LPCTSTR)win_tstring_strdup(t_s) );
free(t_s);
}
static const char * StatusString(int iStatus)
{
static const char *ptr = "Unknown";
switch (iStatus)
{
case media_auditor::CORRECT:
ptr = "Passed";
break;
case media_auditor::BEST_AVAILABLE:
ptr = "Best available";
break;
case media_auditor::NONE_NEEDED:
ptr = "None Required";
break;
case media_auditor::NOTFOUND:
ptr = "Not found";
break;
case media_auditor::INCORRECT:
ptr = "Failed";
break;
}
return ptr;
}
|