📄 selectfile.cpp
字号:
// SelectFile.cpp: implementation of the CSelectFile class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "SelectFile.h"
#include <io.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSelectFile::CSelectFile()
{
m_strFilePatchName = "";
m_rs = start;
nFileLen = -1;
}
CSelectFile::~CSelectFile()
{
}
// 获取文件所在的路径 [5/6/2008 By willing]
CString CSelectFile::GetFilePatch()
{
if ("" == m_strFilePatchName)
{
return "";
}
if (FALSE == IsExist())
{
// 文件不存在 [5/6/2008 By willing]
return "";
}
int nIndex = m_strFilePatchName.ReverseFind('\\');
if (0 > nIndex)
{
return "";
}
return m_strFilePatchName.Left(nIndex+1);
}
// 判断该文件是否存在 [5/6/2008 By willing]
BOOL CSelectFile::IsExist()
{
BOOL bRe = FALSE;// 默认不存在 [5/6/2008 By willing]
if (_access(m_strFilePatchName,0) == 0)
{
bRe = TRUE;
}
return bRe;
}
// 获取文件名称,不含路径 [5/6/2008 By willing]
CString CSelectFile::GetFileName()
{
if ("" == m_strFilePatchName)
{
return "";
}
if (FALSE == IsExist())
{
// 文件不存在 [5/6/2008 By willing]
return "";
}
int nIndex = m_strFilePatchName.ReverseFind('\\');
if (0 > nIndex)
{
return "";
}
return m_strFilePatchName.Right(m_strFilePatchName.GetLength() - nIndex - 1);
}
// 获取文件的扩展名 [5/6/2008 By willing]
DWORD CSelectFile::GetFileExt(CString &strExt)
{
if ("" == m_strFilePatchName)
{
return -1;
}
if (FALSE == IsExist())
{
// 文件不存在,或不具有可读属性 [5/6/2008 By willing]
return -2;
}
int nIndex = m_strFilePatchName.ReverseFind('.');
if (0 > nIndex)
{
// 该文件没有扩展名 [5/6/2008 By willing]
strExt="";
return 0;
}
strExt = m_strFilePatchName.Right(m_strFilePatchName.GetLength() - nIndex - 1);
return 0;
}
// 获取文件的完整的路径 [5/7/2008 By willing]
CString CSelectFile::GetFilePatchName()
{
return m_strFilePatchName;
}
// 设置文件的完成路径 [5/7/2008 By willing]
void CSelectFile::SetFilePatchName(const CString strFilePatchName)
{
m_strFilePatchName = strFilePatchName;
return;
}
// 判断是否是文件 [5/7/2008 By willing]
BOOL CSelectFile::IsFile()
{
if ("" == m_strFilePatchName)
{
return FALSE;
}
WIN32_FIND_DATA fd;
HANDLE hFind = ::FindFirstFile(m_strFilePatchName,&fd);
if (hFind == INVALID_HANDLE_VALUE)
{
return FALSE;
}
// 判断是否是文件夹 [5/25/2007 Add By willing]
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
::FindClose(hFind);
return FALSE;
}else{
::FindClose(hFind);
return TRUE;
}
return FALSE;
}
// 获取文件长度 [5/7/2008 By willing]
int CSelectFile::GetFileLen()
{
if (nFileLen != -1)
{
return nFileLen;
}
CString strMsg = "";
CFile selfile;
OutputDebugString("判断文件大小");
OutputDebugString(m_strFilePatchName);
if (FALSE == selfile.Open(m_strFilePatchName,CFile::shareDenyRead))
{
strMsg.Format("打开文件失败 %0x",GetLastError());
OutputDebugString(strMsg);
return -1;
}
nFileLen = selfile.GetLength();
selfile.Close();
return nFileLen;
}
// 获取当该文件的处理进度状态 [5/8/2008 By willing]
RunState CSelectFile::GetRunState()
{
return m_rs;
}
// 设置状态 [5/8/2008 By willing]
void CSelectFile::SetRunState(const RunState rs)
{
m_rs = rs;
return;
}
// 获取加密后的要生成的加密文件名称 [5/8/2008 By willing]
CString CSelectFile::GetEncFilePatchName()
{
if ("" == m_strFilePatchName)
{
return "";
}
if (IsFile() == FALSE)
{
return "";
}
CString strExt = "";
if (GetFileExt(strExt) != 0)
{
return "";
}
CString strRe = m_strFilePatchName;
if ("" == strExt)
{
// 带加密文件没有扩展名 [5/8/2008 By willing]
strRe += ".jde";
}else{
strExt = "."+strExt;
strRe.Replace(strExt,".jde");
}
return strRe;
}
// 清空该对象的所有信息 [8/12/2008 By willing]
void CSelectFile::Clear()
{
return;
m_strFilePatchName = "";
m_rs = start;
nFileLen = -1;
}
// 判断该文件是否是加密过的文件 [8/15/2008 By willing]
BOOL CSelectFile::CheckFile()
{
CString strExt = "";
if (GetFileExt(strExt) != 0)
{
return TRUE;
}
if ("" == strExt)
{
return FALSE;
}else if (strExt == "jde"){
return TRUE;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -