static void RefreshPatch() { SendMessage(GetDlgItem(hIpsDlg, IDC_TEXTCOMMENT), WM_SETTEXT, (WPARAM)0, (LPARAM)NULL); SendDlgItemMessage(hIpsDlg, IDC_SCREENSHOT_H, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hPreview); HTREEITEM hSelectHandle = (HTREEITEM)SendMessage(hIpsList, TVM_GETNEXTITEM, TVGN_CARET, ~0U); if (hBmp) { DeleteObject((HGDIOBJ)hBmp); hBmp = NULL; } for (int i = 0; i < nNumPatches; i++) { if (hSelectHandle == hPatchHandlesIndex[i]) { TCHAR *PatchDesc = NULL; FILE *fp = _tfopen(szPatchFileNames[i], _T("r")); if (fp) { PatchDesc = GetPatchDescByLangcode(fp, nIpsSelectedLanguage); // If not available - try English first if (PatchDesc == NULL) PatchDesc = GetPatchDescByLangcode(fp, 0); // Simplified Chinese is the reference language (should always be available!!) if (PatchDesc == NULL) PatchDesc = GetPatchDescByLangcode(fp, 1); SendMessage(GetDlgItem(hIpsDlg, IDC_TEXTCOMMENT), WM_SETTEXT, (WPARAM)0, (LPARAM)PatchDesc); fclose(fp); } fp = NULL; TCHAR szImageFileName[MAX_PATH]; szImageFileName[0] = _T('\0'); _tcscpy(szImageFileName, szPatchFileNames[i]); szImageFileName[_tcslen(szImageFileName) - 3] = _T('p'); szImageFileName[_tcslen(szImageFileName) - 2] = _T('n'); szImageFileName[_tcslen(szImageFileName) - 1] = _T('g'); fp = _tfopen(szImageFileName, _T("rb")); HBITMAP hNewImage = NULL; if (fp) { hNewImage = PNGLoadBitmap(hIpsDlg, fp, 304, 228, 3); fclose(fp); } if (hNewImage) { DeleteObject((HGDIOBJ)hBmp); hBmp = hNewImage; SendDlgItemMessage(hIpsDlg, IDC_SCREENSHOT_H, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBmp); } else { SendDlgItemMessage(hIpsDlg, IDC_SCREENSHOT_H, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hPreview); } } } }
LPWSTR GetPatchDesc(const WCHAR *game_name, const WCHAR *patch_name) { FILE *fp; LPWSTR desc = NULL; WCHAR szFilename[MAX_PATH]; swprintf(szFilename, TEXT("%s\\%s\\%s.dat"), GetIPSDir(), game_name, patch_name); if ((fp = wfopen(szFilename, TEXT("r"))) != NULL) { /* Get localized desc */ desc = GetPatchDescByLangcode(fp, GetLangcode()); /* Get English desc if localized version is not found */ if (desc == NULL) desc = GetPatchDescByLangcode(fp, UI_LANG_EN_US); fclose(fp); } return desc; }
static void FillListBox() { WIN32_FIND_DATA wfd; HANDLE hSearch; TCHAR szFilePath[MAX_PATH]; TCHAR szFilePathSearch[MAX_PATH]; TCHAR szFileName[MAX_PATH]; TCHAR *PatchDesc = NULL; TCHAR PatchName[256]; int nHandlePos = 0; TV_INSERTSTRUCT TvItem; memset(&TvItem, 0, sizeof(TvItem)); TvItem.item.mask = TVIF_TEXT | TVIF_PARAM; TvItem.hInsertAfter = TVI_LAST; _stprintf(szFilePath, _T("%s%s\\"), szAppIpsPath, BurnDrvGetText(DRV_NAME)); _stprintf(szFilePathSearch, _T("%s*.dat"), szFilePath); hSearch = FindFirstFile(szFilePathSearch, &wfd); if (hSearch != INVALID_HANDLE_VALUE) { int Done = 0; while (!Done ) { memset(szFileName, '\0', MAX_PATH); _stprintf(szFileName, _T("%s%s"), szFilePath, wfd.cFileName); FILE *fp = _tfopen(szFileName, _T("r")); if (fp) { PatchDesc = NULL; memset(PatchName, '\0', 256); PatchDesc = GetPatchDescByLangcode(fp, nIpsSelectedLanguage); // If not available - try English first if (PatchDesc == NULL) PatchDesc = GetPatchDescByLangcode(fp, 0); // Simplified Chinese is the reference language (should always be available!!) if (PatchDesc == NULL) PatchDesc = GetPatchDescByLangcode(fp, 1); for (unsigned int i = 0; i < _tcslen(PatchDesc); i++) { if (PatchDesc[i] == '\r' || PatchDesc[i] == '\n') break; PatchName[i] = PatchDesc[i]; } // Check for categories TCHAR *Tokens; int nNumTokens = 0; int nNumNodes = 0; TCHAR szCategory[256]; unsigned int nPatchNameLength = _tcslen(PatchName); Tokens = _tcstok(PatchName, _T("/")); while (Tokens != NULL) { if (nNumTokens == 0) { int bAddItem = 1; // Check if item already exists nNumNodes = SendMessage(hIpsList, TVM_GETCOUNT, (WPARAM)0, (LPARAM)0); for (int i = 0; i < nNumNodes; i++) { TCHAR Temp[256]; TVITEM Tvi; memset(&Tvi, 0, sizeof(Tvi)); Tvi.hItem = hItemHandles[i]; Tvi.mask = TVIF_TEXT | TVIF_HANDLE; Tvi.pszText = Temp; Tvi.cchTextMax = 256; SendMessage(hIpsList, TVM_GETITEM, (WPARAM)0, (LPARAM)&Tvi); if (!_tcsicmp(Tvi.pszText, Tokens)) bAddItem = 0; } if (bAddItem) { TvItem.hParent = TVI_ROOT; TvItem.item.pszText = Tokens; hItemHandles[nHandlePos] = (HTREEITEM)SendMessage(hIpsList, TVM_INSERTITEM, 0, (LPARAM)&TvItem); nHandlePos++; } if (_tcslen(Tokens) == nPatchNameLength) { hPatchHandlesIndex[nPatchIndex] = hItemHandles[nHandlePos - 1]; _tcscpy(szPatchFileNames[nPatchIndex], szFileName); nPatchIndex++; } _tcscpy(szCategory, Tokens); } else { HTREEITEM hNode = TVI_ROOT; // See which category we should be in nNumNodes = SendMessage(hIpsList, TVM_GETCOUNT, (WPARAM)0, (LPARAM)0); for (int i = 0; i < nNumNodes; i++) { TCHAR Temp[256]; TVITEM Tvi; memset(&Tvi, 0, sizeof(Tvi)); Tvi.hItem = hItemHandles[i]; Tvi.mask = TVIF_TEXT | TVIF_HANDLE; Tvi.pszText = Temp; Tvi.cchTextMax = 256; SendMessage(hIpsList, TVM_GETITEM, (WPARAM)0, (LPARAM)&Tvi); if (!_tcsicmp(Tvi.pszText, szCategory)) hNode = Tvi.hItem; } TvItem.hParent = hNode; TvItem.item.pszText = Tokens; hItemHandles[nHandlePos] = (HTREEITEM)SendMessage(hIpsList, TVM_INSERTITEM, 0, (LPARAM)&TvItem); hPatchHandlesIndex[nPatchIndex] = hItemHandles[nHandlePos]; _tcscpy(szPatchFileNames[nPatchIndex], szFileName); nHandlePos++; nPatchIndex++; } Tokens = _tcstok(NULL, _T("/")); nNumTokens++; } fclose(fp); } Done = !FindNextFile(hSearch, &wfd); } FindClose(hSearch); } nNumPatches = nPatchIndex; // Expand all branches int nNumNodes = SendMessage(hIpsList, TVM_GETCOUNT, (WPARAM)0, (LPARAM)0);; for (int i = 0; i < nNumNodes; i++) { SendMessage(hIpsList, TVM_EXPAND, TVE_EXPAND, (LPARAM)hItemHandles[i]); } }