📄 fileviewdlg.cpp
字号:
// FileViewDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "ULExplorer.h"
#include "FileViewDlg.h"
#include "FSSigleton.h"
#include "SystemInfoView.h"
IMPLEMENT_DYNAMIC(CHexEdit, CXTHexEdit)
BEGIN_MESSAGE_MAP(CHexEdit, CXTHexEdit)
//{{AFX_MSG_MAP(CXTHexEdit)
ON_WM_CONTEXTMENU()
ON_WM_NCPAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// CFileViewDlg 对话框
IMPLEMENT_DYNAMIC(CFileViewDlg, CXTResizeDialog)
BEGIN_MESSAGE_MAP(CFileViewDlg, CXTResizeDialog)
ON_WM_SIZE()
ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
ON_NOTIFY(TCN_SELCHANGE, IDC_FILEDLG_TAB, OnTcnSelchangeFiledlgTab)
END_MESSAGE_MAP()
CFileViewDlg::CFileViewDlg(CWnd* pParent /*=NULL*/)
: CXTResizeDialog(CFileViewDlg::IDD, pParent)
{
}
CFileViewDlg::~CFileViewDlg()
{
}
void CFileViewDlg::DoDataExchange(CDataExchange* pDX)
{
CXTResizeDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT_ASCII, m_EditASCII);
DDX_Control(pDX, IDC_EDIT_HEX, m_EditHex);
DDX_Control(pDX, IDC_FILEDLG_TAB, m_TabCtrl);
DDX_Control(pDX, IDOK, m_BtnSave);
DDX_Control(pDX, IDCANCEL, m_BtnExit);
}
// CFileViewDlg 消息处理程序
BOOL CFileViewDlg::OnInitDialog()
{
CXTResizeDialog::OnInitDialog();
CXTPPaintManager::SetTheme(xtpThemeOffice2003);
VERIFY(InitTabCtrl() != -1);
VERIFY(InitEdit() != -1);
VERIFY(AddTabViews() != -1);
SetResize(IDC_FILEDLG_TAB, SZ_TOP_LEFT, SZ_BOTTOM_RIGHT);
SetResize(IDOK, SZ_BOTTOM_RIGHT, SZ_BOTTOM_RIGHT);
SetResize(IDCANCEL, SZ_BOTTOM_RIGHT, SZ_BOTTOM_RIGHT);
((CXTButtonThemeOfficeXP*)CXTButton::GetDefaultTheme())->UseWordTheme(TRUE);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
BOOL CFileViewDlg::SetFilePath(CString Path)
{
if ( Path.IsEmpty() )
return FALSE;
m_strFilePath = Path;
return TRUE;
}
int CFileViewDlg::InitTabCtrl()
{
m_TabCtrl.ModifyStyle(0L, WS_CLIPCHILDREN|WS_CLIPSIBLINGS);
CXTPTabPaintManager* PaintManager = ((CXTPTabPaintManager*)m_TabCtrl.GetPaintManager());
PaintManager->SetAppearance(xtpTabAppearancePropertyPage2003);
PaintManager->SetColor(xtpTabColorOffice2003);
PaintManager->m_clientFrame = xtpTabFrameNone;
PaintManager->DisableLunaColors(FALSE);
PaintManager->SetOneNoteColors(TRUE);
PaintManager->m_bBoldSelected = FALSE;
return 0;
}
int CFileViewDlg::InitEdit()
{
m_hFile = theFileSys.Open(m_strFilePath, O_RDONLY, 0);
if (m_hFile<0)
return FALSE;
m_FileSize = theFileSys.GetFileSize(m_hFile);
if (m_FileSize<0||m_FileSize>10*1024*1024)
{
AfxMessageBox("文件大小违规\n可能发生错误\n请重建虚拟磁盘");
theFileSys.Close(m_hFile);
return -1;
}
if ( m_FileSize>0 )
{
m_pData = new BYTE[m_FileSize+1];
theFileSys.Read(m_hFile, (char*)m_pData, m_FileSize);
m_pData[m_FileSize] = 0;
m_EditASCII.SetWindowText((LPCTSTR)m_pData);
}
m_EditASCII.LimitText(10*1024*1024);
m_EditASCII.SetParent(&m_TabCtrl);
m_EditHex.ModifyStyle(0, ES_READONLY);
m_EditHex.SetBPR(16);
m_EditHex.SetAddressBase(0);
//m_EditHex.SetOptions(FALSE, FALSE, TRUE, m_bWideAddress);
m_EditHex.SetDisabledBackColor(RGB(255,255,255));
m_EditHex.SetDisabledTextColor(RGB(0, 0, 0));
m_EditHex.SetData(m_pData, m_FileSize, 1024*1024);
m_EditHex.SetParent(&m_TabCtrl);
m_EditHex.MoveWindow(0, 0, 0, 0);
m_PropertyGrid.Create( CXTPEmptyRect(), this, 87876 );
m_PropertyGrid.SetParent(&m_TabCtrl);
m_PropertyGrid.SetTheme(xtpGridThemeCool);
m_PropertyGrid.SetCustomColors( RGB(200, 200, 200), 0, RGB(182, 210, 189), RGB(247, 243, 233), RGB(0, 0, 0));
m_PropertyGrid.SetHelpHeight(0);
CXTPPropertyGridItem* pCategory = m_PropertyGrid.AddCategory(_T("文件控制块"));
FILE_INFO FI;
theFileSys.GetFileAttr(m_hFile, &FI);
/*
// 文件控制块
struct FILE_INFO
{
unsigned short fi_mode; // 文件类型和属性(rwx 位)
unsigned short fi_uid; // 用户id(文件拥有者标识符)
unsigned long fi_size; // 文件大小(字节数)
unsigned long fi_mtime; // 修改时间(自1970.1.1:0 算起,秒)
unsigned char fi_gid; // 组id(文件拥有者所在的组)
unsigned char fi_nlinks; // 文件目录项链接数
unsigned short fi_zone[9]; // 直接(0-6),间接(7)或双重间接(8)逻辑块号
struct task_struct *fi_wait;// 等待该i 节点的进程
unsigned long fi_atime; // 最后访问时间
unsigned long fi_ctime; // i 节点自身修改时间
unsigned short fi_dev; // i 节点所在的设备号
unsigned short fi_num; // i 节点号
unsigned short fi_count; // i 节点被使用的次数,0 表示该i 节点空闲
unsigned char fi_lock; // 锁定标志
unsigned char fi_dirt; // 已修改(脏)标志
unsigned char fi_pipe; // 管道标志
unsigned char fi_mount; // 安装标志
unsigned char fi_seek; // 搜寻标志(lseek 时)
unsigned char fi_update; // 更新标志
};
*/
CString tmp;
tmp.Format("0x%08X",FI.fi_mode);
pCategory->AddChildItem(new CPropertyGridItemEx(_T("文件类型和属性"), tmp));
tmp.Format("0x%08X",FI.fi_uid);
pCategory->AddChildItem(new CPropertyGridItemEx(_T("用户ID"), tmp));
tmp.Format("0x%08X",FI.fi_gid);
pCategory->AddChildItem(new CPropertyGridItemEx(_T("组ID"), tmp));
tmp.Format("0x%08X",FI.fi_num);
pCategory->AddChildItem(new CPropertyGridItemEx(_T("文件i节点号"), tmp));
tmp.Format("0x%08X",FI.fi_size);
pCategory->AddChildItem(new CPropertyGridItemEx(_T("文件大小(字节数)"), tmp));
tmp.Format("0x%08X",FI.fi_nlinks);
pCategory->AddChildItem(new CPropertyGridItemEx(_T("文件链接数"), tmp));
tm* pTime;
pTime = localtime( &(FI.fi_mtime));
tmp.Format("%d年%d月%d日%d时%d分%d秒", 1900+pTime->tm_year, 1+pTime->tm_mon, pTime->tm_mday,
pTime->tm_hour, pTime->tm_min, pTime->tm_sec);
pCategory->AddChildItem(new CPropertyGridItemEx(_T("修改时间"), tmp));
pTime = localtime( &(FI.fi_atime));
tmp.Format("%d年%d月%d日%d时%d分%d秒", 1900+pTime->tm_year, 1+pTime->tm_mon, pTime->tm_mday,
pTime->tm_hour, pTime->tm_min, pTime->tm_sec);
pCategory->AddChildItem(new CPropertyGridItemEx(_T("最后访问时间"), tmp));
//CXTPPropertyGridItem* pCategoryOne = pCategory->AddChildItem(new CXTPPropertyGridItemCategory(_T("存储块索引表")));
CXTPPropertyGridItem* pCategoryOne = m_PropertyGrid.AddCategory(_T("存储块索引表"));
tmp.Format("0x%08X",FI.fi_zone[0]);
pCategoryOne->AddChildItem(new CPropertyGridItemEx(_T("直接索引块0"), tmp));
tmp.Format("0x%08X",FI.fi_zone[1]);
pCategoryOne->AddChildItem(new CPropertyGridItemEx(_T("直接索引块1"), tmp));
tmp.Format("0x%08X",FI.fi_zone[2]);
pCategoryOne->AddChildItem(new CPropertyGridItemEx(_T("直接索引块2"), tmp));
tmp.Format("0x%08X",FI.fi_zone[3]);
pCategoryOne->AddChildItem(new CPropertyGridItemEx(_T("直接索引块3"), tmp));
tmp.Format("0x%08X",FI.fi_zone[4]);
pCategoryOne->AddChildItem(new CPropertyGridItemEx(_T("直接索引块4"), tmp));
tmp.Format("0x%08X",FI.fi_zone[5]);
pCategoryOne->AddChildItem(new CPropertyGridItemEx(_T("直接索引块5"), tmp));
tmp.Format("0x%08X",FI.fi_zone[6]);
pCategoryOne->AddChildItem(new CPropertyGridItemEx(_T("直接索引块6"), tmp));
tmp.Format("0x%08X",FI.fi_zone[7]);
pCategoryOne->AddChildItem(new CPropertyGridItemEx(_T("一级间接索引块0"), tmp));
tmp.Format("0x%08X",FI.fi_zone[8]);
pCategoryOne->AddChildItem(new CPropertyGridItemEx(_T("一级间接索引块1"), tmp));
tmp.Format("0x%08X",FI.fi_zone[9]);
pCategoryOne->AddChildItem(new CPropertyGridItemEx(_T("二级间接索引块0"), tmp));
pCategoryOne->Expand();
pCategory->Expand();
theFileSys.Close(m_hFile);
return 0;
}
int CFileViewDlg::AddTabViews()
{
if (!m_TabCtrl.InsertItem(0, _T(" 文件控制块 "), m_PropertyGrid.m_hWnd, 0))
{
TRACE0("Failed to create File Control Block. \n");
return -1;
}
if (!m_TabCtrl.InsertItem(1, _T(" ASCII模式 "), m_EditASCII.m_hWnd, 0))
{
TRACE0("Failed to create Edit ASCII. \n");
return -1;
}
if (!m_TabCtrl.InsertItem(2, _T(" HEX模式 "), m_EditHex.m_hWnd, 0))
{
TRACE0("Failed to create Edit Hex. \n");
return -1;
}
CRect rcClient, rcBtn;
GetClientRect(&rcClient);
m_BtnSave.GetWindowRect(&rcBtn);
m_TabCtrl.MoveWindow(0, 0, rcClient.Width(), rcClient.Height()-rcBtn.Height()-4);
return 0;
}
void CFileViewDlg::OnSize(UINT nType, int cx, int cy)
{
CXTResizeDialog::OnSize(nType, cx, cy);
}
void CFileViewDlg::OnBnClickedOk()
{
m_hFile = theFileSys.Open(m_strFilePath, O_RDWR | O_TRUNC, 0);
if ( m_hFile<0 )
{
AfxMessageBox("文件写入失败");
}
else
{
CString tmp;
m_EditASCII.GetWindowText(tmp);
theFileSys.Write(m_hFile, tmp.LockBuffer(), tmp.GetLength());
theFileSys.Close(m_hFile);
}
//CDialog::OnOK();
}
void CFileViewDlg::OnBnClickedCancel()
{
CDialog::OnCancel();
}
void CFileViewDlg::OnOK()
{
// TODO: 在此添加专用代码和/或调用基类
// CDialog::OnOK();
}
void CFileViewDlg::OnCancel()
{
// TODO: 在此添加专用代码和/或调用基类
// CDialog::OnCancel();
}
void CFileViewDlg::OnTcnSelchangeFiledlgTab(NMHDR* /*pNMHDR*/, LRESULT* pResult)
{
TRACE("CFileViewDlg::OnTcnSelchangeFiledlgTab\n");
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -