(svn r7466) -Cleanup: [win32] Coding style, indentation, variable localization.

pull/155/head
Darkvater 18 years ago
parent bf3b850c53
commit e3d94c6e12

@ -129,34 +129,30 @@ static uint32 CalcCRC(byte *data, uint size, uint32 crc) {
static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename) static void GetFileInfo(DebugFileInfo *dfi, const TCHAR *filename)
{ {
HANDLE file;
memset(dfi, 0, sizeof(dfi)); memset(dfi, 0, sizeof(dfi));
{ file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
HANDLE file; if (file != INVALID_HANDLE_VALUE) {
byte buffer[1024]; byte buffer[1024];
DWORD numread; DWORD numread;
uint32 filesize = 0; uint32 filesize = 0;
FILETIME write_time; FILETIME write_time;
uint32 crc = (uint32)-1; uint32 crc = (uint32)-1;
file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, for (;;) {
OPEN_EXISTING, 0, 0); if (ReadFile(file, buffer, sizeof(buffer), &numread, NULL) == 0 || numread == 0)
if (file != INVALID_HANDLE_VALUE) { break;
for (;;) { filesize += numread;
if (ReadFile(file, buffer, sizeof(buffer), &numread, NULL) == 0 || crc = CalcCRC(buffer, numread, crc);
numread == 0) }
break; dfi->size = filesize;
filesize += numread; dfi->crc32 = crc ^ (uint32)-1;
crc = CalcCRC(buffer, numread, crc);
}
dfi->size = filesize;
dfi->crc32 = crc ^ (uint32)-1;
if (GetFileTime(file, NULL, NULL, &write_time)) { if (GetFileTime(file, NULL, NULL, &write_time)) {
FileTimeToSystemTime(&write_time, &dfi->file_time); FileTimeToSystemTime(&write_time, &dfi->file_time);
}
CloseHandle(file);
} }
CloseHandle(file);
} }
} }
@ -185,23 +181,22 @@ static char *PrintModuleInfo(char *output, HMODULE mod)
static char *PrintModuleList(char *output) static char *PrintModuleList(char *output)
{ {
BOOL (WINAPI *EnumProcessModules)(HANDLE,HMODULE*,DWORD,LPDWORD); BOOL (WINAPI *EnumProcessModules)(HANDLE, HMODULE*, DWORD, LPDWORD);
HANDLE proc;
HMODULE modules[100];
DWORD needed;
BOOL res;
int count,i;
if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0\0")) { if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0\0")) {
proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); HMODULE modules[100];
if (proc) { DWORD needed;
BOOL res;
int count, i;
HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
if (proc != NULL) {
res = EnumProcessModules(proc, modules, sizeof(modules), &needed); res = EnumProcessModules(proc, modules, sizeof(modules), &needed);
CloseHandle(proc); CloseHandle(proc);
if (res) { if (res) {
count = count = min(needed / sizeof(HMODULE), lengthof(modules));
min(needed / sizeof(HMODULE), lengthof(modules));
for (i = 0; i != count; i++) for (i = 0; i != count; i++) output = PrintModuleInfo(output, modules[i]);
output = PrintModuleInfo(output, modules[i]);
return output; return output;
} }
} }
@ -257,7 +252,6 @@ static const char wininet_files[] =
static WinInetProcs _wininet; static WinInetProcs _wininet;
static const TCHAR *SubmitCrashReport(HWND wnd, void *msg, size_t msglen, const TCHAR *arg) static const TCHAR *SubmitCrashReport(HWND wnd, void *msg, size_t msglen, const TCHAR *arg)
{ {
HINTERNET inet, conn, http; HINTERNET inet, conn, http;
@ -367,60 +361,57 @@ static bool DoEmergencySave(HWND wnd)
static INT_PTR CALLBACK CrashDialogFunc(HWND wnd,UINT msg,WPARAM wParam,LPARAM lParam) static INT_PTR CALLBACK CrashDialogFunc(HWND wnd,UINT msg,WPARAM wParam,LPARAM lParam)
{ {
switch (msg) { switch (msg) {
case WM_INITDIALOG: { case WM_INITDIALOG: {
#if defined(UNICODE) #if defined(UNICODE)
wchar_t crash_msgW[8096]; wchar_t crash_msgW[8096];
#endif #endif
SetDlgItemText(wnd, 10, _crash_desc); SetDlgItemText(wnd, 10, _crash_desc);
SetDlgItemText(wnd, 11, MB_TO_WIDE_BUFFER(_crash_msg, crash_msgW, lengthof(crash_msgW))); SetDlgItemText(wnd, 11, MB_TO_WIDE_BUFFER(_crash_msg, crash_msgW, lengthof(crash_msgW)));
SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE); SendDlgItemMessage(wnd, 11, WM_SETFONT, (WPARAM)GetStockObject(ANSI_FIXED_FONT), FALSE);
SetWndSize(wnd, -1); SetWndSize(wnd, -1);
} return TRUE; } return TRUE;
case WM_COMMAND: case WM_COMMAND:
switch (wParam) { switch (wParam) {
case 12: // Close case 12: /* Close */
ExitProcess(0); ExitProcess(0);
case 13: { // Emergency save case 13: /* Emergency save */
if (DoEmergencySave(wnd)) { if (DoEmergencySave(wnd)) {
MessageBox(wnd, _save_succeeded, _T("Save successful"), MB_ICONINFORMATION); MessageBox(wnd, _save_succeeded, _T("Save successful"), MB_ICONINFORMATION);
} else { } else {
MessageBox(wnd, _T("Save failed"), _T("Save failed"), MB_ICONINFORMATION); MessageBox(wnd, _T("Save failed"), _T("Save failed"), MB_ICONINFORMATION);
} }
break; break;
} case 14: { /* Submit crash report */
case 14: { // Submit crash report const TCHAR *s;
const TCHAR *s;
SetCursor(LoadCursor(NULL, IDC_WAIT));
SetCursor(LoadCursor(NULL, IDC_WAIT));
s = SubmitCrashReport(wnd, _crash_msg, strlen(_crash_msg), _T(""));
s = SubmitCrashReport(wnd, _crash_msg, strlen(_crash_msg), _T("")); if (s != NULL) {
if (s != NULL) { MessageBox(wnd, s, _T("Error"), MB_ICONSTOP);
MessageBox(wnd, s, _T("Error"), MB_ICONSTOP); break;
break; }
}
// try to submit emergency savegame
// try to submit emergency savegame if (_did_emerg_save || DoEmergencySave(wnd)) SubmitFile(wnd, _T("crash.sav"));
if (_did_emerg_save || DoEmergencySave(wnd)) SubmitFile(wnd, _T("crash.sav"));
// try to submit the autosaved game
// try to submit the autosaved game if (_opt.autosave) {
if (_opt.autosave) { TCHAR buf[40];
TCHAR buf[40]; _sntprintf(buf, lengthof(buf), _T("autosave%d.sav"), (_autosave_ctr - 1) & 3);
_sntprintf(buf, lengthof(buf), _T("autosave%d.sav"), (_autosave_ctr - 1) & 3); SubmitFile(wnd, buf);
SubmitFile(wnd, buf); }
EnableWindow(GetDlgItem(wnd, 14), FALSE);
SetCursor(LoadCursor(NULL, IDC_ARROW));
MessageBox(wnd, _T("Crash report submitted. Thank you."), _T("Crash Report"), MB_ICONINFORMATION);
} break;
case 15: /* Expand window to show crash-message */
_expanded ^= 1;
SetWndSize(wnd, _expanded);
break;
} }
EnableWindow(GetDlgItem(wnd, 14), FALSE); return TRUE;
SetCursor(LoadCursor(NULL, IDC_ARROW)); case WM_CLOSE: ExitProcess(0);
MessageBox(wnd, _T("Crash report submitted. Thank you."), _T("Crash Report"), MB_ICONINFORMATION);
break;
}
case 15: // Expand
_expanded ^= 1;
SetWndSize(wnd, _expanded);
break;
}
return TRUE;
case WM_CLOSE:
ExitProcess(0);
} }
return FALSE; return FALSE;
@ -775,12 +766,10 @@ static int ParseCommandLine(char *line, char **argv, int max_argc)
do { do {
// skip whitespace // skip whitespace
while (*line == ' ' || *line == '\t') while (*line == ' ' || *line == '\t') line++;
line++;
// end? // end?
if (*line == '\0') if (*line == '\0') break;
break;
// special handling when quoted // special handling when quoted
if (*line == '"') { if (*line == '"') {
@ -808,7 +797,6 @@ void CreateConsole(void)
CONSOLE_SCREEN_BUFFER_INFO coninfo; CONSOLE_SCREEN_BUFFER_INFO coninfo;
if (_has_console) return; if (_has_console) return;
_has_console = true; _has_console = true;
AllocConsole(); AllocConsole();
@ -883,7 +871,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
_set_error_mode(_OUT_TO_MSGBOX); // force assertion output to messagebox _set_error_mode(_OUT_TO_MSGBOX); // force assertion output to messagebox
// setup random seed to something quite random /* setup random seed to something quite random */
_random_seeds[1][0] = _random_seeds[0][0] = GetTickCount(); _random_seeds[1][0] = _random_seeds[0][0] = GetTickCount();
_random_seeds[1][1] = _random_seeds[0][1] = _random_seeds[0][0] * 0x1234567; _random_seeds[1][1] = _random_seeds[0][1] = _random_seeds[0][0] * 0x1234567;
SeedMT(_random_seeds[0][0]); SeedMT(_random_seeds[0][0]);

Loading…
Cancel
Save