Click here to Skip to main content
15,894,460 members
Articles / Programming Languages / C++

Debug Toolkit

Rate me:
Please Sign up or sign in to vote.
4.20/5 (5 votes)
27 Mar 2000 180.7K   1.5K   88  
A complete debug toolkit to add intelligent debugging capability to your application.
//
// Please do not customise this code
//
// Portions (c) Keith Westley 2000

#ifndef FILEINFO_H
#define FILEINFO_H

class CFileInfo : public CObject
{
protected:

   CString _sFile;
   BY_HANDLE_FILE_INFORMATION _fileInformation;
   BOOL _fFileInformationValid;
   BOOL _fFileExists;
   CString _sPathName;
   void*   _pVersion;
   HMODULE _hModule;

public:

   CFileInfo(const CString& sFileName);
   virtual ~CFileInfo(void)
   {
      if (_pVersion != NULL)
      {
         free(_pVersion);
      }
   }
   BOOL Exists(void) const
   {
      return _fFileExists;
   }

   static CString GetHeadings(void)
   {
      CString sRC;
      
      sRC = "File,Created,Modified,Version,Size,FullName,HModule";

      return sRC;
   }

   CString GetFileDetails(void) const
   {
      CString sRC;

      CString sSize;
      sSize.Format("%lu", Size());

      sRC = _sFile + "," + Created().Format("%d/%m/%Y %H:%M:%S") +
                     "," + LastModified().Format("%d/%m/%Y %H:%M:%S") +
                     "," + Version() +
                     "," + sSize + 
                     "," + FullFileName() +
                     "," + HModuleS();

      return sRC;
   }
   
   CTime LastModified(void) const
   {
      CTime timeRC;

      if (_fFileInformationValid)
      {
         CTime time(_fileInformation.ftLastWriteTime);
         timeRC = time;
      }

      return timeRC;
   }
   CTime LastAccessed(void) const
   {
      CTime timeRC;

      if (_fFileInformationValid)
      {
         CTime time(_fileInformation.ftLastAccessTime);
         timeRC = time;
      }

      return timeRC;
   }
   CTime Created(void) const
   {
      CTime timeRC;

      if (_fFileInformationValid)
      {
         CTime time(_fileInformation.ftCreationTime);
         timeRC = time;
      }

      return timeRC;
   }
   CString HModuleS(void) const
   {
      CString s;

      s.Format("%lx", _hModule);
      
      return s;
   }
   HMODULE HModuleH(void) const
   {
      return _hModule;
   }
   CString Version(void) const;
   DWORDLONG VersionDL(void) const;
   DWORDLONG SizeDWL(void) const
   {        
      DWORDLONG dwlRC = 0;

      if (_fFileInformationValid)
      {
         dwlRC = _fileInformation.nFileSizeHigh;
         (dwlRC << 32);
         dwlRC = dwlRC + _fileInformation.nFileSizeLow;
      }

      return dwlRC;
   }
   DWORD Size(void) const;
   CString Directory(void) const
   {
      CString sRC;

      if (_fFileExists)
      {
         char drive[_MAX_DRIVE];
         char dir[_MAX_DIR];
         char fname[_MAX_FNAME];
         char ext[_MAX_EXT];

         _splitpath(_sPathName, drive, dir, fname, ext);

         sRC = dir; 
      }

      return sRC;
   }
   CString Extension(void) const
   {
      CString sRC;

      if (_fFileExists)
      {
         char drive[_MAX_DRIVE];
         char dir[_MAX_DIR];
         char fname[_MAX_FNAME];
         char ext[_MAX_EXT];

         _splitpath(_sPathName, drive, dir, fname, ext);

         sRC = ext; 
      }

      return sRC;
   }
   CString BaseFileName(void) const
   {
      CString sRC;

      if (_fFileExists)
      {
         char drive[_MAX_DRIVE];
         char dir[_MAX_DIR];
         char fname[_MAX_FNAME];
         char ext[_MAX_EXT];

         _splitpath(_sPathName, drive, dir, fname, ext);

         sRC = fname; 
      }

      return sRC;
   }
   CString Drive(void) const
   {
      CString sRC;

      if (_fFileExists)
      {
         char drive[_MAX_DRIVE];
         char dir[_MAX_DIR];
         char fname[_MAX_FNAME];
         char ext[_MAX_EXT];

         _splitpath(_sPathName, drive, dir, fname, ext);

         sRC = drive; 
      }

      return sRC;
   }
   DWORD Attributes(void) const
   {
      if (_fFileInformationValid)
      {
         return _fileInformation.dwFileAttributes;
      }
      else
      {
         return 0;
      }
   }
   CString FullFileName(void) const
   {
      CString sRC;

      if (_fFileExists)
      {
         sRC = _sPathName;
      }

      return sRC;
   }
};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions