科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网网络频道用于 Foxmail 的辅助工具 SmartFox

用于 Foxmail 的辅助工具 SmartFox

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

本文旨在介绍 Foxmail 的账号存储机制,并基于此编写一个辅助工具 SmartFox ,实现闪存“随身邮”功能。

作者:巧巧读书 来源:巧巧读书 2008年7月25日

关键字: 电子邮件 SmartFox Foxmail

  • 评论
  • 分享微博
  • 分享邮件

在本页阅读全文(共2页)

  void CSmartFoxDlg::ClearUp()

  {

  if (m_pRootStg != NULL) m_pRootStg->Release();

  if (m_pVer30Stg != NULL) m_pVer30Stg->Release();

  if (m_pStream  != NULL) m_pStream->Release();

  if (m_pBuffer  != NULL)

  {

  IMalloc * pMalloc;

  ::CoGetMalloc(MEMCTX_TASK, &pMalloc);

  pMalloc->Free(m_pBuffer);

  pMalloc->Release();

  }

  ::CoUninitialize();

  OnCancel();

  }

  // All codes below find out driver letter and directories of each account.

  char CSmartFoxDlg::GetDriver()

  {

  char sCurDir[256];

  int ret = ::GetCurrentDirectory(256, sCurDir);

  if (ret == NULL) throw "取当前驱动器盘符时失败";

  else return sCurDir[0];

  }

  IStream * CSmartFoxDlg::GetIStream()

  {

  USES_CONVERSION;

  // Get interface Storage pointer of Accounts.CFG

  IStream * pStream;

  HRESULT  hr;

  hr = ::StgOpenStorage(T2COLE("Accounts.CFG"),

  NULL,

  STGM_READWRITE|STGM_SHARE_EXCLUSIVE,

  NULL,

  0,

  &m_pRootStg);

  if (hr != S_OK) throw "打开Accounts.CFG文件时失败";

  hr = m_pRootStg->OpenStorage(T2COLE("Ver30"),

  NULL,

  STGM_READWRITE|STGM_SHARE_EXCLUSIVE,

  NULL,

  0,

  &m_pVer30Stg);

  if (hr != S_OK) throw "打开Ver30存储时失败";

  hr = m_pVer30Stg->OpenStream(T2COLE("accounts.cfg"),

  NULL,

  STGM_READWRITE|STGM_SHARE_EXCLUSIVE,

  NULL,

  &pStream);

  if (hr != S_OK) throw "打开accounts.cfg流时失败";

  return pStream;

  }

  char * CSmartFoxDlg::GetBuffer(IStream * pStream)

  {

  STATSTG  StatStg;

  IMalloc * pMalloc;

  char *   pBuffer;

  HRESULT  hr;

  hr = pStream->Stat(&StatStg, NULL);

  if (hr != S_OK) throw "读取accounts.cfg流的大小时失败";

  hr = ::CoGetMalloc(MEMCTX_TASK, &pMalloc);

  if (hr != S_OK) throw "获取COM库的IMalloc接口指针时失败";

  pBuffer = (char *)pMalloc->Alloc(ULONG(StatStg.cbSize.QuadPart));

  if (pBuffer == NULL) throw "申请缓冲区时失败";

  pMalloc->Release();

  return pBuffer;

  }

  void CSmartFoxDlg::GetAccountInfo(IStream * pStream, char * pBuffer)

  {

  // I will find out names and directories of each account.

  STATSTG  StatStg;

  ULONG   cbReaded;

  HRESULT  hr;

  char *   p = pBuffer;

  DWORD    cAccount;

  DWORD   len;

  CString  name;  // Gets the name of account.

  CString  path;  // Gets the path of account.

  CString  strEdit;  //Displays text in edit control.

  CEdit *  pEdit = (CEdit *) GetDlgItem(IDC_EDIT);

  strEdit.Format("闪存当前为%c:盘, 现存账号及其目录: \r\n", m_Driver);

  hr = pStream->Stat(&StatStg, NULL);

  if (hr != S_OK) throw "读取accounts.cfg流的大小时失败";

  hr = pStream->Read(pBuffer, ULONG(StatStg.cbSize.QuadPart), &cbReaded);

  if (hr != S_OK) throw "读取accounts.cfg流的内容时失败";

  p += 0x40;

  cAccount = (*p);  //Count of accounts.

  p += 0x4;

  for (DWORD i = 1; i <= cAccount; i++)

  {

  // Value of (*p) is index of account.

  if (DWORD(*p) != i) throw "accounts.cfg流损坏";

  p += 0x4;  //Skips the index number.

  len = DWORD(*p);  //Gets length of name.

  p += 0x4;  //Skips the length number. The string does not include NULL.

  name.Empty();

  path.Empty();

  for (DWORD n = 0; n <len; n++, p++) name += char (*p); // Gets account name.

  len = DWORD(*p); // Gets length of directory.

  p += 4; // Skips the length number.

  m_aryPosition.Add(p-pBuffer); //Stores offset into array.

  for (n = 0; n< len; n++, p++) path += char (*p); //Gets account path.

  strEdit += name+"\t"+path+"\r\n";

  p += 0x18; //Skips 0x18 Nulls.

  }

  pEdit->SetWindowText(strEdit);

  }

  void CSmartFoxDlg::ModifyAccountDriver(IStream *pStream, char * pBuffer)

  {

  STATSTG  StatStg;

  ULONG   cbWrited;

  HRESULT  hr;

  LARGE_INTEGER MovOffset;

  ULARGE_INTEGER NewPosition;

  char *   p;

  for (int i = 0; i< m_aryPosition.GetSize(); i++)

  {

  p = pBuffer + m_aryPosition.GetAt(i);

  (*p) = m_Driver;

  }

  hr = pStream->Stat(&StatStg, NULL);

  if (hr != S_OK) throw "读取accounts.cfg流的大小时失败";

  MovOffset.QuadPart = 0;

  hr = pStream->Seek(MovOffset, 0, &NewPosition);

  if (hr != S_OK) throw "移动accounts.cfg流的读写指针时失败";

  pStream->Write(pBuffer, ULONG(StatStg.cbSize.QuadPart), &cbWrited);

  if (hr != S_OK) throw "向accounts.cfg流写入数据时失败";

  }  编译链接生成 SmartFox.EXE 后,将其拷贝到 Foxmail 在闪存上的安装目录。利用 SmartFox.EXE 运行 Foxmail 就可以实现“随身邮”的功能了!

    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章