📄 tnamebreakerdlg1.cpp
字号:
nResult = (pInfo1->dwIndex < pInfo2->dwIndex) ? -1 : 1;
break;
case 1:
if(pInfo1->dwHashIndex != pInfo2->dwHashIndex)
nResult = (pInfo1->dwHashIndex < pInfo2->dwHashIndex) ? -1 : 1;
break;
case 2:
if(pInfo1->dwCodeName1 != pInfo2->dwCodeName1)
nResult = (pInfo1->dwCodeName1 < pInfo2->dwCodeName1) ? -1 : 1;
break;
case 3:
if(pInfo1->dwCodeName2 != pInfo2->dwCodeName2)
nResult = (pInfo1->dwCodeName2 < pInfo2->dwCodeName2) ? -1 : 1;
break;
case 4:
if(pInfo1->dwSeed != pInfo2->dwSeed)
nResult = (pInfo1->dwSeed < pInfo2->dwSeed) ? -1 : 1;
break;
case 5:
if(pInfo1->dwFileSize != pInfo2->dwFileSize)
nResult = (pInfo1->dwFileSize < pInfo2->dwFileSize) ? -1 : 1;
break;
case 6:
nResult = stricmp(pInfo1->szExt, pInfo2->szExt);
break;
case 7:
nResult = stricmp(pInfo1->szFullName, pInfo2->szFullName);
break;
}
// If the result is still fifty-fifty, continue comparing
// if(nResult == 0)
// nResult = stricmp(pInfo1->szPlainName, pInfo2->szPlainName);
// if(nResult == 0 && szExt1 != NULL && szExt2 != NULL)
// nResult = stricmp(szExt1, szExt2);
// if(nResult == 0 && pInfo1->dwFileSize != pInfo2->dwFileSize)
// nResult = (pInfo1->dwFileSize < pInfo2->dwFileSize) ? -1 : 1;
// If descending, reverse the result
if(m_bAscending == FALSE)
nResult = -nResult;
return nResult;
}
//-----------------------------------------------------------------------------
// TNameBreakerDlg message handlers
BOOL TNameBreakerDlg::OnInitDialog()
{
HINSTANCE hInst = AfxGetResourceHandle();
LOGFONT LogFont;
CWnd * pStatusText;
char szText[MAX_PATH];
CDialog::OnInitDialog();
// Initialize anchors
m_Anchors.AddAnchor(m_hWnd, IDC_FILELIST, akAll);
m_Anchors.AddAnchor(m_hWnd, IDC_STATUSTEXT, akLeft | akRight | akBottom);
m_Anchors.AddAnchor(m_hWnd, IDC_ELAPSEDTIME, akLeft | akRight | akBottom);
m_Anchors.AddAnchor(m_hWnd, IDC_NDETECTED, akLeft | akRight | akBottom);
m_Anchors.AddAnchor(m_hWnd, IDC_DETECT, akRight | akBottom);
m_Anchors.AddAnchor(m_hWnd, IDC_SAVELIST, akRight | akBottom);
m_Anchors.AddAnchor(m_hWnd, IDC_CLOSE, akRight | akBottom);
// Initialize list view font
m_FileList.GetFont()->GetLogFont(&LogFont);
strcpy(LogFont.lfFaceName, "Courier");
m_pFont = new CFont;
m_pFont->CreateFontIndirect(&LogFont);
m_FileList.SetFont(m_pFont, FALSE);
// Initialize font for status text
if((pStatusText = GetDlgItem(IDC_STATUSTEXT)) != NULL)
pStatusText->SetFont(m_pFont, FALSE);
// Initialize font for listview
m_FileList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
// Initialize the listview columns
LoadString(hInst, IDS_INDEX, szText, sizeof(szText)-1);
m_FileList.InsertColumn(0, szText, LVCFMT_LEFT, 50, 0);
LoadString(hInst, IDS_HASH_INDEX, szText, sizeof(szText)-1);
m_FileList.InsertColumn(1, szText, LVCFMT_LEFT, 80, 0);
LoadString(hInst, IDS_CODENAME1, szText, sizeof(szText)-1);
m_FileList.InsertColumn(2, szText, LVCFMT_LEFT, 90, 0);
LoadString(hInst, IDS_CODENAME2, szText, sizeof(szText)-1);
m_FileList.InsertColumn(3, szText, LVCFMT_LEFT, 90, 0);
LoadString(hInst, IDS_SEED, szText, sizeof(szText)-1);
m_FileList.InsertColumn(4, szText, LVCFMT_LEFT, 80, 0);
LoadString(hInst, IDS_SIZE, szText, sizeof(szText)-1);
m_FileList.InsertColumn(5, szText, LVCFMT_LEFT, 90, 0);
LoadString(hInst, IDS_EXTENSION, szText, sizeof(szText)-1);
m_FileList.InsertColumn(6, szText, LVCFMT_LEFT, 50, 0);
LoadString(hInst, IDS_FILENAME, szText, sizeof(szText)-1);
m_FileList.InsertColumn(7, szText, LVCFMT_LEFT, 230, 0);
// Set the dialog's width to the whole screen width
ShowWindow(SW_SHOWMAXIMIZED);
// Load the archive
LoadArchive(m_strMpqName, m_strFileList);
return TRUE;
}
void TNameBreakerDlg::OnSize(UINT nType, int cx, int cy)
{
LVCOLUMN lvc;
RECT rect;
int nColumnWidth = 0;
// Make ancestor handle the event
CDialog::OnSize(nType, cx, cy);
// Command the parent
switch(nType)
{
case SIZE_MINIMIZED:
m_bMinimized = TRUE;
CommandParent(SW_SHOWMINIMIZED);
break;
case SIZE_RESTORED:
case SIZE_MAXIMIZED:
if(m_bMinimized == TRUE)
CommandParent(m_nOldShow);
m_Anchors.AnchorAllObjects(m_hWnd);
m_bMinimized = FALSE;
break;
}
// Adjust the width of the last column
if(m_FileList.m_hWnd != NULL)
{
// Count the size of columns 1 - 6
ZeroMemory(&lvc, sizeof(LVCOLUMN));
for(int i = 0; i < 7; i++)
{
lvc.mask = LVCF_WIDTH;
m_FileList.GetColumn(i, &lvc);
nColumnWidth += lvc.cx;
}
// Adjust the last column
m_FileList.GetClientRect(&rect);
lvc.cx = rect.right - nColumnWidth;
if((::GetWindowLong(m_FileList.m_hWnd, GWL_STYLE) & WS_VSCROLL) == 0)
lvc.cx -= GetSystemMetrics(SM_CXVSCROLL);
if(lvc.cx > 0)
m_FileList.SetColumn(7, &lvc);
}
}
void TNameBreakerDlg::OnContextMenu(CWnd * /* pWnd */, CPoint point)
{
HMENU hMenu = LoadMenu(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_CTXNAMEBREAKER));
HMENU hSubMenu = NULL;
// If valid context menu
if((hSubMenu = GetSubMenu(hMenu, 0)) != NULL)
TrackPopupMenu(hSubMenu, (TPM_LEFTBUTTON | TPM_RIGHTBUTTON), point.x, point.y, 0, m_hWnd, NULL);
}
void TNameBreakerDlg::OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW * pNMListView = (NM_LISTVIEW*)pNMHDR;
TNameInfo * pInfo = NULL;
int nFocused = m_FileList.GetNextItem(-1, LVNI_FOCUSED);
if(pNMListView->iSubItem != m_uSortColumn)
{
m_uSortColumn = pNMListView->iSubItem;
m_bAscending = TRUE;
}
else
m_bAscending = !m_bAscending;
// If no item focused, do nothing
if(nFocused != -1)
pInfo = (TNameInfo *)m_FileList.GetItemData(nFocused);
m_FileList.SortItems(CompareFunc, (DWORD)this);
if(pInfo != NULL)
m_FileList.EnsureVisible(FindItemByFileIndex(pInfo->dwIndex), FALSE);
*pResult = 0;
}
// Name breaking status information
void TNameBreakerDlg::OnTimer(UINT)
{
RefreshDetectInfo(FALSE);
}
// Called when the "Close" button was pressed
void TNameBreakerDlg::OnCloseClick()
{
if(StopWorkThread() == TRUE)
EndDialog(IDOK);
}
// Called when "x" icon pressed
void TNameBreakerDlg::OnClose()
{
if(StopWorkThread() == FALSE)
return;
CDialog::OnClose();
}
// On item deletion, delete the item data
void TNameBreakerDlg::OnDeleteItem(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW * pNMListView = (NM_LISTVIEW*)pNMHDR;
TNameInfo * pInfo = (TNameInfo *)pNMListView->lParam;
if(pInfo != NULL)
delete pInfo;
*pResult = 0;
}
void TNameBreakerDlg::OnLoadArchive(WPARAM /* wParam */, LPARAM /* lParam */)
{
LoadArchive(m_strMpqName, m_strFileList);
}
// Called when double-clicked on an entry in ListView
void TNameBreakerDlg::OnFileListDblClk(NMHDR * /* pNMHDR */, LRESULT * pResult)
{
if(m_hThread == NULL)
{
int nIndex = m_FileList.GetNextItem(-1, LVNI_FOCUSED);
if(nIndex != -1)
DetectFileNames(nIndex);
}
*pResult = 0;
}
// Called by the worker thread when a name has been found
void TNameBreakerDlg::OnNameFound(WPARAM wParam, LPARAM lParam)
{
TNameInfo * pInfo = NULL;;
CString str;
char * szFileName = (char *)lParam;
int nIndex = -1;
// Find the item
nIndex = FindItemByFileIndex((DWORD)wParam);
if(nIndex != -1)
pInfo = (TNameInfo *)m_FileList.GetItemData(nIndex);
// If bad structure or it has already a name, do nothing
if(pInfo == NULL || (pInfo->dwFlags & DTI_FILENAME))
return;
// Store the file name into the listview
SetDetectInfo(pInfo, -1, -1, -1, -1, -1, -1, NULL, szFileName);
strlwr(pInfo->szFullName);
UpdateItemLabels(nIndex, pInfo);
// Update counts and play the notification sound
m_dwUnknowns--;
m_nDetected++;
UpdateNDetected();
UpdateNUnknowns();
PlaySound(MAKEINTRESOURCE(IDR_NAMEDETECTED), AfxGetResourceHandle(), SND_RESOURCE | SND_ASYNC);
// If auto-save list file, do it now.
if(cfg.bAutoSave)
SaveListFile(m_strFileList);
}
void TNameBreakerDlg::OnWorkComplete(WPARAM /* wParam */, LPARAM lParam)
{
CString str;
// Update the information about the detecting
RefreshDetectInfo(TRUE);
// Kill the timer
if(m_nTimer != 0)
{
KillTimer(m_nTimer);
m_nTimer = 0;
}
// Cleanup the working thread
if(m_hThread != NULL)
CloseHandle(m_hThread);
m_hThread = NULL;
// Free memory
FreeStringList(m_dto.pFolderList);
if(m_dto.szExts != NULL)
{
delete m_dto.szExts;
m_dto.szExts = NULL;
}
// Clear status text and change the text of "Detect/Stop" button
str.LoadString(IDS_DETECT);
GetDlgItem(IDC_DETECT)->SetWindowText(str);
// Notify the user that we have finished the work
if(lParam == ERROR_SUCCESS)
AfxMessageBox(IDS_WORKCOMPLETE, MB_OK | MB_ICONINFORMATION);
}
void TNameBreakerDlg::OnSaveList()
{
SaveListFile(NULL);
}
void TNameBreakerDlg::OnPrevUnknown()
{
FocusNextUnknown(-1);
}
void TNameBreakerDlg::OnNextUnknown()
{
FocusNextUnknown(+1);
}
void TNameBreakerDlg::OnHexView()
{
THexViewer dlg(this);
TNameInfo * pInfo;
HANDLE hMpq = NULL;
HANDLE hFile = NULL;
char Data[0x1000];
DWORD dwDataSize = 0;
int nIndex = m_FileList.GetNextItem(-1, LVNI_FOCUSED);
int nError = ERROR_SUCCESS;
// Retrieve pointer to the file info
pInfo = (TNameInfo *)m_FileList.GetItemData(nIndex);
// Open the archive
if(nError == ERROR_SUCCESS)
{
if(!SFileOpenArchive(m_strMpqName, 0, 0, &hMpq))
nError = GetLastError();
}
if(nError == ERROR_SUCCESS)
{
char * szFileName = (pInfo->dwFlags & DTI_FILENAME) ? pInfo->szFullName : (char *)pInfo->dwIndex;
SFileSetLocale(pInfo->lcLocale);
if(!SFileOpenFileEx(hMpq, szFileName, 0, &hFile))
nError = GetLastError();
}
if(nError == ERROR_SUCCESS)
{
if(!SFileReadFile(hFile, Data, sizeof(Data), &dwDataSize, NULL))
nError = GetLastError();
if(nError == ERROR_HANDLE_EOF)
nError = ERROR_SUCCESS;
}
if(hFile != NULL)
SFileCloseFile(hFile);
if(hMpq != NULL)
SFileCloseArchive(hMpq);
if(nError == ERROR_SUCCESS)
{
dlg.SetData(Data, dwDataSize);
dlg.DoModal();
}
else
AfxMessageBox(IDS_EREADFILEDATA, MB_OK | MB_ICONINFORMATION);
}
// Called when pressed the "Detect/Stop" button
void TNameBreakerDlg::OnDetect()
{
// If we are idle, start the work
if(m_hThread == NULL)
{
int nIndex = m_FileList.GetNextItem(-1, LVNI_FOCUSED);
if(nIndex != -1)
DetectFileNames(nIndex);
}
// Otherwise stop the work
else
StopWorkThread();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -