Warning: when in save mode, the content of buf might be overwritten by the save filename which user changed.
| 1811 | |
| 1812 | // Warning: when in save mode, the content of buf might be overwritten by the save filename which user changed. |
| 1813 | bool ShowINESFileBox(HWND parent, char* buf, iNES_HEADER* header) |
| 1814 | { |
| 1815 | char filename[2048] = { 0 }, path[2048] = { 0 }; |
| 1816 | bool success = true; |
| 1817 | |
| 1818 | if (header) |
| 1819 | { |
| 1820 | // When open this dialog for saving prpose, the buf must be a separate buf. |
| 1821 | if (buf && buf != LoadedRomFName) |
| 1822 | { |
| 1823 | extern std::string GetRomName(bool force = false); |
| 1824 | extern std::string GetRomPath(bool force = false); |
| 1825 | strcpy(filename, GetRomName(true).c_str()); |
| 1826 | char* second = strchr(filename, '|'); |
| 1827 | if (second) |
| 1828 | { |
| 1829 | char _filename[2048]; |
| 1830 | strcpy(_filename, second + 1); |
| 1831 | char* third = strrchr(filename, '\\'); |
| 1832 | if (third) |
| 1833 | strcpy(_filename, third + 1); |
| 1834 | strcpy(filename, _filename); |
| 1835 | } |
| 1836 | char header_str[32]; |
| 1837 | sprintf(header_str, " [%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X].nes", header->ROM_size, header->VROM_size, header->ROM_size, header->ROM_type2, header->ROM_type3, header->Upper_ROM_VROM_size, header->RAM_size, header->VRAM_size, header->TV_system, header->VS_hardware, header->misc_roms, header->expansion); |
| 1838 | strcat(filename, header_str); |
| 1839 | strcpy(path, GetRomPath(true).c_str()); |
| 1840 | } |
| 1841 | else |
| 1842 | success = false; |
| 1843 | } |
| 1844 | else { |
| 1845 | if (!buf) |
| 1846 | buf = LoadedRomFName; |
| 1847 | } |
| 1848 | |
| 1849 | if (success) |
| 1850 | { |
| 1851 | OPENFILENAME ofn; |
| 1852 | memset(&ofn, 0, sizeof(OPENFILENAME)); |
| 1853 | ofn.lStructSize = sizeof(OPENFILENAME); |
| 1854 | ofn.lpstrTitle = header ? "Save NES file" : "Open NES file"; |
| 1855 | ofn.lpstrFilter = "NES ROM file (*.nes)\0*.nes\0All files (*.*)\0*.*\0\0"; |
| 1856 | ofn.hInstance = fceu_hInstance; |
| 1857 | ofn.hwndOwner = parent; |
| 1858 | ofn.lpstrFile = filename; |
| 1859 | ofn.nMaxFile = 2048; |
| 1860 | ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; |
| 1861 | ofn.lpstrInitialDir = path; |
| 1862 | ofn.lpstrDefExt = "nes"; |
| 1863 | |
| 1864 | if (header ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn)) |
| 1865 | strcpy(buf, filename); |
| 1866 | else |
| 1867 | success = false; |
| 1868 | } |
| 1869 | |
| 1870 | return success; |
no test coverage detected