?? mysplitterdlg.cpp
字號:
// MySplitterDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MySplitter.h"
#include "MySplitterDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMySplitterDlg dialog
CMySplitterDlg::CMySplitterDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMySplitterDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMySplitterDlg)
m_strCutNum = _T("");
m_strCutUnit = _T("");
m_strFileName = _T("");
m_strSavePath = _T("");
m_strFileSize = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bEqVolume=TRUE;
}
void CMySplitterDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMySplitterDlg)
DDX_Control(pDX, IDC_EDCUTNUM, m_edCutNum);
DDX_Control(pDX, IDC_EDCUTUNIT, m_edCutUnit);
DDX_Text(pDX, IDC_EDCUTNUM, m_strCutNum);
DDX_Text(pDX, IDC_EDCUTUNIT, m_strCutUnit);
DDX_Text(pDX, IDC_EDFILENAME, m_strFileName);
DDX_Text(pDX, IDC_EDFILESAVE, m_strSavePath);
DDX_Text(pDX, IDC_FILESIZE, m_strFileSize);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMySplitterDlg, CDialog)
//{{AFX_MSG_MAP(CMySplitterDlg)
ON_BN_CLICKED(IDC_RAD_EQVOL, OnRadEqvol)
ON_BN_CLICKED(IDC_RAD_UNIT, OnRadUnit)
ON_BN_CLICKED(IDC_BROWSE_FILE, OnBrowseFile)
ON_BN_CLICKED(IDC_BROWSE_SAVE, OnBrowseSave)
ON_EN_CHANGE(IDC_EDCUTUNIT, OnChangeEdcutunit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMySplitterDlg message handlers
BOOL CMySplitterDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_edCutNum.EnableWindow(m_bEqVolume);
m_edCutUnit.EnableWindow(!m_bEqVolume);
CButton *RadEqVol=(CButton *)GetDlgItem(IDC_RAD_EQVOL);
CButton *RadEqUnit=(CButton *)GetDlgItem(IDC_RAD_UNIT);
RadEqVol->SetCheck(m_bEqVolume);
RadEqUnit->SetCheck(!m_bEqVolume);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMySplitterDlg::OnRadEqvol()
{
m_bEqVolume=TRUE;
m_edCutNum.EnableWindow(m_bEqVolume);
m_edCutUnit.EnableWindow(!m_bEqVolume);
}
void CMySplitterDlg::OnRadUnit()
{
m_bEqVolume=FALSE;
m_edCutNum.EnableWindow(m_bEqVolume);
m_edCutUnit.EnableWindow(!m_bEqVolume);
}
void CMySplitterDlg::OnBrowseFile()
{
struct _stat ST;
CFileDialog fileDialog(TRUE,NULL,NULL,NULL,
"所有文件(*.*)|*.*||");
if (fileDialog.DoModal() == IDOK)
{
m_strFileName = fileDialog.GetPathName();
// 如果輸入的文件名為空,返回.
if(m_strFileName.IsEmpty()) return;
// 獲取文件的長度.
_stat(m_strFileName, &ST);
m_strFileSize.Format("%d",ST.st_size);
UpdateData(FALSE);
}
}
void CMySplitterDlg::OnBrowseSave()
{
CString strResult ="";
LPMALLOC lpMalloc; // pointer to IMalloc
if (::SHGetMalloc(&lpMalloc) != NOERROR)
{
AfxMessageBox("Path operation error!");
return ;
}
char szDisplayName[_MAX_PATH];
char szBuffer[_MAX_PATH];
BROWSEINFO browseInfo;
browseInfo.hwndOwner = this->m_hWnd;
// set root at Desktop
browseInfo.pidlRoot = NULL;
browseInfo.pszDisplayName = szDisplayName;
browseInfo.lpszTitle = "請選擇分類數(shù)據(jù)路徑"; // Dialog title
browseInfo.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS;
browseInfo.lpfn = NULL; // not used
browseInfo.lParam = 0; // not used
LPITEMIDLIST lpItemIDList;
if ((lpItemIDList = ::SHBrowseForFolder(&browseInfo))
!= NULL)
{
// Get the path of the selected folder from the item ID list.
if (::SHGetPathFromIDList(lpItemIDList, szBuffer))
{
// At this point, szBuffer contains the path the user chose.
if (szBuffer[0] == '\0')
{
// SHGetPathFromIDList failed, or SHBrowseForFolder failed.
AfxMessageBox("Fail to get directory!",
MB_ICONSTOP|MB_OK);
return ;
}
// We have a path in szBuffer! Return it.
strResult = szBuffer;
}
else
{
// The thing referred to by lpItemIDList
// might not have been a file system object.
// For whatever reason, SHGetPathFromIDList didn't work!
AfxMessageBox("Fail to get directory!",
MB_ICONSTOP|MB_OK);
return ;
}
lpMalloc->Free(lpItemIDList);
lpMalloc->Release();
}
m_strSavePath=strResult;
UpdateData(FALSE);
}
//---------------------------------------------------------------------------
void CMySplitterDlg::AddDirSplash(CString &strDir)
{
CString strTmp=strDir;
strTmp.TrimRight();
if((!strTmp.IsEmpty())&&(strTmp.Right(1)!='\\'))
strTmp +="\\";
strDir=strTmp;
}
//---------------------------------------------------------------------------
BOOL CMySplitterDlg::DoSplit()
{
// 檢查被分割的文件名.
if(m_strFileName.IsEmpty()) return FALSE;
CString strFilePath,strShortName;
// 控制程序的系統(tǒng)文件名.
CString strFileDest;
CThreadFCut sect;
// 給文件目錄路徑增加分隔線.
AddDirSplash(m_strSavePath);
// 分離文件路徑和短文件名.
sect.BreakFileName(m_strFileName,strFilePath,strShortName);
// 如果保存分割后的文件的目錄為空,取當前目錄保存分割后的文件.
if(m_strSavePath.IsEmpty())
m_strSavePath = strFilePath;
if(m_bEqVolume){
// 等體積分割.
if(m_strCutNum.IsEmpty()) return FALSE;
sect.DoVolumeCut(strFilePath,m_strSavePath,
strShortName,atoi(m_strCutNum));
// 產(chǎn)生控制程序的目標文件名.
strFileDest.Format("%s_%sv.exe",m_strSavePath+strShortName,m_strCutNum);
CopyObjectToDest(strFileDest);
}
else{
// 固定長度單位分割.
if(m_strCutUnit.IsEmpty()) return FALSE;
sect.DoUnitCut(strFilePath,m_strSavePath,
m_strFileName,atoi(m_strCutUnit));
// 獲得控制程序的目標文件名.
strFileDest.Format("%s_%ss.exe",m_strSavePath+strShortName,m_strCutUnit);
CopyObjectToDest(strFileDest);
}
return TRUE;
}
//---------------------------------------------------------------------------
void CMySplitterDlg::CopyObjectToDest(CString strFileDest)
{
struct _stat ST;
FILE *fpread,*fpwrite;
CString strFilePath,strShortName;
TCHAR szModule[MAX_PATH];
// 獲得應用程序名.
GetModuleFileName(0, szModule, sizeof(szModule));
// 獲取文件長度.
_stat(szModule, &ST);
UINT nFilesize=ST.st_size;
// 打開文件.
if((fpread=fopen(szModule,"rb"))==NULL)
return;
// 打開文件.
if((fpwrite=fopen(strFileDest,"wb"))==NULL)
return;
// MySplitter.exe裸體文件長度.
UINT nPos =126976;
// 設置文件讀指針起始位置.
fseek(fpread,nPos,SEEK_SET);
int c;
// 把控制程序數(shù)據(jù)寫入到strFileDest.
while((c=fgetc(fpread))!=EOF)
{
fputc(c,fpwrite);
}
fclose(fpread);
fclose(fpwrite);
}
//---------------------------------------------------------------------------
void CMySplitterDlg::OnChangeEdcutunit()
{
// 計算分割段的段數(shù).
UpdateData();
long nFilesize=atoi(m_strFileSize);
long nSize=atoi(m_strCutUnit);
int nSectNum= nFilesize/nSize;
// 有多余的長度.
if(nFilesize%nSize!=0) nSectNum ++;
m_strCutNum.Format("%d",nSectNum);
UpdateData(FALSE);
}
//---------------------------------------------------------------------------
void CMySplitterDlg::OnOK()
{
UpdateData();
if(DoSplit()){
AfxMessageBox("文件分割成功!:)");
}
else{
AfxMessageBox("文件分割不成功:(((");
}
CDialog::OnOK();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -