# PROP Use_Debug_Libraries 1\r
# PROP Output_Dir "Debug"\r
# PROP Intermediate_Dir "Debug"\r
+# PROP Ignore_Export_Lib 0\r
# PROP Target_Dir ""\r
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c\r
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c\r
# ADD BSC32 /nologo\r
LINK32=link.exe\r
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib setupapi.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept\r
\r
!ENDIF \r
\r
# End Source File\r
# Begin Source File\r
\r
+SOURCE=.\src\rawdisk.c\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\src\widgets.c\r
# End Source File\r
# End Group\r
# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
# Begin Source File\r
\r
+SOURCE=.\src\rawdisk.h\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\src\widgets.h\r
# End Source File\r
# End Group\r
#include <stdlib.h>
#include <windows.h>
#include "widgets.h"
+#include "rawdisk.h"
static struct wgt_window *win;
static struct wgt_widget *lb_instto, *bn_inst, *bn_cancel, *cb_devs, *ck_usbonly;
+static struct rawdisk_device rawdev[64];
+static int num_rawdev;
static void onclick(struct wgt_widget *w);
static void onmodify(struct wgt_widget *w);
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprevinst, char *cmdline, int showcmd)
{
- int x, y;
+ int i, x, y;
MSG msg;
- static const char *items[] = {
- "item one",
- "item two",
- "item three"
- };
+ static const char *items[64];
+ if((num_rawdev = rawdisk_detect(rawdev, sizeof rawdev / sizeof *rawdev)) == -1) {
+ return 1;
+ }
+ for(i=0; i<num_rawdev; i++) {
+ items[i] = rawdev[i].name;
+ }
if(!(win = wgt_window("256boss USB stick installer", 400, 300))) {
return 1;
lb_instto = wgt_label(win, "Install to device:", 10, 10);
x = wgt_xpos_after(lb_instto, WGT_AUTO);
- cb_devs = wgt_combo(win, items, sizeof items / sizeof *items, 0,
- x, 10, WGT_AUTO, WGT_AUTO, onmodify);
+ cb_devs = wgt_combo(win, items, num_rawdev, 0, x, 10, WGT_AUTO, WGT_AUTO,
+ onmodify);
y = wgt_ypos_after(cb_devs, 16);
ck_usbonly = wgt_checkbox(win, "only show USB devices", 1, x, y,
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <windows.h>
+#include <setupapi.h>
+#include <devguid.h>
+#include <winioctl.h>
+#include "rawdisk.h"
+
+static GUID guid_iface_disk = {0x53f56307, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b}};
+
+int rawdisk_detect(struct rawdisk_device *disks, int max_disks)
+{
+ int devidx, ifidx, count;
+ HDEVINFO devset;
+ SP_DEVINFO_DATA devdata;
+ SP_DEVICE_INTERFACE_DATA devif;
+ SP_DEVICE_INTERFACE_DETAIL_DATA_A *devdetail;
+ DWORD size, regtype;
+ char devname[1024];
+
+ if((devset = SetupDiGetClassDevs(&guid_iface_disk, 0, 0,
+ DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)) == INVALID_HANDLE_VALUE) {
+ fprintf(stderr, "failed to enumerate devices\n");
+ return -1;
+ }
+
+ count = 0;
+ devidx = 0;
+ for(;;) {
+ memset(&devdata, 0, sizeof devdata);
+ devdata.cbSize = sizeof devdata;
+ if(!SetupDiEnumDeviceInfo(devset, devidx, &devdata)) {
+ if(GetLastError() == ERROR_NO_MORE_ITEMS) break;
+ devidx++;
+ continue;
+ }
+
+ regtype = SPDRP_PHYSICAL_DEVICE_OBJECT_NAME;
+ SetupDiGetDeviceRegistryProperty(devset, &devdata, SPDRP_FRIENDLYNAME,
+ ®type, (unsigned char*)devname, sizeof devname, &size);
+
+ count = 0;
+ ifidx = 0;
+ for(;;) {
+ memset(&devif, 0, sizeof devif);
+ devif.cbSize = sizeof devif;
+ if(!SetupDiEnumDeviceInterfaces(devset, &devdata, &guid_iface_disk, ifidx, &devif)) {
+ if(GetLastError() == ERROR_NO_MORE_ITEMS) break;
+ ifidx++;
+ continue;
+ }
+
+ SetupDiGetDeviceInterfaceDetail(devset, &devif, 0, 0, &size, 0);
+ if(!(devdetail = malloc(size))) {
+ fprintf(stderr, "failed to allocate device interface detail buffer (size: %lu)\n", (unsigned long)size);
+ return -1;
+ }
+ devdetail->cbSize = sizeof *devdetail;
+ SetupDiGetDeviceInterfaceDetail(devset, &devif, devdetail, size, 0, 0);
+
+
+ if(count < max_disks) {
+ disks[count].path = strdup(devdetail->DevicePath);
+ disks[count].name = strdup(devname);
+ if(!disks[count].path || !disks[count].name) {
+ fprintf(stderr, "failed to allocate device strings\n");
+ return -1;
+ }
+ count++;
+ }
+
+ free(devdetail);
+ ifidx++;
+ }
+
+ devidx++;
+ }
+
+ return count;
+}
--- /dev/null
+#ifndef RAWDISK_H_
+#define RAWDISK_H_
+
+struct rawdisk_device {
+ char *name;
+ char *path;
+};
+
+int rawdisk_detect(struct rawdisk_device *disks, int max_disks);
+
+#endif /* RAWDISK_H_ */
\ No newline at end of file