📄 tmainfrm1.cpp
字号:
}
// Add all files associated with the item
pFileList = m_pTreeView->GetItemData(hItem);
for(pos = pFileList->GetHeadPosition(); pos != NULL; )
{
pInfo = (TFileInfo *)pFileList->GetNext(pos);
pList->AddTail(pInfo);
}
}
void TMainFrame::AddFolderToList(CPtrList * pList, const char * szFolder)
{
WIN32_FIND_DATA wf;
HANDLE hFind;
char szFullPath[MAX_PATH];
char * szStr;
BOOL bResult = TRUE;
// Change folder
SetStatusText(IDS_BUILDINGLIST);
SetCurrentDirectory(szFolder);
hFind = FindFirstFile("*", &wf);
while(hFind != INVALID_HANDLE_VALUE && bResult)
{
if(wf.cFileName[0] != '.' && wf.cFileName[1] != '.')
{
if(wf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
AddFolderToList(pList, wf.cFileName);
SetCurrentDirectory("..");
}
else
{
GetFullPathName(wf.cFileName, sizeof(szFullPath)-1, szFullPath, &szStr);
szStr = new char[strlen(szFullPath) + 1];
strcpy(szStr, szFullPath);
pList->AddTail(szStr);
}
}
bResult = FindNextFile(hFind, &wf);
}
// Close the search handle
if(hFind != INVALID_HANDLE_VALUE)
FindClose(hFind);
}
// Removes all items with special language versions.
void TMainFrame::RemoveNonNeutralItems(CPtrList * pList)
{
TFileInfo * pInfo;
POSITION savePos;
POSITION pos = pList->GetHeadPosition();
while(pos != NULL)
{
savePos = pos;
pInfo = (TFileInfo *)pList->GetNext(pos);
if(pInfo->lcLocale != LANG_NEUTRAL)
pList->RemoveAt(savePos);
}
}
// Frees the work info structure
void TMainFrame::FreeWorkInfo(TWorkInfo * pWork)
{
if(pWork->pFileList != NULL)
{
CPtrList * pList = pWork->pFileList;
if(pWork->bFreeList)
{
for(POSITION pos = pList->GetHeadPosition(); pos != NULL; )
delete (char *)pList->GetNext(pos);
}
pList->RemoveAll();
delete pList;
}
delete pWork;
}
// Builds the file list from selected items
CPtrList * TMainFrame::CreateFileList(HWND hListView)
{
TFileInfo * pInfo = NULL;
CPtrList * pList = new CPtrList;
HTREEITEM hItem;
int nSelected = ListView_GetNextItem(hListView, -1, LVNI_SELECTED);
// Notify the user that we build the file list
SetStatusText(IDS_BUILDINGLIST);
// No selection - no fun
while(nSelected != -1)
{
pInfo = m_pListView->GetItemData(nSelected, &hItem);
// If it is a directory, do recursive search
if(pInfo == NULL)
AddFolderToList(pList, hItem);
// Otherwise, add the file
else
pList->AddTail(pInfo);
// Move to the next item
nSelected = ListView_GetNextItem(hListView, nSelected, LVNI_SELECTED);
}
SetStatusText(AFX_IDS_IDLEMESSAGE);
return pList;
}
// Creates list of added files from Add file dialog
CPtrList * TMainFrame::CreateFileList(CFileDialog * pDlg)
{
CPtrList * pFileList = new CPtrList;
POSITION pos = pDlg->GetStartPosition();
while(pos != NULL)
{
CString strFile = pDlg->GetNextPathName(pos);
char * szFileName = new char[strFile.GetLength() + 1];
strcpy(szFileName, strFile);
pFileList->AddTail(szFileName);
}
return pFileList;
}
CPtrList * TMainFrame::CreateFileList(HDROP hDropInfo, DWORD & nRelPathStart)
{
CPtrList * pFileList = new CPtrList;
char szFileName[MAX_PATH];
char szSaveDir[MAX_PATH];
char * szStr;
UINT nFiles = DragQueryFile(hDropInfo, (UINT)-1, szFileName, sizeof(szFileName) - 1);
// Save the current directory
GetCurrentDirectory(sizeof(szSaveDir) - 1, szSaveDir);
for(UINT i = 0; i < nFiles; i++)
{
DragQueryFile(hDropInfo, i, szFileName, sizeof(szFileName) - 1);
if(GetFileAttributes(szFileName) & FILE_ATTRIBUTE_DIRECTORY)
AddFolderToList(pFileList, szFileName);
else
{
szStr = new char[strlen(szFileName) + 1];
strcpy(szStr, szFileName);
pFileList->AddTail(szStr);
}
}
// Retrieve relative path name
if(nFiles > 0)
nRelPathStart = GetPlainName(szFileName) - (char *)szFileName;
// Restore the current directory
SetCurrentDirectory(szSaveDir);
return pFileList;
}
HDROP TMainFrame::CreateDropFiles(CPtrList * pFileList)
{
TFileInfo * pInfo;
DROPFILES * pDrop;
POSITION pos;
CString strLocName;
char * pDropFiles;
DWORD dwDropSize = sizeof(DROPFILES);
HDROP hDrop;
for(pos = pFileList->GetHeadPosition(); pos != NULL; )
{
pInfo = (TFileInfo *)pFileList->GetNext(pos);
strLocName = GetLocalFileName(pInfo->szFullName, FALSE);
dwDropSize += strLocName.GetLength() + 1;
}
// Allocate space for the items
hDrop = (HDROP)::GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, dwDropSize + 2);
if(hDrop != NULL)
{
pDrop = (DROPFILES *)::GlobalLock(hDrop);
pDrop->pFiles = sizeof(DROPFILES);
pDropFiles = (char *)(pDrop + 1);
for(pos = pFileList->GetHeadPosition(); pos != NULL; )
{
pInfo = (TFileInfo *)pFileList->GetNext(pos);
strLocName = GetLocalFileName(pInfo->szFullName, FALSE);
strcpy(pDropFiles, strLocName);
pDropFiles += strLocName.GetLength() + 1;
}
::GlobalUnlock(hDrop);
}
return hDrop;
}
int TMainFrame::InitFunctionTable(BOOL bUseStormDll)
{
int nError = ERROR_SUCCESS;
// Load the Storm.dll
if(nError == ERROR_SUCCESS && m_hStorm == NULL && bUseStormDll)
{
if((m_hStorm = LoadDLL("Storm.dll")) == NULL)
{
AfxMessageBox(IDS_CANTLOADSTORMDLL, MB_OK | MB_ICONERROR, 0);
bUseStormDll = FALSE;
}
}
// If Storm.dll was loaded correctly and we demand to use it, get their proc addresses
if(nError == ERROR_SUCCESS && bUseStormDll)
{
pSFileOpenArchive = (SFILEOPENARCHIVE )GetDLLProcAddress(m_hStorm, (LPCSTR)266);
pSFileCloseArchive = (SFILECLOSEARCHIVE )GetDLLProcAddress(m_hStorm, (LPCSTR)252);
pSFileOpenFileEx = (SFILEOPENFILEEX )GetDLLProcAddress(m_hStorm, (LPCSTR)268);
pSFileCloseFile = (SFILECLOSEFILE )GetDLLProcAddress(m_hStorm, (LPCSTR)253);
pSFileGetFileSize = (SFILEGETFILESIZE )GetDLLProcAddress(m_hStorm, (LPCSTR)265);
pSFileSetFilePointer = (SFILESETFILEPOINTER)GetDLLProcAddress(m_hStorm, (LPCSTR)271);
pSFileReadFile = (SFILEREADFILE )GetDLLProcAddress(m_hStorm, (LPCSTR)269);
pSFileSetLocale = (SFILESETLOCALE )GetDLLProcAddress(m_hStorm, (LPCSTR)272);
if(!pSFileOpenArchive || !pSFileCloseArchive || !pSFileOpenFileEx || !pSFileCloseFile ||
!pSFileGetFileSize || !pSFileSetFilePointer || !pSFileReadFile)
{
AfxMessageBox(IDS_PROCMISSING, MB_OK | MB_ICONERROR);
m_bUseStormDll = FALSE;
nError = ERROR_CAN_NOT_COMPLETE;
}
}
if(nError != ERROR_SUCCESS || m_bUseStormDll == FALSE)
{
pSFileOpenArchive = SFileOpenArchive;
pSFileCloseArchive = SFileCloseArchive;
pSFileOpenFileEx = SFileOpenFileEx;
pSFileCloseFile = SFileCloseFile;
pSFileGetFileSize = SFileGetFileSize;
pSFileSetFilePointer = SFileSetFilePointer;
pSFileReadFile = SFileReadFile;
pSFileSetLocale = SFileSetLocale;
nError = ERROR_SUCCESS;
}
// Save the variable
cfg.bUseStorm = m_bUseStormDll = bUseStormDll;
return nError;
}
// This function checks the selection on the list view.
BOOL TMainFrame::CheckListSelection(DWORD dwFlags)
{
HWND hListView = m_pListView->GetHwnd();
int nSelected = ListView_GetSelectedCount(hListView);
UINT nIDError = 0;
// If no selected, try some focused.
if(nSelected == 0)
{
nSelected = ListView_GetNextItem(hListView, -1, LVNI_FOCUSED);
if(nSelected != -1)
nSelected = 1;
}
// If no item selected
if((dwFlags & ESEL_NO_SELECTED) && nSelected == 0)
nIDError = IDS_NOITEMSSELECTED;
// If more than one item selected
if((dwFlags & ESEL_MORE_SELECTED) && nSelected > 1)
nIDError = IDS_CANTDOWITHMULTIPLE;
// If a folder selected
if(dwFlags & ESEL_DIR_SELECTED)
{
HTREEITEM hItem;
nSelected = ListView_GetNextItem(hListView, -1, LVNI_FOCUSED);
if(m_pListView->GetItemData(nSelected, &hItem) == NULL)
nIDError = IDS_CANTDOWITHDIRS;
}
// If files were loaded by nameless access
if((dwFlags & ESEL_NAMELESS) && m_bNameless)
nIDError = IDS_CANTDOONNAMELESS;
// Resolve result
if(nIDError != 0)
AfxMessageBox(nIDError, MB_OK | MB_ICONINFORMATION);
return (nIDError == 0);
}
int TMainFrame::DragFiles()
{
TWorkInfo * pWork = NULL;
CPtrList * pFileList = NULL;
TDataSource DropData;
if(!HasDocAndIsIdle())
return ERROR_SUCCESS;
// Check the selection. There must be at least one entry
if(CheckListSelection(ESEL_NO_SELECTED) == FALSE)
return ERROR_SUCCESS;
// Create file list for the selected items
if((pFileList = CreateFileList(m_pListView->GetHwnd())) == NULL)
return ERROR_SUCCESS;
pWork = CreateWorkInfo(WORK_EXTRACT_FILES);
pWork->pFileList = pFileList;
pWork->bKeepPath = FALSE;
pWork->bOverwriteAll = TRUE;
m_pListView->DragAcceptFiles(FALSE);
DropData.SetWorkData(this, pWork);
if((DropData.m_hDrop = CreateDropFiles(pFileList)) != NULL)
{
DropData.DelayRenderData(CF_HDROP);
DropData.DoDragDrop(DROPEFFECT_COPY, NULL);
}
m_pListView->DragAcceptFiles(TRUE);
return ERROR_SUCCESS;
}
// Asks the user for the added flags
int TMainFrame::AskForAddFlags()
{
TAddFileOptionsDlg dlg(this);
int nResult = IDOK;
// Call the dialog only when enabled in configuration
if(cfg.bShowOptionsOnAdd)
nResult = dlg.DoModal();
return nResult;
}
//-----------------------------------------------------------------------------
// TMainFrame message handlers
BOOL TMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if(!CFrameWnd::PreCreateWindow(cs))
return FALSE;
return TRUE;
}
int TMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
HWND hWnd;
int nMaxX = GetSystemMetrics(SM_CXSCREEN);
int nMaxY = GetSystemMetrics(SM_CYSCREEN);
if(CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if(!m_wndToolBar.CreateEx(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndDlgBar.Create(this, IDD_DIALOGBAR, CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
{
TRACE0("Failed to create dialogbar\n");
return -1; // fail to create
}
if(!m_wndReBar.Create(this) || !m_wndReBar.AddBar(&m_wndToolBar) || !m_wndReBar.AddBar(&m_wndDlgBar))
{
TRACE0("Failed to create rebar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
// Create internal variables
m_hStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
// Initialize the function table from Storm.dll or from StormLib
InitFunctionTable(cfg.bUseStorm);
DragAcceptFiles(TRUE);
// Initialize the search mask
if((hWnd = ::GetDlgItem(m_wndDlgBar.m_hWnd, IDC_MPQSEARCHMASK)) != NULL)
::SetWindowText(hWnd, m_strMask);
// Check the right window position and move the window
if(cfg.rectMainWnd.left < 0)
cfg.rectMainWnd.left = 0;
if(cfg.rectMainWnd.top < 0)
cfg.rectMainWnd.top = 0;
if(cfg.rectMainWnd.right > nMaxX)
cfg.rectMainWnd.right = nMaxX;
if(cfg.rectMainWnd.bottom > nMaxY)
cfg.rectMainWnd.bottom = nMaxY;
MoveWindow(&cfg.rectMainWnd, FALSE);
return 0;
}
// Handles Enter pressed in Dialogbar
BOOL TMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
{
char szMask[256];
UINT nNotify = HIWORD(wParam);
UINT nCtrlID = LOWORD(wParam);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -