DelFileDlg.cpp
资源名称:DXGuide.zip [点击查看]
上传用户:wymy58
上传日期:2007-01-07
资源大小:2086k
文件大小:5k
源码类别:
DirextX编程
开发平台:
Visual C++
- // DelFileDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "PFM.h"
- #include "DelFileDlg.h"
- #include "MainFrm.h"
- #include <direct.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDelFileDlg dialog
- CDelFileDlg::CDelFileDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CDelFileDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDelFileDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CDelFileDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDelFileDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDelFileDlg, CDialog)
- //{{AFX_MSG_MAP(CDelFileDlg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDelFileDlg message handlers
- void CDelFileDlg::OnOK()
- {
- // TODO: Add extra validation here
- CWaitCursor wc;
- GetDlgItem(IDOK)->EnableWindow(FALSE);
- GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
- m_fl = gCurPan?gRightPan:gLeftPan;
- m_strPath = gCurPan?gRightPath:gLeftPath;
- if (m_strPath.Right(1) == "\")
- {
- DeleteD();
- m_fl->LoadDirectory(m_strPath);
- }
- else
- {
- DeleteF();
- m_fl->LoadFastfile(m_strPath);
- }
- CDialog::OnOK();
- }
- void CDelFileDlg::DeleteDir(LPCTSTR strPath)
- {
- CString sPath = strPath;
- CString curPath = sPath+"\";
- BOOL bLoop;
- CFileFind ff;
- bLoop = ff.FindFile(curPath+"*.*");
- while (bLoop)
- {
- bLoop = ff.FindNextFile();
- if (ff.IsDots())
- continue;
- if (ff.IsDirectory())
- DeleteDir(curPath+ff.GetFileName());
- else
- CFile::Remove(ff.GetFilePath());
- }
- _rmdir(sPath);
- }
- void CDelFileDlg::DeleteD()
- {
- LPWIN32_FIND_DATA pFd;
- char drive[_MAX_DRIVE];
- char dir[_MAX_DIR];
- char fname[_MAX_FNAME];
- char ext[_MAX_EXT];
- CString strName;
- int nItem = m_fl->GetNextItem(-1, LVNI_ALL|LVNI_SELECTED);
- while (nItem != -1)
- {
- pFd = (LPWIN32_FIND_DATA)m_fl->GetItemData(nItem);
- if (pFd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- {
- _splitpath(pFd->cFileName,drive,dir,fname,ext);
- strName = fname;
- strName += ext;
- if (strName == "..")
- ;
- else
- DeleteDir(strName);
- }
- else
- CFile::Remove(pFd->cFileName);
- nItem = m_fl->GetNextItem(nItem, LVNI_ALL|LVNI_SELECTED);
- }
- }
- void CDelFileDlg::DeleteF()
- {
- LPWIN32_FIND_DATA pFd;
- CString strDest = m_strPath.Left(
- m_strPath.ReverseFind('\')+1);
- LVITEM lvi;
- int nItem = m_fl->GetNextItem(-1, LVNI_ALL);
- while (nItem!=-1)
- {
- lvi.mask = LVIF_STATE;
- lvi.iItem = nItem;
- lvi.iSubItem = 0;
- lvi.stateMask = 0xFFFF;
- // get all state flags
- m_fl->GetItem(&lvi);
- if (lvi.state & LVIS_SELECTED)
- ;
- else
- {
- pFd = (LPWIN32_FIND_DATA)m_fl->GetItemData(nItem);
- if (pFd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- ;
- else
- m_map.SetAt(pFd->cFileName, pFd->cFileName);
- }
- nItem = m_fl->GetNextItem(nItem, LVNI_ALL);
- }
- CFile fPf;
- FILE_ENTRY *pFe;
- PACK_FILE_HEAD pfh;
- if (!fPf.Open(strDest+"$$$$$$$$.$$$", CFile::modeCreate|CFile::modeWrite|CFile::typeBinary))
- {
- MessageBox("包文件创建失败!","PackFile Maker", MB_OK|MB_ICONSTOP);
- return;
- }
- pfh.dwEntryCount = m_map.GetCount();
- memcpy(&pfh.dwFlag, "DXGF", 4);
- pfh.dwHeadSize = sizeof(PACK_FILE_HEAD);
- pfh.wMajorVersion = 0x1;
- pfh.wMinorVersion = 0x0;
- strcpy(pfh.szDescription, "This file is created by DirectX Guide");
- pFe = NULL;
- pFe = new FILE_ENTRY[pfh.dwEntryCount+1];
- if (pFe == NULL)
- {
- MessageBox("内存申请失败!", "PackFile Maker", MB_OK|MB_ICONSTOP);
- return;
- }
- DWORD dwCnt = 0;
- CString key, val;
- POSITION ps;
- ps = m_map.GetStartPosition();
- while (ps)
- {
- m_map.GetNextAssoc(ps, key, val);
- strcpy(pFe[dwCnt].szFileName, key);
- dwCnt++;
- }
- qsort(pFe, pfh.dwEntryCount, sizeof(FILE_ENTRY), Compare);
- LONG lOffset = sizeof(PACK_FILE_HEAD) + (pfh.dwEntryCount+1)*sizeof(FILE_ENTRY);
- CFastFile fin;
- // DWORD dwSize = 0;
- for (dwCnt=0; dwCnt<pfh.dwEntryCount; dwCnt++)
- {
- if (!fin.Open(m_fl->GetFastFileManager(), pFe[dwCnt].szFileName))
- {
- MessageBox("文件打开失败!", "PackFile Maker", MB_OK|MB_ICONSTOP);
- fPf.Close();
- delete [] pFe;
- return;
- }
- pFe[dwCnt].lOffset = lOffset;
- memcpy(&(pFe[dwCnt].ftCreationTime), &(fin.m_pFE->ftCreationTime), sizeof(FILETIME));
- memcpy(&(pFe[dwCnt].ftWriteTime), &(fin.m_pFE->ftWriteTime), sizeof(FILETIME));
- fPf.Seek(lOffset, CFile::begin);
- fPf.Write(fin.GetPtr(), fin.GetFileSize());
- lOffset += fin.GetFileSize();
- // dwSize += fin.GetFileSize();
- }
- strcpy(pFe[pfh.dwEntryCount].szFileName, "-[The End]-");
- pFe[pfh.dwEntryCount].lOffset = lOffset;
- pfh.dwFileSize = lOffset;
- fPf.Seek(0, CFile::begin);
- fPf.Write(&pfh, sizeof(pfh));
- fPf.Write(pFe, (pfh.dwEntryCount+1)*sizeof(FILE_ENTRY));
- fPf.Close();
- delete [] pFe;
- m_fl->Unload();
- CFile::Remove(m_strPath);
- CFile::Rename(strDest+"$$$$$$$$.$$$", m_strPath);
- m_fl->LoadFastfile(m_strPath);
- }