zoukankan      html  css  js  c++  java
  • 启程光盘助手_演示代码


    typedef struct SciFileHeader
    {
        long lType;
        char strBuffer[52];
        long nDiskSize;
        long nFileNum;
        long nFolderNum;
        long nCommentStartAddr;
        long nCommentLen;
        long nCommentEndAddr;
        long nCoverLen;   
    }SciFileHeader;

    typedef struct SciBlockInfo
    {
        long ChildItemAddr;
        long NextItemAddr;
        long filenamelength;
        long filetype;
        long info4;
        long filelength;
        FILETIME filetime;
    }SciBlockInfo;

    typedef struct TreeItem
    {
        TreeItem* lpChildItem;
        TreeItem* lpNextItem;
        long filenamelength;
        long filetype;
        long info4;
        long filelength;
        SYSTEMTIME filetime;
        char strFileName[MAX_PATH];
    }TreeItem;

    void DeleteItem(TreeItem* lpItem);
    TreeItem* NewItem();
    TreeItem* ParseFile(HANDLE hFile);


    void CTestMfcDlg::OnOK()
    {
        DWORD nRead;
        HANDLE hFile = NULL;
        CString m_strFileName;
        HTREEITEM hRoot = NULL;
        TreeItem *lpTemp = NULL;
        SciFileHeader stFileHead;

        m_stEditCtrl.GetWindowText(m_strFileName);

        if (m_strFileName.IsEmpty())
            return;
        if (m_strFileName.GetLength() <= 0)
            return;

        if (GetFileAttributes(m_strFileName) == 0xffffffff)
            return;

        hFile = CreateFile(m_strFileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
        if (INVALID_HANDLE_VALUE == hFile)
            return;

        if (!ReadFile(hFile,&stFileHead,sizeof(SciFileHeader),&nRead,NULL))
            goto Exit;

        if (nRead != sizeof(SciFileHeader))
            goto Exit;

        if (stFileHead.lType != 0x46494353)
            goto Exit;

        //解析文件
        lpTemp = ParseFile(hFile);
        if (lpTemp == NULL)
            goto Exit;
        CloseHandle(hFile);

        m_strFileName.Format("%s | %d | %d | %d",stFileHead.strBuffer,stFileHead.nDiskSize,
                                                 stFileHead.nFolderNum,stFileHead.nFileNum);

        //插入树中
        hRoot = m_stTreeCtrl.InsertItem(m_strFileName);
        if (hRoot == NULL)
        {
            DeleteItem(lpTemp);
            return;
        }

        InsertTreeItem(lpTemp,hRoot);
        DeleteItem(lpTemp);
        return;

    Exit:
        CloseHandle(hFile);
     // TODO: Add extra validation here
    }


    TreeItem* ParseFile(HANDLE hFile)
    {
        DWORD nRead;
        TreeItem* lpTemp;
        char strBuffer[MAX_PATH];
        SciBlockInfo stBlockInfo;

        if (hFile == NULL)
            return NULL;

        lpTemp = NULL;

        ZeroMemory(&stBlockInfo,sizeof(SciBlockInfo));

        //读取数据
        if (!ReadFile(hFile,&stBlockInfo,sizeof(SciBlockInfo),&nRead,NULL))
            return NULL;

        //判断读取是否正确
        if (nRead != sizeof(SciBlockInfo))
            return NULL;

        //校验文件长度是否正确
        if (stBlockInfo.filenamelength >= MAX_PATH)
            return NULL;

        //读取文件名
        if (!ReadFile(hFile,strBuffer,stBlockInfo.filenamelength,&nRead,NULL))
            return NULL;

        //判断读取是否正确
        if (nRead != stBlockInfo.filenamelength)
            return NULL;
       
        strBuffer[stBlockInfo.filenamelength] = '';

        //OK可以赋值了
        lpTemp = NewItem();
        if (lpTemp == NULL)
            return NULL;

        lpTemp->filenamelength = stBlockInfo.filenamelength;
        lpTemp->filetype       = stBlockInfo.filetype;
        lpTemp->info4          = stBlockInfo.info4;
        lpTemp->filelength     = stBlockInfo.filelength;

        CopyMemory(lpTemp->strFileName,strBuffer,MAX_PATH);

        FileTimeToSystemTime(&(stBlockInfo.filetime),&(lpTemp->filetime));

        if (stBlockInfo.ChildItemAddr != -1)
            lpTemp->lpChildItem = ParseFile(hFile);
       
        if (stBlockInfo.NextItemAddr != -1)
            lpTemp->lpNextItem = ParseFile(hFile);

        return lpTemp;
    }

  • 相关阅读:
    WPF 关于拖拽打开文件的注意事项
    asp.net core 3.1中对Mongodb BsonDocument的序列化和反序列化支持
    用百度webuploader分片上传大文件
    多线程学习笔记
    web.config数据库连接字符串加密
    Visual Studio 2010 常用快捷方式
    Team Foundation Server 2013 日常使用使用手册(四)分支与合并
    Team Foundation Server 2013 日常使用使用手册(三)上传新工程、创建任务、创建bug、设置预警
    Team Foundation Server 2013 日常使用使用手册(二)修改、签入、撤销、回滚、对比代码变更
    Team Foundation Server 2013 日常使用使用手册(一)-本地连接TFS、查看任务
  • 原文地址:https://www.cnblogs.com/eaglexmw/p/3680981.html
Copyright © 2011-2022 走看看