/*******************************************************************

Copyright (c) 2004 Open Mobile Alliance, Ltd.  All Rights Reserved.

This software is made available under the usage and distribution terms 
covered by the Common Public License 1.0 and by using this software you
are bound by the terms and conditions of the same.

EXCEPT AS EXPRESSLY SET FORTH IN THE COMMON PUBLIC LICENSE,
THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   
Each recipient is solely responsible for determining the 
appropriateness of using and distributing this program and assumes 
all risks associated with its exercise of rights under the Common 
Public License, including but not limited to the risks and 
costs of program errors, compliance with applicable laws, 
damage to or loss of data, programs or equipment, and 
unavailability or interruption of operations.

********************************************************************/

// LoadError.cpp : implementation file
//

#include "stdafx.h"
#include "SCTS3DevMan.h"
#include "LoadError.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLoadError dialog


CLoadError::CLoadError(time_t _timeStamp,char *_title,char *_error,CWnd* pParent /*=NULL*/)
	: CDialog(CLoadError::IDD, pParent),timeStamp(_timeStamp),title(_title),error(_error)
{
	//{{AFX_DATA_INIT(CLoadError)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CLoadError::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLoadError)
	DDX_Control(pDX, IDC_FILELIST, m_list);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLoadError, CDialog)
	//{{AFX_MSG_MAP(CLoadError)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLoadError message handlers

BOOL CLoadError::OnInitDialog() 
{
	CDialog::OnInitDialog();
	CFileFind fileFind;
	CFileStatus fileStatus;
	CString searchString;
	BOOL flag;
	if (title) SetWindowText(title);
	if (error) GetDlgItem(IDC_ERRORDESC)->SetWindowText(error);
	m_list.InsertItem(0,appPath);
	searchString=logPath;
	searchString+="\\*.*";
	flag=fileFind.FindFile(searchString);
	while (flag)
	{
		flag=fileFind.FindNextFile();
		if (CFile::GetStatus(fileFind.GetFilePath(),fileStatus) && fileStatus.m_ctime>=timeStamp)
			m_list.InsertItem(1,fileFind.GetFilePath());
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CLoadError::OnOK() 
{
	char buffer[256];
	BROWSEINFO browseInfo={GetSafeHwnd(),0,0,"Select Folder :",BIF_RETURNONLYFSDIRS,0,0,0};
	if (SHGetPathFromIDList(SHBrowseForFolder(&browseInfo),buffer))
	{
		char fileName[256];
		char *name;
		int cnt=m_list.GetItemCount();
		int len=strlen(buffer);
		while (cnt--)
		{
			m_list.GetItemText(cnt,0,fileName,256);
			name=fileName+strlen(fileName);
			while (*(--name)!='\\');
			strcpy(buffer+len,name);
			if (cnt) 
				MoveFile(fileName,buffer);
			else
				CopyFile(fileName,buffer,FALSE);
		}
	}
	CDialog::OnOK();
}

void CLoadError::OnCancel() 
{
	int cnt=m_list.GetItemCount();
	while (--cnt) DeleteFile(m_list.GetItemText(cnt,0));
	CDialog::OnCancel();
}
