MCPcopy Create free account
hub / github.com/TASEmulators/fceux / GetComboBoxByteSize

Function GetComboBoxByteSize

src/drivers/win/header_editor.cpp:1683–1751  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1681}
1682
1683int GetComboBoxByteSize(HWND hwnd, UINT id, int* value, iNES_HEADER* header)
1684{
1685 char* name = "";
1686 char buf[256];
1687
1688 enum errors {
1689 OK = 0,
1690 FORMAT_ERR,
1691 MINUS_ERR,
1692 UNIT_ERR
1693 };
1694
1695 int err = errors::OK;
1696
1697 switch (id)
1698 {
1699 case IDC_PRGROM_COMBO: name = "PRG ROM"; break;
1700 case IDC_PRGRAM_COMBO: name = "PRG RAM"; break;
1701 case IDC_PRGNVRAM_COMBO: name = "PRG NVRAM"; break;
1702 case IDC_CHRROM_COMBO: name = "CHR ROM"; break;
1703 case IDC_CHRRAM_COMBO: name = "CHR RAM"; break;
1704 case IDC_CHRNVRAM_COMBO: name = "CHR NVRAM"; break;
1705 }
1706
1707 if (!GetComboBoxListItemData(hwnd, id, value, buf, header))
1708 {
1709 char buf2[4];
1710 if (sscanf(buf, "%d%3[KMB]", value, buf2) < 2 || !strcmp(buf2, ""))
1711 err = errors::FORMAT_ERR;
1712 else
1713 {
1714 if (*value < 0)
1715 err = errors::MINUS_ERR;
1716 else if (!strcmp(buf2, "KB") || !strcmp(buf2, "K"))
1717 *value *= 1024;
1718 else if (!strcmp(buf2, "MB") || !strcmp(buf2, "M"))
1719 *value *= 1024 * 1024;
1720 else if (strcmp(buf2, "B"))
1721 err = errors::UNIT_ERR;
1722 }
1723 }
1724
1725 if (err)
1726 {
1727 if (header)
1728 {
1729 switch (err)
1730 {
1731 case errors::FORMAT_ERR:
1732 sprintf(buf, "%s size you entered is invalid, it should be positive decimal integer followed with unit, e.g. 1024B, 128KB, 4MB", name);
1733 break;
1734 case errors::UNIT_ERR:
1735 sprintf(buf, "The unit of %s size you entered is invalid, it must be B, KB or MB", name);
1736 break;
1737 case errors::MINUS_ERR:
1738 sprintf(buf, "Negative value of %s is not supported by NES header.", name);
1739 break;
1740 }

Callers 1

WriteHeaderDataFunction · 0.85

Calls 1

GetComboBoxListItemDataFunction · 0.85

Tested by

no test coverage detected