|
/***************************************************************************/
/* NOTE: */
/* This document is copyright (c) by Oz Solomonovich, and is bound by the */
/* MIT open source license (www.opensource.org/licenses/mit-license.html). */
/* See License.txt for more information. */
/***************************************************************************/
// FileInfoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "wtsdk_samp.h"
#include "FileInfoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFileInfoDlg dialog
//avoid hardcoding, following the MS docs here
#define WT_GET_FILE_ATTRIBUTES_ERROR 0xFFFFFFFF
#define WT_FILE_ATTR_STRING_FORMAT "[%s%s%s%s]"
#define WT_FILE_ATTR_TXT_NONE "-"
#define WT_FILE_ATTR_TXT_READONLY "r"
#define WT_FILE_ATTR_TXT_ARCHIVE "a"
#define WT_FILE_ATTR_TXT_HIDDEN "h"
#define WT_FILE_ATTR_TXT_SYSTEM "s"
// format an attribute string for a specified file (i.e. [-a--])
// function courtesy of Jerzy Kaczorowski [kaczoroj@hotmail.com]
BOOL FormatAttributesString(CString &oAttributesString, LPCTSTR lpszFileName)
{
BOOL bRes = FALSE;
DWORD dwFileAttributes;
dwFileAttributes = GetFileAttributes(lpszFileName);
if( dwFileAttributes != WT_GET_FILE_ATTRIBUTES_ERROR )
{
oAttributesString.Format( WT_FILE_ATTR_STRING_FORMAT,
dwFileAttributes & FILE_ATTRIBUTE_READONLY ? WT_FILE_ATTR_TXT_READONLY : WT_FILE_ATTR_TXT_NONE,
dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE ? WT_FILE_ATTR_TXT_ARCHIVE : WT_FILE_ATTR_TXT_NONE,
dwFileAttributes & FILE_ATTRIBUTE_HIDDEN ? WT_FILE_ATTR_TXT_HIDDEN : WT_FILE_ATTR_TXT_NONE,
dwFileAttributes & FILE_ATTRIBUTE_SYSTEM ? WT_FILE_ATTR_TXT_SYSTEM : WT_FILE_ATTR_TXT_NONE );
bRes = TRUE;
}
return bRes;
}
#define TIME_FMT "%c"
CFileInfoDlg::CFileInfoDlg(const char *pszFileName, CWnd* pParent /*=NULL*/)
: CDialog(CFileInfoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFileInfoDlg)
m_sFileName = _T("Unavailable");
m_sAttribs = _T("Unavailable");
m_sSize = _T("Unavailable");
m_sTimeAccess = _T("Unavailable");
m_sTimeCreate = _T("Unavailable");
m_sTimeWrite = _T("Unavailable");
//}}AFX_DATA_INIT
TRY
{
char buf[2048];
CFile file(pszFileName, CFile::modeRead);
_fullpath(buf, pszFileName, sizeof(buf));
m_sFileName = buf;
FILETIME m, a, c;
GetFileTime((HANDLE)(HFILE)file, &c, &a, &m);
m_sTimeWrite = CTime(m).Format(TIME_FMT);
m_sTimeAccess = CTime(a).Format(TIME_FMT);
m_sTimeCreate = CTime(c).Format(TIME_FMT);
m_sSize.Format("%d", GetFileSize((HANDLE)(HFILE)file, NULL));
FormatAttributesString(m_sAttribs, pszFileName);
}
CATCH(CException, e)
{
}
END_CATCH
}
void CFileInfoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileInfoDlg)
DDX_Text(pDX, IDC_FULL_FILE_NAME, m_sFileName);
DDX_Text(pDX, IDC_STATIC_ATTRIBS, m_sAttribs);
DDX_Text(pDX, IDC_STATIC_SIZE, m_sSize);
DDX_Text(pDX, IDC_STATIC_TIME_ACCESS, m_sTimeAccess);
DDX_Text(pDX, IDC_STATIC_TIME_CREATE, m_sTimeCreate);
DDX_Text(pDX, IDC_STATIC_TIME_WRITE, m_sTimeWrite);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFileInfoDlg, CDialog)
//{{AFX_MSG_MAP(CFileInfoDlg)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileInfoDlg message handlers
|
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.