editor: clean up error reporting

This commit is contained in:
Erik Faye-Lund 2010-05-01 19:15:13 +02:00
parent 12328ce6b8
commit d68a38f451

View File

@ -10,6 +10,7 @@
#include <objbase.h> #include <objbase.h>
#include <commdlg.h> #include <commdlg.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h>
// Windows XP look and feel. Seems to enable Vista look as well. // Windows XP look and feel. Seems to enable Vista look as well.
#pragma comment(linker, \ #pragma comment(linker, \
@ -29,6 +30,30 @@ const char *mainWindowTitle = "GNU Rocket System";
const wchar_t *mainWindowTitleW = L"GNU Rocket System"; const wchar_t *mainWindowTitleW = L"GNU Rocket System";
const char *keyName = "SOFTWARE\\GNU Rocket"; const char *keyName = "SOFTWARE\\GNU Rocket";
void verror(const char *fmt, va_list va)
{
char temp[4096];
vsnprintf(temp, sizeof(temp), fmt, va);
MessageBox(NULL, temp, mainWindowTitle, MB_OK | MB_ICONERROR);
}
void error(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
verror(fmt, va);
va_end(va);
}
void die(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
verror(fmt, va);
va_end(va);
exit(EXIT_FAILURE);
}
HINSTANCE hInst; HINSTANCE hInst;
HWND hwnd = NULL; HWND hwnd = NULL;
TrackView *trackView = NULL; TrackView *trackView = NULL;
@ -204,7 +229,8 @@ void loadDocument(const std::wstring &_fileName)
SendMessage(hwnd, WM_CURRVALDIRTY, 0, 0); SendMessage(hwnd, WM_CURRVALDIRTY, 0, 0);
InvalidateRect(trackViewWin, NULL, FALSE); InvalidateRect(trackViewWin, NULL, FALSE);
} }
else MessageBox(hwnd, "failed to open file", mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND); else
error("failed to open file");
} }
void fileOpen() void fileOpen()
@ -252,7 +278,8 @@ void fileSaveAs()
mruFileList.update(); mruFileList.update();
DrawMenuBar(hwnd); DrawMenuBar(hwnd);
} }
else MessageBox(hwnd, "Failed to save file", mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND); else
error("Failed to save file");
} }
} }
@ -262,7 +289,7 @@ void fileSave()
else if (!document.save(fileName.c_str())) else if (!document.save(fileName.c_str()))
{ {
document.sendSaveCommand(); document.sendSaveCommand();
MessageBox(hwnd, "Failed to save file", mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND); error("Failed to save file");
} }
} }
@ -313,10 +340,7 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
if (ERROR_SUCCESS != RegOpenKey(HKEY_CURRENT_USER, keyName, &regConfigKey)) if (ERROR_SUCCESS != RegOpenKey(HKEY_CURRENT_USER, keyName, &regConfigKey))
{ {
if (ERROR_SUCCESS != RegCreateKey(HKEY_CURRENT_USER, keyName, &regConfigKey)) if (ERROR_SUCCESS != RegCreateKey(HKEY_CURRENT_USER, keyName, &regConfigKey))
{ die("failed to create registry key");
printf("failed to create reg key\n");
exit(-1);
}
} }
/* Recent Files menu */ /* Recent Files menu */
@ -427,7 +451,8 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
{ {
int rows = int(trackView->getRows()); int rows = int(trackView->getRows());
INT_PTR result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SETROWS), hwnd, (DLGPROC)setRowsDialogProc, (LPARAM)&rows); INT_PTR result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SETROWS), hwnd, (DLGPROC)setRowsDialogProc, (LPARAM)&rows);
if (FAILED(result)) MessageBox(hwnd, "unable to create dialog box", mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND); if (FAILED(result))
error("unable to create dialog box");
} }
break; break;
@ -435,7 +460,8 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
{ {
int initialBias = 0; int initialBias = 0;
INT_PTR result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_BIASSELECTION), hwnd, (DLGPROC)biasSelectionDialogProc, (LPARAM)&initialBias); INT_PTR result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_BIASSELECTION), hwnd, (DLGPROC)biasSelectionDialogProc, (LPARAM)&initialBias);
if (FAILED(result)) MessageBox(hwnd, "unable to create dialog box", mainWindowTitle, MB_OK | MB_ICONERROR | MB_SETFOREGROUND); if (FAILED(result))
error("unable to create dialog box");
} }
break; break;
} }
@ -507,20 +533,6 @@ static ATOM registerMainWindowClass(HINSTANCE hInstance)
return RegisterClassExW(&wc); return RegisterClassExW(&wc);
} }
#include <stdarg.h>
void die(const char *fmt, ...)
{
char temp[4096];
va_list va;
va_start(va, fmt);
vfprintf(stderr, fmt, va);
vsnprintf(temp, sizeof(temp), fmt, va);
va_end(va);
MessageBox(NULL, temp, mainWindowTitle, MB_OK | MB_ICONERROR);
exit(EXIT_FAILURE);
}
SOCKET clientConnect(SOCKET serverSocket, sockaddr_in *host) SOCKET clientConnect(SOCKET serverSocket, sockaddr_in *host)
{ {
sockaddr_in hostTemp; sockaddr_in hostTemp;