/***************************************************************************
**
**    $Header:  
**
**    $Log:   
** 
** Initial revision.
**
****************************************************************************/

/////////////////////////////////////////////////////////////////////////////
//
//  File name:  FLSDLG.CPP
//
//  Description:The implement file for the class: CFlsDlg
//
//  Author:     Jerry Yan
//
//  Date:       03/20/96
//
//  Modification:
//
//     
//
//
//  Copyright (C) 1996 Microtek International. All rights reserved.
//
/////////////////////////////////////////////////////////////////////////////


// flsdlg.cpp : implementation file
//


#include "stdafx.h"
#include "flsrom.h" 
#include <direct.h> 
#include <dos.h>          
#include <ctype.h>
#include "flsdlg.h"          
#include "flsinfo.h"   
//#include "abitype.h" 

//#include "abireg51.h"


BOOL NeedCheck=TRUE; 
char *CPULIST[64]={
        "EP80C31"    ,//=00      xx   SUPPORT
        "EP80C51"    ,//=01      xx   SUPPORT
        "EP80C32"    ,//=02      xx   SUPPORT
        "EP80C52"    ,//=03      xx   SUPPORT
        "EP80C154"   ,//=04      xx   SUPPORT
        "EP85154"   ,//=05      x
        "EP8344"    ,//=06      xx   SUPPORT
        "EP8044"    ,//=07      x
        "EP80C152JA"  ,//=08    xx   SUPPORT
        "EP83C152JA"  ,//=09    xx   SUPPORT
        "EP80C152JB"  ,//=10    xx   SUPPORT
        "EP83C152JB"  ,//=11    xx
        "EP80C152JC"  ,//=12    xx   SUPPORT
        "EP83C152JC"  ,//=13    xx   SUPPORT
        "EP80C152JD"  ,//=14    xx   SUPPORT
        "EP83C152JD"  ,//=15    xx
        "EP80C51FA/FB/FC"  ,//=16      xx    SUPPORT
        "EP83C51FA/FB/FC"  ,//=17      xx    SUPPORT
        "EP80C552"  ,//=18      xx     SUPPORT
        "EP83C552"  ,//=19      xx     SUPPORT
        "EP80C562"  ,//=20
        "EP83C562"  ,//=21
        "EP80C752"  ,//=22      xx
        "EP83C752"  ,//=23      xx     SUPPORT
        "EP80C652" ,//=24      xx     SUPPORT
        "EP83C652" ,//=25      xx     SUPPORT
        "EP80C528"  ,//=26      xx
        "EP83C528"  ,//=27      xx
        "EP80C550"  ,//=28     xx     SUPPORT
        "EP83C550"  ,//=29     xx     SUPPORT
        "EP80C575"  ,//=30
        "EP83C575"  ,//=31
        "EP80C592"  ,//=32
        "EP83C592"  ,//=33
        "EP80CL31"  ,//=34     xx     SUPPORT
        "EP80CL51"  ,//=35     xx     SUPPORT
        "EP80C451"  ,//=36
        "EP83C451"  ,//=37
        "EP80C750"  ,//=38       xx
        "EP83C750"  ,//=39       xx     SUPPORT
        "EP80C751"  ,//=40       xx
        "EP83C751" ,//=41       xx     SUPPORT
        "EP80CL410" ,//=42      xx     SUPPORT
        "EP83CL410" ,//=43      xx     SUPPORT
        "EP80CL781" ,//=44
        "EP83CL781" ,//=45      xx     SUPPORT
        "EP80CL782" ,//=46
        "EP83CL782" ,//=47      xx     SUPPORT
        "EP80CL580" ,//=48      xx     SUPPORT
        "EP83CL580" ,//=49      xx     SUPPORT
        "EP80C320"   //=50      xx     SUPPORT
} ;

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif             


/////////////////////////////////////////////////////////////////////////////
// Type definitions.


/////////////////////////////////////////////////////////////////////////////
// Macro definitions.


/////////////////////////////////////////////////////////////////////////////
// Static variables.


/////////////////////////////////////////////////////////////////////////////
// External variables.


/////////////////////////////////////////////////////////////////////////////
// CFlsDlg dialog


