void CPointEditAnologIn::OnCheckChange() 
{
	// TODO: Add your control notification handler code here
	if(m_ctrlCheckChange.GetCheck())
	{
		CString strMessage;
		strMessage.Format("要修改当前点的信息吗?");
		if(AfxMessageBox(strMessage, MB_ICONQUESTION |MB_OKCANCEL)==IDOK)
		{
			m_ctrlEditChannel.SetReadOnly(TRUE);
			m_ctrlEditAddress.SetReadOnly(TRUE);
			m_ctrlEditPoint.SetReadOnly(TRUE);
			m_ctrlComboTrunkNo.EnableWindow(FALSE);
			m_ctrlComboSensorType.EnableWindow(FALSE);
			m_ctrlComboSensorName.EnableWindow(FALSE);
			m_ctrlComboSensorAccuracy.EnableWindow(FALSE);
			m_ctrlCheckMultiConv.EnableWindow(FALSE);
		}
		SetUpdateInfo();
	}
	else
	{
			m_ctrlEditChannel.SetReadOnly(FALSE);
			m_ctrlEditAddress.SetReadOnly(FALSE);
			m_ctrlEditPoint.SetReadOnly(FALSE);
			m_ctrlComboTrunkNo.EnableWindow(TRUE);
			m_ctrlComboSensorType.EnableWindow(TRUE);
			m_ctrlComboSensorName.EnableWindow(TRUE);
			m_ctrlComboSensorAccuracy.EnableWindow(TRUE);
			m_ctrlCheckMultiConv.EnableWindow(TRUE);
	}
}
bool  CGameUpdate::UpdateBefore(__int64 qUpdateBytes)
{
	//check disk free room.
	wchar_t szLog[1024] = {0};
	qUpdateBytes += SAVE_DISK_ROOMSIZE;
	LARGE_INTEGER liSize = {0};
	hy_GetDiskRoomSize(m_strCliPath[0], &liSize);
	if (liSize.QuadPart >= qUpdateBytes)
		return true;
	
	//删除游戏,保证空间足够。
	if (m_dwUptFlag & UPDATE_FLAG_DELETE_GAME)
	{
		SetUpdateStatus(UPDATE_STATUS_DELETE_GAME);
		std::vector<tagGameInfo*> list;
		GetAllGameList(list);
		for (size_t idx=0; idx<list.size(); idx++)
		{
			if (!CheckState())
			{
				std::for_each(list.begin(), list.end(), Delete_Pointer<tagGameInfo>);
				return false;
			}

			tagGameInfo* pGame = list[idx];
			if (PathFileExistsA(pGame->CliPath) && pGame->CliPath[0] == m_strCliPath[0] &&
				lstrcmpiW(_bstr_t(pGame->CliPath), m_strCliPath.c_str()) != 0)
			{
				std::wstring str(_bstr_t(pGame->CliPath));
				std::wstring str2 = hy_ConvertPath(str);
				
				SetUpdateInfo(INFO_STR_DELETEGAME, str.c_str());

				DeleteGame(str2.c_str());
				hy_DyncaRefreDriver(str[0]);

				hy_GetDiskRoomSize(m_strCliPath[0], &liSize);
				if (liSize.QuadPart >= qUpdateBytes)
				{
					std::for_each(list.begin(), list.end(), Delete_Pointer<tagGameInfo>);
					return true;
				}
				else
				{
					swprintf_s(szLog, L"i8desk: free size:%dM, need size:%dM.", (DWORD)(liSize.QuadPart / 1000 / 1000),
						(DWORD)(qUpdateBytes / 1000 / 1000));
					OutputDebugStringW(szLog);
				}
			}
		}
		std::for_each(list.begin(), list.end(), Delete_Pointer<tagGameInfo>);
	}
	//空间不足,返回错误。
	SetErrorInfo(UPT_ERR_DISKNOROOM, (DWORD)(liSize.QuadPart / 1000 / 1000), (DWORD)(qUpdateBytes / 1000 / 1000));
	return false;
}
void CPointEditAnologIn::OnDblclkListConv(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CString strMessage;
	strMessage.Format("要修改当前点的信息吗?");
	if(AfxMessageBox(strMessage, MB_ICONQUESTION |MB_OKCANCEL)==IDOK)
	{
		m_ctrlEditChannel.SetReadOnly(TRUE);
		m_ctrlEditAddress.SetReadOnly(TRUE);
		m_ctrlEditPoint.SetReadOnly(TRUE);
		m_ctrlComboTrunkNo.EnableWindow(FALSE);
		m_ctrlComboSensorType.EnableWindow(FALSE);
		m_ctrlComboSensorName.EnableWindow(FALSE);
		m_ctrlComboSensorAccuracy.EnableWindow(FALSE);
		m_ctrlCheckMultiConv.EnableWindow(FALSE);
		m_ctrlCheckChange.SetCheck(1);
	}
	SetUpdateInfo();
	*pResult = 0;
}
bool CGameUpdate::CompareIdxfile(__int64& qUpdateBytes, IdxMap& mFiles)
{
	DWORD ret = ERROR_SUCCESS;
	qUpdateBytes = 0;

	//recv game info.(version,idxfile size)
	SetUpdateInfo(INFO_STR_GETGAMEINFO);
	if (!m_Server.GetGameInfo(m_dwGid, m_strSvrPath.c_str(), m_dwSvrIdxVer, m_nIdxfileSize, m_ftIdxfile))
	{
		SetErrorInfo(UPT_ERR_GETGAMEINFO);
		m_Server.ReportGameIdxError(m_dwGid);

		return false;
	}

	//compare game block.
	if (m_dwUptFlag & UPDATE_FLAG_FORCE_UPDATE)
	{
		//recv server idxfile.
		SetUpdateInfo(INFO_STR_DOWNIDXFILE);
		if (!m_Server.RecvIdxfile(m_strSvrPath.c_str(), m_pIdxfile, m_nIdxfileSize))
		{
			SetErrorInfo(UPT_ERR_DWNIDX);
			return false;
		}

		//parse server idxfile.
		SetUpdateInfo(INFO_STR_PRASEIDXFILE);
		ret = Idxfile_Parse(m_pIdxfile, m_nIdxfileSize, m_vFiles, m_vBlocks, mFiles);
		if (ret != ERROR_SUCCESS)
		{
			SetErrorInfo(UPT_ERR_PARSEIDX, ret);
			return false;
		}

		//set block to updated.
		for (std::vector<tagIdxFile*>::iterator it = m_vFiles.begin(); it != m_vFiles.end(); it++)
		{
			(*it)->update = 1;
		}
		for (std::vector<tagIdxBlock*>::iterator it = m_vBlocks.begin(); it != m_vBlocks.end(); it++)
		{
			(*it)->update = 1;
			qUpdateBytes += (*it)->blksize;
		}
	}
	else
	{
		//先对比版本号
		if (!(m_dwUptFlag & UPDATE_FLAG_QUICK_COMPARE) && m_dwSvrIdxVer != -1 && 
			m_dwSvrIdxVer == Idxfile_GetVersion((m_strCliPath + INDEX_FILE_NAMEW).c_str()))
		{
			//version equal,don't update and delete morefile.
			if (m_dwUptFlag & UPDATE_FLAG_DELETE_MOREFILE)
				m_dwUptFlag &= ~UPDATE_FLAG_DELETE_MOREFILE;
			return true;
		}
		else
		{
			//快速对比是,是根据磁盘上的文件对比。因此把索引删除。
			if (m_dwUptFlag & UPDATE_FLAG_QUICK_COMPARE)
			{
				std::wstring file = m_strCliPath + INDEX_FILE_NAMEW;
				SetFileAttributesW(file.c_str(), FILE_ATTRIBUTE_NORMAL);
				DeleteFileW(file.c_str());
			}
			//recv server idxfile.
			SetUpdateInfo(INFO_STR_DOWNIDXFILE);
			if (!m_Server.RecvIdxfile(m_strSvrPath.c_str(), m_pIdxfile, m_nIdxfileSize))
			{
				SetErrorInfo(UPT_ERR_DWNIDX);
				return false;
			}

			//parse server idxfile.
			SetUpdateInfo(INFO_STR_PRASEIDXFILE);
			ret = Idxfile_Parse(m_pIdxfile, m_nIdxfileSize, m_vFiles, m_vBlocks, mFiles);
			if (ret != ERROR_SUCCESS)
			{
				SetErrorInfo(UPT_ERR_PARSEIDX, ret);
				return false;
			}

			//对比两个索引,如果本地索引不存在,或者文件不正确,则扫描磁盘文件。
			std::vector<tagIdxFile*>  m_LocalVFiles;
			std::vector<tagIdxBlock*> m_LocalBlocks;
			IdxMap m_LocalMFiles;
			std::wstring idxfile = m_strCliPath + INDEX_FILE_NAMEW;
			if (ERROR_SUCCESS == Idxfile_Parse(idxfile.c_str(), m_LocalVFiles, m_LocalBlocks, m_LocalMFiles))
				Idxfile_Compare(mFiles, m_vBlocks, m_LocalMFiles, m_LocalBlocks, qUpdateBytes, CallBack, this);
			else
				Idxfile_Compare(m_strCliPath.c_str(), m_vFiles, m_vBlocks, qUpdateBytes, CallBack, this);
			std::for_each(m_LocalVFiles.begin(), m_LocalVFiles.end(), Delete_Pointer<tagIdxFile>);
			std::for_each(m_LocalBlocks.begin(), m_LocalBlocks.end(), Delete_Pointer<tagIdxBlock>);
		}
	}
	//delete idxfile.
	DeleteIdxfile();
	return true;
}