// AllPages.cpp : implementation file
//
#include "stdafx.h"
#include "SCMTool.h"
#include "AllPages.h"
#include "TreeReport.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAllPages
IMPLEMENT_DYNAMIC(CAllPages, CPropertySheet)
CAllPages::CAllPages(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
m_hIcon = AfxGetApp()->LoadIcon(IDI_SCMICON);
m_psh.dwFlags |= PSP_USEHICON;
m_psh.hIcon = m_hIcon; //set icon.
AddPage(&m_label); //add the setting folder.
AddPage(&m_labreport);
AddPage(&m_report);
AddPage(&m_treereport);
// AddPage(&m_ConfCtrl);
}
CAllPages::CAllPages(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
m_hIcon = AfxGetApp()->LoadIcon(IDI_SCMICON);
m_psh.dwFlags |= PSP_USEHICON;
m_psh.hIcon = m_hIcon; //set icon.
AddPage(&m_label); //add the setting folder.
AddPage(&m_labreport);
AddPage(&m_report);
AddPage(&m_treereport);
// AddPage(&m_ConfCtrl);
}
CAllPages::~CAllPages()
{
}
BEGIN_MESSAGE_MAP(CAllPages, CPropertySheet)
//{{AFX_MSG_MAP(CAllPages)
ON_WM_CREATE()
ON_WM_HELPINFO()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAllPages message handlers
int CAllPages::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
ModifyStyle(0, WS_MINIMIZEBOX, 0);
ModifyStyle(0, WS_MAXIMIZEBOX, 0);
return 0;
}
void CAllPages::WinHelp(DWORD dwData, UINT nCmd)
{
// TODO: Add your specialized code here and/or call the base class
CString Command=_T("");
Command += Cmd() + _T(" /c NSCMUserGuide.Doc");
CSCMToolApp::RunProcess(Command,1,NULL,_T("."));
// CPropertySheet::WinHelp(dwData, nCmd);
}
BOOL CAllPages::OnHelpInfo(HELPINFO* pHelpInfo)
{
// TODO: Add your message handler code here and/or call default
CString Command=_T("");
Command += Cmd() + _T(" /c NSCMUserGuide.Doc");
CSCMToolApp::RunProcess(Command,1,NULL,_T("."));
// return CPropertySheet::OnHelpInfo(pHelpInfo);
return (TRUE);
}
CString CAllPages::GetDate()
{
CString date;
time_t osBinaryTime; // C run-time time (defined in <time.h>)
time( &osBinaryTime ) ; // Get the current time from the operating system.
CTime t( osBinaryTime ); // CTime from C run-time time
int day = t.GetDay();
int month = t.GetMonth();
int year = t.GetYear();
if((month<10)&&(day<10)) date.Format(_T("%d0%d0%d"),year,month,day);
else if(month<10) date.Format(_T("%d0%d%d"),year,month,day);
else if(day<10) date.Format(_T("%d%d0%d"),year,month,day);
else if((month>=10)&&(day>=10)) date.Format(_T("%d%d%d"),year,month,day);
return date;
}
int CAllPages::ConvertFileIntoString(TCHAR *pFileName,CString *Buf,int undernscm)
{
#ifdef _UNICODE
CFile FileName;
CFileException e;
DWORD Length;
UINT nBytesRead;
CString Path = GetCurDir() + pFileName;
if( !FileName.Open( Path, CFile::modeRead, &e ) )
{
TRACE(_T("sorry, can't open file %s ,error=%u\n"),pFileName,e.m_cause);
return(0);
}
Length = FileName.GetLength();
char* CharBuff = new char[ Length+1 ];
nBytesRead = FileName.Read( CharBuff,(UINT)Length );
CharBuff[ nBytesRead ] = '\0';
/* if ( Length >= 2 )
{
if ( '\n' == CharBuff[ Length - 1 ] )
CharBuff[ Length - 1 ] = '\0';
if ( '\r' == CharBuff[ Length - 2 ] )
CharBuff[ Length - 2 ] = '\0';
}
*/ TCHAR* UnicodeBuff = new TCHAR[ Length+1 ];
MultiByteToWideChar( CP_ACP, 0, CharBuff, Length, UnicodeBuff, Length+1 );
if ( CharBuff )
delete [] CharBuff;
*Buf += UnicodeBuff;
*Buf = Buf->Left(Length);
if ( UnicodeBuff )
delete [] UnicodeBuff;
FileName.Close();
return(1);
#else
CFile FileName;
CFileException e;
DWORD Length;
UINT nBytesRead;
CString Path=_T("");
if (undernscm)
Path = GetCurMFCDir() + pFileName;
else
Path = pFileName;
pFileName = Path.GetBuffer(0);
if( !FileName.Open( pFileName, CFile::modeRead, &e ) )
{
TRACE(_T("sorry, can't open file %s ,error=%u\n"),pFileName,e.m_cause);
return(0);
}
Length = FileName.GetLength();
nBytesRead = FileName.Read((void *) Buf->GetBufferSetLength((int)Length ),(UINT)Length);
FileName.Close();
return(1);
#endif
}
void CAllPages::AddStringToList(CListBox *icontrol,CString Buf)
{
int i=0;
CString Line;
while (i > -1)
{
i = Buf.Find(_T("\n"));
if (i == -1) break;
Line = Buf.Left(i);
Line.TrimRight();
icontrol->AddString(Line);
Buf=Buf.Mid(i+1);
Line.Empty();
}
}
void CAllPages::AddStringToCombo(CComboBox *icontrol,CString Buf)
{
int i=0;
CString Line;
while (i > -1)
{
i = Buf.Find(_T("\n"));
if (i == -1) break;
Line = Buf.Left(i);
Line.TrimRight();
icontrol->AddString(Line);
Buf=Buf.Mid(i+1);
Line.Empty();
}
}
CString CAllPages::ReplaceAll(CString string,CString replaced, CString newchar)
{
int index,len;
CString str1, str2;
while(-1<(index = string.Find(replaced)))
{
str1 = string.Left(index);
len = replaced.GetLength();
str2 = string.Mid(index+len);
string = str1 + newchar + str2;
}
return(string);
}
CString CAllPages::GetChangeList(CListBox *icontrol)
{
int Count,*data;
CString changlst,list;
if(Count = icontrol->GetCount( ))//Count = Number of Items in the ListBox
{
data = new int[Count];
icontrol->GetSelItems(Count, data );
int SelCount = icontrol->GetSelCount( ); //SelCount = Number of the selected Items
for(int i=0;i < SelCount;i++)
{
icontrol->GetText(data[i], changlst );
int index = changlst.Find(_T("on"));
list += changlst.Left(index);
changlst.Empty();
}
delete[] data;
}
return list;
}
CString CAllPages::GetCurMFCDir() //for directories who have space in their name
{
TCHAR SCMToolDir[ 256 ];
GetEnvironmentVariable( _T("SCMTool"),SCMToolDir, sizeof(SCMToolDir) );
return SCMToolDir;
}
CString CAllPages::GetCurDir()
{
TCHAR Dir[ 256 ];
GetEnvironmentVariable( _T("SCMTool"),Dir, sizeof(Dir) );
CString SCMToolDir = Dir;
int space = SCMToolDir.Find(_T(" "));
if(space>-1) //if there is space in the directory name put " "
{
CString Begin = SCMToolDir.Left(space);
CString End = SCMToolDir.Mid(space);
int i = Begin.ReverseFind(_T('\\'));
int j = End.Find(_T('\\'));
if(j == -1) j= End.GetLength();
SCMToolDir = Begin.Left(i+1) + _T('"') + Begin.Mid(i+1) + End.Left(j)+'"'+End.Mid(j);
}
return SCMToolDir;
}
CString CAllPages::rep(CString Switch)
{
CString rep = Cmd();
rep += _T(" /c ");
//rep += GetCurDir();
rep += _T("rep ") + Switch + _T(" ");
return rep;
}
CString CAllPages::tdl(CString Switch)
{
CString tdl = Cmd(); //Name
tdl += _T(" /c ");
// tdl += GetCurDir();
tdl += _T("tdl ") + Switch + _T(" ");
return tdl;
}
CString CAllPages::Cmd()
{
TCHAR Name[ 256 ];
GetEnvironmentVariable( _T("ComSpec"), Name, sizeof(Name) );
CString Cmd = Name;
return Cmd;
}