diff --git a/Source/Project64/User Interface/Gui Class.h b/Source/Project64/User Interface/Gui Class.h index 76926bf01..292f6e026 100644 --- a/Source/Project64/User Interface/Gui Class.h +++ b/Source/Project64/User Interface/Gui Class.h @@ -23,11 +23,11 @@ class CriticalSection; enum { - WM_HIDE_CUROSR = WM_USER + 10, - WM_MAKE_FOCUS = WM_USER + 17, + WM_HIDE_CUROSR = WM_USER + 10, + WM_MAKE_FOCUS = WM_USER + 17, WM_RESET_PLUGIN = WM_USER + 18, - WM_GAME_CLOSED = WM_USER + 19, - WM_BROWSER_TOP = WM_USER + 40, + WM_GAME_CLOSED = WM_USER + 19, + WM_BROWSER_TOP = WM_USER + 40, }; class CMainGui : diff --git a/Source/Project64/User Interface/Rom Browser Class.cpp b/Source/Project64/User Interface/Rom Browser Class.cpp index e93eba363..a4c3169ea 100644 --- a/Source/Project64/User Interface/Rom Browser Class.cpp +++ b/Source/Project64/User Interface/Rom Browser Class.cpp @@ -15,533 +15,533 @@ m_ZipIniFile(NULL), m_AllowSelectionLastRom(true), m_WatchThreadID(0) { - if (g_Settings) - { - m_RomIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_RomDatabase).c_str()); - m_NotesIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_Notes).c_str()); - m_ExtIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_ExtInfo).c_str()); - m_ZipIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_7zipCache).c_str()); - } + if (g_Settings) + { + m_RomIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_RomDatabase).c_str()); + m_NotesIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_Notes).c_str()); + m_ExtIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_ExtInfo).c_str()); + m_ZipIniFile = new CIniFile(g_Settings->LoadStringVal(SupportFile_7zipCache).c_str()); + } - m_hRomList = 0; - m_Visible = false; - m_WatchThread = NULL; - m_WatchStopEvent = NULL; + m_hRomList = 0; + m_Visible = false; + m_WatchThread = NULL; + m_WatchStopEvent = NULL; - GetFieldInfo(m_Fields); - m_FieldType.resize(m_Fields.size()); + GetFieldInfo(m_Fields); + m_FieldType.resize(m_Fields.size()); } CRomBrowser::~CRomBrowser(void) { - m_StopRefresh = true; - WatchThreadStop(); - DeallocateBrushs(); + m_StopRefresh = true; + WatchThreadStop(); + DeallocateBrushs(); - if (m_RomIniFile) - { - delete m_RomIniFile; - m_RomIniFile = NULL; - } - if (m_NotesIniFile) - { - delete m_NotesIniFile; - m_NotesIniFile = NULL; - } - if (m_ExtIniFile) - { - delete m_ExtIniFile; - m_ExtIniFile = NULL; - } - if (m_ZipIniFile) - { - delete m_ZipIniFile; - m_ZipIniFile = NULL; - } + if (m_RomIniFile) + { + delete m_RomIniFile; + m_RomIniFile = NULL; + } + if (m_NotesIniFile) + { + delete m_NotesIniFile; + m_NotesIniFile = NULL; + } + if (m_ExtIniFile) + { + delete m_ExtIniFile; + m_ExtIniFile = NULL; + } + if (m_ZipIniFile) + { + delete m_ZipIniFile; + m_ZipIniFile = NULL; + } } void CRomBrowser::AddField(ROMBROWSER_FIELDS_LIST & Fields, LPCSTR Name, int Pos, int ID, int Width, LanguageStringID LangID, bool UseDefault) { - Fields.push_back(ROMBROWSER_FIELDS(Name, Pos, ID, Width, LangID, UseDefault)); + Fields.push_back(ROMBROWSER_FIELDS(Name, Pos, ID, Width, LangID, UseDefault)); } void CRomBrowser::GetFieldInfo(ROMBROWSER_FIELDS_LIST & Fields, bool UseDefault /* = false */) { - Fields.clear(); + Fields.clear(); - AddField(Fields, "File Name", -1, RB_FileName, 218, RB_FILENAME, UseDefault); - AddField(Fields, "Internal Name", -1, RB_InternalName, 200, RB_INTERNALNAME, UseDefault); - AddField(Fields, "Good Name", 0, RB_GoodName, 218, RB_GOODNAME, UseDefault); - AddField(Fields, "Status", 1, RB_Status, 92, RB_STATUS, UseDefault); - AddField(Fields, "Rom Size", -1, RB_RomSize, 100, RB_ROMSIZE, UseDefault); - AddField(Fields, "Notes (Core)", 2, RB_CoreNotes, 120, RB_NOTES_CORE, UseDefault); - AddField(Fields, "Notes (default plugins)", 3, RB_PluginNotes, 188, RB_NOTES_PLUGIN, UseDefault); - AddField(Fields, "Notes (User)", -1, RB_UserNotes, 100, RB_NOTES_USER, UseDefault); - AddField(Fields, "Cartridge ID", -1, RB_CartridgeID, 100, RB_CART_ID, UseDefault); - AddField(Fields, "Manufacturer", -1, RB_Manufacturer, 100, RB_MANUFACTUER, UseDefault); - AddField(Fields, "Country", -1, RB_Country, 100, RB_COUNTRY, UseDefault); - AddField(Fields, "Developer", -1, RB_Developer, 100, RB_DEVELOPER, UseDefault); - AddField(Fields, "CRC1", -1, RB_Crc1, 100, RB_CRC1, UseDefault); - AddField(Fields, "CRC2", -1, RB_Crc2, 100, RB_CRC2, UseDefault); - AddField(Fields, "CIC Chip", -1, RB_CICChip, 100, RB_CICCHIP, UseDefault); - AddField(Fields, "Release Date", -1, RB_ReleaseDate, 100, RB_RELEASE_DATE, UseDefault); - AddField(Fields, "Genre", -1, RB_Genre, 100, RB_GENRE, UseDefault); - AddField(Fields, "Players", -1, RB_Players, 100, RB_PLAYERS, UseDefault); - AddField(Fields, "Force Feedback", -1, RB_ForceFeedback, 100, RB_FORCE_FEEDBACK, UseDefault); - AddField(Fields, "File Format", -1, RB_FileFormat, 100, RB_FILE_FORMAT, UseDefault); + AddField(Fields, "File Name", -1, RB_FileName, 218, RB_FILENAME, UseDefault); + AddField(Fields, "Internal Name", -1, RB_InternalName, 200, RB_INTERNALNAME, UseDefault); + AddField(Fields, "Good Name", 0, RB_GoodName, 218, RB_GOODNAME, UseDefault); + AddField(Fields, "Status", 1, RB_Status, 92, RB_STATUS, UseDefault); + AddField(Fields, "Rom Size", -1, RB_RomSize, 100, RB_ROMSIZE, UseDefault); + AddField(Fields, "Notes (Core)", 2, RB_CoreNotes, 120, RB_NOTES_CORE, UseDefault); + AddField(Fields, "Notes (default plugins)", 3, RB_PluginNotes, 188, RB_NOTES_PLUGIN, UseDefault); + AddField(Fields, "Notes (User)", -1, RB_UserNotes, 100, RB_NOTES_USER, UseDefault); + AddField(Fields, "Cartridge ID", -1, RB_CartridgeID, 100, RB_CART_ID, UseDefault); + AddField(Fields, "Manufacturer", -1, RB_Manufacturer, 100, RB_MANUFACTUER, UseDefault); + AddField(Fields, "Country", -1, RB_Country, 100, RB_COUNTRY, UseDefault); + AddField(Fields, "Developer", -1, RB_Developer, 100, RB_DEVELOPER, UseDefault); + AddField(Fields, "CRC1", -1, RB_Crc1, 100, RB_CRC1, UseDefault); + AddField(Fields, "CRC2", -1, RB_Crc2, 100, RB_CRC2, UseDefault); + AddField(Fields, "CIC Chip", -1, RB_CICChip, 100, RB_CICCHIP, UseDefault); + AddField(Fields, "Release Date", -1, RB_ReleaseDate, 100, RB_RELEASE_DATE, UseDefault); + AddField(Fields, "Genre", -1, RB_Genre, 100, RB_GENRE, UseDefault); + AddField(Fields, "Players", -1, RB_Players, 100, RB_PLAYERS, UseDefault); + AddField(Fields, "Force Feedback", -1, RB_ForceFeedback, 100, RB_FORCE_FEEDBACK, UseDefault); + AddField(Fields, "File Format", -1, RB_FileFormat, 100, RB_FILE_FORMAT, UseDefault); } int CRomBrowser::CalcSortPosition(DWORD lParam) { - int Start = 0; - int End = ListView_GetItemCount((HWND)m_hRomList) - 1; - if (End < 0) - { - return 0; - } + int Start = 0; + int End = ListView_GetItemCount((HWND)m_hRomList) - 1; + if (End < 0) + { + return 0; + } - for (int SortIndex = NoOfSortKeys; SortIndex >= 0; SortIndex--) - { - stdstr SortFieldName = g_Settings->LoadStringIndex(RomBrowser_SortFieldIndex, SortIndex); - if (SortFieldName.length() == 0) - { - continue; - } + for (int SortIndex = NoOfSortKeys; SortIndex >= 0; SortIndex--) + { + stdstr SortFieldName = g_Settings->LoadStringIndex(RomBrowser_SortFieldIndex, SortIndex); + if (SortFieldName.length() == 0) + { + continue; + } - if (End == Start) - { - break; - } + if (End == Start) + { + break; + } - size_t index; - for (index = 0; index < m_Fields.size(); index++) - { - if (_stricmp(m_Fields[index].Name(), SortFieldName.c_str()) == 0) { break; } - } - if (index >= m_Fields.size()) { continue; } - SORT_FIELD SortFieldInfo; - SortFieldInfo._this = this; - SortFieldInfo.Key = index; - SortFieldInfo.KeyAscend = g_Settings->LoadBoolIndex(RomBrowser_SortAscendingIndex, SortIndex); + size_t index; + for (index = 0; index < m_Fields.size(); index++) + { + if (_stricmp(m_Fields[index].Name(), SortFieldName.c_str()) == 0) { break; } + } + if (index >= m_Fields.size()) { continue; } + SORT_FIELD SortFieldInfo; + SortFieldInfo._this = this; + SortFieldInfo.Key = index; + SortFieldInfo.KeyAscend = g_Settings->LoadBoolIndex(RomBrowser_SortAscendingIndex, SortIndex); - //calc new start and end - int LastTestPos = -1; - while (Start < End) - { - int TestPos = (int)floor((float)((Start + End) / 2)); - if (LastTestPos == TestPos) - { - TestPos += 1; - } - LastTestPos = TestPos; + //calc new start and end + int LastTestPos = -1; + while (Start < End) + { + int TestPos = (int)floor((float)((Start + End) / 2)); + if (LastTestPos == TestPos) + { + TestPos += 1; + } + LastTestPos = TestPos; - LV_ITEM lvItem; - memset(&lvItem, 0, sizeof(LV_ITEM)); - lvItem.mask = LVIF_PARAM; - lvItem.iItem = TestPos; - if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) - { - return End; - } + LV_ITEM lvItem; + memset(&lvItem, 0, sizeof(LV_ITEM)); + lvItem.mask = LVIF_PARAM; + lvItem.iItem = TestPos; + if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) + { + return End; + } - int Result = RomList_CompareItems(lParam, lvItem.lParam, (DWORD)&SortFieldInfo); - if (Result < 0) - { - if (End == TestPos) - { - break; - } - End = TestPos; - } - else if (Result > 0) - { - if (Start == TestPos) - { - break; - } - Start = TestPos; - } - else - { - //Find new start - float Left = (float)Start; - float Right = (float)TestPos; - while (Left < Right) - { - int NewTestPos = (int)floor((Left + Right) / 2); - if (LastTestPos == NewTestPos) - { - NewTestPos += 1; - } - LastTestPos = NewTestPos; + int Result = RomList_CompareItems(lParam, lvItem.lParam, (DWORD)&SortFieldInfo); + if (Result < 0) + { + if (End == TestPos) + { + break; + } + End = TestPos; + } + else if (Result > 0) + { + if (Start == TestPos) + { + break; + } + Start = TestPos; + } + else + { + //Find new start + float Left = (float)Start; + float Right = (float)TestPos; + while (Left < Right) + { + int NewTestPos = (int)floor((Left + Right) / 2); + if (LastTestPos == NewTestPos) + { + NewTestPos += 1; + } + LastTestPos = NewTestPos; - LV_ITEM lvItem; - memset(&lvItem, 0, sizeof(LV_ITEM)); - lvItem.mask = LVIF_PARAM; - lvItem.iItem = NewTestPos; - if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) - { - return End; - } + LV_ITEM lvItem; + memset(&lvItem, 0, sizeof(LV_ITEM)); + lvItem.mask = LVIF_PARAM; + lvItem.iItem = NewTestPos; + if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) + { + return End; + } - int Result = RomList_CompareItems(lParam, lvItem.lParam, (DWORD)&SortFieldInfo); - if (Result <= 0) - { - if (Right == NewTestPos) - { - break; - } - Right = (float)NewTestPos; - } - else if (Result > 0) - { - Left = Left != (float)NewTestPos ? (float)NewTestPos : Left + 1; - } - } - Start = (int)((float)Right); + int Result = RomList_CompareItems(lParam, lvItem.lParam, (DWORD)&SortFieldInfo); + if (Result <= 0) + { + if (Right == NewTestPos) + { + break; + } + Right = (float)NewTestPos; + } + else if (Result > 0) + { + Left = Left != (float)NewTestPos ? (float)NewTestPos : Left + 1; + } + } + Start = (int)((float)Right); - //Find new end - Left = (float)TestPos; - Right = (float)End; - while (Left < Right) - { - int NewTestPos = (int)ceil((Left + Right) / 2); - if (LastTestPos == NewTestPos) - { - NewTestPos -= 1; - } - LastTestPos = NewTestPos; + //Find new end + Left = (float)TestPos; + Right = (float)End; + while (Left < Right) + { + int NewTestPos = (int)ceil((Left + Right) / 2); + if (LastTestPos == NewTestPos) + { + NewTestPos -= 1; + } + LastTestPos = NewTestPos; - LV_ITEM lvItem; - memset(&lvItem, 0, sizeof(LV_ITEM)); - lvItem.mask = LVIF_PARAM; - lvItem.iItem = NewTestPos; - if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) { return End; } + LV_ITEM lvItem; + memset(&lvItem, 0, sizeof(LV_ITEM)); + lvItem.mask = LVIF_PARAM; + lvItem.iItem = NewTestPos; + if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) { return End; } - int Result = RomList_CompareItems(lParam, lvItem.lParam, (DWORD)&SortFieldInfo); - if (Result >= 0) - { - if (Left == NewTestPos) - { - break; - } - Left = (float)NewTestPos; - } - if (Result < 0) - { - Right = (float)NewTestPos; - } - } - End = (int)Left; - break; - } - } - } + int Result = RomList_CompareItems(lParam, lvItem.lParam, (DWORD)&SortFieldInfo); + if (Result >= 0) + { + if (Left == NewTestPos) + { + break; + } + Left = (float)NewTestPos; + } + if (Result < 0) + { + Right = (float)NewTestPos; + } + } + End = (int)Left; + break; + } + } + } - //Compare end with item to see if we should do it after or before it - for (int SortIndex = 0; SortIndex < NoOfSortKeys; SortIndex++) - { - stdstr SortFieldName = g_Settings->LoadStringIndex(RomBrowser_SortFieldIndex, SortIndex); - if (SortFieldName.length() == 0) - { - continue; - } + //Compare end with item to see if we should do it after or before it + for (int SortIndex = 0; SortIndex < NoOfSortKeys; SortIndex++) + { + stdstr SortFieldName = g_Settings->LoadStringIndex(RomBrowser_SortFieldIndex, SortIndex); + if (SortFieldName.length() == 0) + { + continue; + } - size_t index; - for (index = 0; index < m_Fields.size(); index++) - { - if (_stricmp(m_Fields[index].Name(), SortFieldName.c_str()) == 0) { break; } - } - if (index >= m_Fields.size()) { continue; } - SORT_FIELD SortFieldInfo; - SortFieldInfo._this = this; - SortFieldInfo.Key = index; - SortFieldInfo.KeyAscend = g_Settings->LoadBoolIndex(RomBrowser_SortAscendingIndex, SortIndex) != 0; + size_t index; + for (index = 0; index < m_Fields.size(); index++) + { + if (_stricmp(m_Fields[index].Name(), SortFieldName.c_str()) == 0) { break; } + } + if (index >= m_Fields.size()) { continue; } + SORT_FIELD SortFieldInfo; + SortFieldInfo._this = this; + SortFieldInfo.Key = index; + SortFieldInfo.KeyAscend = g_Settings->LoadBoolIndex(RomBrowser_SortAscendingIndex, SortIndex) != 0; - LV_ITEM lvItem; - memset(&lvItem, 0, sizeof(LV_ITEM)); - lvItem.mask = LVIF_PARAM; - lvItem.iItem = End; - if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) { return End; } + LV_ITEM lvItem; + memset(&lvItem, 0, sizeof(LV_ITEM)); + lvItem.mask = LVIF_PARAM; + lvItem.iItem = End; + if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) { return End; } - int Result = RomList_CompareItems(lParam, lvItem.lParam, (DWORD)&SortFieldInfo); - if (Result < 0) - { - return End; - } - if (Result > 0) - { - return End + 1; - } - } - return End + 1; + int Result = RomList_CompareItems(lParam, lvItem.lParam, (DWORD)&SortFieldInfo); + if (Result < 0) + { + return End; + } + if (Result > 0) + { + return End + 1; + } + } + return End + 1; } void CRomBrowser::AddRomToList(const char * RomLocation, const char * lpLastRom) { - ROM_INFO RomInfo; + ROM_INFO RomInfo; - memset(&RomInfo, 0, sizeof(ROM_INFO)); - strncpy(RomInfo.szFullFileName, RomLocation, sizeof(RomInfo.szFullFileName) - 1); - if (!FillRomInfo(&RomInfo)) { return; } - AddRomInfoToList(RomInfo, lpLastRom); + memset(&RomInfo, 0, sizeof(ROM_INFO)); + strncpy(RomInfo.szFullFileName, RomLocation, sizeof(RomInfo.szFullFileName) - 1); + if (!FillRomInfo(&RomInfo)) { return; } + AddRomInfoToList(RomInfo, lpLastRom); } void CRomBrowser::AddRomInfoToList(ROM_INFO &RomInfo, const char * lpLastRom) { - int ListPos = m_RomInfo.size(); - m_RomInfo.push_back(RomInfo); + int ListPos = m_RomInfo.size(); + m_RomInfo.push_back(RomInfo); - LV_ITEM lvItem; - memset(&lvItem, 0, sizeof(lvItem)); - lvItem.mask = LVIF_TEXT | LVIF_PARAM; - lvItem.iItem = CalcSortPosition(ListPos); - lvItem.lParam = (LPARAM)ListPos; - lvItem.pszText = LPSTR_TEXTCALLBACK; + LV_ITEM lvItem; + memset(&lvItem, 0, sizeof(lvItem)); + lvItem.mask = LVIF_TEXT | LVIF_PARAM; + lvItem.iItem = CalcSortPosition(ListPos); + lvItem.lParam = (LPARAM)ListPos; + lvItem.pszText = LPSTR_TEXTCALLBACK; - int index = ListView_InsertItem((HWND)m_hRomList, &lvItem); + int index = ListView_InsertItem((HWND)m_hRomList, &lvItem); - int iItem = ListView_GetNextItem((HWND)m_hRomList, -1, LVNI_SELECTED); - //if (iItem == -1) { return; } + int iItem = ListView_GetNextItem((HWND)m_hRomList, -1, LVNI_SELECTED); + //if (iItem == -1) { return; } - //if the last rom then highlight the item - if (iItem < 0 && _stricmp(RomInfo.szFullFileName, lpLastRom) == 0) - { - ListView_SetItemState((HWND)m_hRomList, index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); - } + //if the last rom then highlight the item + if (iItem < 0 && _stricmp(RomInfo.szFullFileName, lpLastRom) == 0) + { + ListView_SetItemState((HWND)m_hRomList, index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); + } - if (iItem >= 0) - { - ListView_EnsureVisible((HWND)m_hRomList, iItem, FALSE); - } + if (iItem >= 0) + { + ListView_EnsureVisible((HWND)m_hRomList, iItem, FALSE); + } } void CRomBrowser::AllocateBrushs(void) { - for (size_t count = 0; count < m_RomInfo.size(); count++) - { - if (m_RomInfo[count].SelColor == -1) - { - m_RomInfo[count].SelColorBrush = (DWORD)((HBRUSH)(COLOR_HIGHLIGHT + 1)); - } - else - { - m_RomInfo[count].SelColorBrush = (DWORD)CreateSolidBrush(m_RomInfo[count].SelColor); - } - } + for (size_t count = 0; count < m_RomInfo.size(); count++) + { + if (m_RomInfo[count].SelColor == -1) + { + m_RomInfo[count].SelColorBrush = (DWORD)((HBRUSH)(COLOR_HIGHLIGHT + 1)); + } + else + { + m_RomInfo[count].SelColorBrush = (DWORD)CreateSolidBrush(m_RomInfo[count].SelColor); + } + } } void CRomBrowser::CreateRomListControl(void) { - m_hRomList = (HWND)CreateWindow(WC_LISTVIEW, NULL, - WS_TABSTOP | WS_VISIBLE | WS_CHILD | LVS_OWNERDRAWFIXED | - LVS_SINGLESEL | LVS_REPORT, - 0, 0, 0, 0, m_MainWindow, (HMENU)IDC_ROMLIST, GetModuleHandle(NULL), NULL); - ResetRomBrowserColomuns(); - LoadRomList(); + m_hRomList = (HWND)CreateWindow(WC_LISTVIEW, NULL, + WS_TABSTOP | WS_VISIBLE | WS_CHILD | LVS_OWNERDRAWFIXED | + LVS_SINGLESEL | LVS_REPORT, + 0, 0, 0, 0, m_MainWindow, (HMENU)IDC_ROMLIST, GetModuleHandle(NULL), NULL); + ResetRomBrowserColomuns(); + LoadRomList(); } void CRomBrowser::DeallocateBrushs(void) { - for (size_t count = 0; count < m_RomInfo.size(); count++) - { - if (m_RomInfo[count].SelColor == -1) - { - continue; - } - if (m_RomInfo[count].SelColorBrush) - { - DeleteObject((HBRUSH)m_RomInfo[count].SelColorBrush); - m_RomInfo[count].SelColorBrush = NULL; - } - } + for (size_t count = 0; count < m_RomInfo.size(); count++) + { + if (m_RomInfo[count].SelColor == -1) + { + continue; + } + if (m_RomInfo[count].SelColorBrush) + { + DeleteObject((HBRUSH)m_RomInfo[count].SelColorBrush); + m_RomInfo[count].SelColorBrush = NULL; + } + } } void CRomBrowser::FillRomExtensionInfo(ROM_INFO * pRomInfo) { - //Initialize the structure - pRomInfo->UserNotes[0] = 0; - pRomInfo->Developer[0] = 0; - pRomInfo->ReleaseDate[0] = 0; - pRomInfo->Genre[0] = 0; - pRomInfo->Players = 1; - pRomInfo->CoreNotes[0] = 0; - pRomInfo->PluginNotes[0] = 0; - strcpy(pRomInfo->GoodName, "#340#"); - strcpy(pRomInfo->Status, "Unknown"); + //Initialize the structure + pRomInfo->UserNotes[0] = 0; + pRomInfo->Developer[0] = 0; + pRomInfo->ReleaseDate[0] = 0; + pRomInfo->Genre[0] = 0; + pRomInfo->Players = 1; + pRomInfo->CoreNotes[0] = 0; + pRomInfo->PluginNotes[0] = 0; + strcpy(pRomInfo->GoodName, "#340#"); + strcpy(pRomInfo->Status, "Unknown"); - //Get File Identifier - char Identifier[100]; - sprintf(Identifier, "%08X-%08X-C:%X", pRomInfo->CRC1, pRomInfo->CRC2, pRomInfo->Country); + //Get File Identifier + char Identifier[100]; + sprintf(Identifier, "%08X-%08X-C:%X", pRomInfo->CRC1, pRomInfo->CRC2, pRomInfo->Country); - //Rom Notes - if (m_Fields[RB_UserNotes].Pos() >= 0) - { - m_NotesIniFile->GetString(Identifier, "Note", "", pRomInfo->UserNotes, sizeof(pRomInfo->UserNotes)); - } + //Rom Notes + if (m_Fields[RB_UserNotes].Pos() >= 0) + { + m_NotesIniFile->GetString(Identifier, "Note", "", pRomInfo->UserNotes, sizeof(pRomInfo->UserNotes)); + } - //Rom Extension info - if (m_Fields[RB_Developer].Pos() >= 0) - { - m_ExtIniFile->GetString(Identifier, "Developer", "", pRomInfo->Developer, sizeof(pRomInfo->Developer)); - } - if (m_Fields[RB_ReleaseDate].Pos() >= 0) - { - m_ExtIniFile->GetString(Identifier, "ReleaseDate", "", pRomInfo->ReleaseDate, sizeof(pRomInfo->ReleaseDate)); - } - if (m_Fields[RB_Genre].Pos() >= 0) - { - m_ExtIniFile->GetString(Identifier, "Genre", "", pRomInfo->Genre, sizeof(pRomInfo->Genre)); - } - if (m_Fields[RB_Players].Pos() >= 0) - { - m_ExtIniFile->GetNumber(Identifier, "Players", 1, (uint32_t &)pRomInfo->Players); - } - if (m_Fields[RB_ForceFeedback].Pos() >= 0) - { - m_ExtIniFile->GetString(Identifier, "ForceFeedback", "unknown", pRomInfo->ForceFeedback, sizeof(pRomInfo->ForceFeedback)); - } + //Rom Extension info + if (m_Fields[RB_Developer].Pos() >= 0) + { + m_ExtIniFile->GetString(Identifier, "Developer", "", pRomInfo->Developer, sizeof(pRomInfo->Developer)); + } + if (m_Fields[RB_ReleaseDate].Pos() >= 0) + { + m_ExtIniFile->GetString(Identifier, "ReleaseDate", "", pRomInfo->ReleaseDate, sizeof(pRomInfo->ReleaseDate)); + } + if (m_Fields[RB_Genre].Pos() >= 0) + { + m_ExtIniFile->GetString(Identifier, "Genre", "", pRomInfo->Genre, sizeof(pRomInfo->Genre)); + } + if (m_Fields[RB_Players].Pos() >= 0) + { + m_ExtIniFile->GetNumber(Identifier, "Players", 1, (uint32_t &)pRomInfo->Players); + } + if (m_Fields[RB_ForceFeedback].Pos() >= 0) + { + m_ExtIniFile->GetString(Identifier, "ForceFeedback", "unknown", pRomInfo->ForceFeedback, sizeof(pRomInfo->ForceFeedback)); + } - //Rom Settings - if (m_Fields[RB_GoodName].Pos() >= 0) - { - m_RomIniFile->GetString(Identifier, "Good Name", pRomInfo->GoodName, pRomInfo->GoodName, sizeof(pRomInfo->GoodName)); - } - m_RomIniFile->GetString(Identifier, "Status", pRomInfo->Status, pRomInfo->Status, sizeof(pRomInfo->Status)); - if (m_Fields[RB_CoreNotes].Pos() >= 0) - { - m_RomIniFile->GetString(Identifier, "Core Note", "", pRomInfo->CoreNotes, sizeof(pRomInfo->CoreNotes)); - } - if (m_Fields[RB_PluginNotes].Pos() >= 0) - { - m_RomIniFile->GetString(Identifier, "Plugin Note", "", pRomInfo->PluginNotes, sizeof(pRomInfo->PluginNotes)); - } + //Rom Settings + if (m_Fields[RB_GoodName].Pos() >= 0) + { + m_RomIniFile->GetString(Identifier, "Good Name", pRomInfo->GoodName, pRomInfo->GoodName, sizeof(pRomInfo->GoodName)); + } + m_RomIniFile->GetString(Identifier, "Status", pRomInfo->Status, pRomInfo->Status, sizeof(pRomInfo->Status)); + if (m_Fields[RB_CoreNotes].Pos() >= 0) + { + m_RomIniFile->GetString(Identifier, "Core Note", "", pRomInfo->CoreNotes, sizeof(pRomInfo->CoreNotes)); + } + if (m_Fields[RB_PluginNotes].Pos() >= 0) + { + m_RomIniFile->GetString(Identifier, "Plugin Note", "", pRomInfo->PluginNotes, sizeof(pRomInfo->PluginNotes)); + } - //Get the text color - char String[100]; - m_RomIniFile->GetString("Rom Status", pRomInfo->Status, "000000", String, 7); - pRomInfo->TextColor = (std::strtoul(String, 0, 16) & 0xFFFFFF); - pRomInfo->TextColor = (pRomInfo->TextColor & 0x00FF00) | ((pRomInfo->TextColor >> 0x10) & 0xFF) | ((pRomInfo->TextColor & 0xFF) << 0x10); + //Get the text color + char String[100]; + m_RomIniFile->GetString("Rom Status", pRomInfo->Status, "000000", String, 7); + pRomInfo->TextColor = (std::strtoul(String, 0, 16) & 0xFFFFFF); + pRomInfo->TextColor = (pRomInfo->TextColor & 0x00FF00) | ((pRomInfo->TextColor >> 0x10) & 0xFF) | ((pRomInfo->TextColor & 0xFF) << 0x10); - //Get the selected color - sprintf(String, "%s.Sel", pRomInfo->Status); - m_RomIniFile->GetString("Rom Status", String, "FFFFFFFF", String, 9); + //Get the selected color + sprintf(String, "%s.Sel", pRomInfo->Status); + m_RomIniFile->GetString("Rom Status", String, "FFFFFFFF", String, 9); uint32_t selcol = std::strtoul(String, NULL, 16); if (selcol & 0x80000000) - { - pRomInfo->SelColor = -1; - } - else - { - selcol = (selcol & 0x00FF00) | ((selcol >> 0x10) & 0xFF) | ((selcol & 0xFF) << 0x10); - pRomInfo->SelColor = selcol; - } + { + pRomInfo->SelColor = -1; + } + else + { + selcol = (selcol & 0x00FF00) | ((selcol >> 0x10) & 0xFF) | ((selcol & 0xFF) << 0x10); + pRomInfo->SelColor = selcol; + } - //Get the selected text color - sprintf(String, "%s.Seltext", pRomInfo->Status); - m_RomIniFile->GetString("Rom Status", String, "FFFFFF", String, 7); - pRomInfo->SelTextColor = (std::strtoul(String, 0, 16) & 0xFFFFFF); - pRomInfo->SelTextColor = (pRomInfo->SelTextColor & 0x00FF00) | ((pRomInfo->SelTextColor >> 0x10) & 0xFF) | ((pRomInfo->SelTextColor & 0xFF) << 0x10); + //Get the selected text color + sprintf(String, "%s.Seltext", pRomInfo->Status); + m_RomIniFile->GetString("Rom Status", String, "FFFFFF", String, 7); + pRomInfo->SelTextColor = (std::strtoul(String, 0, 16) & 0xFFFFFF); + pRomInfo->SelTextColor = (pRomInfo->SelTextColor & 0x00FF00) | ((pRomInfo->SelTextColor >> 0x10) & 0xFF) | ((pRomInfo->SelTextColor & 0xFF) << 0x10); } bool CRomBrowser::FillRomInfo(ROM_INFO * pRomInfo) { - int count; - BYTE RomData[0x1000]; + int count; + BYTE RomData[0x1000]; - if (!LoadDataFromRomFile(pRomInfo->szFullFileName, RomData, sizeof(RomData), &pRomInfo->RomSize, pRomInfo->FileFormat)) - { - return false; - } - else - { - if (strstr(pRomInfo->szFullFileName, "?") != NULL) - { - strcpy(pRomInfo->FileName, strstr(pRomInfo->szFullFileName, "?") + 1); - } - else - { - char drive[_MAX_DRIVE], dir[_MAX_DIR], ext[_MAX_EXT]; - _splitpath(pRomInfo->szFullFileName, drive, dir, pRomInfo->FileName, ext); - } - if (m_Fields[RB_InternalName].Pos() >= 0) - { - memcpy(pRomInfo->InternalName, (void *)(RomData + 0x20), 20); - for (count = 0; count < 20; count += 4) - { - pRomInfo->InternalName[count] ^= pRomInfo->InternalName[count + 3]; - pRomInfo->InternalName[count + 3] ^= pRomInfo->InternalName[count]; - pRomInfo->InternalName[count] ^= pRomInfo->InternalName[count + 3]; - pRomInfo->InternalName[count + 1] ^= pRomInfo->InternalName[count + 2]; - pRomInfo->InternalName[count + 2] ^= pRomInfo->InternalName[count + 1]; - pRomInfo->InternalName[count + 1] ^= pRomInfo->InternalName[count + 2]; - } - pRomInfo->InternalName[21] = '\0'; - } - pRomInfo->CartID[0] = *(RomData + 0x3F); - pRomInfo->CartID[1] = *(RomData + 0x3E); - pRomInfo->CartID[2] = '\0'; - pRomInfo->Manufacturer = *(RomData + 0x38); - pRomInfo->Country = *(RomData + 0x3D); - pRomInfo->CRC1 = *(DWORD *)(RomData + 0x10); - pRomInfo->CRC2 = *(DWORD *)(RomData + 0x14); - pRomInfo->CicChip = GetCicChipID(RomData); + if (!LoadDataFromRomFile(pRomInfo->szFullFileName, RomData, sizeof(RomData), &pRomInfo->RomSize, pRomInfo->FileFormat)) + { + return false; + } + else + { + if (strstr(pRomInfo->szFullFileName, "?") != NULL) + { + strcpy(pRomInfo->FileName, strstr(pRomInfo->szFullFileName, "?") + 1); + } + else + { + char drive[_MAX_DRIVE], dir[_MAX_DIR], ext[_MAX_EXT]; + _splitpath(pRomInfo->szFullFileName, drive, dir, pRomInfo->FileName, ext); + } + if (m_Fields[RB_InternalName].Pos() >= 0) + { + memcpy(pRomInfo->InternalName, (void *)(RomData + 0x20), 20); + for (count = 0; count < 20; count += 4) + { + pRomInfo->InternalName[count] ^= pRomInfo->InternalName[count + 3]; + pRomInfo->InternalName[count + 3] ^= pRomInfo->InternalName[count]; + pRomInfo->InternalName[count] ^= pRomInfo->InternalName[count + 3]; + pRomInfo->InternalName[count + 1] ^= pRomInfo->InternalName[count + 2]; + pRomInfo->InternalName[count + 2] ^= pRomInfo->InternalName[count + 1]; + pRomInfo->InternalName[count + 1] ^= pRomInfo->InternalName[count + 2]; + } + pRomInfo->InternalName[21] = '\0'; + } + pRomInfo->CartID[0] = *(RomData + 0x3F); + pRomInfo->CartID[1] = *(RomData + 0x3E); + pRomInfo->CartID[2] = '\0'; + pRomInfo->Manufacturer = *(RomData + 0x38); + pRomInfo->Country = *(RomData + 0x3D); + pRomInfo->CRC1 = *(DWORD *)(RomData + 0x10); + pRomInfo->CRC2 = *(DWORD *)(RomData + 0x14); + pRomInfo->CicChip = GetCicChipID(RomData); - FillRomExtensionInfo(pRomInfo); + FillRomExtensionInfo(pRomInfo); - if (pRomInfo->SelColor == -1) - { - pRomInfo->SelColorBrush = (DWORD)((HBRUSH)(COLOR_HIGHLIGHT + 1)); - } - else - { - pRomInfo->SelColorBrush = (DWORD)CreateSolidBrush(pRomInfo->SelColor); - } + if (pRomInfo->SelColor == -1) + { + pRomInfo->SelColorBrush = (DWORD)((HBRUSH)(COLOR_HIGHLIGHT + 1)); + } + else + { + pRomInfo->SelColorBrush = (DWORD)CreateSolidBrush(pRomInfo->SelColor); + } - return true; - } + return true; + } } bool CRomBrowser::GetRomFileNames(strlist & FileList, const CPath & BaseDirectory, const stdstr & Directory, bool InWatchThread) { - if (!BaseDirectory.DirectoryExists()) - { - return false; - } - CPath SearchPath(BaseDirectory, "*.*"); - SearchPath.AppendDirectory(Directory.c_str()); + if (!BaseDirectory.DirectoryExists()) + { + return false; + } + CPath SearchPath(BaseDirectory, "*.*"); + SearchPath.AppendDirectory(Directory.c_str()); - if (!SearchPath.FindFirst(CPath::_A_ALLFILES)) - { - return false; - } + if (!SearchPath.FindFirst(CPath::_A_ALLFILES)) + { + return false; + } - do - { - if (InWatchThread && WaitForSingleObject(m_WatchStopEvent, 0) != WAIT_TIMEOUT) - { - return false; - } + do + { + if (InWatchThread && WaitForSingleObject(m_WatchStopEvent, 0) != WAIT_TIMEOUT) + { + return false; + } - if (SearchPath.IsDirectory()) - { - if (g_Settings->LoadDword(RomBrowser_Recursive)) - { - stdstr CurrentDir = Directory + SearchPath.GetCurrentDirectory() + "\\"; - GetRomFileNames(FileList, BaseDirectory, CurrentDir, InWatchThread); - } - } - else - { - AddFileNameToList(FileList, Directory, SearchPath); - } - } while (SearchPath.FindNext()); - return true; + if (SearchPath.IsDirectory()) + { + if (g_Settings->LoadDword(RomBrowser_Recursive)) + { + stdstr CurrentDir = Directory + SearchPath.GetCurrentDirectory() + "\\"; + GetRomFileNames(FileList, BaseDirectory, CurrentDir, InWatchThread); + } + } + else + { + AddFileNameToList(FileList, Directory, SearchPath); + } + } while (SearchPath.FindNext()); + return true; } void CRomBrowser::NotificationCB(LPCWSTR Status, CRomBrowser * /*_this*/) { - g_Notify->DisplayMessage(5, Status); + g_Notify->DisplayMessage(5, Status); } static const char* ROM_extensions[] = { @@ -551,14 +551,14 @@ void CRomBrowser::AddFileNameToList(strlist & FileList, const stdstr & Directory { uint8_t i; - if (FileList.size() > 3000) - { - return; - } + if (FileList.size() > 3000) + { + return; + } - stdstr Drive, Dir, Name, Extension; - File.GetComponents(NULL, &Dir, &Name, &Extension); - Extension.ToLower(); + stdstr Drive, Dir, Name, Extension; + File.GetComponents(NULL, &Dir, &Name, &Extension); + Extension.ToLower(); for (i = 0; i < sizeof(ROM_extensions) / sizeof(ROM_extensions[0]); i++) { if (Extension == ROM_extensions[i]) @@ -573,40 +573,40 @@ void CRomBrowser::AddFileNameToList(strlist & FileList, const stdstr & Directory void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, const stdstr & Directory, const char * lpLastRom) { - CPath SearchPath(BaseDirectory, "*.*"); - SearchPath.AppendDirectory(Directory.c_str()); + CPath SearchPath(BaseDirectory, "*.*"); + SearchPath.AppendDirectory(Directory.c_str()); - //TODO: Fix exception on Windows XP (Visual Studio 2010+) - //WriteTraceF(TraceDebug,__FUNCTION__ ": 1 %s",(LPCSTR)SearchPath); - if (!SearchPath.FindFirst(CPath::_A_ALLFILES)) - { - return; - } + //TODO: Fix exception on Windows XP (Visual Studio 2010+) + //WriteTraceF(TraceDebug,__FUNCTION__ ": 1 %s",(LPCSTR)SearchPath); + if (!SearchPath.FindFirst(CPath::_A_ALLFILES)) + { + return; + } - do - { + do + { uint8_t ext_ID; int8_t new_list_entry = 0; const uint8_t exts = sizeof(ROM_extensions) / sizeof(ROM_extensions[0]); - //TODO: Fix exception on Windows XP (Visual Studio 2010+) - //WriteTraceF(TraceDebug,__FUNCTION__ ": 2 %s m_StopRefresh = %d",(LPCSTR)SearchPath,m_StopRefresh); - if (m_StopRefresh) { break; } + //TODO: Fix exception on Windows XP (Visual Studio 2010+) + //WriteTraceF(TraceDebug,__FUNCTION__ ": 2 %s m_StopRefresh = %d",(LPCSTR)SearchPath,m_StopRefresh); + if (m_StopRefresh) { break; } - if (SearchPath.IsDirectory()) - { - if (g_Settings->LoadDword(RomBrowser_Recursive)) - { - stdstr CurrentDir = Directory + SearchPath.GetCurrentDirectory() + "\\"; - FillRomList(FileList, BaseDirectory, CurrentDir, lpLastRom); - } - continue; - } + if (SearchPath.IsDirectory()) + { + if (g_Settings->LoadDword(RomBrowser_Recursive)) + { + stdstr CurrentDir = Directory + SearchPath.GetCurrentDirectory() + "\\"; + FillRomList(FileList, BaseDirectory, CurrentDir, lpLastRom); + } + continue; + } - AddFileNameToList(FileList, Directory, SearchPath); + AddFileNameToList(FileList, Directory, SearchPath); - stdstr Extension = SearchPath.GetExtension(); - Extension.ToLower(); + stdstr Extension = SearchPath.GetExtension(); + Extension.ToLower(); for (ext_ID = 0; ext_ID < exts; ext_ID++) { @@ -622,928 +622,928 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c continue; } - if (Extension == "7z") - { - try - { - C7zip ZipFile(SearchPath); - if (!ZipFile.OpenSuccess()) - { - continue; - } - char ZipFileName[260]; - stdstr_f SectionName("%s-%d", ZipFile.FileName(ZipFileName, sizeof(ZipFileName)), ZipFile.FileSize()); - SectionName.ToLower(); + if (Extension == "7z") + { + try + { + C7zip ZipFile(SearchPath); + if (!ZipFile.OpenSuccess()) + { + continue; + } + char ZipFileName[260]; + stdstr_f SectionName("%s-%d", ZipFile.FileName(ZipFileName, sizeof(ZipFileName)), ZipFile.FileSize()); + SectionName.ToLower(); - WriteTraceF(TraceDebug, __FUNCTION__ ": 4 %s", SectionName.c_str()); - for (int i = 0; i < ZipFile.NumFiles(); i++) - { - CSzFileItem * f = ZipFile.FileItem(i); - if (f->IsDir) - { - continue; - } - ROM_INFO RomInfo; + WriteTraceF(TraceDebug, __FUNCTION__ ": 4 %s", SectionName.c_str()); + for (int i = 0; i < ZipFile.NumFiles(); i++) + { + CSzFileItem * f = ZipFile.FileItem(i); + if (f->IsDir) + { + continue; + } + ROM_INFO RomInfo; - std::wstring FileNameW = ZipFile.FileNameIndex(i); - if (FileNameW.length() == 0) - { - continue; - } + std::wstring FileNameW = ZipFile.FileNameIndex(i); + if (FileNameW.length() == 0) + { + continue; + } - stdstr FileName; - FileName.FromUTF16(FileNameW.c_str()); - WriteTrace(TraceDebug, __FUNCTION__ ": 5"); - char drive2[_MAX_DRIVE], dir2[_MAX_DIR], FileName2[MAX_PATH], ext2[_MAX_EXT]; - _splitpath(FileName.c_str(), drive2, dir2, FileName2, ext2); + stdstr FileName; + FileName.FromUTF16(FileNameW.c_str()); + WriteTrace(TraceDebug, __FUNCTION__ ": 5"); + char drive2[_MAX_DRIVE], dir2[_MAX_DIR], FileName2[MAX_PATH], ext2[_MAX_EXT]; + _splitpath(FileName.c_str(), drive2, dir2, FileName2, ext2); - WriteTraceF(TraceDebug, __FUNCTION__ ": 6 %s", ext2); - if (_stricmp(ext2, ".bin") == 0) - { - continue; - } - WriteTrace(TraceDebug, __FUNCTION__ ": 7"); - memset(&RomInfo, 0, sizeof(ROM_INFO)); - stdstr_f zipFileName("%s?%s", (LPCSTR)SearchPath, FileName.c_str()); - ZipFile.SetNotificationCallback((C7zip::LP7ZNOTIFICATION)NotificationCB, this); + WriteTraceF(TraceDebug, __FUNCTION__ ": 6 %s", ext2); + if (_stricmp(ext2, ".bin") == 0) + { + continue; + } + WriteTrace(TraceDebug, __FUNCTION__ ": 7"); + memset(&RomInfo, 0, sizeof(ROM_INFO)); + stdstr_f zipFileName("%s?%s", (LPCSTR)SearchPath, FileName.c_str()); + ZipFile.SetNotificationCallback((C7zip::LP7ZNOTIFICATION)NotificationCB, this); - strncpy(RomInfo.szFullFileName, zipFileName.c_str(), sizeof(RomInfo.szFullFileName) - 1); - RomInfo.szFullFileName[sizeof(RomInfo.szFullFileName) - 1] = 0; - strcpy(RomInfo.FileName, strstr(RomInfo.szFullFileName, "?") + 1); - RomInfo.FileFormat = Format_7zip; + strncpy(RomInfo.szFullFileName, zipFileName.c_str(), sizeof(RomInfo.szFullFileName) - 1); + RomInfo.szFullFileName[sizeof(RomInfo.szFullFileName) - 1] = 0; + strcpy(RomInfo.FileName, strstr(RomInfo.szFullFileName, "?") + 1); + RomInfo.FileFormat = Format_7zip; - WriteTrace(TraceDebug, __FUNCTION__ ": 8"); - char szHeader[0x90]; - if (m_ZipIniFile->GetString(SectionName.c_str(), FileName.c_str(), "", szHeader, sizeof(szHeader)) == 0) - { - BYTE RomData[0x1000]; - if (!ZipFile.GetFile(i, RomData, sizeof(RomData))) - { - continue; - } - WriteTrace(TraceDebug, __FUNCTION__ ": 9"); - if (!CN64Rom::IsValidRomImage(RomData)) { continue; } - WriteTrace(TraceDebug, __FUNCTION__ ": 10"); - ByteSwapRomData(RomData, sizeof(RomData)); - WriteTrace(TraceDebug, __FUNCTION__ ": 11"); + WriteTrace(TraceDebug, __FUNCTION__ ": 8"); + char szHeader[0x90]; + if (m_ZipIniFile->GetString(SectionName.c_str(), FileName.c_str(), "", szHeader, sizeof(szHeader)) == 0) + { + BYTE RomData[0x1000]; + if (!ZipFile.GetFile(i, RomData, sizeof(RomData))) + { + continue; + } + WriteTrace(TraceDebug, __FUNCTION__ ": 9"); + if (!CN64Rom::IsValidRomImage(RomData)) { continue; } + WriteTrace(TraceDebug, __FUNCTION__ ": 10"); + ByteSwapRomData(RomData, sizeof(RomData)); + WriteTrace(TraceDebug, __FUNCTION__ ": 11"); - stdstr RomHeader; - for (int x = 0; x < 0x40; x += 4) - { - RomHeader += stdstr_f("%08X", *((DWORD *)&RomData[x])); - } - WriteTraceF(TraceDebug, __FUNCTION__ ": 11a %s", RomHeader.c_str()); - int CicChip = GetCicChipID(RomData); + stdstr RomHeader; + for (int x = 0; x < 0x40; x += 4) + { + RomHeader += stdstr_f("%08X", *((DWORD *)&RomData[x])); + } + WriteTraceF(TraceDebug, __FUNCTION__ ": 11a %s", RomHeader.c_str()); + int CicChip = GetCicChipID(RomData); - //save this info - WriteTrace(TraceDebug, __FUNCTION__ ": 12"); - m_ZipIniFile->SaveString(SectionName.c_str(), FileName.c_str(), RomHeader.c_str()); - m_ZipIniFile->SaveNumber(SectionName.c_str(), stdstr_f("%s-Cic", FileName.c_str()).c_str(), CicChip); - strcpy(szHeader, RomHeader.c_str()); - } - WriteTrace(TraceDebug, __FUNCTION__ ": 13"); - BYTE RomData[0x40]; + //save this info + WriteTrace(TraceDebug, __FUNCTION__ ": 12"); + m_ZipIniFile->SaveString(SectionName.c_str(), FileName.c_str(), RomHeader.c_str()); + m_ZipIniFile->SaveNumber(SectionName.c_str(), stdstr_f("%s-Cic", FileName.c_str()).c_str(), CicChip); + strcpy(szHeader, RomHeader.c_str()); + } + WriteTrace(TraceDebug, __FUNCTION__ ": 13"); + BYTE RomData[0x40]; - for (int x = 0; x < 0x40; x += 4) - { + for (int x = 0; x < 0x40; x += 4) + { const size_t delimit_offset = sizeof("FFFFFFFF") - 1; - const char backup_character = szHeader[2*x + delimit_offset]; + const char backup_character = szHeader[2 * x + delimit_offset]; - szHeader[2*x + delimit_offset] = '\0'; - *(uint32_t *)&RomData[x] = std::strtoul(&szHeader[2*x], NULL, 16); - szHeader[2*x + delimit_offset] = backup_character; - } + szHeader[2 * x + delimit_offset] = '\0'; + *(uint32_t *)&RomData[x] = std::strtoul(&szHeader[2 * x], NULL, 16); + szHeader[2 * x + delimit_offset] = backup_character; + } - WriteTrace(TraceDebug, __FUNCTION__ ": 14"); - memcpy(RomInfo.InternalName, (void *)(RomData + 0x20), 20); - for (int count = 0; count < 20; count += 4) - { - RomInfo.InternalName[count] ^= RomInfo.InternalName[count + 3]; - RomInfo.InternalName[count + 3] ^= RomInfo.InternalName[count]; - RomInfo.InternalName[count] ^= RomInfo.InternalName[count + 3]; - RomInfo.InternalName[count + 1] ^= RomInfo.InternalName[count + 2]; - RomInfo.InternalName[count + 2] ^= RomInfo.InternalName[count + 1]; - RomInfo.InternalName[count + 1] ^= RomInfo.InternalName[count + 2]; - } + WriteTrace(TraceDebug, __FUNCTION__ ": 14"); + memcpy(RomInfo.InternalName, (void *)(RomData + 0x20), 20); + for (int count = 0; count < 20; count += 4) + { + RomInfo.InternalName[count] ^= RomInfo.InternalName[count + 3]; + RomInfo.InternalName[count + 3] ^= RomInfo.InternalName[count]; + RomInfo.InternalName[count] ^= RomInfo.InternalName[count + 3]; + RomInfo.InternalName[count + 1] ^= RomInfo.InternalName[count + 2]; + RomInfo.InternalName[count + 2] ^= RomInfo.InternalName[count + 1]; + RomInfo.InternalName[count + 1] ^= RomInfo.InternalName[count + 2]; + } - RomInfo.RomSize = (int)f->Size; + RomInfo.RomSize = (int)f->Size; - WriteTrace(TraceDebug, __FUNCTION__ ": 15"); - RomInfo.InternalName[21] = '\0'; - RomInfo.CartID[0] = *(RomData + 0x3F); - RomInfo.CartID[1] = *(RomData + 0x3E); - RomInfo.CartID[2] = '\0'; - RomInfo.Manufacturer = *(RomData + 0x38); - RomInfo.Country = *(RomData + 0x3D); - RomInfo.CRC1 = *(DWORD *)(RomData + 0x10); - RomInfo.CRC2 = *(DWORD *)(RomData + 0x14); - m_ZipIniFile->GetNumber(SectionName.c_str(), stdstr_f("%s-Cic", FileName.c_str()).c_str(), (ULONG)-1, (uint32_t &)RomInfo.CicChip); - WriteTrace(TraceDebug, __FUNCTION__ ": 16"); - FillRomExtensionInfo(&RomInfo); + WriteTrace(TraceDebug, __FUNCTION__ ": 15"); + RomInfo.InternalName[21] = '\0'; + RomInfo.CartID[0] = *(RomData + 0x3F); + RomInfo.CartID[1] = *(RomData + 0x3E); + RomInfo.CartID[2] = '\0'; + RomInfo.Manufacturer = *(RomData + 0x38); + RomInfo.Country = *(RomData + 0x3D); + RomInfo.CRC1 = *(DWORD *)(RomData + 0x10); + RomInfo.CRC2 = *(DWORD *)(RomData + 0x14); + m_ZipIniFile->GetNumber(SectionName.c_str(), stdstr_f("%s-Cic", FileName.c_str()).c_str(), (ULONG)-1, (uint32_t &)RomInfo.CicChip); + WriteTrace(TraceDebug, __FUNCTION__ ": 16"); + FillRomExtensionInfo(&RomInfo); - if (RomInfo.SelColor == -1) - { - RomInfo.SelColorBrush = (DWORD)((HBRUSH)(COLOR_HIGHLIGHT + 1)); - } - else - { - RomInfo.SelColorBrush = (DWORD)CreateSolidBrush(RomInfo.SelColor); - } - WriteTrace(TraceDebug, __FUNCTION__ ": 17"); - AddRomInfoToList(RomInfo, lpLastRom); - } - } - catch (...) - { - WriteTraceF(TraceError, __FUNCTION__ "(): execpetion processing %s", (LPCSTR)SearchPath); - } - continue; - } - } while (SearchPath.FindNext()); - m_ZipIniFile->FlushChanges(); + if (RomInfo.SelColor == -1) + { + RomInfo.SelColorBrush = (DWORD)((HBRUSH)(COLOR_HIGHLIGHT + 1)); + } + else + { + RomInfo.SelColorBrush = (DWORD)CreateSolidBrush(RomInfo.SelColor); + } + WriteTrace(TraceDebug, __FUNCTION__ ": 17"); + AddRomInfoToList(RomInfo, lpLastRom); + } + } + catch (...) + { + WriteTraceF(TraceError, __FUNCTION__ "(): execpetion processing %s", (LPCSTR)SearchPath); + } + continue; + } + } while (SearchPath.FindNext()); + m_ZipIniFile->FlushChanges(); } int CRomBrowser::GetCicChipID(BYTE * RomData) { - __int64 CRC = 0; - int count; + __int64 CRC = 0; + int count; - for (count = 0x40; count < 0x1000; count += 4) - { - CRC += *(DWORD *)(RomData + count); - } - switch (CRC) - { - case 0x000000D0027FDF31: return CIC_NUS_6101; - case 0x000000CFFB631223: return CIC_NUS_6101; - case 0x000000D057C85244: return CIC_NUS_6102; - case 0x000000D6497E414B: return CIC_NUS_6103; - case 0x0000011A49F60E96: return CIC_NUS_6105; - case 0x000000D6D5BE5580: return CIC_NUS_6106; - default: - return CIC_UNKNOWN; - } + for (count = 0x40; count < 0x1000; count += 4) + { + CRC += *(DWORD *)(RomData + count); + } + switch (CRC) + { + case 0x000000D0027FDF31: return CIC_NUS_6101; + case 0x000000CFFB631223: return CIC_NUS_6101; + case 0x000000D057C85244: return CIC_NUS_6102; + case 0x000000D6497E414B: return CIC_NUS_6103; + case 0x0000011A49F60E96: return CIC_NUS_6105; + case 0x000000D6D5BE5580: return CIC_NUS_6106; + default: + return CIC_UNKNOWN; + } } void CRomBrowser::HighLightLastRom(void) { - if (!m_AllowSelectionLastRom) - { - return; - } - //Make sure Rom browser is visible - if (!RomBrowserVisible()) { return; } + if (!m_AllowSelectionLastRom) + { + return; + } + //Make sure Rom browser is visible + if (!RomBrowserVisible()) { return; } - //Get the string to the last rom - stdstr LastRom = g_Settings->LoadStringIndex(File_RecentGameFileIndex, 0); - LPCSTR lpLastRom = LastRom.c_str(); + //Get the string to the last rom + stdstr LastRom = g_Settings->LoadStringIndex(File_RecentGameFileIndex, 0); + LPCSTR lpLastRom = LastRom.c_str(); - LV_ITEM lvItem; - lvItem.mask = LVIF_PARAM; + LV_ITEM lvItem; + lvItem.mask = LVIF_PARAM; - int ItemCount = ListView_GetItemCount((HWND)m_hRomList); - for (int index = 0; index < ItemCount; index++) - { - //Get The next item - lvItem.iItem = index; - if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) { return; } + int ItemCount = ListView_GetItemCount((HWND)m_hRomList); + for (int index = 0; index < ItemCount; index++) + { + //Get The next item + lvItem.iItem = index; + if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) { return; } - //Get the rom info for that item - if (lvItem.lParam < 0 || lvItem.lParam >= (LPARAM)m_RomInfo.size()) - { - return; - } - ROM_INFO * pRomInfo = &m_RomInfo[lvItem.lParam]; + //Get the rom info for that item + if (lvItem.lParam < 0 || lvItem.lParam >= (LPARAM)m_RomInfo.size()) + { + return; + } + ROM_INFO * pRomInfo = &m_RomInfo[lvItem.lParam]; - if (!m_AllowSelectionLastRom) - { - return; - } + if (!m_AllowSelectionLastRom) + { + return; + } - //if the last rom then highlight the item - if (_stricmp(pRomInfo->szFullFileName, lpLastRom) == 0) - { - ListView_SetItemState((HWND)m_hRomList, index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); - ListView_EnsureVisible((HWND)m_hRomList, index, FALSE); - return; - } - } + //if the last rom then highlight the item + if (_stricmp(pRomInfo->szFullFileName, lpLastRom) == 0) + { + ListView_SetItemState((HWND)m_hRomList, index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); + ListView_EnsureVisible((HWND)m_hRomList, index, FALSE); + return; + } + } } bool CRomBrowser::LoadDataFromRomFile(char * FileName, BYTE * Data, int DataLen, int * RomSize, FILE_FORMAT & FileFormat) { - BYTE Test[4]; + BYTE Test[4]; - if (_strnicmp(&FileName[strlen(FileName) - 4], ".ZIP", 4) == 0) - { - int len, port = 0, FoundRom; - unz_file_info info; - char zname[132]; - unzFile file; - file = unzOpen(FileName); - if (file == NULL) { return false; } + if (_strnicmp(&FileName[strlen(FileName) - 4], ".ZIP", 4) == 0) + { + int len, port = 0, FoundRom; + unz_file_info info; + char zname[132]; + unzFile file; + file = unzOpen(FileName); + if (file == NULL) { return false; } - port = unzGoToFirstFile(file); - FoundRom = FALSE; - while (port == UNZ_OK && FoundRom == FALSE) - { - unzGetCurrentFileInfo(file, &info, zname, 128, NULL, 0, NULL, 0); - if (unzLocateFile(file, zname, 1) != UNZ_OK) - { - unzClose(file); - return true; - } - if (unzOpenCurrentFile(file) != UNZ_OK) - { - unzClose(file); - return true; - } - unzReadCurrentFile(file, Test, 4); - if (CN64Rom::IsValidRomImage(Test)) - { - FoundRom = true; - memcpy(Data, Test, 4); - len = unzReadCurrentFile(file, &Data[4], DataLen - 4) + 4; + port = unzGoToFirstFile(file); + FoundRom = FALSE; + while (port == UNZ_OK && FoundRom == FALSE) + { + unzGetCurrentFileInfo(file, &info, zname, 128, NULL, 0, NULL, 0); + if (unzLocateFile(file, zname, 1) != UNZ_OK) + { + unzClose(file); + return true; + } + if (unzOpenCurrentFile(file) != UNZ_OK) + { + unzClose(file); + return true; + } + unzReadCurrentFile(file, Test, 4); + if (CN64Rom::IsValidRomImage(Test)) + { + FoundRom = true; + memcpy(Data, Test, 4); + len = unzReadCurrentFile(file, &Data[4], DataLen - 4) + 4; - if ((int)DataLen != len) - { - unzCloseCurrentFile(file); - unzClose(file); - return false; - } - *RomSize = info.uncompressed_size; - if (unzCloseCurrentFile(file) == UNZ_CRCERROR) - { - unzClose(file); - return false; - } - unzClose(file); - } - if (FoundRom == false) - { - unzCloseCurrentFile(file); - port = unzGoToNextFile(file); - } - } - if (FoundRom == false) - { - return false; - } - FileFormat = Format_Zip; - } - else - { - DWORD dwRead; - HANDLE hFile; + if ((int)DataLen != len) + { + unzCloseCurrentFile(file); + unzClose(file); + return false; + } + *RomSize = info.uncompressed_size; + if (unzCloseCurrentFile(file) == UNZ_CRCERROR) + { + unzClose(file); + return false; + } + unzClose(file); + } + if (FoundRom == false) + { + unzCloseCurrentFile(file); + port = unzGoToNextFile(file); + } + } + if (FoundRom == false) + { + return false; + } + FileFormat = Format_Zip; + } + else + { + DWORD dwRead; + HANDLE hFile; - hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, - NULL); + hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, + NULL); - if (hFile == INVALID_HANDLE_VALUE) { return false; } + if (hFile == INVALID_HANDLE_VALUE) { return false; } - SetFilePointer(hFile, 0, 0, FILE_BEGIN); - ReadFile(hFile, Test, 4, &dwRead, NULL); - if (!CN64Rom::IsValidRomImage(Test)) { CloseHandle(hFile); return false; } - SetFilePointer(hFile, 0, 0, FILE_BEGIN); - if (!ReadFile(hFile, Data, DataLen, &dwRead, NULL)) { CloseHandle(hFile); return false; } - *RomSize = GetFileSize(hFile, NULL); - CloseHandle(hFile); - FileFormat = Format_Uncompressed; - } - ByteSwapRomData(Data, DataLen); - return true; + SetFilePointer(hFile, 0, 0, FILE_BEGIN); + ReadFile(hFile, Test, 4, &dwRead, NULL); + if (!CN64Rom::IsValidRomImage(Test)) { CloseHandle(hFile); return false; } + SetFilePointer(hFile, 0, 0, FILE_BEGIN); + if (!ReadFile(hFile, Data, DataLen, &dwRead, NULL)) { CloseHandle(hFile); return false; } + *RomSize = GetFileSize(hFile, NULL); + CloseHandle(hFile); + FileFormat = Format_Uncompressed; + } + ByteSwapRomData(Data, DataLen); + return true; } void CRomBrowser::ByteSwapRomData(BYTE * Data, int DataLen) { - int count; + int count; - switch (*((DWORD *)&Data[0])) - { - case 0x12408037: - for (count = 0; count < DataLen; count += 4) - { - Data[count] ^= Data[count + 2]; - Data[count + 2] ^= Data[count]; - Data[count] ^= Data[count + 2]; - Data[count + 1] ^= Data[count + 3]; - Data[count + 3] ^= Data[count + 1]; - Data[count + 1] ^= Data[count + 3]; - } - break; - case 0x40123780: - for (count = 0; count < DataLen; count += 4) - { - Data[count] ^= Data[count + 3]; - Data[count + 3] ^= Data[count]; - Data[count] ^= Data[count + 3]; - Data[count + 1] ^= Data[count + 2]; - Data[count + 2] ^= Data[count + 1]; - Data[count + 1] ^= Data[count + 2]; - } - break; - case 0x80371240: break; - } + switch (*((DWORD *)&Data[0])) + { + case 0x12408037: + for (count = 0; count < DataLen; count += 4) + { + Data[count] ^= Data[count + 2]; + Data[count + 2] ^= Data[count]; + Data[count] ^= Data[count + 2]; + Data[count + 1] ^= Data[count + 3]; + Data[count + 3] ^= Data[count + 1]; + Data[count + 1] ^= Data[count + 3]; + } + break; + case 0x40123780: + for (count = 0; count < DataLen; count += 4) + { + Data[count] ^= Data[count + 3]; + Data[count + 3] ^= Data[count]; + Data[count] ^= Data[count + 3]; + Data[count + 1] ^= Data[count + 2]; + Data[count + 2] ^= Data[count + 1]; + Data[count + 1] ^= Data[count + 2]; + } + break; + case 0x80371240: break; + } } void CRomBrowser::LoadRomList(void) { - stdstr FileName = g_Settings->LoadStringVal(SupportFile_RomListCache); + stdstr FileName = g_Settings->LoadStringVal(SupportFile_RomListCache); - //Open the cache file - HANDLE hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); - if (hFile == INVALID_HANDLE_VALUE) { - //if file does not exist then refresh the data - RefreshRomBrowser(); - return; - } + //Open the cache file + HANDLE hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); + if (hFile == INVALID_HANDLE_VALUE) { + //if file does not exist then refresh the data + RefreshRomBrowser(); + return; + } - DWORD dwRead; - unsigned char md5[16]; - ReadFile(hFile, &md5, sizeof(md5), &dwRead, NULL); + DWORD dwRead; + unsigned char md5[16]; + ReadFile(hFile, &md5, sizeof(md5), &dwRead, NULL); - //Read the size of ROM_INFO - int RomInfoSize = 0; - ReadFile(hFile, &RomInfoSize, sizeof(RomInfoSize), &dwRead, NULL); - if (RomInfoSize != sizeof(ROM_INFO) || dwRead != sizeof(RomInfoSize)) { - CloseHandle(hFile); - RefreshRomBrowser(); - return; - } + //Read the size of ROM_INFO + int RomInfoSize = 0; + ReadFile(hFile, &RomInfoSize, sizeof(RomInfoSize), &dwRead, NULL); + if (RomInfoSize != sizeof(ROM_INFO) || dwRead != sizeof(RomInfoSize)) { + CloseHandle(hFile); + RefreshRomBrowser(); + return; + } - //Read the Number of entries - int Entries = 0; - ReadFile(hFile, &Entries, sizeof(Entries), &dwRead, NULL); + //Read the Number of entries + int Entries = 0; + ReadFile(hFile, &Entries, sizeof(Entries), &dwRead, NULL); - //Read Every Entry - DeallocateBrushs(); - m_RomInfo.clear(); - for (int count = 0; count < Entries; count++) { - ROM_INFO RomInfo; - ReadFile(hFile, &RomInfo, RomInfoSize, &dwRead, NULL); - RomInfo.SelColorBrush = NULL; + //Read Every Entry + DeallocateBrushs(); + m_RomInfo.clear(); + for (int count = 0; count < Entries; count++) { + ROM_INFO RomInfo; + ReadFile(hFile, &RomInfo, RomInfoSize, &dwRead, NULL); + RomInfo.SelColorBrush = NULL; - LV_ITEM lvItem; - memset(&lvItem, 0, sizeof(lvItem)); - lvItem.mask = LVIF_TEXT | LVIF_PARAM; - lvItem.iItem = ListView_GetItemCount((HWND)m_hRomList); - lvItem.lParam = (LPARAM)m_RomInfo.size(); - lvItem.pszText = LPSTR_TEXTCALLBACK; + LV_ITEM lvItem; + memset(&lvItem, 0, sizeof(lvItem)); + lvItem.mask = LVIF_TEXT | LVIF_PARAM; + lvItem.iItem = ListView_GetItemCount((HWND)m_hRomList); + lvItem.lParam = (LPARAM)m_RomInfo.size(); + lvItem.pszText = LPSTR_TEXTCALLBACK; - ListView_InsertItem((HWND)m_hRomList, &lvItem); - m_RomInfo.push_back(RomInfo); - } - CloseHandle(hFile); - AllocateBrushs(); - RomList_SortList(); + ListView_InsertItem((HWND)m_hRomList, &lvItem); + m_RomInfo.push_back(RomInfo); + } + CloseHandle(hFile); + AllocateBrushs(); + RomList_SortList(); } void CRomBrowser::MenuSetText(HMENU hMenu, int MenuPos, const wchar_t * Title, char * ShortCut) { - MENUITEMINFOW MenuInfo; - wchar_t String[256]; + MENUITEMINFOW MenuInfo; + wchar_t String[256]; - if (Title == NULL || wcslen(Title) == 0) { return; } + if (Title == NULL || wcslen(Title) == 0) { return; } - memset(&MenuInfo, 0, sizeof(MENUITEMINFO)); - MenuInfo.cbSize = sizeof(MENUITEMINFO); - MenuInfo.fMask = MIIM_TYPE; - MenuInfo.fType = MFT_STRING; - MenuInfo.fState = MFS_ENABLED; - MenuInfo.dwTypeData = String; - MenuInfo.cch = 256; + memset(&MenuInfo, 0, sizeof(MENUITEMINFO)); + MenuInfo.cbSize = sizeof(MENUITEMINFO); + MenuInfo.fMask = MIIM_TYPE; + MenuInfo.fType = MFT_STRING; + MenuInfo.fState = MFS_ENABLED; + MenuInfo.dwTypeData = String; + MenuInfo.cch = 256; - GetMenuItemInfoW(hMenu, MenuPos, TRUE, &MenuInfo); - wcscpy(String, Title); - if (wcschr(String, '\t') != NULL) { *(wcschr(String, '\t')) = '\0'; } - if (ShortCut) { swprintf(String, sizeof(String) / sizeof(String[0]), L"%s\t%s", String, ShortCut); } - SetMenuItemInfoW(hMenu, MenuPos, TRUE, &MenuInfo); + GetMenuItemInfoW(hMenu, MenuPos, TRUE, &MenuInfo); + wcscpy(String, Title); + if (wcschr(String, '\t') != NULL) { *(wcschr(String, '\t')) = '\0'; } + if (ShortCut) { swprintf(String, sizeof(String) / sizeof(String[0]), L"%s\t%s", String, ShortCut); } + SetMenuItemInfoW(hMenu, MenuPos, TRUE, &MenuInfo); } void CRomBrowser::RefreshRomBrowser(void) { - DWORD ThreadID; + DWORD ThreadID; - if (m_RefreshThread) - { - return; - } - WriteTrace(TraceDebug, __FUNCTION__ ": 1"); - m_StopRefresh = false; - m_RefreshThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)RefreshRomBrowserStatic, (LPVOID)this, 0, &ThreadID); - WriteTrace(TraceDebug, __FUNCTION__ ": 2"); + if (m_RefreshThread) + { + return; + } + WriteTrace(TraceDebug, __FUNCTION__ ": 1"); + m_StopRefresh = false; + m_RefreshThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)RefreshRomBrowserStatic, (LPVOID)this, 0, &ThreadID); + WriteTrace(TraceDebug, __FUNCTION__ ": 2"); } void CRomBrowser::RefreshRomBrowserStatic(CRomBrowser * _this) { - try - { - if (_this->m_hRomList == NULL) { return; } + try + { + if (_this->m_hRomList == NULL) { return; } - //delete cache - stdstr CacheFileName = g_Settings->LoadStringVal(SupportFile_RomListCache); - DeleteFile(CacheFileName.c_str()); + //delete cache + stdstr CacheFileName = g_Settings->LoadStringVal(SupportFile_RomListCache); + DeleteFile(CacheFileName.c_str()); - //clear all current items - WriteTrace(TraceDebug, __FUNCTION__ " 1"); - ListView_DeleteAllItems((HWND)_this->m_hRomList); - _this->DeallocateBrushs(); - _this->m_RomInfo.clear(); - WriteTrace(TraceDebug, __FUNCTION__ " 2"); - InvalidateRect((HWND)_this->m_hRomList, NULL, TRUE); - Sleep(100); - WriteTrace(TraceDebug, __FUNCTION__ " 3"); + //clear all current items + WriteTrace(TraceDebug, __FUNCTION__ " 1"); + ListView_DeleteAllItems((HWND)_this->m_hRomList); + _this->DeallocateBrushs(); + _this->m_RomInfo.clear(); + WriteTrace(TraceDebug, __FUNCTION__ " 2"); + InvalidateRect((HWND)_this->m_hRomList, NULL, TRUE); + Sleep(100); + WriteTrace(TraceDebug, __FUNCTION__ " 3"); - if (_this->m_WatchRomDir != g_Settings->LoadStringVal(Directory_Game)) - { - WriteTrace(TraceDebug, __FUNCTION__ " 4"); - _this->WatchThreadStop(); - WriteTrace(TraceDebug, __FUNCTION__ " 5"); - _this->WatchThreadStart(); - WriteTrace(TraceDebug, __FUNCTION__ " 6"); - } + if (_this->m_WatchRomDir != g_Settings->LoadStringVal(Directory_Game)) + { + WriteTrace(TraceDebug, __FUNCTION__ " 4"); + _this->WatchThreadStop(); + WriteTrace(TraceDebug, __FUNCTION__ " 5"); + _this->WatchThreadStart(); + WriteTrace(TraceDebug, __FUNCTION__ " 6"); + } - WriteTrace(TraceDebug, __FUNCTION__ " 7"); - stdstr RomDir = g_Settings->LoadStringVal(Directory_Game); - stdstr LastRom = g_Settings->LoadStringIndex(File_RecentGameFileIndex, 0); - WriteTrace(TraceDebug, __FUNCTION__ " 8"); + WriteTrace(TraceDebug, __FUNCTION__ " 7"); + stdstr RomDir = g_Settings->LoadStringVal(Directory_Game); + stdstr LastRom = g_Settings->LoadStringIndex(File_RecentGameFileIndex, 0); + WriteTrace(TraceDebug, __FUNCTION__ " 8"); - strlist FileNames; - _this->FillRomList(FileNames, CPath(RomDir), stdstr(""), LastRom.c_str()); - WriteTrace(TraceDebug, __FUNCTION__ " 9"); - _this->SaveRomList(FileNames); - WriteTrace(TraceDebug, __FUNCTION__ " 10"); - CloseHandle(_this->m_RefreshThread); - _this->m_RefreshThread = NULL; - WriteTrace(TraceDebug, __FUNCTION__ " 11"); - } - catch (...) - { - WriteTrace(TraceError, __FUNCTION__ "(): Unhandled Exception "); - } + strlist FileNames; + _this->FillRomList(FileNames, CPath(RomDir), stdstr(""), LastRom.c_str()); + WriteTrace(TraceDebug, __FUNCTION__ " 9"); + _this->SaveRomList(FileNames); + WriteTrace(TraceDebug, __FUNCTION__ " 10"); + CloseHandle(_this->m_RefreshThread); + _this->m_RefreshThread = NULL; + WriteTrace(TraceDebug, __FUNCTION__ " 11"); + } + catch (...) + { + WriteTrace(TraceError, __FUNCTION__ "(): Unhandled Exception "); + } } void CRomBrowser::ResetRomBrowserColomuns(void) { - size_t Coloumn, index; - LV_COLUMNW lvColumn; - wchar_t szString[300]; + size_t Coloumn, index; + LV_COLUMNW lvColumn; + wchar_t szString[300]; - GetFieldInfo(m_Fields); + GetFieldInfo(m_Fields); - //Remove all current coloumns - memset(&lvColumn, 0, sizeof(lvColumn)); - lvColumn.mask = LVCF_FMT; - while (ListView_GetColumn((HWND)m_hRomList, 0, &lvColumn)) - { - ListView_DeleteColumn((HWND)m_hRomList, 0); - } + //Remove all current coloumns + memset(&lvColumn, 0, sizeof(lvColumn)); + lvColumn.mask = LVCF_FMT; + while (ListView_GetColumn((HWND)m_hRomList, 0, &lvColumn)) + { + ListView_DeleteColumn((HWND)m_hRomList, 0); + } - //Add Colomuns - lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; - lvColumn.fmt = LVCFMT_LEFT; - lvColumn.pszText = szString; + //Add Colomuns + lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + lvColumn.fmt = LVCFMT_LEFT; + lvColumn.pszText = szString; - for (Coloumn = 0; Coloumn < m_Fields.size(); Coloumn++) - { - for (index = 0; index < m_Fields.size(); index++) - { - if (m_Fields[index].Pos() == Coloumn) { break; } - } - if (index == m_Fields.size() || m_Fields[index].Pos() != Coloumn) - { - m_FieldType[Coloumn] = -1; - break; - } + for (Coloumn = 0; Coloumn < m_Fields.size(); Coloumn++) + { + for (index = 0; index < m_Fields.size(); index++) + { + if (m_Fields[index].Pos() == Coloumn) { break; } + } + if (index == m_Fields.size() || m_Fields[index].Pos() != Coloumn) + { + m_FieldType[Coloumn] = -1; + break; + } - m_FieldType[Coloumn] = m_Fields[index].ID(); - lvColumn.cx = m_Fields[index].ColWidth(); - wcsncpy(szString, GS(m_Fields[index].LangID()), sizeof(szString) / sizeof(szString[0])); - SendMessage(m_hRomList, LVM_INSERTCOLUMNW, (WPARAM)(int)(Coloumn), (LPARAM)(const LV_COLUMNW *)(&lvColumn)); - } + m_FieldType[Coloumn] = m_Fields[index].ID(); + lvColumn.cx = m_Fields[index].ColWidth(); + wcsncpy(szString, GS(m_Fields[index].LangID()), sizeof(szString) / sizeof(szString[0])); + SendMessage(m_hRomList, LVM_INSERTCOLUMNW, (WPARAM)(int)(Coloumn), (LPARAM)(const LV_COLUMNW *)(&lvColumn)); + } } void CRomBrowser::ResizeRomList(WORD nWidth, WORD nHeight) { - if (RomBrowserVisible()) - { - if (g_Settings->LoadDword(RomBrowser_Maximized) == 0 && nHeight != 0) - { - if (g_Settings->LoadDword(RomBrowser_Width) != nWidth) - { - g_Settings->SaveDword(RomBrowser_Width, nWidth); - } - if (g_Settings->LoadDword(RomBrowser_Height) != nHeight) - { - g_Settings->SaveDword(RomBrowser_Height, nHeight); - } - } - if (IsWindow((HWND)m_StatusWindow)) - { - RECT rc; + if (RomBrowserVisible()) + { + if (g_Settings->LoadDword(RomBrowser_Maximized) == 0 && nHeight != 0) + { + if (g_Settings->LoadDword(RomBrowser_Width) != nWidth) + { + g_Settings->SaveDword(RomBrowser_Width, nWidth); + } + if (g_Settings->LoadDword(RomBrowser_Height) != nHeight) + { + g_Settings->SaveDword(RomBrowser_Height, nHeight); + } + } + if (IsWindow((HWND)m_StatusWindow)) + { + RECT rc; - GetWindowRect((HWND)m_StatusWindow, &rc); - nHeight -= (WORD)(rc.bottom - rc.top); - } - MoveWindow((HWND)m_hRomList, 0, 0, nWidth, nHeight, TRUE); - } + GetWindowRect((HWND)m_StatusWindow, &rc); + nHeight -= (WORD)(rc.bottom - rc.top); + } + MoveWindow((HWND)m_hRomList, 0, 0, nWidth, nHeight, TRUE); + } } bool CRomBrowser::RomBrowserVisible(void) { - if (!IsWindow((HWND)m_hRomList)) { return false; } - if (!IsWindowVisible((HWND)m_hRomList)) { return false; } - if (!m_Visible) { return false; } - return true; + if (!IsWindow((HWND)m_hRomList)) { return false; } + if (!IsWindowVisible((HWND)m_hRomList)) { return false; } + if (!m_Visible) { return false; } + return true; } void CRomBrowser::RomBrowserToTop(void) { - BringWindowToTop((HWND)m_hRomList); - SetFocus((HWND)m_hRomList); + BringWindowToTop((HWND)m_hRomList); + SetFocus((HWND)m_hRomList); } void CRomBrowser::RomBrowserMaximize(bool Mazimize) { - g_Settings->SaveDword(RomBrowser_Maximized, (DWORD)Mazimize); + g_Settings->SaveDword(RomBrowser_Maximized, (DWORD)Mazimize); } bool CRomBrowser::RomListDrawItem(int idCtrl, DWORD lParam) { - if (idCtrl != IDC_ROMLIST) { return false; } - LPDRAWITEMSTRUCT ditem = (LPDRAWITEMSTRUCT)lParam; + if (idCtrl != IDC_ROMLIST) { return false; } + LPDRAWITEMSTRUCT ditem = (LPDRAWITEMSTRUCT)lParam; - RECT rcItem, rcDraw; - char String[300]; - LV_ITEM lvItem; - HBRUSH hBrush; - LV_COLUMN lvc; - int nColumn; + RECT rcItem, rcDraw; + char String[300]; + LV_ITEM lvItem; + HBRUSH hBrush; + LV_COLUMN lvc; + int nColumn; - lvItem.mask = LVIF_PARAM; - lvItem.iItem = ditem->itemID; - if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) { return false; } - lvItem.state = ListView_GetItemState((HWND)m_hRomList, ditem->itemID, -1); - bool bSelected = (lvItem.state & LVIS_SELECTED) != 0; + lvItem.mask = LVIF_PARAM; + lvItem.iItem = ditem->itemID; + if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) { return false; } + lvItem.state = ListView_GetItemState((HWND)m_hRomList, ditem->itemID, -1); + bool bSelected = (lvItem.state & LVIS_SELECTED) != 0; - if (lvItem.lParam < 0 || lvItem.lParam >= (LPARAM)m_RomInfo.size()) - { - return true; - } - ROM_INFO * pRomInfo = &m_RomInfo[lvItem.lParam]; - if (pRomInfo == NULL) - { - return true; - } - if (bSelected) - { - hBrush = (HBRUSH)pRomInfo->SelColorBrush; - SetTextColor(ditem->hDC, pRomInfo->SelTextColor); - } - else - { - hBrush = (HBRUSH)(COLOR_WINDOW + 1); - SetTextColor(ditem->hDC, pRomInfo->TextColor); - } - FillRect(ditem->hDC, &ditem->rcItem, hBrush); - SetBkMode(ditem->hDC, TRANSPARENT); + if (lvItem.lParam < 0 || lvItem.lParam >= (LPARAM)m_RomInfo.size()) + { + return true; + } + ROM_INFO * pRomInfo = &m_RomInfo[lvItem.lParam]; + if (pRomInfo == NULL) + { + return true; + } + if (bSelected) + { + hBrush = (HBRUSH)pRomInfo->SelColorBrush; + SetTextColor(ditem->hDC, pRomInfo->SelTextColor); + } + else + { + hBrush = (HBRUSH)(COLOR_WINDOW + 1); + SetTextColor(ditem->hDC, pRomInfo->TextColor); + } + FillRect(ditem->hDC, &ditem->rcItem, hBrush); + SetBkMode(ditem->hDC, TRANSPARENT); - //Draw - ListView_GetItemRect((HWND)m_hRomList, ditem->itemID, &rcItem, LVIR_LABEL); - ListView_GetItemText((HWND)m_hRomList, ditem->itemID, 0, String, sizeof(String)); - memcpy(&rcDraw, &rcItem, sizeof(RECT)); - rcDraw.right -= 3; - std::wstring text = stdstr(String).ToUTF16(); - if (wcscmp(L"#340#", text.c_str()) == 0) - { - text = GS(RB_NOT_GOOD_FILE); - } + //Draw + ListView_GetItemRect((HWND)m_hRomList, ditem->itemID, &rcItem, LVIR_LABEL); + ListView_GetItemText((HWND)m_hRomList, ditem->itemID, 0, String, sizeof(String)); + memcpy(&rcDraw, &rcItem, sizeof(RECT)); + rcDraw.right -= 3; + std::wstring text = stdstr(String).ToUTF16(); + if (wcscmp(L"#340#", text.c_str()) == 0) + { + text = GS(RB_NOT_GOOD_FILE); + } - DrawTextW(ditem->hDC, text.c_str(), text.length(), &rcDraw, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_WORD_ELLIPSIS); + DrawTextW(ditem->hDC, text.c_str(), text.length(), &rcDraw, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_WORD_ELLIPSIS); - memset(&lvc, 0, sizeof(lvc)); - lvc.mask = LVCF_FMT | LVCF_WIDTH; - for (nColumn = 1; ListView_GetColumn((HWND)m_hRomList, nColumn, &lvc); nColumn += 1) - { - rcItem.left = rcItem.right; - rcItem.right += lvc.cx; + memset(&lvc, 0, sizeof(lvc)); + lvc.mask = LVCF_FMT | LVCF_WIDTH; + for (nColumn = 1; ListView_GetColumn((HWND)m_hRomList, nColumn, &lvc); nColumn += 1) + { + rcItem.left = rcItem.right; + rcItem.right += lvc.cx; - ListView_GetItemText((HWND)m_hRomList, ditem->itemID, nColumn, String, sizeof(String)); - memcpy(&rcDraw, &rcItem, sizeof(RECT)); - rcDraw.right -= 3; - std::wstring text = stdstr(String).ToUTF16(); - if (wcscmp(L"#340#", text.c_str()) == 0) - { - text = GS(RB_NOT_GOOD_FILE); - } - DrawTextW(ditem->hDC, text.c_str(), text.length(), &rcDraw, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_WORD_ELLIPSIS); - } - return true; + ListView_GetItemText((HWND)m_hRomList, ditem->itemID, nColumn, String, sizeof(String)); + memcpy(&rcDraw, &rcItem, sizeof(RECT)); + rcDraw.right -= 3; + std::wstring text = stdstr(String).ToUTF16(); + if (wcscmp(L"#340#", text.c_str()) == 0) + { + text = GS(RB_NOT_GOOD_FILE); + } + DrawTextW(ditem->hDC, text.c_str(), text.length(), &rcDraw, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_WORD_ELLIPSIS); + } + return true; } bool CRomBrowser::RomListNotify(int idCtrl, DWORD pnmh) { - if (idCtrl != IDC_ROMLIST) { return false; } - if (!RomBrowserVisible()) { return false; } + if (idCtrl != IDC_ROMLIST) { return false; } + if (!RomBrowserVisible()) { return false; } - switch (((LPNMHDR)pnmh)->code) - { - case LVN_COLUMNCLICK: RomList_ColoumnSortList(pnmh); break; - case NM_RETURN: RomList_OpenRom(pnmh); break; - case NM_DBLCLK: RomList_OpenRom(pnmh); break; - case LVN_GETDISPINFO: RomList_GetDispInfo(pnmh); break; - case NM_RCLICK: RomList_PopupMenu(pnmh); break; - case NM_CLICK: - { - LONG iItem = ListView_GetNextItem((HWND)m_hRomList, -1, LVNI_SELECTED); - if (iItem != -1) - { - m_AllowSelectionLastRom = false; - } - } - break; - default: - return false; - } - return true; + switch (((LPNMHDR)pnmh)->code) + { + case LVN_COLUMNCLICK: RomList_ColoumnSortList(pnmh); break; + case NM_RETURN: RomList_OpenRom(pnmh); break; + case NM_DBLCLK: RomList_OpenRom(pnmh); break; + case LVN_GETDISPINFO: RomList_GetDispInfo(pnmh); break; + case NM_RCLICK: RomList_PopupMenu(pnmh); break; + case NM_CLICK: + { + LONG iItem = ListView_GetNextItem((HWND)m_hRomList, -1, LVNI_SELECTED); + if (iItem != -1) + { + m_AllowSelectionLastRom = false; + } + } + break; + default: + return false; + } + return true; } void CRomBrowser::RomList_ColoumnSortList(DWORD pnmh) { - LPNMLISTVIEW pnmv = (LPNMLISTVIEW)pnmh; - size_t index; + LPNMLISTVIEW pnmv = (LPNMLISTVIEW)pnmh; + size_t index; - for (index = 0; index < m_Fields.size(); index++) - { - if (m_Fields[index].Pos() == (size_t)pnmv->iSubItem) { break; } - } - if (m_Fields.size() == index) { return; } - if (_stricmp(g_Settings->LoadStringIndex(RomBrowser_SortFieldIndex, 0).c_str(), m_Fields[index].Name()) == 0) - { - g_Settings->SaveBoolIndex(RomBrowser_SortAscendingIndex, 0, !g_Settings->LoadBoolIndex(RomBrowser_SortAscendingIndex, 0)); - } - else - { - int count; + for (index = 0; index < m_Fields.size(); index++) + { + if (m_Fields[index].Pos() == (size_t)pnmv->iSubItem) { break; } + } + if (m_Fields.size() == index) { return; } + if (_stricmp(g_Settings->LoadStringIndex(RomBrowser_SortFieldIndex, 0).c_str(), m_Fields[index].Name()) == 0) + { + g_Settings->SaveBoolIndex(RomBrowser_SortAscendingIndex, 0, !g_Settings->LoadBoolIndex(RomBrowser_SortAscendingIndex, 0)); + } + else + { + int count; - for (count = NoOfSortKeys; count > 0; count--) - { - g_Settings->SaveStringIndex(RomBrowser_SortFieldIndex, count, g_Settings->LoadStringIndex(RomBrowser_SortFieldIndex, count - 1).c_str()); - g_Settings->SaveBoolIndex(RomBrowser_SortAscendingIndex, count, g_Settings->LoadBoolIndex(RomBrowser_SortAscendingIndex, count - 1)); - } - g_Settings->SaveStringIndex(RomBrowser_SortFieldIndex, 0, m_Fields[index].Name()); - g_Settings->SaveBoolIndex(RomBrowser_SortAscendingIndex, 0, true); - } - RomList_SortList(); + for (count = NoOfSortKeys; count > 0; count--) + { + g_Settings->SaveStringIndex(RomBrowser_SortFieldIndex, count, g_Settings->LoadStringIndex(RomBrowser_SortFieldIndex, count - 1).c_str()); + g_Settings->SaveBoolIndex(RomBrowser_SortAscendingIndex, count, g_Settings->LoadBoolIndex(RomBrowser_SortAscendingIndex, count - 1)); + } + g_Settings->SaveStringIndex(RomBrowser_SortFieldIndex, 0, m_Fields[index].Name()); + g_Settings->SaveBoolIndex(RomBrowser_SortAscendingIndex, 0, true); + } + RomList_SortList(); } int CALLBACK CRomBrowser::RomList_CompareItems(DWORD lParam1, DWORD lParam2, DWORD lParamSort) { - SORT_FIELD * SortFieldInfo = (SORT_FIELD *)lParamSort; - CRomBrowser * _this = SortFieldInfo->_this; - if (lParam1 < 0 || lParam1 >= _this->m_RomInfo.size()) - { - return 0; - } - if (lParam2 < 0 || lParam2 >= _this->m_RomInfo.size()) - { - return 0; - } - ROM_INFO * pRomInfo1 = &_this->m_RomInfo[SortFieldInfo->KeyAscend ? lParam1 : lParam2]; - ROM_INFO * pRomInfo2 = &_this->m_RomInfo[SortFieldInfo->KeyAscend ? lParam2 : lParam1]; - int result; + SORT_FIELD * SortFieldInfo = (SORT_FIELD *)lParamSort; + CRomBrowser * _this = SortFieldInfo->_this; + if (lParam1 < 0 || lParam1 >= _this->m_RomInfo.size()) + { + return 0; + } + if (lParam2 < 0 || lParam2 >= _this->m_RomInfo.size()) + { + return 0; + } + ROM_INFO * pRomInfo1 = &_this->m_RomInfo[SortFieldInfo->KeyAscend ? lParam1 : lParam2]; + ROM_INFO * pRomInfo2 = &_this->m_RomInfo[SortFieldInfo->KeyAscend ? lParam2 : lParam1]; + int result; - switch (SortFieldInfo->Key) - { - case RB_FileName: result = (int)lstrcmpi(pRomInfo1->FileName, pRomInfo2->FileName); break; - case RB_InternalName: result = (int)lstrcmpi(pRomInfo1->InternalName, pRomInfo2->InternalName); break; - case RB_GoodName: result = (int)lstrcmpi(pRomInfo1->GoodName, pRomInfo2->GoodName); break; - case RB_Status: result = (int)lstrcmpi(pRomInfo1->Status, pRomInfo2->Status); break; - case RB_RomSize: result = (int)pRomInfo1->RomSize - (int)pRomInfo2->RomSize; break; - case RB_CoreNotes: result = (int)lstrcmpi(pRomInfo1->CoreNotes, pRomInfo2->CoreNotes); break; - case RB_PluginNotes: result = (int)lstrcmpi(pRomInfo1->PluginNotes, pRomInfo2->PluginNotes); break; - case RB_UserNotes: result = (int)lstrcmpi(pRomInfo1->UserNotes, pRomInfo2->UserNotes); break; - case RB_CartridgeID: result = (int)lstrcmpi(pRomInfo1->CartID, pRomInfo2->CartID); break; - case RB_Manufacturer: result = (int)pRomInfo1->Manufacturer - (int)pRomInfo2->Manufacturer; break; - case RB_Country: result = (int)pRomInfo1->Country - (int)pRomInfo2->Country; break; - case RB_Developer: result = (int)lstrcmpi(pRomInfo1->Developer, pRomInfo2->Developer); break; - case RB_Crc1: result = (int)pRomInfo1->CRC1 - (int)pRomInfo2->CRC1; break; - case RB_Crc2: result = (int)pRomInfo1->CRC2 - (int)pRomInfo2->CRC2; break; - case RB_CICChip: result = (int)pRomInfo1->CicChip - (int)pRomInfo2->CicChip; break; - case RB_ReleaseDate: result = (int)lstrcmpi(pRomInfo1->ReleaseDate, pRomInfo2->ReleaseDate); break; - case RB_Players: result = (int)pRomInfo1->Players - (int)pRomInfo2->Players; break; - case RB_ForceFeedback: result = (int)lstrcmpi(pRomInfo1->ForceFeedback, pRomInfo2->ForceFeedback); break; - case RB_Genre: result = (int)lstrcmpi(pRomInfo1->Genre, pRomInfo2->Genre); break; - case RB_FileFormat: result = (int)pRomInfo1->FileFormat - (int)pRomInfo2->FileFormat; break; - default: result = 0; break; - } - return result; + switch (SortFieldInfo->Key) + { + case RB_FileName: result = (int)lstrcmpi(pRomInfo1->FileName, pRomInfo2->FileName); break; + case RB_InternalName: result = (int)lstrcmpi(pRomInfo1->InternalName, pRomInfo2->InternalName); break; + case RB_GoodName: result = (int)lstrcmpi(pRomInfo1->GoodName, pRomInfo2->GoodName); break; + case RB_Status: result = (int)lstrcmpi(pRomInfo1->Status, pRomInfo2->Status); break; + case RB_RomSize: result = (int)pRomInfo1->RomSize - (int)pRomInfo2->RomSize; break; + case RB_CoreNotes: result = (int)lstrcmpi(pRomInfo1->CoreNotes, pRomInfo2->CoreNotes); break; + case RB_PluginNotes: result = (int)lstrcmpi(pRomInfo1->PluginNotes, pRomInfo2->PluginNotes); break; + case RB_UserNotes: result = (int)lstrcmpi(pRomInfo1->UserNotes, pRomInfo2->UserNotes); break; + case RB_CartridgeID: result = (int)lstrcmpi(pRomInfo1->CartID, pRomInfo2->CartID); break; + case RB_Manufacturer: result = (int)pRomInfo1->Manufacturer - (int)pRomInfo2->Manufacturer; break; + case RB_Country: result = (int)pRomInfo1->Country - (int)pRomInfo2->Country; break; + case RB_Developer: result = (int)lstrcmpi(pRomInfo1->Developer, pRomInfo2->Developer); break; + case RB_Crc1: result = (int)pRomInfo1->CRC1 - (int)pRomInfo2->CRC1; break; + case RB_Crc2: result = (int)pRomInfo1->CRC2 - (int)pRomInfo2->CRC2; break; + case RB_CICChip: result = (int)pRomInfo1->CicChip - (int)pRomInfo2->CicChip; break; + case RB_ReleaseDate: result = (int)lstrcmpi(pRomInfo1->ReleaseDate, pRomInfo2->ReleaseDate); break; + case RB_Players: result = (int)pRomInfo1->Players - (int)pRomInfo2->Players; break; + case RB_ForceFeedback: result = (int)lstrcmpi(pRomInfo1->ForceFeedback, pRomInfo2->ForceFeedback); break; + case RB_Genre: result = (int)lstrcmpi(pRomInfo1->Genre, pRomInfo2->Genre); break; + case RB_FileFormat: result = (int)pRomInfo1->FileFormat - (int)pRomInfo2->FileFormat; break; + default: result = 0; break; + } + return result; } void CRomBrowser::RomList_GetDispInfo(DWORD pnmh) { - LV_DISPINFO * lpdi = (LV_DISPINFO *)pnmh; - if (lpdi->item.lParam < 0 || lpdi->item.lParam >= (LPARAM)m_RomInfo.size()) - { - return; - } + LV_DISPINFO * lpdi = (LV_DISPINFO *)pnmh; + if (lpdi->item.lParam < 0 || lpdi->item.lParam >= (LPARAM)m_RomInfo.size()) + { + return; + } - ROM_INFO * pRomInfo = &m_RomInfo[lpdi->item.lParam]; + ROM_INFO * pRomInfo = &m_RomInfo[lpdi->item.lParam]; - if (pRomInfo == NULL) - { - strcpy(lpdi->item.pszText, " "); - return; - } + if (pRomInfo == NULL) + { + strcpy(lpdi->item.pszText, " "); + return; + } - switch (m_FieldType[lpdi->item.iSubItem]) { - case RB_FileName: strncpy(lpdi->item.pszText, pRomInfo->FileName, lpdi->item.cchTextMax); break; - case RB_InternalName: strncpy(lpdi->item.pszText, pRomInfo->InternalName, lpdi->item.cchTextMax); break; - case RB_GoodName: strncpy(lpdi->item.pszText, pRomInfo->GoodName, lpdi->item.cchTextMax); break; - case RB_CoreNotes: strncpy(lpdi->item.pszText, pRomInfo->CoreNotes, lpdi->item.cchTextMax); break; - case RB_PluginNotes: strncpy(lpdi->item.pszText, pRomInfo->PluginNotes, lpdi->item.cchTextMax); break; - case RB_Status: strncpy(lpdi->item.pszText, pRomInfo->Status, lpdi->item.cchTextMax); break; - case RB_RomSize: sprintf(lpdi->item.pszText, "%.1f MBit", (float)pRomInfo->RomSize / 0x20000); break; - case RB_CartridgeID: strncpy(lpdi->item.pszText, pRomInfo->CartID, lpdi->item.cchTextMax); break; - case RB_Manufacturer: - switch (pRomInfo->Manufacturer) - { - case 'N':strncpy(lpdi->item.pszText, "Nintendo", lpdi->item.cchTextMax); break; - case 0: strncpy(lpdi->item.pszText, "None", lpdi->item.cchTextMax); break; - default: sprintf(lpdi->item.pszText, "(Unknown %c (%X))", pRomInfo->Manufacturer, pRomInfo->Manufacturer); break; - } - break; - case RB_Country: - switch (pRomInfo->Country) - { - case '7': strncpy(lpdi->item.pszText, "Beta", lpdi->item.cchTextMax); break; - case 'A': strncpy(lpdi->item.pszText, "NTSC", lpdi->item.cchTextMax); break; - case 'D': strncpy(lpdi->item.pszText, "Germany", lpdi->item.cchTextMax); break; - case 'E': strncpy(lpdi->item.pszText, "America", lpdi->item.cchTextMax); break; - case 'F': strncpy(lpdi->item.pszText, "France", lpdi->item.cchTextMax); break; - case 'J': strncpy(lpdi->item.pszText, "Japan", lpdi->item.cchTextMax); break; - case 'I': strncpy(lpdi->item.pszText, "Italy", lpdi->item.cchTextMax); break; - case 'P': strncpy(lpdi->item.pszText, "Europe", lpdi->item.cchTextMax); break; - case 'S': strncpy(lpdi->item.pszText, "Spain", lpdi->item.cchTextMax); break; - case 'U': strncpy(lpdi->item.pszText, "Australia", lpdi->item.cchTextMax); break; - case 'X': strncpy(lpdi->item.pszText, "PAL", lpdi->item.cchTextMax); break; - case 'Y': strncpy(lpdi->item.pszText, "PAL", lpdi->item.cchTextMax); break; - case 0: strncpy(lpdi->item.pszText, "None", lpdi->item.cchTextMax); break; - default: sprintf(lpdi->item.pszText, "Unknown %c (%02X)", pRomInfo->Country, pRomInfo->Country); break; - } - break; - case RB_Crc1: sprintf(lpdi->item.pszText, "0x%08X", pRomInfo->CRC1); break; - case RB_Crc2: sprintf(lpdi->item.pszText, "0x%08X", pRomInfo->CRC2); break; - case RB_CICChip: - if (pRomInfo->CicChip < 0) - { - sprintf(lpdi->item.pszText, "Unknown CIC Chip"); - } - else - { - sprintf(lpdi->item.pszText, "CIC-NUS-610%d", pRomInfo->CicChip); - } - break; - case RB_UserNotes: strncpy(lpdi->item.pszText, pRomInfo->UserNotes, lpdi->item.cchTextMax); break; - case RB_Developer: strncpy(lpdi->item.pszText, pRomInfo->Developer, lpdi->item.cchTextMax); break; - case RB_ReleaseDate: strncpy(lpdi->item.pszText, pRomInfo->ReleaseDate, lpdi->item.cchTextMax); break; - case RB_Genre: strncpy(lpdi->item.pszText, pRomInfo->Genre, lpdi->item.cchTextMax); break; - case RB_Players: sprintf(lpdi->item.pszText, "%d", pRomInfo->Players); break; - case RB_ForceFeedback: strncpy(lpdi->item.pszText, pRomInfo->ForceFeedback, lpdi->item.cchTextMax); break; - case RB_FileFormat: - switch (pRomInfo->FileFormat) - { - case Format_Uncompressed: strncpy(lpdi->item.pszText, "Uncompressed", lpdi->item.cchTextMax); break; - case Format_Zip: strncpy(lpdi->item.pszText, "Zip", lpdi->item.cchTextMax); break; - case Format_7zip: strncpy(lpdi->item.pszText, "7zip", lpdi->item.cchTextMax); break; - default: sprintf(lpdi->item.pszText, "Unknown (%X)", pRomInfo->FileFormat); break; - } - break; - default: strncpy(lpdi->item.pszText, " ", lpdi->item.cchTextMax); - } - if (lpdi->item.pszText == NULL || strlen(lpdi->item.pszText) == 0) { strcpy(lpdi->item.pszText, " "); } + switch (m_FieldType[lpdi->item.iSubItem]) { + case RB_FileName: strncpy(lpdi->item.pszText, pRomInfo->FileName, lpdi->item.cchTextMax); break; + case RB_InternalName: strncpy(lpdi->item.pszText, pRomInfo->InternalName, lpdi->item.cchTextMax); break; + case RB_GoodName: strncpy(lpdi->item.pszText, pRomInfo->GoodName, lpdi->item.cchTextMax); break; + case RB_CoreNotes: strncpy(lpdi->item.pszText, pRomInfo->CoreNotes, lpdi->item.cchTextMax); break; + case RB_PluginNotes: strncpy(lpdi->item.pszText, pRomInfo->PluginNotes, lpdi->item.cchTextMax); break; + case RB_Status: strncpy(lpdi->item.pszText, pRomInfo->Status, lpdi->item.cchTextMax); break; + case RB_RomSize: sprintf(lpdi->item.pszText, "%.1f MBit", (float)pRomInfo->RomSize / 0x20000); break; + case RB_CartridgeID: strncpy(lpdi->item.pszText, pRomInfo->CartID, lpdi->item.cchTextMax); break; + case RB_Manufacturer: + switch (pRomInfo->Manufacturer) + { + case 'N':strncpy(lpdi->item.pszText, "Nintendo", lpdi->item.cchTextMax); break; + case 0: strncpy(lpdi->item.pszText, "None", lpdi->item.cchTextMax); break; + default: sprintf(lpdi->item.pszText, "(Unknown %c (%X))", pRomInfo->Manufacturer, pRomInfo->Manufacturer); break; + } + break; + case RB_Country: + switch (pRomInfo->Country) + { + case '7': strncpy(lpdi->item.pszText, "Beta", lpdi->item.cchTextMax); break; + case 'A': strncpy(lpdi->item.pszText, "NTSC", lpdi->item.cchTextMax); break; + case 'D': strncpy(lpdi->item.pszText, "Germany", lpdi->item.cchTextMax); break; + case 'E': strncpy(lpdi->item.pszText, "America", lpdi->item.cchTextMax); break; + case 'F': strncpy(lpdi->item.pszText, "France", lpdi->item.cchTextMax); break; + case 'J': strncpy(lpdi->item.pszText, "Japan", lpdi->item.cchTextMax); break; + case 'I': strncpy(lpdi->item.pszText, "Italy", lpdi->item.cchTextMax); break; + case 'P': strncpy(lpdi->item.pszText, "Europe", lpdi->item.cchTextMax); break; + case 'S': strncpy(lpdi->item.pszText, "Spain", lpdi->item.cchTextMax); break; + case 'U': strncpy(lpdi->item.pszText, "Australia", lpdi->item.cchTextMax); break; + case 'X': strncpy(lpdi->item.pszText, "PAL", lpdi->item.cchTextMax); break; + case 'Y': strncpy(lpdi->item.pszText, "PAL", lpdi->item.cchTextMax); break; + case 0: strncpy(lpdi->item.pszText, "None", lpdi->item.cchTextMax); break; + default: sprintf(lpdi->item.pszText, "Unknown %c (%02X)", pRomInfo->Country, pRomInfo->Country); break; + } + break; + case RB_Crc1: sprintf(lpdi->item.pszText, "0x%08X", pRomInfo->CRC1); break; + case RB_Crc2: sprintf(lpdi->item.pszText, "0x%08X", pRomInfo->CRC2); break; + case RB_CICChip: + if (pRomInfo->CicChip < 0) + { + sprintf(lpdi->item.pszText, "Unknown CIC Chip"); + } + else + { + sprintf(lpdi->item.pszText, "CIC-NUS-610%d", pRomInfo->CicChip); + } + break; + case RB_UserNotes: strncpy(lpdi->item.pszText, pRomInfo->UserNotes, lpdi->item.cchTextMax); break; + case RB_Developer: strncpy(lpdi->item.pszText, pRomInfo->Developer, lpdi->item.cchTextMax); break; + case RB_ReleaseDate: strncpy(lpdi->item.pszText, pRomInfo->ReleaseDate, lpdi->item.cchTextMax); break; + case RB_Genre: strncpy(lpdi->item.pszText, pRomInfo->Genre, lpdi->item.cchTextMax); break; + case RB_Players: sprintf(lpdi->item.pszText, "%d", pRomInfo->Players); break; + case RB_ForceFeedback: strncpy(lpdi->item.pszText, pRomInfo->ForceFeedback, lpdi->item.cchTextMax); break; + case RB_FileFormat: + switch (pRomInfo->FileFormat) + { + case Format_Uncompressed: strncpy(lpdi->item.pszText, "Uncompressed", lpdi->item.cchTextMax); break; + case Format_Zip: strncpy(lpdi->item.pszText, "Zip", lpdi->item.cchTextMax); break; + case Format_7zip: strncpy(lpdi->item.pszText, "7zip", lpdi->item.cchTextMax); break; + default: sprintf(lpdi->item.pszText, "Unknown (%X)", pRomInfo->FileFormat); break; + } + break; + default: strncpy(lpdi->item.pszText, " ", lpdi->item.cchTextMax); + } + if (lpdi->item.pszText == NULL || strlen(lpdi->item.pszText) == 0) { strcpy(lpdi->item.pszText, " "); } } void CRomBrowser::RomList_OpenRom(DWORD /*pnmh*/) { - ROM_INFO * pRomInfo; - LV_ITEM lvItem; - LONG iItem; + ROM_INFO * pRomInfo; + LV_ITEM lvItem; + LONG iItem; - iItem = ListView_GetNextItem((HWND)m_hRomList, -1, LVNI_SELECTED); - if (iItem == -1) { return; } + iItem = ListView_GetNextItem((HWND)m_hRomList, -1, LVNI_SELECTED); + if (iItem == -1) { return; } - memset(&lvItem, 0, sizeof(LV_ITEM)); - lvItem.mask = LVIF_PARAM; - lvItem.iItem = iItem; - if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) { return; } - if (lvItem.lParam < 0 || lvItem.lParam >= (LPARAM)m_RomInfo.size()) - { - return; - } - pRomInfo = &m_RomInfo[lvItem.lParam]; + memset(&lvItem, 0, sizeof(LV_ITEM)); + lvItem.mask = LVIF_PARAM; + lvItem.iItem = iItem; + if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) { return; } + if (lvItem.lParam < 0 || lvItem.lParam >= (LPARAM)m_RomInfo.size()) + { + return; + } + pRomInfo = &m_RomInfo[lvItem.lParam]; - if (!pRomInfo) { return; } - m_StopRefresh = true; - CN64System::RunFileImage(pRomInfo->szFullFileName); + if (!pRomInfo) { return; } + m_StopRefresh = true; + CN64System::RunFileImage(pRomInfo->szFullFileName); } void CRomBrowser::RomList_PopupMenu(DWORD /*pnmh*/) { - LONG iItem = ListView_GetNextItem((HWND)m_hRomList, -1, LVNI_SELECTED); - m_SelectedRom = ""; - if (iItem != -1) - { - LV_ITEM lvItem; - memset(&lvItem, 0, sizeof(LV_ITEM)); - lvItem.mask = LVIF_PARAM; - lvItem.iItem = iItem; - if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) { return; } - if (lvItem.lParam < 0 || lvItem.lParam >= (LPARAM)m_RomInfo.size()) - { - return; - } - ROM_INFO * pRomInfo = &m_RomInfo[lvItem.lParam]; + LONG iItem = ListView_GetNextItem((HWND)m_hRomList, -1, LVNI_SELECTED); + m_SelectedRom = ""; + if (iItem != -1) + { + LV_ITEM lvItem; + memset(&lvItem, 0, sizeof(LV_ITEM)); + lvItem.mask = LVIF_PARAM; + lvItem.iItem = iItem; + if (!ListView_GetItem((HWND)m_hRomList, &lvItem)) { return; } + if (lvItem.lParam < 0 || lvItem.lParam >= (LPARAM)m_RomInfo.size()) + { + return; + } + ROM_INFO * pRomInfo = &m_RomInfo[lvItem.lParam]; - if (!pRomInfo) { return; } - m_SelectedRom = pRomInfo->szFullFileName; - } + if (!pRomInfo) { return; } + m_SelectedRom = pRomInfo->szFullFileName; + } - //Load the menu - HMENU hMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_POPUP)); - HMENU hPopupMenu = (HMENU)GetSubMenu(hMenu, 0); + //Load the menu + HMENU hMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_POPUP)); + HMENU hPopupMenu = (HMENU)GetSubMenu(hMenu, 0); - //Fix up menu - MenuSetText(hPopupMenu, 0, GS(POPUP_PLAY), NULL); - MenuSetText(hPopupMenu, 2, GS(MENU_REFRESH), NULL); - MenuSetText(hPopupMenu, 3, GS(MENU_CHOOSE_ROM), NULL); - MenuSetText(hPopupMenu, 5, GS(POPUP_INFO), NULL); - MenuSetText(hPopupMenu, 6, GS(POPUP_GFX_PLUGIN), NULL); - MenuSetText(hPopupMenu, 8, GS(POPUP_SETTINGS), NULL); - MenuSetText(hPopupMenu, 9, GS(POPUP_CHEATS), NULL); + //Fix up menu + MenuSetText(hPopupMenu, 0, GS(POPUP_PLAY), NULL); + MenuSetText(hPopupMenu, 2, GS(MENU_REFRESH), NULL); + MenuSetText(hPopupMenu, 3, GS(MENU_CHOOSE_ROM), NULL); + MenuSetText(hPopupMenu, 5, GS(POPUP_INFO), NULL); + MenuSetText(hPopupMenu, 6, GS(POPUP_GFX_PLUGIN), NULL); + MenuSetText(hPopupMenu, 8, GS(POPUP_SETTINGS), NULL); + MenuSetText(hPopupMenu, 9, GS(POPUP_CHEATS), NULL); - if (m_SelectedRom.size() == 0) - { - DeleteMenu(hPopupMenu, 9, MF_BYPOSITION); - DeleteMenu(hPopupMenu, 8, MF_BYPOSITION); - DeleteMenu(hPopupMenu, 7, MF_BYPOSITION); - DeleteMenu(hPopupMenu, 6, MF_BYPOSITION); - DeleteMenu(hPopupMenu, 5, MF_BYPOSITION); - DeleteMenu(hPopupMenu, 4, MF_BYPOSITION); - DeleteMenu(hPopupMenu, 1, MF_BYPOSITION); - DeleteMenu(hPopupMenu, 0, MF_BYPOSITION); - } - else - { - bool inBasicMode = g_Settings->LoadDword(UserInterface_BasicMode) != 0; - bool CheatsRemembered = g_Settings->LoadDword(Setting_RememberCheats) != 0; - if (!CheatsRemembered) { DeleteMenu(hPopupMenu, 9, MF_BYPOSITION); } - if (inBasicMode) { DeleteMenu(hPopupMenu, 8, MF_BYPOSITION); } - if (inBasicMode && !CheatsRemembered) { DeleteMenu(hPopupMenu, 7, MF_BYPOSITION); } - DeleteMenu(hPopupMenu, 6, MF_BYPOSITION); - if (!inBasicMode && g_Plugins && g_Plugins->Gfx() && g_Plugins->Gfx()->GetRomBrowserMenu != NULL) - { - HMENU GfxMenu = (HMENU)g_Plugins->Gfx()->GetRomBrowserMenu(); - if (GfxMenu) - { - MENUITEMINFO lpmii; - InsertMenuW(hPopupMenu, 6, MF_POPUP | MF_BYPOSITION, (DWORD)GfxMenu, GS(POPUP_GFX_PLUGIN)); - lpmii.cbSize = sizeof(MENUITEMINFO); - lpmii.fMask = MIIM_STATE; - lpmii.fState = 0; - SetMenuItemInfo(hPopupMenu, (DWORD)GfxMenu, MF_BYCOMMAND, &lpmii); - } - } - } + if (m_SelectedRom.size() == 0) + { + DeleteMenu(hPopupMenu, 9, MF_BYPOSITION); + DeleteMenu(hPopupMenu, 8, MF_BYPOSITION); + DeleteMenu(hPopupMenu, 7, MF_BYPOSITION); + DeleteMenu(hPopupMenu, 6, MF_BYPOSITION); + DeleteMenu(hPopupMenu, 5, MF_BYPOSITION); + DeleteMenu(hPopupMenu, 4, MF_BYPOSITION); + DeleteMenu(hPopupMenu, 1, MF_BYPOSITION); + DeleteMenu(hPopupMenu, 0, MF_BYPOSITION); + } + else + { + bool inBasicMode = g_Settings->LoadDword(UserInterface_BasicMode) != 0; + bool CheatsRemembered = g_Settings->LoadDword(Setting_RememberCheats) != 0; + if (!CheatsRemembered) { DeleteMenu(hPopupMenu, 9, MF_BYPOSITION); } + if (inBasicMode) { DeleteMenu(hPopupMenu, 8, MF_BYPOSITION); } + if (inBasicMode && !CheatsRemembered) { DeleteMenu(hPopupMenu, 7, MF_BYPOSITION); } + DeleteMenu(hPopupMenu, 6, MF_BYPOSITION); + if (!inBasicMode && g_Plugins && g_Plugins->Gfx() && g_Plugins->Gfx()->GetRomBrowserMenu != NULL) + { + HMENU GfxMenu = (HMENU)g_Plugins->Gfx()->GetRomBrowserMenu(); + if (GfxMenu) + { + MENUITEMINFO lpmii; + InsertMenuW(hPopupMenu, 6, MF_POPUP | MF_BYPOSITION, (DWORD)GfxMenu, GS(POPUP_GFX_PLUGIN)); + lpmii.cbSize = sizeof(MENUITEMINFO); + lpmii.fMask = MIIM_STATE; + lpmii.fState = 0; + SetMenuItemInfo(hPopupMenu, (DWORD)GfxMenu, MF_BYCOMMAND, &lpmii); + } + } + } - //Get the current Mouse location - POINT Mouse; - GetCursorPos(&Mouse); + //Get the current Mouse location + POINT Mouse; + GetCursorPos(&Mouse); - //Show the menu - TrackPopupMenu(hPopupMenu, 0, Mouse.x, Mouse.y, 0, m_MainWindow, NULL); - DestroyMenu(hMenu); + //Show the menu + TrackPopupMenu(hPopupMenu, 0, Mouse.x, Mouse.y, 0, m_MainWindow, NULL); + DestroyMenu(hMenu); } void CRomBrowser::RomList_SortList(void) { - SORT_FIELD SortFieldInfo; + SORT_FIELD SortFieldInfo; - for (int count = NoOfSortKeys; count >= 0; count--) - { - stdstr SortFieldName = g_Settings->LoadStringIndex(RomBrowser_SortFieldIndex, count); + for (int count = NoOfSortKeys; count >= 0; count--) + { + stdstr SortFieldName = g_Settings->LoadStringIndex(RomBrowser_SortFieldIndex, count); - size_t index; - for (index = 0; index < m_Fields.size(); index++) - { - if (_stricmp(m_Fields[index].Name(), SortFieldName.c_str()) == 0) { break; } - } - if (index >= m_Fields.size()) { continue; } - SortFieldInfo._this = this; - SortFieldInfo.Key = index; - SortFieldInfo.KeyAscend = g_Settings->LoadBoolIndex(RomBrowser_SortAscendingIndex, count) != 0; - ListView_SortItems((HWND)m_hRomList, RomList_CompareItems, &SortFieldInfo); - } + size_t index; + for (index = 0; index < m_Fields.size(); index++) + { + if (_stricmp(m_Fields[index].Name(), SortFieldName.c_str()) == 0) { break; } + } + if (index >= m_Fields.size()) { continue; } + SortFieldInfo._this = this; + SortFieldInfo.Key = index; + SortFieldInfo.KeyAscend = g_Settings->LoadBoolIndex(RomBrowser_SortAscendingIndex, count) != 0; + ListView_SortItems((HWND)m_hRomList, RomList_CompareItems, &SortFieldInfo); + } } /* @@ -1552,372 +1552,372 @@ void CRomBrowser::RomList_SortList(void) */ void CRomBrowser::SaveRomList(strlist & FileList) { - MD5 ListHash = RomListHash(FileList); + MD5 ListHash = RomListHash(FileList); - stdstr FileName = g_Settings->LoadStringVal(SupportFile_RomListCache); - HANDLE hFile = CreateFile(FileName.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); + stdstr FileName = g_Settings->LoadStringVal(SupportFile_RomListCache); + HANDLE hFile = CreateFile(FileName.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); - DWORD dwWritten; - WriteFile(hFile, ListHash.raw_digest(), 16, &dwWritten, NULL); + DWORD dwWritten; + WriteFile(hFile, ListHash.raw_digest(), 16, &dwWritten, NULL); - //Write the size of ROM_INFO - int RomInfoSize = sizeof(ROM_INFO); - WriteFile(hFile, &RomInfoSize, sizeof(RomInfoSize), &dwWritten, NULL); + //Write the size of ROM_INFO + int RomInfoSize = sizeof(ROM_INFO); + WriteFile(hFile, &RomInfoSize, sizeof(RomInfoSize), &dwWritten, NULL); - //Write the Number of entries - int Entries = m_RomInfo.size(); - WriteFile(hFile, &Entries, sizeof(Entries), &dwWritten, NULL); + //Write the Number of entries + int Entries = m_RomInfo.size(); + WriteFile(hFile, &Entries, sizeof(Entries), &dwWritten, NULL); - //Write Every Entry - for (int count = 0; count < Entries; count++) - { - ROM_INFO * RomInfo = &m_RomInfo[count]; - WriteFile(hFile, RomInfo, RomInfoSize, &dwWritten, NULL); - } + //Write Every Entry + for (int count = 0; count < Entries; count++) + { + ROM_INFO * RomInfo = &m_RomInfo[count]; + WriteFile(hFile, RomInfo, RomInfoSize, &dwWritten, NULL); + } - //Close the file handle - CloseHandle(hFile); + //Close the file handle + CloseHandle(hFile); } void CRomBrowser::SaveRomListColoumnInfo(void) { - WriteTrace(TraceDebug, __FUNCTION__ ": Start"); - // if (!RomBrowserVisible()) { return; } - if (g_Settings == NULL) { return; } + WriteTrace(TraceDebug, __FUNCTION__ ": Start"); + // if (!RomBrowserVisible()) { return; } + if (g_Settings == NULL) { return; } - LV_COLUMN lvColumn; + LV_COLUMN lvColumn; - memset(&lvColumn, 0, sizeof(lvColumn)); - lvColumn.mask = LVCF_WIDTH; + memset(&lvColumn, 0, sizeof(lvColumn)); + lvColumn.mask = LVCF_WIDTH; - for (size_t Coloumn = 0; ListView_GetColumn((HWND)m_hRomList, Coloumn, &lvColumn); Coloumn++) - { - size_t index; - bool bFound = false; - for (index = 0; index < m_Fields.size(); index++) - { - if (m_Fields[index].Pos() == Coloumn) - { - bFound = true; - break; - } - } - if (bFound) - { - if (m_Fields[index].ColWidth() != lvColumn.cx) - { - m_Fields[index].SetColWidth(lvColumn.cx); - } - } - } - WriteTrace(TraceDebug, __FUNCTION__ ": Done"); + for (size_t Coloumn = 0; ListView_GetColumn((HWND)m_hRomList, Coloumn, &lvColumn); Coloumn++) + { + size_t index; + bool bFound = false; + for (index = 0; index < m_Fields.size(); index++) + { + if (m_Fields[index].Pos() == Coloumn) + { + bFound = true; + break; + } + } + if (bFound) + { + if (m_Fields[index].ColWidth() != lvColumn.cx) + { + m_Fields[index].SetColWidth(lvColumn.cx); + } + } + } + WriteTrace(TraceDebug, __FUNCTION__ ": Done"); } int CALLBACK CRomBrowser::SelectRomDirCallBack(HWND hwnd, DWORD uMsg, DWORD /*lp*/, DWORD lpData) { - switch (uMsg) - { - case BFFM_INITIALIZED: - // WParam is TRUE since you are passing a path. - // It would be FALSE if you were passing a pidl. - if (lpData) - { - SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData); - SetWindowTextW(hwnd, GS(DIR_SELECT_ROM)); - } - break; - } - return 0; + switch (uMsg) + { + case BFFM_INITIALIZED: + // WParam is TRUE since you are passing a path. + // It would be FALSE if you were passing a pidl. + if (lpData) + { + SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData); + SetWindowTextW(hwnd, GS(DIR_SELECT_ROM)); + } + break; + } + return 0; } void CRomBrowser::SelectRomDir(void) { - wchar_t SelectedDir[MAX_PATH]; - LPITEMIDLIST pidl; - BROWSEINFOW bi; + wchar_t SelectedDir[MAX_PATH]; + LPITEMIDLIST pidl; + BROWSEINFOW bi; - WriteTrace(TraceDebug, __FUNCTION__ " 1"); - stdstr RomDir = g_Settings->LoadStringVal(Directory_Game); - bi.hwndOwner = m_MainWindow; - bi.pidlRoot = NULL; - bi.pszDisplayName = SelectedDir; - bi.lpszTitle = GS(SELECT_ROM_DIR); - bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS; - bi.lpfn = (BFFCALLBACK)SelectRomDirCallBack; - bi.lParam = (DWORD)RomDir.c_str(); - WriteTrace(TraceDebug, __FUNCTION__ " 2"); - if ((pidl = SHBrowseForFolderW(&bi)) != NULL) - { - WriteTrace(TraceDebug, __FUNCTION__ " 3"); - char Directory[_MAX_PATH]; - if (SHGetPathFromIDList(pidl, Directory)) - { - int len = strlen(Directory); + WriteTrace(TraceDebug, __FUNCTION__ " 1"); + stdstr RomDir = g_Settings->LoadStringVal(Directory_Game); + bi.hwndOwner = m_MainWindow; + bi.pidlRoot = NULL; + bi.pszDisplayName = SelectedDir; + bi.lpszTitle = GS(SELECT_ROM_DIR); + bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS; + bi.lpfn = (BFFCALLBACK)SelectRomDirCallBack; + bi.lParam = (DWORD)RomDir.c_str(); + WriteTrace(TraceDebug, __FUNCTION__ " 2"); + if ((pidl = SHBrowseForFolderW(&bi)) != NULL) + { + WriteTrace(TraceDebug, __FUNCTION__ " 3"); + char Directory[_MAX_PATH]; + if (SHGetPathFromIDList(pidl, Directory)) + { + int len = strlen(Directory); - WriteTrace(TraceDebug, __FUNCTION__ " 4"); - if (Directory[len - 1] != '\\') - { - strcat(Directory, "\\"); - } - WriteTrace(TraceDebug, __FUNCTION__ " 5"); - WriteTrace(TraceDebug, __FUNCTION__ " 6"); - g_Settings->SaveString(Directory_Game, Directory); - WriteTrace(TraceDebug, __FUNCTION__ " 7"); - Notify().AddRecentDir(Directory); - WriteTrace(TraceDebug, __FUNCTION__ " 8"); - RefreshRomBrowser(); - WriteTrace(TraceDebug, __FUNCTION__ " 9"); - } - } + WriteTrace(TraceDebug, __FUNCTION__ " 4"); + if (Directory[len - 1] != '\\') + { + strcat(Directory, "\\"); + } + WriteTrace(TraceDebug, __FUNCTION__ " 5"); + WriteTrace(TraceDebug, __FUNCTION__ " 6"); + g_Settings->SaveString(Directory_Game, Directory); + WriteTrace(TraceDebug, __FUNCTION__ " 7"); + Notify().AddRecentDir(Directory); + WriteTrace(TraceDebug, __FUNCTION__ " 8"); + RefreshRomBrowser(); + WriteTrace(TraceDebug, __FUNCTION__ " 9"); + } + } } void CRomBrowser::FixRomListWindow(void) { - //Change the window Style - long Style = GetWindowLong(m_MainWindow, GWL_STYLE) | WS_SIZEBOX | WS_MAXIMIZEBOX; - SetWindowLong(m_MainWindow, GWL_STYLE, Style); + //Change the window Style + long Style = GetWindowLong(m_MainWindow, GWL_STYLE) | WS_SIZEBOX | WS_MAXIMIZEBOX; + SetWindowLong(m_MainWindow, GWL_STYLE, Style); - //Get the current window size - RECT rect; - GetWindowRect(m_MainWindow, &rect); + //Get the current window size + RECT rect; + GetWindowRect(m_MainWindow, &rect); - //We find the middle position of the screen, we use this if theres no setting - int X = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2; - int Y = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2; + //We find the middle position of the screen, we use this if theres no setting + int X = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2; + int Y = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2; - //Load the value from settings, if none is available, default to above - g_Settings->LoadDword(RomBrowser_Top, (uint32_t &)Y); - g_Settings->LoadDword(RomBrowser_Left, (uint32_t &)X); + //Load the value from settings, if none is available, default to above + g_Settings->LoadDword(RomBrowser_Top, (uint32_t &)Y); + g_Settings->LoadDword(RomBrowser_Left, (uint32_t &)X); - SetWindowPos(m_MainWindow, NULL, X, Y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); + SetWindowPos(m_MainWindow, NULL, X, Y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); - //Fix height and width - int Width = g_Settings->LoadDword(RomBrowser_Width); - int Height = g_Settings->LoadDword(RomBrowser_Height); + //Fix height and width + int Width = g_Settings->LoadDword(RomBrowser_Width); + int Height = g_Settings->LoadDword(RomBrowser_Height); - if (Width < 200) { Width = 200; } - if (Height < 200) { Height = 200; } + if (Width < 200) { Width = 200; } + if (Height < 200) { Height = 200; } - RECT rcClient; - rcClient.top = 0; - rcClient.bottom = Height; - rcClient.left = 0; - rcClient.right = Width; - AdjustWindowRect(&rcClient, GetWindowLong(m_MainWindow, GWL_STYLE), true); + RECT rcClient; + rcClient.top = 0; + rcClient.bottom = Height; + rcClient.left = 0; + rcClient.right = Width; + AdjustWindowRect(&rcClient, GetWindowLong(m_MainWindow, GWL_STYLE), true); - int WindowHeight = rcClient.bottom - rcClient.top; - int WindowWidth = rcClient.right - rcClient.left; + int WindowHeight = rcClient.bottom - rcClient.top; + int WindowWidth = rcClient.right - rcClient.left; - SetWindowPos(m_MainWindow, NULL, 0, 0, WindowWidth, WindowHeight, SWP_NOMOVE | SWP_NOZORDER); + SetWindowPos(m_MainWindow, NULL, 0, 0, WindowWidth, WindowHeight, SWP_NOMOVE | SWP_NOZORDER); } void CRomBrowser::ShowRomList(void) { - if (m_Visible || g_Settings->LoadBool(GameRunning_CPU_Running)) { return; } - m_ShowingRomBrowser = true; - WatchThreadStop(); - if (m_hRomList == NULL) { CreateRomListControl(); } - EnableWindow((HWND)m_hRomList, TRUE); - ShowWindow((HWND)m_hRomList, SW_SHOW); - FixRomListWindow(); - m_AllowSelectionLastRom = true; + if (m_Visible || g_Settings->LoadBool(GameRunning_CPU_Running)) { return; } + m_ShowingRomBrowser = true; + WatchThreadStop(); + if (m_hRomList == NULL) { CreateRomListControl(); } + EnableWindow((HWND)m_hRomList, TRUE); + ShowWindow((HWND)m_hRomList, SW_SHOW); + FixRomListWindow(); + m_AllowSelectionLastRom = true; - //Make sure selected item is visible - int iItem = ListView_GetNextItem((HWND)m_hRomList, -1, LVNI_SELECTED); - ListView_EnsureVisible((HWND)m_hRomList, iItem, FALSE); + //Make sure selected item is visible + int iItem = ListView_GetNextItem((HWND)m_hRomList, -1, LVNI_SELECTED); + ListView_EnsureVisible((HWND)m_hRomList, iItem, FALSE); - //Mark the window as visible - m_Visible = true; + //Mark the window as visible + m_Visible = true; - RECT rcWindow; - if (GetClientRect(m_MainWindow, &rcWindow)) - { - ResizeRomList((WORD)rcWindow.right, (WORD)rcWindow.bottom); - } + RECT rcWindow; + if (GetClientRect(m_MainWindow, &rcWindow)) + { + ResizeRomList((WORD)rcWindow.right, (WORD)rcWindow.bottom); + } - InvalidateRect((HWND)m_hRomList, NULL, TRUE); + InvalidateRect((HWND)m_hRomList, NULL, TRUE); - //Start thread to watch for dir changed - WatchThreadStart(); - m_ShowingRomBrowser = false; + //Start thread to watch for dir changed + WatchThreadStart(); + m_ShowingRomBrowser = false; } void CRomBrowser::HideRomList(void) { - if (!RomBrowserVisible()) { return; } - ShowWindow(m_MainWindow, SW_HIDE); + if (!RomBrowserVisible()) { return; } + ShowWindow(m_MainWindow, SW_HIDE); - SaveRomListColoumnInfo(); - WatchThreadStop(); + SaveRomListColoumnInfo(); + WatchThreadStop(); - //Make sure the window does disappear - Sleep(100); + //Make sure the window does disappear + Sleep(100); - //Disable the rom list - EnableWindow((HWND)m_hRomList, FALSE); - ShowWindow((HWND)m_hRomList, SW_HIDE); + //Disable the rom list + EnableWindow((HWND)m_hRomList, FALSE); + ShowWindow((HWND)m_hRomList, SW_HIDE); - if (g_Settings->LoadBool(RomBrowser_Maximized)) { ShowWindow(m_MainWindow, SW_RESTORE); } + if (g_Settings->LoadBool(RomBrowser_Maximized)) { ShowWindow(m_MainWindow, SW_RESTORE); } - //Change the window style - long Style = GetWindowLong(m_MainWindow, GWL_STYLE) & ~(WS_SIZEBOX | WS_MAXIMIZEBOX); - SetWindowLong(m_MainWindow, GWL_STYLE, Style); + //Change the window style + long Style = GetWindowLong(m_MainWindow, GWL_STYLE) & ~(WS_SIZEBOX | WS_MAXIMIZEBOX); + SetWindowLong(m_MainWindow, GWL_STYLE, Style); - //Move window to correct location - RECT rect; - GetWindowRect(m_MainWindow, &rect); - int X = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2; - int Y = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2; - g_Settings->LoadDword(UserInterface_MainWindowTop, (uint32_t &)Y); - g_Settings->LoadDword(UserInterface_MainWindowLeft, (uint32_t &)X); - SetWindowPos(m_MainWindow, NULL, X, Y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); + //Move window to correct location + RECT rect; + GetWindowRect(m_MainWindow, &rect); + int X = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2; + int Y = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2; + g_Settings->LoadDword(UserInterface_MainWindowTop, (uint32_t &)Y); + g_Settings->LoadDword(UserInterface_MainWindowLeft, (uint32_t &)X); + SetWindowPos(m_MainWindow, NULL, X, Y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); - //Mark the window as not visible - m_Visible = false; + //Mark the window as not visible + m_Visible = false; - //Make the main window visible again - ShowWindow(m_MainWindow, SW_SHOW); - BringWindowToTop(m_MainWindow); - PostMessage(m_MainWindow, WM_MAKE_FOCUS, 0, 0); + //Make the main window visible again + ShowWindow(m_MainWindow, SW_SHOW); + BringWindowToTop(m_MainWindow); + PostMessage(m_MainWindow, WM_MAKE_FOCUS, 0, 0); } bool CRomBrowser::RomDirNeedsRefresh(void) { - bool InWatchThread = (m_WatchThreadID == GetCurrentThreadId()); + bool InWatchThread = (m_WatchThreadID == GetCurrentThreadId()); - //Get Old MD5 of file names - stdstr FileName = g_Settings->LoadStringVal(SupportFile_RomListCache); - HANDLE hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - //if file does not exist then refresh the data - return true; - } + //Get Old MD5 of file names + stdstr FileName = g_Settings->LoadStringVal(SupportFile_RomListCache); + HANDLE hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); + if (hFile == INVALID_HANDLE_VALUE) + { + //if file does not exist then refresh the data + return true; + } - DWORD dwRead; - unsigned char CurrentFileMD5[16]; - ReadFile(hFile, &CurrentFileMD5, sizeof(CurrentFileMD5), &dwRead, NULL); - CloseHandle(hFile); + DWORD dwRead; + unsigned char CurrentFileMD5[16]; + ReadFile(hFile, &CurrentFileMD5, sizeof(CurrentFileMD5), &dwRead, NULL); + CloseHandle(hFile); - //Get Current MD5 of file names - strlist FileNames; - if (!GetRomFileNames(FileNames, CPath(g_Settings->LoadStringVal(Directory_Game)), stdstr(""), InWatchThread)) - { - return false; - } - FileNames.sort(); + //Get Current MD5 of file names + strlist FileNames; + if (!GetRomFileNames(FileNames, CPath(g_Settings->LoadStringVal(Directory_Game)), stdstr(""), InWatchThread)) + { + return false; + } + FileNames.sort(); - MD5 NewMd5 = RomListHash(FileNames); - if (memcmp(NewMd5.raw_digest(), CurrentFileMD5, sizeof(CurrentFileMD5)) != 0) - { - return true; - } - return false; + MD5 NewMd5 = RomListHash(FileNames); + if (memcmp(NewMd5.raw_digest(), CurrentFileMD5, sizeof(CurrentFileMD5)) != 0) + { + return true; + } + return false; } MD5 CRomBrowser::RomListHash(strlist & FileList) { - stdstr NewFileNames; - FileList.sort(); - for (strlist::iterator iter = FileList.begin(); iter != FileList.end(); iter++) - { - NewFileNames += *iter; - NewFileNames += ";"; - } - MD5 md5Hash((const unsigned char *)NewFileNames.c_str(), NewFileNames.length()); - WriteTraceF(TraceDebug, __FUNCTION__ ": %s - %s", md5Hash.hex_digest(), NewFileNames.c_str()); - return md5Hash; + stdstr NewFileNames; + FileList.sort(); + for (strlist::iterator iter = FileList.begin(); iter != FileList.end(); iter++) + { + NewFileNames += *iter; + NewFileNames += ";"; + } + MD5 md5Hash((const unsigned char *)NewFileNames.c_str(), NewFileNames.length()); + WriteTraceF(TraceDebug, __FUNCTION__ ": %s - %s", md5Hash.hex_digest(), NewFileNames.c_str()); + return md5Hash; } void CRomBrowser::WatchRomDirChanged(CRomBrowser * _this) { - try - { - WriteTrace(TraceDebug, __FUNCTION__ ": 1"); - _this->m_WatchRomDir = g_Settings->LoadStringVal(Directory_Game); - WriteTrace(TraceDebug, __FUNCTION__ ": 2"); - if (_this->RomDirNeedsRefresh()) - { - WriteTrace(TraceDebug, __FUNCTION__ ": 2a"); - PostMessage((HWND)_this->m_MainWindow, WM_COMMAND, ID_FILE_REFRESHROMLIST, 0); - } - WriteTrace(TraceDebug, __FUNCTION__ ": 3"); - HANDLE hChange[] = { - _this->m_WatchStopEvent, - FindFirstChangeNotification(_this->m_WatchRomDir.c_str(), g_Settings->LoadDword(RomBrowser_Recursive), FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE), - }; - WriteTrace(TraceDebug, __FUNCTION__ ": 4"); - for (;;) - { - WriteTrace(TraceDebug, __FUNCTION__ ": 5"); - if (WaitForMultipleObjects(sizeof(hChange) / sizeof(hChange[0]), hChange, false, INFINITE) == WAIT_OBJECT_0) - { - WriteTrace(TraceDebug, __FUNCTION__ ": 5a"); - FindCloseChangeNotification(hChange[1]); - return; - } - WriteTrace(TraceDebug, __FUNCTION__ ": 5b"); - if (_this->RomDirNeedsRefresh()) - { - PostMessage((HWND)_this->m_MainWindow, WM_COMMAND, ID_FILE_REFRESHROMLIST, 0); - } - WriteTrace(TraceDebug, __FUNCTION__ ": 5c"); - if (!FindNextChangeNotification(hChange[1])) - { - FindCloseChangeNotification(hChange[1]); - return; - } - WriteTrace(TraceDebug, __FUNCTION__ ": 5d"); - } - } - catch (...) - { - WriteTraceF(TraceError, __FUNCTION__ ": Unhandled Exception"); - } + try + { + WriteTrace(TraceDebug, __FUNCTION__ ": 1"); + _this->m_WatchRomDir = g_Settings->LoadStringVal(Directory_Game); + WriteTrace(TraceDebug, __FUNCTION__ ": 2"); + if (_this->RomDirNeedsRefresh()) + { + WriteTrace(TraceDebug, __FUNCTION__ ": 2a"); + PostMessage((HWND)_this->m_MainWindow, WM_COMMAND, ID_FILE_REFRESHROMLIST, 0); + } + WriteTrace(TraceDebug, __FUNCTION__ ": 3"); + HANDLE hChange[] = { + _this->m_WatchStopEvent, + FindFirstChangeNotification(_this->m_WatchRomDir.c_str(), g_Settings->LoadDword(RomBrowser_Recursive), FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE), + }; + WriteTrace(TraceDebug, __FUNCTION__ ": 4"); + for (;;) + { + WriteTrace(TraceDebug, __FUNCTION__ ": 5"); + if (WaitForMultipleObjects(sizeof(hChange) / sizeof(hChange[0]), hChange, false, INFINITE) == WAIT_OBJECT_0) + { + WriteTrace(TraceDebug, __FUNCTION__ ": 5a"); + FindCloseChangeNotification(hChange[1]); + return; + } + WriteTrace(TraceDebug, __FUNCTION__ ": 5b"); + if (_this->RomDirNeedsRefresh()) + { + PostMessage((HWND)_this->m_MainWindow, WM_COMMAND, ID_FILE_REFRESHROMLIST, 0); + } + WriteTrace(TraceDebug, __FUNCTION__ ": 5c"); + if (!FindNextChangeNotification(hChange[1])) + { + FindCloseChangeNotification(hChange[1]); + return; + } + WriteTrace(TraceDebug, __FUNCTION__ ": 5d"); + } + } + catch (...) + { + WriteTraceF(TraceError, __FUNCTION__ ": Unhandled Exception"); + } } void CRomBrowser::WatchThreadStart(void) { - WriteTrace(TraceDebug, __FUNCTION__ ": 1"); - WatchThreadStop(); - WriteTrace(TraceDebug, __FUNCTION__ ": 2"); - m_WatchStopEvent = CreateEvent(NULL, true, false, NULL); - WriteTrace(TraceDebug, __FUNCTION__ ": 3"); - m_WatchThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WatchRomDirChanged, this, 0, &m_WatchThreadID); - WriteTrace(TraceDebug, __FUNCTION__ ": 4"); + WriteTrace(TraceDebug, __FUNCTION__ ": 1"); + WatchThreadStop(); + WriteTrace(TraceDebug, __FUNCTION__ ": 2"); + m_WatchStopEvent = CreateEvent(NULL, true, false, NULL); + WriteTrace(TraceDebug, __FUNCTION__ ": 3"); + m_WatchThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WatchRomDirChanged, this, 0, &m_WatchThreadID); + WriteTrace(TraceDebug, __FUNCTION__ ": 4"); } void CRomBrowser::WatchThreadStop(void) { - if (m_WatchThread == NULL) - { - return; - } - WriteTrace(TraceDebug, __FUNCTION__ ": 1"); - SetEvent(m_WatchStopEvent); - DWORD ExitCode = 0; - for (int count = 0; count < 20; count++) - { - WriteTrace(TraceDebug, __FUNCTION__ ": 2"); - GetExitCodeThread(m_WatchThread, &ExitCode); - if (ExitCode != STILL_ACTIVE) - { - break; - } - Sleep(200); - } - WriteTrace(TraceDebug, __FUNCTION__ ": 3"); - if (ExitCode == STILL_ACTIVE) - { - WriteTrace(TraceDebug, __FUNCTION__ ": 3a"); - TerminateThread(m_WatchThread, 0); - } - WriteTrace(TraceDebug, __FUNCTION__ ": 4"); + if (m_WatchThread == NULL) + { + return; + } + WriteTrace(TraceDebug, __FUNCTION__ ": 1"); + SetEvent(m_WatchStopEvent); + DWORD ExitCode = 0; + for (int count = 0; count < 20; count++) + { + WriteTrace(TraceDebug, __FUNCTION__ ": 2"); + GetExitCodeThread(m_WatchThread, &ExitCode); + if (ExitCode != STILL_ACTIVE) + { + break; + } + Sleep(200); + } + WriteTrace(TraceDebug, __FUNCTION__ ": 3"); + if (ExitCode == STILL_ACTIVE) + { + WriteTrace(TraceDebug, __FUNCTION__ ": 3a"); + TerminateThread(m_WatchThread, 0); + } + WriteTrace(TraceDebug, __FUNCTION__ ": 4"); - CloseHandle(m_WatchThread); - CloseHandle(m_WatchStopEvent); - m_WatchStopEvent = NULL; - m_WatchThread = NULL; - m_WatchThreadID = 0; - WriteTrace(TraceDebug, __FUNCTION__ ": 5"); + CloseHandle(m_WatchThread); + CloseHandle(m_WatchStopEvent); + m_WatchStopEvent = NULL; + m_WatchThread = NULL; + m_WatchThreadID = 0; + WriteTrace(TraceDebug, __FUNCTION__ ": 5"); } \ No newline at end of file diff --git a/Source/Project64/User Interface/Rom Browser.h b/Source/Project64/User Interface/Rom Browser.h index 0d177d36d..112a4d232 100644 --- a/Source/Project64/User Interface/Rom Browser.h +++ b/Source/Project64/User Interface/Rom Browser.h @@ -16,54 +16,54 @@ class CMainGui; class CPlugins; class ROMBROWSER_FIELDS { - stdstr m_Name; - size_t m_Pos, m_DefaultPos; - int m_ID; - uint32_t m_ColWidth; - LanguageStringID m_LangID; - bool m_PosChanged; + stdstr m_Name; + size_t m_Pos, m_DefaultPos; + int m_ID; + uint32_t m_ColWidth; + LanguageStringID m_LangID; + bool m_PosChanged; public: - ROMBROWSER_FIELDS(const char * Name, int Pos, int ID, int ColWidth, LanguageStringID LangID, bool UseDefault) : - m_Name(Name), - m_Pos(Pos), - m_DefaultPos(Pos), - m_ID(ID), - m_ColWidth(ColWidth), - m_LangID(LangID), - m_PosChanged(false) + ROMBROWSER_FIELDS(const char * Name, int Pos, int ID, int ColWidth, LanguageStringID LangID, bool UseDefault) : + m_Name(Name), + m_Pos(Pos), + m_DefaultPos(Pos), + m_ID(ID), + m_ColWidth(ColWidth), + m_LangID(LangID), + m_PosChanged(false) - { - if (!UseDefault) - { - m_PosChanged = g_Settings->LoadDwordIndex(RomBrowser_PosIndex, m_ID, (uint32_t &)m_Pos); - g_Settings->LoadDwordIndex(RomBrowser_WidthIndex, m_ID, m_ColWidth); - } - } - inline LPCSTR Name(void) const { return m_Name.c_str(); } - inline size_t Pos(void) const { return m_Pos; } - inline bool PosChanged(void) const { return m_PosChanged; } - inline int ID(void) const { return m_ID; } - inline int ColWidth(void) const { return m_ColWidth; } - inline LanguageStringID LangID(void) const { return m_LangID; } + { + if (!UseDefault) + { + m_PosChanged = g_Settings->LoadDwordIndex(RomBrowser_PosIndex, m_ID, (uint32_t &)m_Pos); + g_Settings->LoadDwordIndex(RomBrowser_WidthIndex, m_ID, m_ColWidth); + } + } + inline LPCSTR Name(void) const { return m_Name.c_str(); } + inline size_t Pos(void) const { return m_Pos; } + inline bool PosChanged(void) const { return m_PosChanged; } + inline int ID(void) const { return m_ID; } + inline int ColWidth(void) const { return m_ColWidth; } + inline LanguageStringID LangID(void) const { return m_LangID; } - void SetColWidth(int ColWidth) - { - m_ColWidth = ColWidth; - g_Settings->SaveDwordIndex(RomBrowser_WidthIndex, m_ID, m_ColWidth); - } - void SetColPos(int Pos) - { - m_Pos = Pos; - g_Settings->SaveDwordIndex(RomBrowser_PosIndex, m_ID, m_Pos); - m_PosChanged = true; - } - void ResetPos(void) - { - m_Pos = m_DefaultPos; - g_Settings->DeleteSettingIndex(RomBrowser_PosIndex, m_ID); - m_PosChanged = false; - } + void SetColWidth(int ColWidth) + { + m_ColWidth = ColWidth; + g_Settings->SaveDwordIndex(RomBrowser_WidthIndex, m_ID, m_ColWidth); + } + void SetColPos(int Pos) + { + m_Pos = Pos; + g_Settings->SaveDwordIndex(RomBrowser_PosIndex, m_ID, m_Pos); + m_PosChanged = true; + } + void ResetPos(void) + { + m_Pos = m_DefaultPos; + g_Settings->DeleteSettingIndex(RomBrowser_PosIndex, m_ID); + m_PosChanged = false; + } }; typedef std::vector ROMBROWSER_FIELDS_LIST; @@ -71,143 +71,143 @@ typedef std::vector FIELD_TYPE_LIST; class CRomBrowser; struct SORT_FIELD { - CRomBrowser * _this; - int Key; - bool KeyAscend; + CRomBrowser * _this; + int Key; + bool KeyAscend; }; class C7zip; class CRomBrowser { - enum { IDC_ROMLIST = 223 }; - enum { - RB_FileName = 0, RB_InternalName = 1, RB_GoodName = 2, - RB_Status = 3, RB_RomSize = 4, RB_CoreNotes = 5, - RB_PluginNotes = 6, RB_UserNotes = 7, RB_CartridgeID = 8, - RB_Manufacturer = 9, RB_Country = 10, RB_Developer = 11, - RB_Crc1 = 12, RB_Crc2 = 13, RB_CICChip = 14, - RB_ReleaseDate = 15, RB_Genre = 16, RB_Players = 17, - RB_ForceFeedback = 18, RB_FileFormat = 19 - }; + enum { IDC_ROMLIST = 223 }; + enum { + RB_FileName = 0, RB_InternalName = 1, RB_GoodName = 2, + RB_Status = 3, RB_RomSize = 4, RB_CoreNotes = 5, + RB_PluginNotes = 6, RB_UserNotes = 7, RB_CartridgeID = 8, + RB_Manufacturer = 9, RB_Country = 10, RB_Developer = 11, + RB_Crc1 = 12, RB_Crc2 = 13, RB_CICChip = 14, + RB_ReleaseDate = 15, RB_Genre = 16, RB_Players = 17, + RB_ForceFeedback = 18, RB_FileFormat = 19 + }; - enum FILE_FORMAT { - Format_Uncompressed, - Format_Zip, - Format_7zip, - }; + enum FILE_FORMAT { + Format_Uncompressed, + Format_Zip, + Format_7zip, + }; - enum - { - NoOfSortKeys = 3 - }; + enum + { + NoOfSortKeys = 3 + }; - struct ROM_INFO { - char szFullFileName[300]; - FILE_FORMAT FileFormat; - char Status[60]; - char FileName[200]; - char InternalName[22]; - char GoodName[200]; - char CartID[3]; - char PluginNotes[250]; - char CoreNotes[250]; - char UserNotes[250]; - char Developer[30]; - char ReleaseDate[30]; - char Genre[15]; - int Players; - DWORD TextColor; - int SelColor; - DWORD SelTextColor; - DWORD SelColorBrush; - int RomSize; - BYTE Manufacturer; - BYTE Country; - DWORD CRC1; - DWORD CRC2; - int CicChip; - char ForceFeedback[15]; - }; + struct ROM_INFO { + char szFullFileName[300]; + FILE_FORMAT FileFormat; + char Status[60]; + char FileName[200]; + char InternalName[22]; + char GoodName[200]; + char CartID[3]; + char PluginNotes[250]; + char CoreNotes[250]; + char UserNotes[250]; + char Developer[30]; + char ReleaseDate[30]; + char Genre[15]; + int Players; + DWORD TextColor; + int SelColor; + DWORD SelTextColor; + DWORD SelColorBrush; + int RomSize; + BYTE Manufacturer; + BYTE Country; + DWORD CRC1; + DWORD CRC2; + int CicChip; + char ForceFeedback[15]; + }; - typedef std::vector ROMINFO_LIST; + typedef std::vector ROMINFO_LIST; - HWND & m_MainWindow; - HWND & m_StatusWindow; - HWND m_hRomList; - ROMBROWSER_FIELDS_LIST m_Fields; - FIELD_TYPE_LIST m_FieldType; - ROMINFO_LIST m_RomInfo; - stdstr m_SelectedRom; - bool m_Visible; - bool m_ShowingRomBrowser; - HANDLE m_RefreshThread; - bool m_StopRefresh; - CIniFile * m_RomIniFile; - CIniFile * m_NotesIniFile; - CIniFile * m_ExtIniFile; - CIniFile * m_ZipIniFile; - bool m_AllowSelectionLastRom; + HWND & m_MainWindow; + HWND & m_StatusWindow; + HWND m_hRomList; + ROMBROWSER_FIELDS_LIST m_Fields; + FIELD_TYPE_LIST m_FieldType; + ROMINFO_LIST m_RomInfo; + stdstr m_SelectedRom; + bool m_Visible; + bool m_ShowingRomBrowser; + HANDLE m_RefreshThread; + bool m_StopRefresh; + CIniFile * m_RomIniFile; + CIniFile * m_NotesIniFile; + CIniFile * m_ExtIniFile; + CIniFile * m_ZipIniFile; + bool m_AllowSelectionLastRom; - void AddFileNameToList(strlist & FileList, const stdstr & Directory, CPath & File); - void AddRomToList(const char * RomLocation, const char * lpLastRom); - void AddRomInfoToList(ROM_INFO &RomInfo, const char * lpLastRom); - void AllocateBrushs(void); - static void ByteSwapRomData(BYTE * Data, int DataLen); - int CalcSortPosition(DWORD lParam); - void CreateRomListControl(void); - void DeallocateBrushs(void); - void FillRomExtensionInfo(ROM_INFO * pRomInfo); - bool FillRomInfo(ROM_INFO * pRomInfo); - void FillRomList(strlist & FileList, const CPath & BaseDirectory, const stdstr & Directory, const char * lpLastRom); - void FixRomListWindow(void); - static int GetCicChipID(BYTE * RomData); - bool LoadDataFromRomFile(char * FileName, BYTE * Data, int DataLen, int * RomSize, FILE_FORMAT & FileFormat); - void LoadRomList(void); - void MenuSetText(HMENU hMenu, int MenuPos, const wchar_t * Title, char * ShortCut); - void SaveRomList(strlist & FileList); - void RomList_ColoumnSortList(DWORD pnmh); - void RomList_GetDispInfo(DWORD pnmh); - void RomList_OpenRom(DWORD pnmh); - void RomList_PopupMenu(DWORD pnmh); - void RomList_SortList(void); - bool GetRomFileNames(strlist & FileList, const CPath & BaseDirectory, const stdstr & Directory, bool InWatchThread); - MD5 RomListHash(strlist & FileList); + void AddFileNameToList(strlist & FileList, const stdstr & Directory, CPath & File); + void AddRomToList(const char * RomLocation, const char * lpLastRom); + void AddRomInfoToList(ROM_INFO &RomInfo, const char * lpLastRom); + void AllocateBrushs(void); + static void ByteSwapRomData(BYTE * Data, int DataLen); + int CalcSortPosition(DWORD lParam); + void CreateRomListControl(void); + void DeallocateBrushs(void); + void FillRomExtensionInfo(ROM_INFO * pRomInfo); + bool FillRomInfo(ROM_INFO * pRomInfo); + void FillRomList(strlist & FileList, const CPath & BaseDirectory, const stdstr & Directory, const char * lpLastRom); + void FixRomListWindow(void); + static int GetCicChipID(BYTE * RomData); + bool LoadDataFromRomFile(char * FileName, BYTE * Data, int DataLen, int * RomSize, FILE_FORMAT & FileFormat); + void LoadRomList(void); + void MenuSetText(HMENU hMenu, int MenuPos, const wchar_t * Title, char * ShortCut); + void SaveRomList(strlist & FileList); + void RomList_ColoumnSortList(DWORD pnmh); + void RomList_GetDispInfo(DWORD pnmh); + void RomList_OpenRom(DWORD pnmh); + void RomList_PopupMenu(DWORD pnmh); + void RomList_SortList(void); + bool GetRomFileNames(strlist & FileList, const CPath & BaseDirectory, const stdstr & Directory, bool InWatchThread); + MD5 RomListHash(strlist & FileList); - static void __stdcall NotificationCB(LPCWSTR Status, CRomBrowser * _this); + static void __stdcall NotificationCB(LPCWSTR Status, CRomBrowser * _this); - //Watch Directory Changed function - HANDLE m_WatchThread, m_WatchStopEvent; - DWORD m_WatchThreadID; - stdstr m_WatchRomDir; - void WatchThreadStart(void); - void WatchThreadStop(void); - bool RomDirNeedsRefresh(void); // Called from watch thread - static void WatchRomDirChanged(CRomBrowser * _this); - static void RefreshRomBrowserStatic(CRomBrowser * _this); - static void AddField(ROMBROWSER_FIELDS_LIST & Fields, LPCSTR Name, int Pos, int ID, int Width, LanguageStringID LangID, bool UseDefault); + //Watch Directory Changed function + HANDLE m_WatchThread, m_WatchStopEvent; + DWORD m_WatchThreadID; + stdstr m_WatchRomDir; + void WatchThreadStart(void); + void WatchThreadStop(void); + bool RomDirNeedsRefresh(void); // Called from watch thread + static void WatchRomDirChanged(CRomBrowser * _this); + static void RefreshRomBrowserStatic(CRomBrowser * _this); + static void AddField(ROMBROWSER_FIELDS_LIST & Fields, LPCSTR Name, int Pos, int ID, int Width, LanguageStringID LangID, bool UseDefault); - //Callback - static int CALLBACK SelectRomDirCallBack(HWND hwnd, DWORD uMsg, DWORD lp, DWORD lpData); - static int CALLBACK RomList_CompareItems(DWORD lParam1, DWORD lParam2, DWORD lParamSort); + //Callback + static int CALLBACK SelectRomDirCallBack(HWND hwnd, DWORD uMsg, DWORD lp, DWORD lpData); + static int CALLBACK RomList_CompareItems(DWORD lParam1, DWORD lParam2, DWORD lParamSort); public: - CRomBrowser(HWND & hMainWindow, HWND & StatusWindow); - ~CRomBrowser(void); - void HighLightLastRom(void); - void HideRomList(void); - void RefreshRomBrowser(void); - void ResetRomBrowserColomuns(void); - void ResizeRomList(WORD nWidth, WORD nHeight); - void RomBrowserToTop(void); - void RomBrowserMaximize(bool Mazimize); - bool RomBrowserVisible(void); - bool RomListDrawItem(int idCtrl, DWORD lParam); - bool RomListNotify(int idCtrl, DWORD pnmh); - void SaveRomListColoumnInfo(void); - void SelectRomDir(void); - void ShowRomList(void); - bool ShowingRomBrowser(void) { return m_ShowingRomBrowser; } - LPCSTR CurrentedSelectedRom(void) { return m_SelectedRom.c_str(); } + CRomBrowser(HWND & hMainWindow, HWND & StatusWindow); + ~CRomBrowser(void); + void HighLightLastRom(void); + void HideRomList(void); + void RefreshRomBrowser(void); + void ResetRomBrowserColomuns(void); + void ResizeRomList(WORD nWidth, WORD nHeight); + void RomBrowserToTop(void); + void RomBrowserMaximize(bool Mazimize); + bool RomBrowserVisible(void); + bool RomListDrawItem(int idCtrl, DWORD lParam); + bool RomListNotify(int idCtrl, DWORD pnmh); + void SaveRomListColoumnInfo(void); + void SelectRomDir(void); + void ShowRomList(void); + bool ShowingRomBrowser(void) { return m_ShowingRomBrowser; } + LPCSTR CurrentedSelectedRom(void) { return m_SelectedRom.c_str(); } - static void GetFieldInfo(ROMBROWSER_FIELDS_LIST & Fields, bool UseDefault = false); + static void GetFieldInfo(ROMBROWSER_FIELDS_LIST & Fields, bool UseDefault = false); };