acl/samples/FileDir/FileDirDlg.cpp

753 lines
17 KiB
C++
Raw Normal View History

// FileDirDlg.cpp : ʵ<><CAB5><EFBFBD>ļ<EFBFBD>
//
#include "stdafx.h"
#include "lib_acl.h" // ע<>⣺lib_acl.h <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> stdafx.h <20>ĺ<EFBFBD><C4BA><EFBFBD><E6A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:(
#include "stdlib/avl.h"
#include "FileDir.h"
#include "FileDirDlg.h"
#include "ScanDir.h"
#include ".\filedirdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#ifdef WIN32
#define snprintf _snprintf
#endif
#include <direct.h>
#define __S_ISTYPE(mode, mask) (((mode) & _S_IFMT) == (mask))
#ifndef S_ISDIR
# define S_ISDIR(mode) __S_ISTYPE((mode), _S_IFDIR)
#endif
typedef struct MY_TYPE
{
char name[256];
char value[256];
avl_node_t node;
} MY_TYPE;
// <20><><EFBFBD><EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3>򡰹<EFBFBD><F2A1B0B9>ڡ<EFBFBD><DAA1>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD> CAboutDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// <20>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV ֧<><D6A7>
// ʵ<><CAB5>
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CFileDirDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
CFileDirDlg::CFileDirDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFileDirDlg::IDD, pParent)
, m_dirPath(_T(""))
, m_nested(TRUE)
, m_pScan(NULL)
, m_avlName(_T(""))
, m_avlValue(_T(""))
, m_outName(FALSE)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
avl_create(&m_avlTree, compare_fn, sizeof(MY_TYPE), offsetof(MY_TYPE, node));
}
void CFileDirDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_PATH, m_dirPath);
DDX_Check(pDX, IDC_CHECK_NETSTED, m_nested);
DDX_Text(pDX, IDC_EDIT_AVL_NAME, m_avlName);
DDX_Control(pDX, IDC_EDIT_AV_RESULT, m_debugWin);
DDX_Text(pDX, IDC_EDIT_AVL_VALUE, m_avlValue);
DDX_Check(pDX, IDC_CHECK_OUT_NAME, m_outName);
}
BEGIN_MESSAGE_MAP(CFileDirDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_WM_TIMER()
ON_EN_CHANGE(IDC_EDIT_PATH, OnEnChangeEditPath)
ON_BN_CLICKED(IDC_CHECK_NETSTED, OnBnClickedCheckNetsted)
ON_BN_CLICKED(IDC_BUTTON_SCAN, OnBnClickedButtonScan)
ON_BN_CLICKED(IDC_BUTTON_DELETE, OnBnClickedButtonDelete)
ON_BN_CLICKED(IDC_BUTTON_AVL_ADD, OnBnClickedButtonAvlAdd)
ON_BN_CLICKED(IDC_BUTTON_AVL_FIND, OnBnClickedButtonAvlFind)
ON_BN_CLICKED(IDC_BUTTON_WALK, OnBnClickedButtonWalk)
ON_EN_CHANGE(IDC_EDIT_AVL_NAME, OnEnChangeEditAvlName)
ON_BN_CLICKED(IDC_BUTTON_TEST, OnBnClickedButtonTest)
ON_EN_CHANGE(IDC_EDIT_AVL_VALUE, OnEnChangeEditAvlValue)
ON_BN_CLICKED(IDC_BUTTON_AVL_ADD_BAT, OnBnClickedButtonAvlAddBat)
ON_BN_CLICKED(IDC_BUTTON_AVL_DEL, OnBnClickedButtonAvlDel)
ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnBnClickedButtonClear)
ON_BN_CLICKED(IDC_CHECK_OUT_NAME, OnBnClickedCheckOutName)
ON_BN_CLICKED(IDC_SVN_UPDATE, OnBnClickedSvnUpdate)
END_MESSAGE_MAP()
// CFileDirDlg <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BOOL CFileDirDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// <20><>\<5C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...\<5C><><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ϵͳ<CFB5>˵<EFBFBD><CBB5>С<EFBFBD>
// IDM_ABOUTBOX <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD>Χ<EEB7B6>ڡ<EFBFBD>
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// <20><><EFBFBD>ô˶Ի<CBB6><D4BB><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EAA1A3>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>ǶԻ<C7B6><D4BB><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ܽ<EFBFBD><DCBD>Զ<EFBFBD>
// ִ<>д˲<D0B4><CBB2><EFBFBD>
SetIcon(m_hIcon, TRUE); // <20><><EFBFBD>ô<EFBFBD>ͼ<EFBFBD><CDBC>
SetIcon(m_hIcon, FALSE); // <20><><EFBFBD><EFBFBD>Сͼ<D0A1><CDBC>
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CheckDlgButton(IDC_CHECK_NETSTED, BST_CHECKED);
m_debugWin.SetLimitText(81920);
acl_msg_open("svn.log", "svn_update");
return TRUE; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿ؼ<CBBF><D8BC>Ľ<EFBFBD><C4BD><EFBFBD><E3A3AC><EFBFBD>򷵻<EFBFBD> TRUE
}
void CFileDirDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƹ<EFBFBD>ͼ<EFBFBD><EFBFBD><EAA1A3><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>ĵ<EFBFBD>/<2F><>ͼģ<CDBC>͵<EFBFBD> MFC Ӧ<>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>
// <20><EFBFBD>ɿ<EFBFBD><C9BF><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ɡ<EFBFBD>
void CFileDirDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // <20><><EFBFBD>ڻ<EFBFBD><DABB>Ƶ<EFBFBD><C6B5><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// ʹͼ<CAB9><CDBC><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD>
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
//<2F><><EFBFBD>û<EFBFBD><C3BB>϶<EFBFBD><CFB6><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱϵͳ<CFB5><CDB3><EFBFBD>ô˺<C3B4><CBBA><EFBFBD>ȡ<EFBFBD>ù<EFBFBD><C3B9><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>
HCURSOR CFileDirDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
int CFileDirDlg::GetDirPath(void)
{
CString msg;
if (m_dirPath.GetLength() == 0) {
MessageBox(_T("Please input the dir path ..."), _T("Error"));
return (-1);
}
struct stat sbuf;
if (stat(m_dirPath.GetString(), &sbuf) < 0) {
msg.Format("%s no exist!", m_dirPath.GetString());
MessageBox(msg, "Error");
return (-1);
} else if (!S_ISDIR(sbuf.st_mode)) {
msg.Format("%s is not a directory!", m_dirPath.GetString());
MessageBox(msg, "Error");
return (-1);
}
return 0;
}
void CFileDirDlg::OnTimer(UINT nIDEvent)
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
CDialog::OnTimer(nIDEvent);
ScanDir();
}
void CFileDirDlg::OnEnChangeEditPath()
{
// TODO: <20><><EFBFBD><EFBFBD><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD> RICHEDIT <20>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD>͸<EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д CDialog::OnInitDialog()
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CRichEditCtrl().SetEventMask()<29><>
// ͬʱ<CDAC><CAB1> ENM_CHANGE <20><>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B5BD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UpdateData(TRUE);
}
int CFileDirDlg::ScanCallback(ACL_SCAN_DIR * scan, void * ctx)
{
CFileDirDlg *pfdd = (CFileDirDlg *) ctx;
const char *ptr;
if (pfdd->m_outName) {
ptr = acl_scan_dir_file(scan);
if (ptr && *ptr) {
CString msg;
struct acl_stat sbuf;
acl_scan_stat(scan, &sbuf);
msg.Format(">>>file(%s), size=%I64d\r\n", ptr,
(acl_int64) sbuf.st_size);
pfdd->DebugWinAppend(msg);
}
}
if ((acl_scan_dir_nfiles(pfdd->m_pScan)
+ acl_scan_dir_ndirs(pfdd->m_pScan)) % 100 == 0) {
pfdd->UpdateInfo();
pfdd->SetTimer(TIMER_EVENT_USER_100, 10, NULL);
return (-1); // <20><>ʱֹͣɨ<D6B9><C9A8>
}
return 0;
}
void CFileDirDlg::ScanDir(void)
{
if (acl_scan_dir_end(m_pScan)) {
ScanClose();
return;
}
if (acl_scan_dir_size2(m_pScan) < 0) {
ScanClose();
return;
}
UpdateInfo();
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>Ϣ
void CFileDirDlg::UpdateInfo(void)
{
if (m_pScan == NULL)
return;
CString msg;
msg.Format(_T("%I64u MB"), acl_scan_dir_nsize(m_pScan) / MB);
GetDlgItem(IDC_EDIT_SIZE)->SetWindowText(msg);
msg.Format(_T("%d <20><>"), acl_scan_dir_nfiles(m_pScan));
GetDlgItem(IDC_EDIT_NFILE)->SetWindowText(msg);
msg.Format(_T("%d <20><>"), acl_scan_dir_ndirs(m_pScan));
GetDlgItem(IDC_EDIT_NDIR)->SetWindowText(msg);
}
void CFileDirDlg::ScanClose(void)
{
KillTimer(TIMER_EVENT_USER_100);
UpdateInfo();
acl_scan_dir_close(m_pScan); // <20>ر<EFBFBD>ɨ<EFBFBD><C9A8>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>
m_pScan = NULL;
}
void CFileDirDlg::OnBnClickedCheckNetsted()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UpdateData(TRUE);
}
void CFileDirDlg::OnBnClickedButtonScan()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CString msg;
if (GetDirPath() < 0)
return;
m_pScan = acl_scan_dir_open(m_dirPath.GetString(), m_nested);
if (m_pScan == NULL) {
msg.Format("open dir %s error", m_dirPath.GetString());
MessageBox(msg, "Error");
return;
}
// <20><><EFBFBD>ûص<C3BB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
acl_scan_dir_ctl(m_pScan, ACL_SCAN_CTL_FN, this->ScanCallback,
ACL_SCAN_CTL_CTX, this, ACL_SCAN_CTL_END);
ScanDir();
}
void CFileDirDlg::OnBnClickedButtonDelete()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CString msg;
if (GetDirPath() < 0)
return;
msg.Format("Are you sure to delete %s ?", m_dirPath.GetString());
if (MessageBox(msg, "Warning", MB_YESNO) != IDYES)
return;
CScanDir scan(m_dirPath.GetString(), m_nested);
if (scan.BeginRemove() < 0) {
msg.Format("%s remove error", m_dirPath.GetString());
MessageBox(msg, "Error");
return;
}
__int64 size = scan.TotalSize();
msg.Format(_T("%I64u MB"), size / MB);
GetDlgItem(IDC_EDIT_SIZE)->SetWindowText(msg);
int n = scan.FileCount();
msg.Format(_T("%d <20><>"), n);
GetDlgItem(IDC_EDIT_NFILE)->SetWindowText(msg);
n = scan.DirCount();
msg.Format(_T("%d <20><>"), n);
GetDlgItem(IDC_EDIT_NDIR)->SetWindowText(msg);
}
void CFileDirDlg::OnBnClickedButtonAvlAdd()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MY_TYPE *pm, m;
if (m_avlName.GetLength() == 0) {
MessageBox("Please input searching name!", "error");
GetDlgItem(IDC_EDIT_AVL_NAME)->SetFocus();
return;
}
if (m_avlValue.GetLength() == 0) {
MessageBox("Please input value!", "error");
GetDlgItem(IDC_EDIT_AVL_VALUE)->SetFocus();
return;
}
snprintf(m.name, sizeof(m.name), "%s", m_avlName.GetString());
pm = (MY_TYPE*) avl_find(&m_avlTree, &m, NULL);
if (pm != NULL) {
CString msg;
msg.Format("key(%s) already exist, which value is %s",
m_avlName.GetString(), pm->value);
MessageBox(msg, "error");
return;
}
pm = (MY_TYPE*) acl_mycalloc(1, sizeof(MY_TYPE));
snprintf(pm->name, sizeof(pm->name), "%s", m_avlName.GetString());
snprintf(pm->value, sizeof(pm->value), "%s", m_avlValue.GetString());
avl_add(&m_avlTree, pm);
MessageBox("Add ok!", "ok");
// m_avlName.Empty();
m_avlValue.Empty();
UpdateData(FALSE);
}
void CFileDirDlg::OnBnClickedButtonAvlFind()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MY_TYPE m, *ptr;
CString msg;
if (m_avlName.GetLength() == 0) {
MessageBox("Please input searching name", "error");
GetDlgItem(IDC_EDIT_AVL_NAME)->SetFocus();
return;
}
snprintf(m.name, sizeof(m.name), m_avlName.GetString());
ptr = (MY_TYPE*) avl_find(&m_avlTree, &m, NULL);
if (ptr) {
m_avlValue.Format("%s", ptr->value);
} else {
m_avlValue.Empty();
msg.Format("not find it, name=%s", m.name);
MessageBox(msg);
}
UpdateData(FALSE);
}
int CFileDirDlg::compare_fn(const void* v1, const void* v2)
{
MY_TYPE *m1 = (MY_TYPE*) v1, *m2 = (MY_TYPE*) v2;
return (strcmp(m1->name, m2->name));
}
void CFileDirDlg::OnBnClickedButtonWalk()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MY_TYPE *next;
CString msg;
int n = 0;
next = (MY_TYPE*) avl_first(&m_avlTree);
while (next) {
msg.Format(">>name(%s), value(%s)\r\n", next->name, next->value);
DebugWinAppend(msg);
next = (MY_TYPE*) AVL_NEXT(&m_avlTree, next);
n++;
}
msg.Format(">>ok, total count is %d\r\n", n);
DebugWinAppend(msg);
}
void CFileDirDlg::OnEnChangeEditAvlName()
{
// TODO: <20><><EFBFBD><EFBFBD><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD> RICHEDIT <20>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD>͸<EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д CDialog::OnInitDialog()
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CRichEditCtrl().SetEventMask()<29><>
// ͬʱ<CDAC><CAB1> ENM_CHANGE <20><>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B5BD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UpdateData(TRUE);
}
void CFileDirDlg::OnBnClickedButtonTest()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
avl_node_t *node = (avl_node_t*) acl_mycalloc(1, sizeof(avl_node_t)), *pnode;
avl_index_t where;
where = AVL_MKINDEX(node, 1);
pnode = AVL_INDEX2NODE(where);
CString msg;
msg.Format("addr=%x, %x, %d", pnode, node, pnode);
if (pnode == node) {
MessageBox("ok, ==");
MessageBox(msg);
} else {
MessageBox("no");
}
}
void CFileDirDlg::OnEnChangeEditAvlValue()
{
// TODO: <20><><EFBFBD><EFBFBD><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD> RICHEDIT <20>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD>͸<EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д CDialog::OnInitDialog()
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CRichEditCtrl().SetEventMask()<29><>
// ͬʱ<CDAC><CAB1> ENM_CHANGE <20><>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B5BD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UpdateData(TRUE);
}
void CFileDirDlg::OnBnClickedButtonAvlAddBat()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MY_TYPE *pm, m;
int i, n = 0;
CString msg;
for (i = 0; i < 100; i++) {
snprintf(m.name, sizeof(m.name), "%d", i);
pm = (MY_TYPE*) avl_find(&m_avlTree, &m, NULL);
if (pm != NULL) {
msg.Format(">>key(%s) already exist, value(%s)\r\n",
pm->name, pm->value);
DebugWinAppend(msg);
continue;
}
pm = (MY_TYPE*) acl_mycalloc(1, sizeof(MY_TYPE));
snprintf(pm->name, sizeof(pm->name), "%d", i);
snprintf(pm->value, sizeof(pm->value), "value(%d)", i);
avl_add(&m_avlTree, pm);
msg.Format(">>add one, key(%s), value(%s)\r\n", pm->name, pm->value);
DebugWinAppend(msg);
n++;
}
msg.Format(">>ok, %d records were added\r\n", n);
DebugWinAppend(msg);
}
void CFileDirDlg::OnBnClickedButtonAvlDel()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MY_TYPE m, *pm;
if (m_avlName.GetLength() == 0) {
MessageBox("Please input searching name!", "error");
GetDlgItem(IDC_EDIT_AVL_NAME)->SetFocus();
return;
}
snprintf(m.name, sizeof(m.name), "%s", m_avlName.GetString());
pm = (MY_TYPE*) avl_find(&m_avlTree, &m, NULL);
if (!pm) {
MessageBox("not find", "ok");
} else {
avl_remove(&m_avlTree, pm);
MessageBox("Delete ok!", "ok");
}
m_avlName.Empty();
m_avlValue.Empty();
UpdateData(FALSE);
}
void CFileDirDlg::OnBnClickedButtonClear()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_avlName.Empty();
m_avlValue.Empty();
UpdateData(FALSE);
m_debugWin.SetSel(0, m_debugWin.GetWindowTextLength());
m_debugWin.ReplaceSel("");
}
void CFileDirDlg::DebugWinAppend(CString& msg)
{
m_debugWin.SetSel(m_debugWin.GetWindowTextLength(),
m_debugWin.GetWindowTextLength());
m_debugWin.ReplaceSel(msg.GetString());
}
void CFileDirDlg::OnBnClickedCheckOutName()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UpdateData(TRUE);
}
void CFileDirDlg::OnBnClickedSvnUpdate()
{
// TODO: <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ӿؼ<D3BF>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CString msg;
if (GetDirPath() < 0)
return;
m_pScan = acl_scan_dir_open(m_dirPath.GetString(), m_nested);
if (m_pScan == NULL) {
msg.Format("open dir %s error", m_dirPath.GetString());
MessageBox(msg, "Error");
return;
}
// <20><><EFBFBD>ûص<C3BB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
acl_scan_dir_ctl(m_pScan, ACL_SCAN_CTL_FN, ScanSvnCallback,
ACL_SCAN_CTL_CTX, this, ACL_SCAN_CTL_END);
ScanSvnDir();
}
int CFileDirDlg::ScanSvnCallback(ACL_SCAN_DIR * scan, void * ctx)
{
CFileDirDlg *pfdd = (CFileDirDlg *) ctx;
if ((acl_scan_dir_nfiles(pfdd->m_pScan)
+ acl_scan_dir_ndirs(pfdd->m_pScan)) % 100 == 0)
{
pfdd->UpdateInfo();
pfdd->SetTimer(TIMER_EVENT_USER_100, 10, NULL);
return (-1); // <20><>ʱֹͣɨ<D6B9><C9A8>
}
if (!pfdd->m_outName)
return 0;
const char* filename = acl_scan_dir_file(scan);
const char* path = acl_scan_dir_path(scan);
if (!filename || strcasecmp(filename, "entries") || !path)
return 0;
CString filepath;
filepath.Format("%s/%s", path, filename);
if (acl_strrncasecmp(filepath.GetString(),
".svn/entries", sizeof(".svn/entries") - 1) != 0)
{
return 0;
}
CString msg;
struct acl_stat sbuf;
acl_assert(path);
acl_scan_stat(scan, &sbuf);
msg.Format(">>>file(%s/%s), size=%I64d\r\n",
path, filename, (acl_int64) sbuf.st_size);
pfdd->DebugWinAppend(msg);
return 0;
}
void CFileDirDlg::ScanSvnDir(void)
{
if (acl_scan_dir_end(m_pScan)) {
ScanClose();
return;
}
if (acl_scan_dir_size2(m_pScan) < 0) {
ScanClose();
return;
}
UpdateInfo();
}
BOOL CFileDirDlg::UpdateSvn(const char* filepath)
{
ssize_t file_size;
char* buf = acl_vstream_loadfile2(filepath, &file_size);
if (buf == NULL)
{
acl_msg_error("loadfile(%s) error(%s)",
filepath, acl_last_serror());
return FALSE;
}
ACL_VSTREAM* fp = acl_vstream_fopen(filepath,
O_WRONLY | O_BINARY | O_TRUNC, 0700, 4096);
if (fp == NULL)
{
acl_myfree(buf);
acl_msg_error("fopen(%s) error(%s)",
filepath, acl_last_serror());
return FALSE;
}
ACL_VSTRING* vbuf = acl_vstring_alloc(2048);
const char* ptr = buf;
const char* old_svn = "svn://192.168.1.231";
size_t old_npre = strlen(old_svn);
const char* new_svn = "svn://122.49.0.188";
size_t new_npre = strlen(new_svn);
#define STR acl_vstring_str
#define LEN ACL_VSTRING_LEN
int i = 0;
while (TRUE)
{
// ֻ<><D6BB>Ҫ<EFBFBD>޸<EFBFBD>ǰ 10 <20><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>
if (i++ > 10)
break;
// <20>ӻ<EFBFBD><D3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
const ACL_VSTRING* vp = acl_buffer_gets(vbuf, &ptr, strlen(ptr));
if (vp == NULL)
break;
// <20>Ƚ<EFBFBD>ǰ׺<C7B0>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
if (strncasecmp(old_svn, STR(vp), old_npre) != 0)
{
if (acl_vstream_writen(fp, STR(vp), LEN(vp)) == ACL_VSTREAM_EOF)
{
acl_msg_error("%s(%d): write error(%s)",
__FUNCTION__, __LINE__,
acl_last_serror());
goto end;
}
ACL_VSTRING_RESET(vbuf);
continue;
}
// д<><D0B4><EFBFBD>µ<EFBFBD>ǰ׺
if (acl_vstream_writen(fp, new_svn, new_npre) == ACL_VSTREAM_EOF)
{
acl_msg_error("%s(%d): write error(%s)",
__FUNCTION__, __LINE__, acl_last_serror());
goto end;
}
const char* pleft = STR(vp) + old_npre;
if (*pleft == 0)
{
ACL_VSTRING_RESET(vbuf);
continue;
}
// д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>ಿ<EFBFBD><E0B2BF>
if (acl_vstream_writen(fp, pleft, strlen(pleft)) == ACL_VSTREAM_EOF)
{
acl_msg_error("%s(%d): write error(%s)",
__FUNCTION__, __LINE__, acl_last_serror());
goto end;
}
ACL_VSTRING_RESET(vbuf);
}
ssize_t nleft = (ssize_t) (file_size - (ptr - buf));
if (*ptr && nleft > 0)
{
if (acl_vstream_writen(fp, ptr, nleft) == ACL_VSTREAM_EOF)
acl_msg_error("%s(%d): write nleft(%d) error(%s)",
__FUNCTION__, __LINE__,
(int) nleft, acl_last_serror());
}
end:
acl_vstring_free(vbuf);
acl_vstream_fclose(fp);
acl_myfree(buf);
return TRUE;
}