#define IMG_FNAME "disk.img"
+#define WIN_XPAD 10
+#define WIN_YPAD 15
+
static int instimg(const char *devpath);
static void update_disks(void);
static void onclick(struct wgt_widget *w);
"%s\n"
"\n"
"Please run this installer from the 256boss distribution directory";
-
+static const char *fail_err_str;
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprevinst, char *cmdline, int showcmd)
{
- int x, y;
+ int x, y, width, height, max_width;
MSG msg;
char *msgbuf, *errmsg;
fclose(imgfile);
return 1;
}
- lb_instto = wgt_label(win, "Install to device:", 10, 20);
+
+ max_width = 0;
+ y = WIN_YPAD;
+ lb_instto = wgt_label(win, "Install to device:", WIN_XPAD, WIN_YPAD);
x = wgt_xpos_after(lb_instto, WGT_AUTO);
- cb_devs = wgt_combo(win, items, num_rawdev, 0, x, 20, 270, WGT_AUTO, onmodify);
+ cb_devs = wgt_combo(win, items, num_rawdev, 0, x, WIN_YPAD, 270, WGT_AUTO, onmodify);
+ if((width = wgt_xpos_after(cb_devs, WIN_XPAD)) > max_width) max_width = width;
y = wgt_ypos_after(cb_devs, 16);
ck_usbonly = wgt_checkbox(win, "only show USB devices", 1, x, y,
WGT_AUTO, WGT_AUTO, ck_usbonly_handler);
+ if((width = wgt_xpos_after(ck_usbonly, WIN_XPAD)) > max_width) max_width = width;
y = wgt_ypos_after(ck_usbonly, 32);
bn_inst = wgt_button(win, "Install", 70, y, 100, WGT_AUTO, onclick);
bn_cancel = wgt_button(win, "Cancel", 230, y, 100, WGT_AUTO, onclick);
+ height = wgt_ypos_after(bn_inst, WIN_YPAD);
+
+ wgt_resize_window(win, max_width, height);
+
update_disks();
while(GetMessage(&msg, 0, 0, 0)) {
return 0;
}
-#define WIN_XPAD 10
-#define WIN_YPAD 10
#define MIN_BS (4 * 1024 * 1024)
static int instimg(const char *devpath)
long num_blk_done, total_blk;
int progr;
- if(!(hdev = CreateFile(devpath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
- 0, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, 0))) {
+ if((hdev = CreateFile(devpath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
+ 0, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, 0)) == INVALID_HANDLE_VALUE) {
+ DWORD err = GetLastError();
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, err, 0,
+ &fail_err_str, 0, 0);
return -1;
}
- if(rawdisk_eject(hdev) == 0) {
+ /*if(rawdisk_eject(hdev) == 0) {
rawdisk_load(hdev);
- }
+ }*/
if(DeviceIoControl(hdev, IOCTL_DISK_GET_DRIVE_GEOMETRY, 0, 0, &geom, sizeof geom, &wrcount, 0)) {
blksz = geom.BytesPerSector;
if(!(blkbuf = malloc(blksz))) {
CloseHandle(hdev);
+ fail_err_str = "failed to allocate block buffer";
return -1;
}
height = wgt_ypos_after(bn_cancel_inst, WIN_YPAD);
- max_width += GetSystemMetrics(SM_CXFIXEDFRAME) * 2;
- height += GetSystemMetrics(SM_CYFIXEDFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION);
wgt_resize_window(win_inst, max_width, height);
/* go through any pending messages once first, to allow the window to get drawn correctly */
memset(blkbuf + sz, 0, blksz - sz);
}
SetFilePointer(hdev, num_blk_done * blksz, 0, FILE_BEGIN);
- WriteFile(hdev, blkbuf, blksz, &wrcount, 0);
+ if(!WriteFile(hdev, blkbuf, blksz, &wrcount, 0)) {
+ DWORD err = GetLastError();
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, err, 0,
+ &fail_err_str, 0, 0);
+ goto end;
+ }
num_blk_done++;
progr = num_blk_done * 100 / total_blk;
"If the 256boss partition doesn't show up immediately,\n"
"please eject and re-attach the device\n";
+static const char *fail_fmt = \
+ "Installation failed!\n"
+ "Error: %s\n";
+
static void onclick(struct wgt_widget *w)
{
int sel, len;
if(MessageBox(0, msgbuf, "Proceed with installation?", flags) == IDYES) {
inst_running = 1;
if(instimg(rawdev[sel].path) == -1) {
- MessageBox(0, "Installation failed", 0, MB_OK | MB_ICONSTOP | MB_APPLMODAL | MB_SETFOREGROUND);
+ int prev_len = len;
+ len = strlen(fail_fmt) + (fail_err_str ? strlen(fail_err_str) : strlen("unknown"));
+ if(len > prev_len) {
+ alloca(len - prev_len);
+ }
+ sprintf(msgbuf, fail_fmt, fail_err_str ? fail_err_str : "unknown");
+ MessageBox(0, msgbuf, 0, MB_OK | MB_ICONSTOP | MB_APPLMODAL | MB_SETFOREGROUND);
} else {
MessageBox(0, success_str, "Done", MB_OK | MB_ICONASTERISK | MB_APPLMODAL | MB_SETFOREGROUND);
}
#include <commctrl.h>
#include "widgets.h"
+#define WIN_STYLE WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME
+
struct wgt_window {
HWND handle;
struct wgt_rect rect;
return 0;
}
- if(!(win->handle = CreateWindow(win->cname, title, WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME,
- CW_USEDEFAULT, CW_USEDEFAULT, width, height, 0, 0, hinst, 0))) {
+ rect.left = rect.top = 0;
+ rect.right = width;
+ rect.bottom = height;
+ AdjustWindowRect(&rect, WIN_STYLE, FALSE);
+
+ if(!(win->handle = CreateWindow(win->cname, title, WIN_STYLE, CW_USEDEFAULT,
+ CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top,
+ 0, 0, hinst, 0))) {
fprintf(stderr, "wgt_create_window: failed to create window\n");
UnregisterClass(title, hinst);
return 0;
void wgt_resize_window(struct wgt_window *win, int width, int height)
{
- MoveWindow(win->handle, win->rect.x, win->rect.y, width, height, TRUE);
+ RECT rect;
+
win->rect.width = width;
win->rect.height = height;
+
+ rect.left = win->rect.x;
+ rect.top = win->rect.y;
+ rect.right = rect.left + width;
+ rect.bottom = rect.top + height;
+ if(AdjustWindowRect(&rect, WIN_STYLE, FALSE)) {
+ width = rect.right - rect.left;
+ height = rect.bottom - rect.top;
+ }
+ MoveWindow(win->handle, win->rect.x, win->rect.y, width, height, TRUE);
}
void wgt_quit_on_close(struct wgt_window *win, int quit)