CFlsDlg::CFlsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFlsDlg::IDD, pParent)
{                             
    CString strDefaultPath;
    _getdcwd( _getdrive(),m_strEditPath.GetBuffer(63),63);
	//{{AFX_DATA_INIT(CFlsDlg)
	//}}AFX_DATA_INIT                            
	m_strEditPath.ReleaseBuffer();
} 

CFlsDlg::~CFlsDlg()
{
//	delete m_pDownload;
	CDialog::~CDialog();
}	


void CFlsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFlsDlg)
	DDX_Text(pDX, IDC_EDIT_PATH, m_strEditPath);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFlsDlg, CDialog)
	//{{AFX_MSG_MAP(CFlsDlg)
	ON_LBN_DBLCLK(IDC_LIST1, OnDblclkList1)
	ON_WM_CREATE()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CFlsDlg message handlers

BOOL CFlsDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();  
	CString strTitle;
	strTitle.LoadString(IDS_TITLE);
	SetWindowText((strTitle));
	UpdateData(FALSE);
	UINT i=0;
    while(CPULIST[i]!=NULL)
      ((CListBox*)GetDlgItem(IDC_LIST1))->AddString(CPULIST[i++]);
      
    ((CListBox*)GetDlgItem(IDC_LIST1))->SetSel(0);  
	CRect rect;
	GetWindowRect(&rect);
	int x,y;
	x=(::GetSystemMetrics(SM_CXSCREEN)-rect.Width() )/2;
	y=(::GetSystemMetrics(SM_CYSCREEN)-rect.Height() )/2;
	SetWindowPos( &wndTop,x,y,0,0,SWP_NOSIZE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


void CFlsDlg::OnDblclkList1()
{
   GetDlgItem(IDOK)->SendMessage( WM_LBUTTONDOWN );
   GetDlgItem(IDOK)->SendMessage( WM_LBUTTONUP);
}



void CFlsDlg::OnOK() 
{
    UpdateData(TRUE);
    
    _chdir(m_strEditPath.GetBuffer(64));
	m_strEditPath.ReleaseBuffer();
	
    int current_sel;
	( (CListBox*)GetDlgItem(IDC_LIST1) )->GetCurSel();
	
	current_sel=( (CListBox*)GetDlgItem(IDC_LIST1) )->GetCurSel();
	if(current_sel!=LB_ERR) 	
	switch (((CFlsromApp*)AfxGetApp())->SearchFW(current_sel) )
	{ 
	  case 0:break;
	  case 1:AfxMessageBox("Communication Failue !",MB_OK);break;

	  case 2:AfxMessageBox("No Compatible file exists. \nPlease install the file in current directory",MB_OK);
             break;
	  case 3:AfxMessageBox("DownLoad Error!",MB_OK);break;  
      default:break;
      }       
	CDialog::OnOK();
}


void CFlsDlg::OnPaint() 
{                     
	CPaintDC dc(this); // device context for painting
//  Do not call CDialog::OnPaint() for painting messages
}
    
void CFlsDlg::DrawFrame(CDC * pdc, CRect rect)
{
    
 	ScreenToClient(&rect);
	rect.InflateRect(1,1);
	    
    CPen* pOldPen,*pPen=new CPen;
//  pPen->CreatePen(PS_SOLID, 1,RGB(0,0,0) );
    CPoint points[4];   
    points[0]=CPoint(rect.left,rect.bottom);
    points[1]=CPoint(rect.left,rect.top);
    points[2]=CPoint(rect.right,rect.top);
    points[3]=CPoint(rect.right,rect.bottom); 
//    pOldPen=pdc->SelectObject(pPen); 
    pdc->MoveTo(points[0]);
 	pdc->LineTo(points[1]);
 	pdc->LineTo(points[2]);
    pPen->DeleteObject();
       
    pPen->CreatePen(PS_SOLID,1,RGB(255,255,255) );
    pOldPen=pdc->SelectObject(pPen);
 	pdc->LineTo(points[3]);
 	pdc->LineTo(points[0]);
    pdc->SelectObject(pOldPen);
    pPen->DeleteObject();
}    




