DecodeBTDlg.cpp
资源名称:DecodeBT.rar [点击查看]
上传用户:likl4521
上传日期:2020-06-11
资源大小:22k
文件大小:4k
源码类别:
网格计算
开发平台:
Visual C++
- // DecodeBTDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "DecodeBT.h"
- #include "DecodeBTDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDecodeBTDlg dialog
- CDecodeBTDlg::CDecodeBTDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CDecodeBTDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDecodeBTDlg)
- m_edit = _T("");
- //}}AFX_DATA_INIT
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CDecodeBTDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDecodeBTDlg)
- DDX_Text(pDX, IDC_EDIT1, m_edit);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDecodeBTDlg, CDialog)
- //{{AFX_MSG_MAP(CDecodeBTDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDecodeBTDlg message handlers
- BOOL CDecodeBTDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- // TODO: Add extra initialization here
- return TRUE; // return TRUE unless you set the focus to a control
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CDecodeBTDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- 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;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- HCURSOR CDecodeBTDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CDecodeBTDlg::OnOK()
- {
- // TODO: Add extra validation here
- CFile file;
- CFileDialog fd(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, "BT种子文件(*.torrent)|*.torrent||");
- if ((fd.DoModal() == IDOK) &&
- file.Open(fd.GetPathName(), CFile::modeRead | CFile::shareDenyNone))
- {
- char *dat;
- DWORD len;
- len = file.GetLength();
- dat = new char[len+10];
- file.ReadHuge(dat, len);
- file.Close();
- strcpy(dat+len, "eeeeeeee");
- m_edit = "";
- Decode(0, 0, dat);
- UpdateData(FALSE);
- delete []dat;
- }
- // CDialog::OnOK();
- }
- BOOL CDecodeBTDlg::Decode(int mode, int level, char *dat)
- {
- #define CRLF {m_edit += "rn"; for (i=level; i-->0; m_edit+="t");}
- static char *s = NULL;
- int i;
- bool j;
- char ch;
- char *p;
- if (dat != NULL)
- s = dat;
- j = true;
- while ((ch = *s++) != 'e')
- {
- switch (ch)
- {
- case 'd': //dictionary
- m_edit += "{";
- level++;
- CRLF;
- Decode(ch, level);
- level--;
- m_edit += "}";
- CRLF;
- break;
- case 'l': //list
- if (mode != 'l') CRLF;
- m_edit += "[";
- level++;
- CRLF;
- Decode(ch, level);
- level--;
- m_edit += "]";
- CRLF;
- break;
- case 'i': //integer
- strtoul(s, &p, 10);
- i = p - s;
- p = new char[i+1];
- strncpy(p, s, i);
- s += i + 1;
- p[i] = ' ';
- m_edit += p;
- delete []p;
- break;
- default: //string
- i = strtoul(s-1, &s, 10);
- s++;
- p = new char[i+1];
- strncpy(p, s, i);
- s += i;
- p[i] = ' ';
- m_edit += p;
- delete []p;
- }
- switch (mode)
- {
- case 'd':
- if (j)
- {
- m_edit += " : ";
- }
- else
- {
- m_edit += "rn";
- i = level;
- if (*s == 'e') i -= 1;
- for (; i-->0; m_edit+="t");
- }
- j = !j;
- break;
- case 'l':
- if (*s == 'e')
- {m_edit += "rn"; for (i=level-1; i-->0; m_edit+="t");}
- break;
- }
- }
- return TRUE;
- }