Esempio n. 1
0
BOOL CMainFrame::DonwLoadFile(PSTR pURL, LPSTR SaveAsFilePath)
{
	CInternetSession session; 
	CHttpConnection* pServer = NULL; 
	CHttpFile * pHttpFile = NULL;
	CString strServerName;  //去掉http://
	CString strObject;  
	INTERNET_PORT nPort;
	DWORD dwServiceType; 
	DWORD dwHttpRequestFlags = INTERNET_FLAG_NO_AUTO_REDIRECT; //请求标志
	const TCHAR szHeaders[]=_T("Accept: text/*\r\nUser-Agent:HttpClient\r\n");
	
	BOOL OK=AfxParseURL( 
		pURL, 
		dwServiceType, 
		strServerName, 
		strObject, 
		nPort ); 
	
	pServer = session.GetHttpConnection(strServerName, nPort); //获得服务器名
	
	pHttpFile = pServer-> OpenRequest( CHttpConnection::HTTP_VERB_GET,
		strObject,
		NULL, 
		1, 
		NULL, 
		NULL,
		dwHttpRequestFlags);
	
	pHttpFile->AddRequestHeaders(szHeaders);

	try
	{
		pHttpFile->SendRequest(); //发送请求
	}
	catch (CInternetException* IE)
	{
		return false;
	}

	CStdioFile f; 
	if( !f.Open( SaveAsFilePath, 
		CFile::modeCreate | CFile::modeWrite | CFile::typeBinary ) )
	{ 
		return false;
	}
	
	TCHAR szBuf[1024];
	int length=0;
	long a=pHttpFile->GetLength();
	while (length=pHttpFile->Read(szBuf, 1023))
		f.Write(szBuf,length);
	f.Close();
	pHttpFile ->Close();
	pServer ->Close();
	if (pHttpFile != NULL) delete pHttpFile;
	if (pServer != NULL) delete pServer;
	session.Close();
	return true;
}
Esempio n. 2
0
void COTDKView::gAddSigInTest(CString csNameNode, CString csBuf, int iCountT)
{
	LPTSTR p=NULL; DWORD dwPosition=NULL;
	CString s1=' '; CStdioFile Fl;
	COTDKDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc); 
	s1 = csBuf.Mid(0,4);
	p =  s1.GetBuffer(4);
	//здесь добавить блок сравнения первой и второй сигнатуры
	Fl.Open(csNameNode + ".sig", CFile::modeReadWrite); 
	if (iCountT == 1) {
		if (iCountTest==1) dwPosition = pDoc->gGetPosString(0, "ffff", &Fl);
		else dwPosition = pDoc->stPos.dwPos1;
	}
	else if (iCountT == 2) {
		if (iCountTest==2) {
			pDoc->stPos.dwPos1 = pDoc->gGetPosString(0, "ffff", &Fl);
			pDoc->stPos.dwPos2 = pDoc->gGetPosString(pDoc->stPos.dwPos1, "ffff", &Fl);
		}
		dwPosition = pDoc->stPos.dwPos2;
	}
	else {
		pDoc->stPos.dwPos1 = pDoc->gGetPosString(0, "ffff", &Fl);
		pDoc->stPos.dwPos2 = pDoc->gGetPosString(pDoc->stPos.dwPos1, "ffff", &Fl);
		pDoc->stPos.dwPos3 = pDoc->gGetPosString(pDoc->stPos.dwPos2, "ffff", &Fl);
		dwPosition = pDoc->stPos.dwPos3;
	}
	Fl.Seek((LONG)dwPosition-1, CFile::begin);
	Fl.Write(p,4); 	Fl.Close();
}
Esempio n. 3
0
void trackconnect::OnBnClickedButtonConnect()
{
	char *fileName = "loginInfo.txt";
	//CFile myFile;
	CFileException fileException;
	CStdioFile myFile;

	CString usrename, passwd;
	BYTE nf1, nf2, nf3, nf4;
	m_ip.GetAddress(nf1, nf2, nf3, nf4);
	m_strIp.Format("%d.%d.%d.%d", nf1, nf2, nf3, nf4);//这里的nf得到的值是IP值了.
	strcpy(m_connectInfo.Ip, m_strIp.GetString());
	m_username.GetWindowText(usrename);
	m_passwd.GetWindowText(passwd);
	if (strcmp(m_strIp.GetString(), "0.0.0.0") == 0)
	{
		MessageBox("IP为空");
		return;
	}
	if (strcmp(usrename.GetString(), "") == 0)
	{
		MessageBox("用户名为空");
		return;
	}
	memcpy(m_connectInfo.passwd, passwd.GetString(), sizeof(m_connectInfo.passwd));
	memcpy(m_connectInfo.username, usrename.GetString(), sizeof(m_connectInfo.username));
	if (m_initNetFun)
	{
		m_initNetFun(m_DialogParam, &m_connectInfo);
	}
	BOOL openResult = myFile.Open(fileName, CFile::modeCreate | CFile::modeReadWrite);
	if (!openResult)
	{
		MessageBox(_T("打开文件错误!"));
	}
	else
	{
		myFile.SeekToBegin();
		myFile.WriteString(usrename);
		myFile.Write(("\r\n"), 2);
		myFile.WriteString(m_strIp);
		myFile.Write(("\r\n"), 2);
		myFile.Flush();
		myFile.Close();
	}
	// TODO: Add your control notification handler code here
}
/**
* 输出现场数据到数据文件
* @param CString strFileName 文件名
* @param byte* pData 数据指针
* @param UINT uiFileSize 数据长度
* @return bool true:成功;false:失败
*/
bool CThreadProcSiteDataOutput::OutputToFile(CString strFileName, byte* pData, UINT uiFileSize)
{
	CStdioFile oFile;
	oFile.Open(strFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
	oFile.Write(pData, uiFileSize);
	oFile.Close();
	return true;
}
void CGUAHAODlg::OnButton4() 
{  
	FILE *fp;
	int i,j;
	char zhanghao[20],mima[20];
    UpdateData(TRUE);
	char* pFileName="bingli.txt";
	CStdioFile bingli;
	CFileException fileException;
	
	if((fp=fopen("yonghu.txt","r"))==NULL)
	{
		MessageBox("存储文件出错!");
		exit(0);
	}
	fscanf(fp,"%s %s",zhanghao,mima);
	  fclose(fp);
	  i=strlen(zhanghao);
	  j=strlen(mima);
	if(bingli.Open(pFileName,CFile::modeReadWrite |CFile::typeText))
	{  
		m_strnum6=m_5;
		m_strnum7=m_7;
		m_strnum8=m_11;
        bingli.SeekToEnd();
		bingli.Write(zhanghao,i);
		bingli.WriteString(" ");
		bingli.Write(mima,j);
		bingli.WriteString(" ");
		bingli.Write(m_strnum6,m_strnum6.GetLength());
		bingli.WriteString(" ");
		bingli.Write(m_strnum7,m_strnum7.GetLength());
		bingli.WriteString(" ");
		bingli.Write(m_strnum8,m_strnum8.GetLength());
		bingli.WriteString(" ");
		bingli.WriteString("\n");
		
		
	}
bingli.Close();
	MessageBox("挂号成功!");
	CDialog::OnOK();
	CLOGDlg dlg;
	dlg.DoModal();
}
Esempio n. 6
0
void CFileClipboardDlg::OnBnClickedFileClipboardSave()
{
    CString szFilename;
    CStdioFile fOutput;
    int nIndex;
    CString szText;

    if (GetFileClipboardFilename(FALSE, &szFilename) == TRUE)
    {
        if (fOutput.Open(szFilename, CFile::typeText|CFile::modeWrite|CFile::modeCreate) == TRUE)
        {
            for (nIndex = 0; nIndex < m_cFileClipboardList.GetItemCount() - 1; nIndex++)
            {
                szText = m_cFileClipboardList.GetItemText(nIndex, 0);
                fOutput.Write(szText.GetBuffer(), szText.GetLength());
                fOutput.Write("\n", 1);
            }
            fOutput.Close();
        }
    }
}
Esempio n. 7
0
BOOL DealerHistoryLog::SetDealerLog(CString log)
{
	CStdioFile file;   
	CString strfilename;
	GetFileName(strfilename);
	if( !file.Open(strfilename, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite) )
	{
		return FALSE;
	} 
	file.SeekToEnd();
//	file.Write("\r\n",2);
	file.Write(log, log.GetLength());
	file.Close();
	return TRUE;
}
Esempio n. 8
0
BOOL CLoginDlg::PreTranslateMessage(MSG* pMsg)
{
	// TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다.

	if(pMsg->message == WM_KEYDOWN)
	{
		if(pMsg->wParam == 'A' && GetKeyState(VK_CONTROL) < 0)
		{
			CString			accountLevel, inputName, inputPwd, inputData;
			CStdioFile		accountFile;
			unsigned char	dataForWrite[1024] = "";
			int				i = 0, len = 0;

			if(m_rdUser.GetCheck() == TRUE)
				accountLevel.Format(_T("%s"), USER_ACCOUNT);
			else
				accountLevel.Format(_T("%s"), ADMIN_ACCOUNT);

			m_edtLoginName.GetWindowText(inputName);
			m_edtLoginPwd.GetWindowText(inputPwd);

			if(inputName.IsEmpty() || inputPwd.IsEmpty())
				return CDialog::PreTranslateMessage(pMsg);

			inputData.Format(_T("%s:%s:%s"),inputName, inputPwd, accountLevel);

			memcpy(dataForWrite, (unsigned char*)(LPCTSTR)inputData, inputData.GetLength());
			len = inputData.GetLength();

			RTrace(_T("Input Data = %s\n"), inputData);

			for(i = 0; i < len; i++)
			{
				dataForWrite[i] = ~dataForWrite[i];
			}
			dataForWrite[i] = 0x0a;

			RTrace(_T("Conversioned Data = %s\n"), dataForWrite);

			accountFile.Open(LOGIN_FILE_NAME, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate | CFile::typeBinary);
			accountFile.SeekToEnd();
			accountFile.Write(dataForWrite, i + 1);
			accountFile.Close();
		}
	}

	return CDialog::PreTranslateMessage(pMsg);
}
Esempio n. 9
0
BOOL CLang::WriteString()
{
	CString str;
	UINT i;

	if(NULL == m_stringAlloc || NULL == m_offsetAlloc)//
	{
		return FALSE;
	}

	CreateDirectory(theApp.ConvertAbsolutePath(_T("Lang")), NULL);//创建文件夹

	str.Format(_T("Lang\\%s.txt"), m_langName[m_activeLang]);
	if(0xFFFFFFFF != GetFileAttributes(theApp.ConvertAbsolutePath(str)))//属性
	{
		return TRUE;
	}

	//open file
	CStdioFile *pFile;
	pFile = new CStdioFile(theApp.ConvertAbsolutePath(str), 
		CFile::modeCreate | CFile::modeWrite | CFile::typeBinary | CFile::shareDenyNone);
	if(NULL == pFile)
	{
		return FALSE;
	}

	USHORT head = UNICODE_TXT_HEAD;
	pFile->Write(&head, 2);
	
	pFile->WriteString(_T("Lang"));//
	pFile->WriteString(_T("{\r\n"));//

	for(i = 0; i < IDS_MAX; i++)
	{
		str.Format(_T("\"%s\",\r\n"), m_stringAlloc+m_offsetAlloc[i]);//
		pFile->WriteString(str);
	}

	pFile->WriteString(_T("}\r\n"));//

	pFile->Close();
	delete pFile;

	return TRUE;
}
Esempio n. 10
0
bool FileMisc::SaveFile(const TCHAR* szPathname, const TCHAR* szText, int nLen)
{
	if (nLen == -1)
	{
		nLen = _tcslen(szText);
	}

	CStdioFile file;

	if (file.Open(szPathname, CFile::modeCreate | CFile::modeWrite))
	{
		file.Write(szText, nLen);
		return true;
	}

	return false;
}
Esempio n. 11
0
/*****************************************************************************
  Function Name    :  COM_bSetCheckSum                                          
  Input(s)         :  omStrConfigFileName : reference to File name          
                      pucCheckSum : Returns computed check sum              
  Output           :  BOOL                                                  
  Functionality    :  This method computes the checksum for a given bytes   
                      in a file. The file is opened and checksum is computed
                      for all bytes except the last byte. Returns TRUE for  
                      sucess and FALSE for failure. The same checksum is    
                      overwritten at the last byte in file. For COM Support                                      
  Member of        :  CComputeCheckSum                                      
  Friend of        :      -        
  Author		   : Anish kr
  Creation Date	   : 6/05/10
  Modifications	   :                                              
******************************************************************************/
BOOL CComputeCheckSum::COM_bSetCheckSum(CString &omStrConfigFileName,
                                        UCHAR* pucCheckSum, CString &strError)
{
    CStdioFile omStdiofile;
    CFileException omException;
    DWORD dwSize                 = 0;
    DWORD dwRead                 = 0;
    BOOL bReturn                 = FALSE;
    BOOL bFileOpen               = FALSE;
    CString omStrStrErrorMessage = _T("");
    TCHAR  acErrorMsg[defSIZE_OF_ERROR_BUFFER];

    // Open the configration file template.
    TRY
    {
        bFileOpen = omStdiofile.Open(omStrConfigFileName,
                                     CFile::modeReadWrite| CFile::typeBinary,
                                     &omException);
        if(bFileOpen!=FALSE)
        {
            UCHAR *pucBuff   = NULL;
            UCHAR  ucCheckSum = 0;
            // Get the size of file
            dwSize = (DWORD)omStdiofile.GetLength();        
            pucBuff = static_cast<UCHAR*> (new UCHAR[dwSize]);
            if(pucBuff!=NULL)
            {
                // Read the whole file and put the content to pucBuff;
                dwRead = omStdiofile.Read(pucBuff,dwSize);
                // compute the checksum
                bReturn = bComputeCheckSum(pucBuff,dwSize, &ucCheckSum);
                if(bReturn == TRUE)
                {
                    // Seek to the last byte to store checksum
                    omStdiofile.Seek(dwSize,CFile::begin);
                    // Write one byte checksum
                    omStdiofile.Write(&ucCheckSum,1);
                    // return the checksum
                    if(pucCheckSum!= NULL )
                    {
                        *pucCheckSum = ucCheckSum;
                    }
                    else
                    {
                        bReturn = FALSE;
                    }
                }
                delete [] pucBuff;
                pucBuff = NULL;
            }
            omStdiofile.Close();
        }
        else
        {
          // Get the exception error message
          omException.GetErrorMessage(acErrorMsg,sizeof(acErrorMsg));
          // configuration file open error notification 
        }
    
    }
    CATCH_ALL(pomE)
    {
      if(pomE != NULL )
      {
        // Get the exception error message
        pomE->GetErrorMessage(acErrorMsg,sizeof(acErrorMsg));
      }
    }
    END_CATCH_ALL
 
    strError = acErrorMsg;
     
    return bReturn;
}
Esempio n. 12
0
int CWebBase::RequestPostPageExExEx(CString & strServer, CString & strObject, 
								  CString & strHead,CString & strPostData,
								  CString &strError,
								  int iGetType,	//表示获取文件,1表示获取验证码
								  int iIsProxy,	//是否使用代理
								  int iProxyType,//代理类型
								  CString strProxyIP,//代理IP
								  int iProxyPort,//代理端口
								  CString strProxyUser,//代理用户名
								  CString strProxyPwd//代理密码
								  )
{
	CHttpFile * pHttpFile;
	char cBuffer[1024];
	unsigned long StatusCode;
	unsigned long  iReadLen = 0;
	int            nStringLen = 0;
	CString        strTemp = "";	
	WORD            wdPort;
	BOOL result;
	int iRet = -1;
	try
	{
		//获取到参数信息
		DWORD dwFlags = GetDwflag();
		pHttpFile = NULL;
		m_strWorkBuf.Empty();
		//设置超时
		SetTimeOut(m_Session, g_iTimeOut);
		//获取连接
		iRet = GetHttpConnectionEx(strServer,strObject,strHead,strError,iIsProxy,iProxyType,strProxyIP,iProxyPort);
		if (iRet < 0)
		{
			return iRet;
		}
		//打开请求对象
		pHttpFile = m_pConnection->OpenRequest( CHttpConnection::HTTP_VERB_POST,
			(LPCTSTR)strObject,NULL, 0,
			NULL, NULL,
			dwFlags );
		if( pHttpFile == NULL )
		{
			strError = "OpenRequest失败";
			return -1;
		}
		//如果是SOCKET5代理,设置账号密码
		// 		if   (!pHttpFile->SetOption(INTERNET_OPTION_PROXY_USERNAME,strProxyUser,strProxyUser.GetLength()))   
		// 		{   
		// 			return -99;
		// 		}
		// 		if   (!pHttpFile->SetOption(INTERNET_OPTION_PROXY_PASSWORD,strProxyPwd,strProxyPwd.GetLength()))   
		// 		{   
		// 			return -99;   
		// 		}
		//发送请求到服务器		
		iRet = SendRequest(pHttpFile,strError,strHead,strPostData,1);/*发送数据*/
		if (iRet < 0)	//发送POST数据失败
		{
			//清除连接对象
			DeleteObjectExEx();
			return iRet; 
		}
		//获取状态码及头信息
		pHttpFile->QueryInfoStatusCode(StatusCode);
		pHttpFile->QueryInfo(HTTP_QUERY_LOCATION,m_strRedirectUrl); 
		pHttpFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF,m_strResponHead);
		iReadLen = (unsigned long )pHttpFile->GetLength();
		m_iStatusCode = StatusCode;
		// 是否重定向
		if ( StatusCode == HTTP_STATUS_OK ||
			StatusCode == HTTP_STATUS_MOVED ||
			StatusCode == HTTP_STATUS_REDIRECT ||
			StatusCode == HTTP_STATUS_REDIRECT_METHOD)
		{
			//获取数据
			if (iGetType == 0)			//读取文本信息
			{
				while(iReadLen >= 0)
				{
					iReadLen = pHttpFile->Read( cBuffer ,1023 );
					if (iReadLen <= 0)
					{
						break;
					}
					m_strWorkBuf += CString( cBuffer ,iReadLen);
				}
			}
			else		//读取验证码
			{
				CStdioFile out;
				out.Open(g_strDirect+g_strFileName, CFile::modeCreate | CFile::modeWrite |CFile::typeBinary);
				while(true)
				{
					iReadLen = pHttpFile->Read(cBuffer ,1);
					if ( iReadLen <= 0)
					{
						break;
					}
					out.Write(cBuffer,1); 
				}
				out.Close();
			}			
		}
		//删除HTTPFILE对象
		DeleteObjectEx(pHttpFile);	
		if(!m_strWorkBuf.IsEmpty()) //解压数据
		{
			//ConvertUtf8ToGBK( m_strWorkBuf );
			return ConvertData(m_strResponHead,strError,m_strWorkBuf);
		}
		return 0;			
	}
	catch(CInternetException * e)
	{
		strError = "抓取网页信息异常";
		DeleteObjectEx(pHttpFile);	
		DeleteObjectExEx();
		e->Delete();
		return -6;
	}
	catch(...)
	{
		strError = "抓取网页信息异常";
		DeleteObjectEx(pHttpFile);	
		DeleteObjectExEx();
		return -7;
	}
	return 0;
}
Esempio n. 13
0
//////////////////////////////////////////////////////////////////////////
//截获异常信息,并生成自定义的异常报告和弹出窗口
//////////////////////////////////////////////////////////////////////////
LONG WINAPI CustomExceptionFun(struct _EXCEPTION_POINTERS* ExceptionInfo)
{
	SetUnhandledExceptionFilter(NULL);
	CString logPath,folderPath,errDetail;
	CString tips;
	CString strDes,strStack;
	CTime timer;
	CStdioFile stFile;
	TCHAR sz_module[MAX_PATH] = {0};
	UINT_PTR section = 0, offset = 0;

	strDes.Format(L"%s\r\n%s",L"我们很抱歉地通知您,程序遇到错误,不得不终止。",L"以下是该错误的详细信息:");
	//werDlg.SetDes(strDes);

	TCHAR szFileName[MAX_PATH];
	::GetModuleFileName(NULL, szFileName, MAX_PATH);  
	*(_tcsrchr(szFileName, _T('\\')) + 1) = 0;

	timer = CTime::GetCurrentTime();
	folderPath.Format(L"%slog\\",szFileName);
	logPath.Format(L"%slog\\dump_%d_%d_%d_%d.txt",
		szFileName,
		timer.GetYear(),
		timer.GetMonth(),
		timer.GetDay(),
		timer.GetHour());

	
	tips.Format(L"%s\r\n%s",L"以上错误信息保存在:",logPath);
	g_strErrLogPath = logPath;

	//生成错误地址
	get_logical_address(ExceptionInfo->ExceptionRecord->ExceptionAddress, sz_module, sizeof(sz_module));

	//生成堆栈信息
	stack_walk(strStack,ExceptionInfo->ContextRecord);

	//生成寄存器信息
#ifdef _M_IX86  // Intel Only!
	CString strReg;
	strReg = L"\nRegisters:\r\n";
	strReg.Format(L"%sEAX:%08X\r\nEBX:%08X\r\nECX:%08X\r\nEDX:%08X\r\nESI:%08X\r\nEDI:%08X\r\n", strReg,ExceptionInfo->ContextRecord->Eax, ExceptionInfo->ContextRecord->Ebx, ExceptionInfo->ContextRecord->Ecx, ExceptionInfo->ContextRecord->Edx, ExceptionInfo->ContextRecord->Esi, ExceptionInfo->ContextRecord->Edi );
	strReg.Format(L"%sCS:EIP: %04X:%08X\r\n",strReg, ExceptionInfo->ContextRecord->SegCs, ExceptionInfo->ContextRecord->Eip);
	strReg.Format(L"%sSS:ESP: %04X:%08X  \r\nEBP:%08X\r\n",strReg, ExceptionInfo->ContextRecord->SegSs, ExceptionInfo->ContextRecord->Esp, ExceptionInfo->ContextRecord->Ebp );
	strReg.Format(L"%sDS:%04X  ES:%04X  FS:%04X  GS:%04X\r\n", strReg,ExceptionInfo->ContextRecord->SegDs, ExceptionInfo->ContextRecord->SegEs, ExceptionInfo->ContextRecord->SegFs, ExceptionInfo->ContextRecord->SegGs );
	strReg.Format(L"%sFlags:%08X\r\n",strReg, ExceptionInfo->ContextRecord->EFlags);
#endif //_M_IX86


	//生成错误详细信息
	errDetail.Format(L"Error Code:%x\r\n%s\r\nAddress:%x\r\n%s\r\n\r\n%s\r\n%s",
		ExceptionInfo->ExceptionRecord->ExceptionCode,
		get_exception_string(ExceptionInfo->ExceptionRecord->ExceptionCode),
		ExceptionInfo->ExceptionRecord->ExceptionAddress,
		sz_module,
		strReg,
		strStack);
	g_strErrDetail = errDetail;

	//写日志
	CFileFind fileFinder;
	if (!fileFinder.FindFile(folderPath))
	{
		if (::CreateDirectory(folderPath,NULL) < 0)
			return EXCEPTION_EXECUTE_HANDLER;
	}

	
	if (stFile.Open(logPath,CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite | CFile::typeBinary))
	{
		stFile.SeekToEnd();
		stFile.Write("\377\376", 2);
		stFile.WriteString(errDetail);
		stFile.Close();
	}

	//werDlg.DoModal();
	CreateWerWindow(logPath,errDetail);

	return EXCEPTION_EXECUTE_HANDLER;
}
Esempio n. 14
0
BOOL CFileTextLines::Save(const CString& sFilePath, bool bSaveAsUTF8, DWORD dwIgnoreWhitespaces /*=0*/, BOOL bIgnoreCase /*= FALSE*/, bool bBlame /*= false*/)
{
	try
	{
		CString destPath = sFilePath;
		// now make sure that the destination directory exists
		int ind = 0;
		while (destPath.Find('\\', ind)>=2)
		{
			if (!PathIsDirectory(destPath.Left(destPath.Find('\\', ind))))
			{
				if (!CreateDirectory(destPath.Left(destPath.Find('\\', ind)), NULL))
					return FALSE;
			}
			ind = destPath.Find('\\', ind)+1;
		}

		CStdioFile file;			// Hugely faster than CFile for big file writes - because it uses buffering
		if (!file.Open(sFilePath, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary))
		{
			m_sErrorString.Format(IDS_ERR_FILE_OPEN, (LPCTSTR)sFilePath);
			return FALSE;
		}
		if ((!bSaveAsUTF8)&&(m_UnicodeType == CFileTextLines::UNICODE_LE))
		{
			//first write the BOM
			UINT16 wBOM = 0xFEFF;
			file.Write(&wBOM, 2);
			for (int i=0; i<GetCount(); i++)
			{
				CString sLine = GetAt(i);
				EOL ending = GetLineEnding(i);
				StripWhiteSpace(sLine,dwIgnoreWhitespaces, bBlame);
				if (bIgnoreCase)
					sLine = sLine.MakeLower();
				file.Write((LPCTSTR)sLine, sLine.GetLength()*sizeof(TCHAR));
				if (ending == EOL_AUTOLINE)
					ending = m_LineEndings;
				switch (ending)
				{
				case EOL_CR:
					sLine = _T("\x0d");
					break;
				case EOL_CRLF:
				case EOL_AUTOLINE:
					sLine = _T("\x0d\x0a");
					break;
				case EOL_LF:
					sLine = _T("\x0a");
					break;
				case EOL_LFCR:
					sLine = _T("\x0a\x0d");
					break;
				default:
					sLine.Empty();
					break;
				}
				if ((m_bReturnAtEnd)||(i != GetCount()-1))
					file.Write((LPCTSTR)sLine, sLine.GetLength()*sizeof(TCHAR));
			}
		}
		else if ((!bSaveAsUTF8)&&((m_UnicodeType == CFileTextLines::ASCII)||(m_UnicodeType == CFileTextLines::AUTOTYPE)))
		{
			for (int i=0; i< GetCount(); i++)
			{
				// Copy CString to 8 bit without conversion
				CString sLineT = GetAt(i);
				CStringA sLine = CStringA(sLineT);
				EOL ending = GetLineEnding(i);

				StripAsciiWhiteSpace(sLine,dwIgnoreWhitespaces, bBlame);
				if (bIgnoreCase)
					sLine = sLine.MakeLower();
				if ((m_bReturnAtEnd)||(i != GetCount()-1))
				{
					if (ending == EOL_AUTOLINE)
						ending = m_LineEndings;
					switch (ending)
					{
					case EOL_CR:
						sLine += '\x0d';
						break;
					case EOL_CRLF:
					case EOL_AUTOLINE:
						sLine.Append("\x0d\x0a", 2);
						break;
					case EOL_LF:
						sLine += '\x0a';
						break;
					case EOL_LFCR:
						sLine.Append("\x0a\x0d", 2);
						break;
					}
				}
				file.Write((LPCSTR)sLine, sLine.GetLength());
			}
		}
		else if ((bSaveAsUTF8)||((m_UnicodeType == CFileTextLines::UTF8BOM)||(m_UnicodeType == CFileTextLines::UTF8)))
		{
			if (m_UnicodeType == CFileTextLines::UTF8BOM)
			{
				//first write the BOM
				UINT16 wBOM = 0xBBEF;
				file.Write(&wBOM, 2);
				UINT8 uBOM = 0xBF;
				file.Write(&uBOM, 1);
			}
			for (int i=0; i<GetCount(); i++)
			{
				CStringA sLine = CUnicodeUtils::GetUTF8(GetAt(i));
				EOL ending = GetLineEnding(i);
				StripAsciiWhiteSpace(sLine,dwIgnoreWhitespaces, bBlame);
				if (bIgnoreCase)
					sLine = sLine.MakeLower();

				if ((m_bReturnAtEnd)||(i != GetCount()-1))
				{
					if (ending == EOL_AUTOLINE)
						ending = m_LineEndings;
					switch (ending)
					{
					case EOL_CR:
						sLine += '\x0d';
						break;
					case EOL_CRLF:
					case EOL_AUTOLINE:
						sLine.Append("\x0d\x0a",2);
						break;
					case EOL_LF:
						sLine += '\x0a';
						break;
					case EOL_LFCR:
						sLine.Append("\x0a\x0d",2);
						break;
					}
				}
				file.Write((LPCSTR)sLine, sLine.GetLength());
			}
		}
		file.Close();
	}
	catch (CException * e)
	{
		e->GetErrorMessage(m_sErrorString.GetBuffer(4096), 4096);
		m_sErrorString.ReleaseBuffer();
		e->Delete();
		return FALSE;
	}
	return TRUE;
}