Exemplo n.º 1
0
void CDisciplineLetterTemplate::OnSelchangeFiles() 
{
  DlgDirSelect(m_pszFile, LETTERTEMPLATE_FILES);

  pEditPREVIEW->SetWindowText("");
//
//  Open the text files for preview
//
  CString    inputLine, outputLine;
  CString    fileName;
  CStdioFile Letter;
  
  fileName = szDisciplineLetterTemplateFolder;
  fileName += "\\";
  fileName += m_pszFile;
  Letter.Open(fileName, CFile::modeRead | CFile::typeText | CFile::shareDenyNone);

  if(Letter.m_pStream)
  {
    Letter.SeekToBegin();
    outputLine = "";
    while(Letter.ReadString(inputLine))
    {
      outputLine += inputLine;
      outputLine += "\r\n";
    }
    pEditPREVIEW->SetWindowText(outputLine);
    Letter.Close();
  }
}
Exemplo n.º 2
0
/******************************************************************
 * File:文件名                                                    *
 * path:数组                                                     *
 * 自动消除空格           *
 ******************************************************************/
BOOL  CStaticAssistant::LoadEncryptInfo(CString FileName,CStringArray *path){
	CStdioFile File;
	CString temppath=_T("");
	try {
		File.Open(FileName,CFile::modeRead);
		int rowLength=0;
		while(File.ReadString(temppath)==true)
		{
			temppath.TrimRight(); temppath.TrimLeft();  //消除空格
			//AfxMessageBox("key=:: "+key+"::");
			if(temppath=="")            continue;
		    else                    rowLength++;
		}
		File.SeekToBegin();
		for(int i=0;i<rowLength;i++)
		{
			File.ReadString(temppath);
			temppath.TrimRight(); temppath.TrimLeft();  //消除空格
			//AfxMessageBox("key=:: "+key+"::");
			if(temppath=="")
			{  i--;	continue;}   //读到空格会回退计数器
			path->SetAtGrow(i,temppath);//加到CArray中
		}
	}catch(...)
	{
		File.Close();
		return false;
		AfxMessageBox("加载重要文件错误,请重试");
	}
	return TRUE;
}
Exemplo n.º 3
0
void CPackControl::OnButtonResult() 
{
	// TODO: Add your control notification handler code here
	CStdioFile f;
	f.Open(m_strResultName,CFile::modeRead);
	if(f.m_hFile!=NULL)
	{
		CTxtdlg dlg(&f);
		dlg.DoModal();
		f.SeekToBegin();
		TXTRESULT TxtResult;
		if(m_TxtResult.strInfo)
			delete[] m_TxtResult.strInfo;
		m_TxtResult.strInfo  =new INT8[f.GetLength()];
		f.Read(m_TxtResult.strInfo,f.GetLength());
		m_TxtResult.nStepCode=m_pControl->nStep;
		m_TxtResult.nAparatusInnerSeriaNumber=0;
		int nSeriaNumber;
		m_pDatalib->GetSeriaNumber(&nSeriaNumber);
		m_TxtResult.nID=nSeriaNumber;
		m_TxtResult.nInfolth=f.GetLength();
		memcpy(m_TxtResult.strName,m_pControl->strItemName,sizeof(char)*_MAX_DESCRIPTION_CNT);
		m_BTStart.EnableWindow(false);
		m_BTResult.EnableWindow(true);
		m_BTSave.EnableWindow(true);
		m_BTResultName.EnableWindow(true);
		m_BTInput.EnableWindow(false);
	}else
	{
		AfxMessageBox("控制结果文件不存在");
	}
	f.Close();
}
Exemplo n.º 4
0
void CCountGen::LoadOldAcc()
{
	CString strFilePath = gl_strExePath + "oldAcc.txt";
	CStdioFile   file;
	CString   cstr;
	CFileException   fe;
	if(file.Open(strFilePath,CFile::modeRead,&fe))   
	{ 
		file.SeekToBegin();
		int idx1=0;
		int idx2=0;
		srand(time(NULL));
		CString strAcc = "";
		CString strPwd = "";
		while (file.ReadString(cstr))
		{
			strAcc = "";
			strPwd = "";
			idx2 =cstr.Find(",");
			if (idx2==-1)
			{
				continue;
			}
			strAcc = cstr.Left(idx2);
			cstr = cstr.Mid(idx2+1);
			idx2 =cstr.Find(",");
			if (idx2==-1)
			{
				continue;
			}
			strPwd = cstr.Left(idx2);
			m_mapOldAcc[strAcc+strPwd] = 1;
		}
	}
}
Exemplo n.º 5
0
/******************************************************************
 *   如过文件中有空格行,则加到第一个空格行处,否则               *
 * 加到文件的末尾,为了方面后面的删除行操作,应该再添加路径末尾   *
 * 自动添加足够(超过需要加密的最长路径的长度)多的空格           *
 ******************************************************************/
BOOL CStaticAssistant::StoreEncryptInfo(CString path,CString fileName){
		CStdioFile File;
		CString spacei="                                                                                                                      ";
		CString temp=_T("");
		int     tempLen=0;
	try{
		File.Open(fileName,CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
		File.SeekToBegin();
		//遍历文件数据获取插入位置
		while(File.ReadString(temp)==true){
			tempLen=temp.GetLength()+2;         //重要,考虑换行符占2字节
			temp.TrimLeft(); temp.TrimRight(); //消除左右空格
			if(temp==""){
				File.Seek(-tempLen,CFile::current);
			    File.WriteString(path);  //写入要加入的路径名
			    return TRUE;
			}
		}
		File.WriteString(path+spacei+"\n");  ///写入末尾
		return TRUE;
	}catch(...){
		File.Close();
		return FALSE;
		AfxMessageBox("保存重要文件失败,请重试!");
	}
	return true;
}
Exemplo n.º 6
0
/******************************************************************
 *  此删除主要使用与此路径名相同长度的空格串来覆盖                *
 ******************************************************************/
BOOL CStaticAssistant::DeleteUncryptInfo(CString path,CString fileName){
		CStdioFile File;
		CString spacei="                                                                                                                               ";
		CString temp=_T("");
		int     tempLen=0;
	try{
		File.Open(fileName,CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
		File.SeekToBegin();
		//遍历文件数据获取插入位置
		while(File.ReadString(temp)==true){
			tempLen=temp.GetLength()+2;         //重要,考虑换行符占2字节
			temp.TrimLeft(); temp.TrimRight(); //消除左右空格
			if(temp==path){
				int len=temp.GetLength();
				spacei=spacei.Left(len);
				File.Seek(-tempLen,CFile::current); //回退文件内部指针
			    File.WriteString(spacei);           //写入要加入的路径名
			    return TRUE;
			}
		}
		File.Close();   
		return FALSE;//关闭文件并返回
	}catch(...){
		File.Close();
		return FALSE;
	}
}
Exemplo n.º 7
0
//////////////////////////////////
// loadFaceImgArray()
//
int faceRecognition::loadFaceImgArray(char * filename)
{
	//////////////////////////////////////////////////////////////////////////
	//改用CStdioFile实现
	CStdioFile imgListFile;
	CString    imgFileName;
	CString     temp;
	CString     tempId1="";
	int iFace, nFaces=0;
	// open the input file
 try{
	imgListFile.Open(filename,CStdioFile::modeRead);
	// count the number of faces
	imgListFile.SeekToBegin();
	while(imgListFile.ReadString(imgFileName)) ++nFaces;
	//20101003_问题一:将文件内部的位置指针重新指向一个流(数据流/文件)的开头 
	imgListFile.SeekToBegin();                
	// allocate the face-image array and person number matrix
	faceImgArr        = (IplImage **)cvAlloc( nFaces*sizeof(IplImage *) );
	personNumTruthMat = cvCreateMat( 1, nFaces, CV_32SC1 );
	// store the face images in an array
	for(iFace=0; iFace<nFaces; iFace++){ 
		//temp.Format("%d %s",personNumTruthMat->data.i+iFace,imgFileName);
		imgListFile.ReadString(temp);
		imgFileName=temp.Right(temp.GetLength()-3);
		tempId1=temp.Left(3);   //读取人脸编号
		//去掉左、右边空格
		tempId1.TrimRight();imgFileName.TrimLeft();
        *(personNumTruthMat->data.i+iFace)=atoi(tempId1.GetBuffer(tempId1.GetLength()));
		//去掉左、右边空格
		imgFileName.TrimRight();imgFileName.TrimLeft();
		imgFileName=imgFileName.GetBuffer(imgFileName.GetLength());
		//AfxMessageBox("$"+imgFileName+"$");
		faceImgArr[iFace] = cvLoadImage(imgFileName, CV_LOAD_IMAGE_GRAYSCALE);
// 		if(!faceImgArr[iFace]){CString S;
// 			    S.Format("Can\'t load image from %s\n", imgFileName); AfxMessageBox(S);return 0;
// 		    AfxMessageBox(S);}
	}
	imgListFile.Close();
 }catch(...){
		imgListFile.Close();
		AfxMessageBox("加载训练图片失败");
		return 0;
	}
	return nFaces;
}
Exemplo n.º 8
0
 /*
 *		here we use following structrue to add functionality
 *		m_fun(0)="funname1@funpos1,funname2@funpos2..."
 *		m_fun(1-FUN_MAX)="parameterstack(1-FUN_MAX)"
 */
bool CTesterProgram::InstallScheme(CString schemename)
{
//	if(m_iStackDepth > 0)		return false;
	CStdioFile csf;

	if(0 == csf.Open(g_Path+"\\Data\\"+schemename+".prg",CFile::modeRead))
		return false;
	csf.SeekToBegin();
	 /*
	 *	Reset the component
	 */
	if(g_TesterConf.m_iRetestID == -1)
		g_Data.ResetRecord();

	m_fun.RemoveAll();
	for(int i=0;i<(FUN_MAX+1);i++)	//add function declaration and function stack
	{
		m_fun.Add(_T(""));
	}
	
	g_TesterConf.m_iRetestID = -1;
	m_iStackDepth = 0;
	
	CString line;
	while(csf.ReadString(line))
	{
		if(line.GetAt(0) == '<')//function declaration
		{
			CString str1;
			int pos=line.Find('>',0);
			str1.Format("%d",m_fun.GetSize());
			m_fun.SetAt(0,m_fun.GetAt(0)+line.Mid(1,pos-1)+'@'+str1+',');
			while(csf.ReadString(line))
			{
				if(line.GetLength() < 1)
					continue;
				if(line.GetAt(0) == '>')
					break;
				m_fun.Add(line);
			}
			m_fun.Add(_T("><"));
		}
	}

	csf.Close();

	if(bLogOn)
		logout.Close();

	bLogOn = (0 != logout.Open(g_Path+"\\Data\\record.txt",CFile::modeCreate|CFile::modeWrite));

	
	return true;

}
Exemplo n.º 9
0
void DLrtfhtml::openfile(CString filename)
{
	CStdioFile rtf;
	rtf.Open(_T("F:\\\\itbook2.tit"),CStdioFile::modeRead);
	int len=rtf.GetLength();
	rtf.SeekToBegin();
	CStringA content;
	rtf.Read(content.GetBuffer(len),len);
	content.ReleaseBuffer();
	rtf.Close();

	char* str,*strd;
	str=strd=new char[len+1];
	memset(str,'\0',sizeof(str));
	int bg,end;
	bg=end=0;
	char* p;
	while((end=content.Find("\\\'",end))>=0)
	{
		if(end==0 || content.GetAt(end-1)!='\\')
		{//转汉字
			CStringA s;
			if(end!=bg)
			{
				strcpy(str,(LPSTR)(LPCSTR)content.Mid(bg,end-bg));
				str+=(end-bg);
			}
			*str=strtol(content.Mid(end+2,2),&p,16);
			str++;
			bg=end+4;
		}
		else
		{// \\' 去斜杆
			if(end!=bg)
			{
				strcpy(str,(LPSTR)(LPCSTR)content.Mid(bg,end-bg-1)); //   '之前还有两个" \ "
				str+=(end-bg-1);
			}
			strcpy(str,(LPSTR)(LPCSTR)content.Mid(end,2));
			str+=2;
			bg=end+2;
		}
		end++;
	}
	int leng=content.GetLength();
	if((content.GetLength()-bg)>2)//如果再最后两个字符找到\'则会=2  当然根据rtf文档绝对不会这样。
		strcpy(str,(LPSTR)(LPCSTR)content.Mid(bg));
	//}
	int  unicodeLen = ::MultiByteToWideChar( CP_ACP,0,strd,-1,NULL,0);  
	MultiByteToWideChar(CP_ACP,0,strd,-1,(LPWSTR)destcon.GetBuffer(unicodeLen),unicodeLen);
	destcon.ReleaseBuffer();
}
Exemplo n.º 10
0
//写到指定的行,及替换原来的行
BOOL faceRecognition::addFaceImgArray(char *name,bool flag,int row){
	CStdioFile  fwrite;
    CString S1="";
	row=row-1;
	CString  temp=CString(name);
	//temp=temp+"\n";//自动加上换行符号
	try{
		if(flag==true) 
		{//for train
			if(fwrite.Open(learnFileListPath,CStdioFile::modeReadWrite|CStdioFile::modeCreate|CStdioFile::modeNoTruncate)==FALSE)
				AfxMessageBox("打开文件 "+CString(learnFileListPath)+" 失败!!");
		}else{
			if(fwrite.Open(testFileListPath,CStdioFile::modeReadWrite)==FALSE)
				AfxMessageBox("打开文件 "+CString(testFileListPath)+" 失败!!");
		}
		fwrite.SeekToBegin();
		for(int i=0; i<row; i++){
			fwrite.ReadString(S1);
		}
        fwrite.ReadString(S1); //指针指向第row+1行开头
		///fwrite.ReadString(S2);
        fwrite.Seek(-S1.GetLength()-2,CFile::current);  //考虑回车换行符//指针指向第row行开头
        fwrite.WriteString(temp);
		// AfxMessageBox(S2);
		//fwrite.WriteString(temp);
// 		int len=S1.GetLength()-2-temp.GetLength();
// 		if(len>0)       //用指定符号覆盖多余字符
		fwrite.SeekToBegin();
		fwrite.Close();
	}catch(CFileException e)
	{
        fwrite.Close();
		AfxMessageBox("文件写入失败::"+CString(name));
	}	 
	return true;
}
Exemplo n.º 11
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
}
Exemplo n.º 12
0
//保存信息到指定文件夹
BOOL CStaticAssistant::StoreEncryptInfo(CMapStringToString *m,CString fileName){
	CStdioFile File;
	try{
		CString key=_T(""), value=_T("");
		File.Open("res/temp.znl",CFile::modeWrite| CFile::modeCreate);
		File.SeekToBegin();
		//遍历Cmap获取数据并写入指定的那个文件
		POSITION pos = m->GetStartPosition();
		while(pos)	{ 
			m->GetNextAssoc(pos,key,value);
			File.WriteString(key+"\n");
			File.WriteString(value+"\n");
			//AfxMessageBox(key+"::"+value);			 
		}
	}catch(...){
		File.Close();
		return false;
		AfxMessageBox("保存重要文件失败,请重试!");
	}
	return true;
}
Exemplo n.º 13
0
int C51JobWebPost::GetGateWayIP(CString &strIP)
{
	CInternetSession session;
	CString strTemp = "";
	char temp[1001] = {0};
	CStdioFile *pFile = session.OpenURL("http://www.ip138.com/ip2city.asp");
	if (pFile != NULL)
	{
		long len = pFile->GetLength();
		if (len > 1000)
		{
			len = 1000;
		}		
		pFile->SeekToBegin();
		pFile->Read(temp,len);
		temp[len] = '\0';
		strTemp.Format("%s",temp);
		strTemp.MakeLower();
		if (strTemp.Find("您的ip地址是:[") !=-1)
		{
			CString strBefore = "您的ip地址是:[";
			CString strAfter = "]";
			strIP = GetKeyString(strTemp,strBefore,strAfter);
			pFile->Close();
			delete pFile;
			pFile = NULL;
			return 0;
		}
		if (pFile == NULL)
		{
			pFile->Close();
			delete pFile;
			pFile = NULL;
		}
		
	}
	return -1;
}
Exemplo n.º 14
0
int SetupMIFLINES(MIFPASSEDDATADef *pMIFPASSEDDATA, MIFLINESDef *pMIFLINES)
{
  MIFLINESDef MIFLINES[TMSRPT61_MAXMIFLINES];
  CString s;
  double  dValue1, dValue2, dValue3, dValue4;
  double  Lat, Long;
  double  distance;
  double  leastDistance;
  BOOL    bDATAFound;
  BOOL    bCoordSysNonEarthFound;
  BOOL    bBreak;
  BOOL    bFound;
  char   *ptr;
  long    firstNODESrecordID;
  long    firstStopNumber;
  long    firstStopNODESrecordID;
  long    toNODESrecordID;
  long    toStopNumber;
  long    toStopNODESrecordID;
  long    NODESrecordID;
  long    previousNODESrecordID;
  long    travelTime;
  int     nI, nJ, nK;
  int     numMultiples;
  int     numSegments;
  int     numMIFLINES;
  int     rcode2;
  int     leastDistanceIndex;
  int     MIFPointer;
//
//  Establish and open the .mif file
//
  CString MIFFileName;
  CStdioFile MIFFile;

  MIFFileName = pMIFPASSEDDATA->szMIFFileName;
//
//  Look for this pattern name attached to the szMIFFileName
//  to see if we have a spcialized trace file
//
  PATTERNNAMESKey0.recordID = pMIFPASSEDDATA->PATTERNNAMESrecordID;
  rcode2 = btrieve(B_GETEQUAL, TMS_PATTERNNAMES, &PATTERNNAMES, &PATTERNNAMESKey0, 0);
  if(rcode2 != 0)
  {
    sprintf(tempString, "***ERR Pattern not found in PATTERNNAMES : RecordID = %ld\r\n", pMIFPASSEDDATA->PATTERNNAMESrecordID);
    _lwrite(pMIFPASSEDDATA->hfErrorLog, tempString, strlen(tempString));
    return(NO_RECORD);
  }
  else
  {
    strncpy(tempString, PATTERNNAMES.name, PATTERNNAMES_NAME_LENGTH);
    trim(tempString, PATTERNNAMES_NAME_LENGTH);
    MIFFileName += tempString;
    MIFFileName += ".mif";
    sprintf(tempString, "***INF Opening Trace File : \"%s\"\r\n", MIFFileName);
    _lwrite(pMIFPASSEDDATA->hfErrorLog, tempString, strlen(tempString));
//
//  The specialized trace file isn't there - look for the regular one
//
    if(MIFFile.Open(MIFFileName, CFile::modeRead | CFile::typeText | CFile::shareDenyNone) == 0)
    {
      sprintf(tempString, "***INF Could not open Trace File : \"%s\"\r\n", MIFFileName);
      _lwrite(pMIFPASSEDDATA->hfErrorLog, tempString, strlen(tempString));
      MIFFileName = pMIFPASSEDDATA->szMIFFileName;
      MIFFileName  += ".mif";
      sprintf(tempString, "***INF Opening Trace File : \"%s\"\r\n", MIFFileName);
      _lwrite(pMIFPASSEDDATA->hfErrorLog, tempString, strlen(tempString));
      if(MIFFile.Open(MIFFileName, CFile::modeRead | CFile::typeText | CFile::shareDenyNone) == 0)
      {
        s.LoadString(ERROR_349);
        sprintf(szarString, s, MIFFileName);
        MessageBeep(MB_ICONINFORMATION);
        MessageBox(NULL, szarString, TMS, MB_OK | MB_ICONINFORMATION);
        sprintf(tempString, "***ERR Could not open Trace File : \"%s\"\r\n", MIFFileName);
        _lwrite(pMIFPASSEDDATA->hfErrorLog, tempString, strlen(tempString));
        return(NO_RECORD);
      }
    }
  }
//
//  Cycle through the .MIF file
//
  bDATAFound = FALSE;
  bCoordSysNonEarthFound = FALSE;
  numMIFLINES = 0;
  MIFFile.SeekToBegin();
  while(MIFFile.ReadString(s))
  {
    s.MakeUpper();
//
//  Scan through until we hit "DATA" and/or "CoordSys"
//
    if(!bDATAFound)
    {
//
//  Is "CoordSys NonEarth" present?
//
      if(!bCoordSysNonEarthFound)
      {
        nI = s.Find("COORDSYS NONEARTH", 0);
        if(nI != -1)
        {
          bCoordSysNonEarthFound = TRUE;
          continue;
        }
      }
//
//  Check for "DATA"
//
      nI = s.Find("DATA", 0);
      if(nI != -1)
      {
        bDATAFound = TRUE;
      }
      continue;
    }
//
//  "DATA" Encountered.  Now look to see what lines are involved.
//
//  "PLINE"
//
    nI = s.Find("PLINE", 0);
    if(nI != -1)
    {
//
//  There are two possibilities in a PLINE statement:
//     1) It's followed (on the same line) by the number of points to follow
//     2) It's followed (on the same line) by the keyword "MULTIPLE" and then the number of sections,
//        with each section starting with the number of points to follow
// 
//  Look for "MULTIPLE"
//
      strcpy(tempString, s);
      nI = s.Find("MULTIPLE", 0);
      if(nI != -1)
      {
        if((ptr = strtok(tempString, wSpace)) == NULL)  // Get rid of "PLINE"
        {
          continue;
        }
        if((ptr = strtok(NULL, wSpace)) == NULL)  // Get rid of "MULTIPLE"
        {
          continue;
        }
        if((ptr = strtok(NULL, wSpace)) == NULL)  // Get the number of multiples
        {
          continue;
        }
        numMultiples = atol(ptr);
        if(!MIFFile.ReadString(s))
        {
          break;
        }
        numSegments = atol(s);
      }
//
//  No "MULTIPLE" - get the number of segments
//
      else
      {
        numMultiples = 1;
        if((ptr = strtok(tempString, wSpace)) == NULL)  // Get rid of "PLINE"
        {
          continue;
        }
        if((ptr = strtok(NULL, wSpace)) == NULL)  // Get the number of segments
        {
          continue;
        }
        numSegments = atol(ptr);
      }
//
//  Loop through the segments and multiples
//
      bBreak = FALSE;
      for(nI = 0; nI < numMultiples; nI++)
      {
        if(bBreak)
        {
          break;
        }
        for(nJ = 0; nJ < numSegments; nJ++)
        {
          if(!MIFFile.ReadString(s))
          {
            bBreak = TRUE;
            break;
          }
          strcpy(tempString, s);
          if((ptr = strtok(tempString, wSpace)) == NULL)  // Take the first numeric
          {
            continue;
          }
          dValue1 = (double)atof(ptr);
          if((ptr = strtok(NULL, wSpace)) == NULL)  // Get the second numeric
          {
            continue;
          }
          dValue2 = (double)atof(ptr);
//
//  Got two doubles - do we have to convert them to Lat/Long?
//
          if(bCoordSysNonEarthFound)
          {
            EN2LL(23, dValue1, dValue2, szUTMZone, &Lat, &Long);
          }
          else
          {
            Long = dValue1;
            Lat  = dValue2;
//            Long = dValue2;
//            Lat  = dValue1;
          }
//
//  Save Lat and Long to the data structure
//
          MIFLINES[numMIFLINES].flags = nJ == 0 ? MIFLINES_FLAG_START : 0;
          if(nJ != numSegments - 1)
          {
            MIFLINES[numMIFLINES].from.longitude = Long;
            MIFLINES[numMIFLINES].from.latitude = Lat;
          }
          if(nJ > 0)
          {
            MIFLINES[numMIFLINES - 1].to.longitude = Long;
            MIFLINES[numMIFLINES - 1].to.latitude = Lat;
          }
          if(nJ != numSegments - 1)
          {
            numMIFLINES++;
            if(numMIFLINES >= TMSRPT61_MAXMIFLINES)
            {
              sprintf(tempString, "***ERR TMSRPT61_MAXMIFLINES too small (1)\r\n");
              _lwrite(pMIFPASSEDDATA->hfErrorLog, tempString, strlen(tempString));
              return(NO_RECORD);
            }
          }
        }
        if(numMultiples > 1)
        {
          if(!MIFFile.ReadString(s))
          {
            bBreak = TRUE;
          }
          else
          {
            numSegments = atol(s);
          }
        }
      }
    }
//
//  "LINE"
//
    else
    {
      nI = s.Find("LINE", 0);
      if(nI != -1)
      {
        strcpy(tempString, s);
        if((ptr = strtok(tempString, wSpace)) == NULL)  // Get rid of "LINE"
        {
          continue;
        }
        if((ptr = strtok(NULL, wSpace)) == NULL)  // Take the first numeric
        {
          continue;
        }
        dValue1 = (double)atof(ptr);
        if((ptr = strtok(NULL, wSpace)) == NULL)  // Get the second numeric
        {
          continue;
        }
        dValue2 = (double)atof(ptr);
        if((ptr = strtok(NULL, wSpace)) == NULL)  // Get the third numeric
        {
          continue;
        }
        dValue3 = (double)atof(ptr);
        if((ptr = strtok(NULL, wSpace)) == NULL)  // Get the fourth numeric
        {
          continue;
        }
        dValue4 = (double)atof(ptr);
//
//  Do we convert?
//
        if(bCoordSysNonEarthFound)
        {
          EN2LL(23, dValue1, dValue2, szUTMZone, &Lat, &Long);
        }
        else
        {
          Long = dValue1;
          Lat  = dValue2;
        }
        MIFLINES[numMIFLINES].flags = MIFLINES_FLAG_START;
        MIFLINES[numMIFLINES].from.longitude = Long;
        MIFLINES[numMIFLINES].from.latitude = Lat;
        if(bCoordSysNonEarthFound)
        {
          EN2LL(23, dValue3, dValue4, szUTMZone, &Lat, &Long);
        }
        else
        {
          Long = dValue3;
          Lat  = dValue4;
        }
        MIFLINES[numMIFLINES].to.longitude = Long;
        MIFLINES[numMIFLINES].to.latitude = Lat;
        numMIFLINES++;
        if(numMIFLINES >= TMSRPT61_MAXMIFLINES)
        {
          sprintf(tempString, "***ERR TMSRPT61_MAXMIFLINES too small (2)\r\n");
          _lwrite(pMIFPASSEDDATA->hfErrorLog, tempString, strlen(tempString));
          return(NO_RECORD);
        }
      }
    }
  }
//
//  Establish the output lines
//
//  Get the first node on the pattern
//
  PATTERNSKey2.ROUTESrecordID = pMIFPASSEDDATA->ROUTESrecordID;
  PATTERNSKey2.SERVICESrecordID = pMIFPASSEDDATA->SERVICESrecordID;
  PATTERNSKey2.directionIndex = pMIFPASSEDDATA->directionIndex;
  PATTERNSKey2.PATTERNNAMESrecordID = pMIFPASSEDDATA->PATTERNNAMESrecordID;
  PATTERNSKey2.nodeSequence = NO_RECORD;
  rcode2 = btrieve(B_GETGREATER, TMS_PATTERNS, &PATTERNS, &PATTERNSKey2, 2);
  if(rcode2 == 0 &&
        PATTERNS.ROUTESrecordID == pMIFPASSEDDATA->ROUTESrecordID &&
        PATTERNS.SERVICESrecordID == pMIFPASSEDDATA->SERVICESrecordID &&
        PATTERNS.directionIndex == pMIFPASSEDDATA->directionIndex &&
        PATTERNS.PATTERNNAMESrecordID == pMIFPASSEDDATA->PATTERNNAMESrecordID)
  {
    NODESrecordID = NodeEquivalenced(PATTERNS.NODESrecordID);
    NODESKey0.recordID = NODESrecordID == NO_RECORD ? PATTERNS.NODESrecordID : NODESrecordID;
    btrieve(B_GETEQUAL, TMS_NODES, &NODES, &NODESKey0, 0);
    firstNODESrecordID = NODES.recordID;
    firstStopNumber = (pMIFPASSEDDATA->directionIndex == 0 ? NODES.OBStopNumber : NODES.IBStopNumber);
    if(firstStopNumber <= 0)
    {
      firstStopNumber = NODES.number;
    }
    if(firstStopNumber > 0)
    {
      bFound = FALSE;
      rcode2 = btrieve(B_GETFIRST, TMS_NODES, &NODES, &NODESKey0, 0);
      while(rcode2 == 0)
      {
        if((NODES.flags & NODES_FLAG_STOP))
        {
          if(NODES.number == firstStopNumber)
          {
            firstStopNODESrecordID = NODES.recordID;
            bFound = TRUE;
            break;
          }
        }
        rcode2 = btrieve(B_GETNEXT, TMS_NODES, &NODES, &NODESKey0, 0);
      }
      if(!bFound)
      {
        NODESKey0.recordID = PATTERNS.NODESrecordID;
        btrieve(B_GETEQUAL, TMS_NODES, &NODES, &NODESKey0, 0);
      }
//
//  Change to stop number (as derived from long name) : Bob Antonisse, 2-Aug-07
//
      else
      {
        strncpy(tempString, NODES.longName, NODES_LONGNAME_LENGTH);
        trim(tempString, NODES_LONGNAME_LENGTH);
        firstStopNumber = atol(&tempString[4]);
      }
    }
    Long = NODES.longitude;
    Lat = NODES.latitude;
  }
  else
  {
    sprintf(tempString, "***ERR Pattern without nodes\r\n");
    _lwrite(pMIFPASSEDDATA->hfErrorLog, tempString, strlen(tempString));
    return(NO_RECORD);
  }
//
//  Locate the closest MIFLINE to the starting node
//  and string the rest of the lines together in order
//
  for(nI = 0; nI < numMIFLINES; nI++)
  {
    leastDistance = 10000;
    leastDistanceIndex = NO_RECORD;
    for(nJ = 0; nJ < numMIFLINES; nJ++)
    {
      if(MIFLINES[nJ].flags & MIFLINES_FLAG_USED)
      {
        continue;
      }
      distance = GreatCircleDistance(Long, Lat, MIFLINES[nJ].from.longitude, MIFLINES[nJ].from.latitude);
      if(distance < leastDistance)
      {
        leastDistance = distance;
        leastDistanceIndex = nJ;
      }
    }
    if(leastDistanceIndex == NO_RECORD)
    {
      sprintf(tempString, "***ERR Least distance index remained at NO_RECORD in search for starting node\r\n");
      _lwrite(pMIFPASSEDDATA->hfErrorLog, tempString, strlen(tempString));
      return(NO_RECORD);
    }
    pMIFLINES[nI] = MIFLINES[leastDistanceIndex];
    Long = MIFLINES[leastDistanceIndex].to.longitude;
    Lat = MIFLINES[leastDistanceIndex].to.latitude;
    MIFLINES[leastDistanceIndex].flags = MIFLINES_FLAG_USED;
  }
  if(pMIFPASSEDDATA->ROUTESrecordID == 16)
  {
    nI = 1;
  }
//
//  Set all the lines to be contiguous (no "pen up")
//  and set all the nodes to NO_RECORD
//

  for(nI = 1; nI < numMIFLINES; nI++)
  {
    pMIFLINES[nI].from.latitude  = pMIFLINES[nI - 1].to.latitude;
    pMIFLINES[nI].from.longitude = pMIFLINES[nI - 1].to.longitude;
  }

//
//  Nodes and associated stops refer to the "from" element of the
//  first line kept in MIFLINES, and to the "to" element of each
//  subsequent line.
//
//  We got the first node in the pattern earlier
//
  pMIFLINES[0].from.latitude = NODES.latitude;
  pMIFLINES[0].from.longitude = NODES.longitude;
  pMIFLINES[0].from.flags = 0;
  pMIFLINES[0].from.NODESrecordID = firstNODESrecordID;
  pMIFLINES[0].from.associatedStopNODESrecordID = firstStopNODESrecordID;
  pMIFLINES[0].from.associatedStopNumber = firstStopNumber;
  pMIFLINES[0].to.flags = 0;
  pMIFLINES[0].to.NODESrecordID = NO_RECORD;
  pMIFLINES[0].to.associatedStopNODESrecordID = NO_RECORD;
  pMIFLINES[0].to.associatedStopNumber = NO_RECORD;
//
//  Clear out the (yet) unused portions of the structure
//
  for(nI = 1; nI < numMIFLINES; nI++)
  {
    pMIFLINES[nI].from.flags = 0;
    pMIFLINES[nI].from.NODESrecordID = NO_RECORD;
    pMIFLINES[nI].from.associatedStopNODESrecordID = NO_RECORD;
    pMIFLINES[nI].from.associatedStopNumber = NO_RECORD;
    pMIFLINES[nI].to.flags = 0;
    pMIFLINES[nI].to.NODESrecordID = NO_RECORD;
    pMIFLINES[nI].to.associatedStopNODESrecordID = NO_RECORD;
    pMIFLINES[nI].to.associatedStopNumber = NO_RECORD;
  }
//
//  And record the nodes/stops as encountered
//
  pMIFPASSEDDATA->NODESrecordIDs[0] = PATTERNS.NODESrecordID;
  pMIFPASSEDDATA->numNodes = 1;
//
//  Put the rest of the pattern nodes/stops into the MIFLINES structure
//
  MIFPointer = 0;
  previousNODESrecordID = PATTERNS.NODESrecordID;
  rcode2 = btrieve(B_GETNEXT, TMS_PATTERNS, &PATTERNS, &PATTERNSKey2, 2);
  while(rcode2 == 0 &&
        PATTERNS.ROUTESrecordID == pMIFPASSEDDATA->ROUTESrecordID &&
        PATTERNS.SERVICESrecordID == pMIFPASSEDDATA->SERVICESrecordID &&
        PATTERNS.directionIndex == pMIFPASSEDDATA->directionIndex &&
        PATTERNS.PATTERNNAMESrecordID == pMIFPASSEDDATA->PATTERNNAMESrecordID)
  {
    pMIFPASSEDDATA->NODESrecordIDs[pMIFPASSEDDATA->numNodes] = PATTERNS.NODESrecordID;
    pMIFPASSEDDATA->numNodes++;
//
//  If we encounter a mid-trip layover, it gets a special record.
//
//  From Orbital:
//    "To declare a mid-trip layover, the pattern in the VTP File must contain exactly one record where the
//    'from timepoint name' and 'to timepoint name' fields are set to exactly the same non-null value.
//    In the example case, they should both be set to 'LTCA'.  It wouldn't work to set one to 'LTCA' and
//    the other to 'LTCD' because our software would interpret this as two distinct timepoints.  The following
//    field pairs must also match:  'from timepoint id' = 'to timepoint id', 'from stop name' = 'to stop name',
//    'from stop id' = 'to stop id', 'from longitude' = 'to longitude', 'from latitude' = 'to latitude'.
//
    if(NodesEquivalent(previousNODESrecordID, PATTERNS.NODESrecordID, &travelTime))
    {
      pMIFLINES[MIFPointer - 1].flags |= MIFLINES_FLAG_NEXTISSAMELOCATION;  // MIFPointer can't be 0
    }
//
//  Not a mid-trip layover
//
    else
    {
//
//  Isolate the node
//
      if(PATTERNS.flags & PATTERNS_FLAG_BUSSTOP)
      {
        NODESKey0.recordID = PATTERNS.NODESrecordID;
        btrieve(B_GETEQUAL, TMS_NODES, &NODES, &NODESKey0, 0);
        toNODESrecordID = NO_RECORD;
        toStopNODESrecordID = NODES.recordID;
        toStopNumber = (pMIFPASSEDDATA->directionIndex == 0 ? NODES.OBStopNumber : NODES.IBStopNumber);
        if(toStopNumber <= 0)
        {
//          toStopNumber = NODES.number;
          strncpy(tempString, NODES.longName, NODES_LONGNAME_LENGTH);
          trim(tempString, NODES_LONGNAME_LENGTH);
          toStopNumber = atol(&tempString[4]);
        }
      }
      else
      {
        NODESrecordID = NodeEquivalenced(PATTERNS.NODESrecordID);
        NODESKey0.recordID = NODESrecordID == NO_RECORD ? PATTERNS.NODESrecordID : NODESrecordID;
        btrieve(B_GETEQUAL, TMS_NODES, &NODES, &NODESKey0, 0);
        toNODESrecordID = NODES.recordID;
        toStopNumber = (pMIFPASSEDDATA->directionIndex == 0 ? NODES.OBStopNumber : NODES.IBStopNumber);
        toStopNODESrecordID = NO_RECORD;
        if(toStopNumber <= 0)
        {
          toStopNumber = NODES.number;
        }
        if(toStopNumber > 0)
        {
          bFound = FALSE;
          rcode2 = btrieve(B_GETFIRST, TMS_NODES, &NODES, &NODESKey0, 0);
          while(rcode2 == 0)
          {
            if((NODES.flags & NODES_FLAG_STOP) && NODES.number == toStopNumber)
            {
              toStopNODESrecordID = NODES.recordID;
              bFound = TRUE;
              break;
            }
            rcode2 = btrieve(B_GETNEXT, TMS_NODES, &NODES, &NODESKey0, 0);
          }
          if(!bFound)
          {
            NODESrecordID = NodeEquivalenced(PATTERNS.NODESrecordID);
            NODESKey0.recordID = NODESrecordID == NO_RECORD ? PATTERNS.NODESrecordID : NODESrecordID;
            btrieve(B_GETEQUAL, TMS_NODES, &NODES, &NODESKey0, 0);
          }
          else
          {
            strncpy(tempString, NODES.longName, NODES_LONGNAME_LENGTH);
            trim(tempString, NODES_LONGNAME_LENGTH);
            toStopNumber = atol(&tempString[4]);
          }
        }
      }
//
//  Find the closest endpoint to the node/stop
//
      if(pMIFPASSEDDATA->ROUTESrecordID == 21)
      {
        int nx = 1;
      }
      leastDistance = 10000;
      leastDistanceIndex = NO_RECORD;
      for(nI = MIFPointer; nI < numMIFLINES; nI++)
      {
        distance = GreatCircleDistance(NODES.longitude, NODES.latitude, pMIFLINES[nI].to.longitude, pMIFLINES[nI].to.latitude);
        if(distance < leastDistance)
        {
          leastDistance = distance;
          leastDistanceIndex = nI;
        }
      }
      if(leastDistanceIndex == NO_RECORD)
      {
        sprintf(tempString, "***ERR Least distance index remained at NO_RECORD in search for subsequent nodes\r\n");
        _lwrite(pMIFPASSEDDATA->hfErrorLog, tempString, strlen(tempString));
        strncpy(szarString, NODES.abbrName, NODES_ABBRNAME_LENGTH);
        trim(szarString, NODES_ABBRNAME_LENGTH);
        sprintf(tempString, "***INF This function failed at or before the search for %s on the pattern\r\n", szarString);
        _lwrite(pMIFPASSEDDATA->hfErrorLog, tempString, strlen(tempString));
        return(NO_RECORD);
      }
//
//  Set the "to" portion of the line to the located node's coordinates
//
      pMIFLINES[leastDistanceIndex].to.flags = PATTERNS.flags;
      pMIFLINES[leastDistanceIndex].to.latitude = NODES.latitude;
      pMIFLINES[leastDistanceIndex].to.longitude = NODES.longitude;
      pMIFLINES[leastDistanceIndex].to.NODESrecordID = toNODESrecordID;
      pMIFLINES[leastDistanceIndex].to.associatedStopNumber = toStopNumber;
      pMIFLINES[leastDistanceIndex].to.associatedStopNODESrecordID = toStopNODESrecordID;
//
//  If we're not on the last one, set the "from" portion of
//  the next line to the located node's coordinates
//
      if(leastDistanceIndex < numMIFLINES - 1)
      {
        pMIFLINES[leastDistanceIndex + 1].from = pMIFLINES[leastDistanceIndex].to;
      }
//
//  Reset the MIFPointer to the next line and cycle back
//
      MIFPointer = leastDistanceIndex + 1;
    }
    previousNODESrecordID = PATTERNS.NODESrecordID;
    rcode2 = btrieve(B_GETNEXT, TMS_PATTERNS, &PATTERNS, &PATTERNSKey2, 2);
  }
//
//  Go through MIFLINES and fill in the "blanks" where lines connect to just other lines
//
//  Do "from" first
//
  long setIndex = 0;

  nI = -1;
  while(nI < numMIFLINES - 1)
  {
    nI++;
    if(nI >= numMIFLINES)
    {
      break;
    }
    if(pMIFLINES[nI].from.NODESrecordID == NO_RECORD &&
          pMIFLINES[nI].from.associatedStopNODESrecordID == NO_RECORD)
    {
      for(bFound = FALSE, nJ = nI; nJ < numMIFLINES; nJ++)
      {
        if(pMIFLINES[nJ].from.NODESrecordID == NO_RECORD &&
              pMIFLINES[nJ].from.associatedStopNODESrecordID == NO_RECORD)
        {
          continue;
        }
        bFound = TRUE;
        break;
      }
      if(!bFound)
      {
        nJ = numMIFLINES;
      }
      for(nK = nI; nK < nJ; nK++)
      {
        pMIFLINES[nK].from.NODESrecordID = pMIFLINES[setIndex].from.NODESrecordID;
        pMIFLINES[nK].from.associatedStopNODESrecordID = pMIFLINES[setIndex].from.associatedStopNODESrecordID;
        pMIFLINES[nK].from.associatedStopNumber = pMIFLINES[setIndex].from.associatedStopNumber;
        pMIFLINES[nK].from.flags = pMIFLINES[setIndex].from.flags;
      }
      nI = nK - 1;
    }
    setIndex = nI;
  }
//
//  Now do "to"
//
  nI = -1;
  while(nI < numMIFLINES - 1)
  {
    nI++;
    if(nI >= numMIFLINES)
    {
      break;
    }
    if(pMIFLINES[nI].to.NODESrecordID == NO_RECORD &&
          pMIFLINES[nI].to.associatedStopNODESrecordID == NO_RECORD)
    {
      for(nJ = nI; nI < numMIFLINES - 1; nJ++)
      {
        if(pMIFLINES[nJ].to.NODESrecordID == NO_RECORD &&
              pMIFLINES[nJ].to.associatedStopNODESrecordID == NO_RECORD)
        {
          continue;
        }
        for(nK = nI; nK < nJ; nK++)
        {
          pMIFLINES[nK].to.NODESrecordID = pMIFLINES[nJ].to.NODESrecordID;
          pMIFLINES[nK].to.associatedStopNODESrecordID = pMIFLINES[nJ].to.associatedStopNODESrecordID;
          pMIFLINES[nK].to.associatedStopNumber = pMIFLINES[nJ].to.associatedStopNumber;
          pMIFLINES[nK].to.flags = pMIFLINES[nJ].to.flags;
        }
        nI = nK - 1;
        break;
      }
    }
  }
//
//
//  Close the file
//
  MIFFile.Close();
//
//  All done
//
//  Return MIFPointer instead of numMIFLINES in case we short turned
//
  return(MIFPointer);
}
Exemplo n.º 15
0
CDibSection* InformApp::GetImage(const char* path)
{
  // Check if it's a PNG file
  CStdioFile imageFile;
  if (!imageFile.Open(path,CFile::modeRead|CFile::typeBinary))
    return 0;
  png_byte fileHeader[8];
  imageFile.Read(fileHeader,8);
  bool isPNG = (png_sig_cmp(fileHeader,0,8) == 0);

  if (isPNG)
  {
    // Prepare to read the PNG file
    png_structp png_ptr = png_create_read_struct
      (PNG_LIBPNG_VER_STRING,(png_voidp)NULL,NULL,NULL);
    if (png_ptr == NULL)
      return 0;
    png_infop info_ptr = png_create_info_struct(png_ptr);
    if (info_ptr == NULL)
    {
      png_destroy_read_struct(&png_ptr,(png_infopp)NULL,(png_infopp)NULL);
      return 0;
    }
    png_infop end_info = png_create_info_struct(png_ptr);
    if (end_info == NULL)
    {
      png_destroy_read_struct(&png_ptr,&info_ptr,(png_infopp)NULL);
      return 0;
    }

    // Set up the point to return to in case of error
    png_bytep* rowPointers = NULL;
    if (setjmp(png_jmpbuf(png_ptr)))
    {
      if (rowPointers)
        delete[] rowPointers;
      png_destroy_read_struct(&png_ptr,&info_ptr,&end_info);
      return 0;
    }

    png_init_io(png_ptr,imageFile.m_pStream);
    png_set_sig_bytes(png_ptr,8);
    png_read_info(png_ptr,info_ptr);

    // Get details of the image
    png_uint_32 width = png_get_image_width(png_ptr,info_ptr);
    png_uint_32 height = png_get_image_height(png_ptr,info_ptr);
    int bit_depth = png_get_bit_depth(png_ptr,info_ptr);
    int color_type = png_get_color_type(png_ptr,info_ptr);

    // Set up transforms to the required format
    if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth <= 8)
      png_set_palette_to_rgb(png_ptr);
    if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
      png_set_expand_gray_1_2_4_to_8(png_ptr);
    if (png_get_valid(png_ptr,info_ptr,PNG_INFO_tRNS))
      png_set_tRNS_to_alpha(png_ptr);
    double gamma;
    if (png_get_gAMA(png_ptr,info_ptr,&gamma))
      png_set_gamma(png_ptr,2.2,gamma);
    if (bit_depth == 16)
      png_set_strip_16(png_ptr);
    if (bit_depth < 8)
      png_set_packing(png_ptr);
    if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
      png_set_gray_to_rgb(png_ptr);
    png_set_bgr(png_ptr);
    png_set_filler(png_ptr,0xFF,PNG_FILLER_AFTER);

    // Create a bitmap
    HDC dc = ::GetDC(NULL);
    CDibSection* dib = new CDibSection();
    BOOL created = dib->CreateBitmap(dc,width,height);
    ::ReleaseDC(NULL,dc);
    if (!created)
    {
      png_destroy_read_struct(&png_ptr,&info_ptr,&end_info);
      return NULL;
    }

    // Read in the image
    rowPointers = new png_bytep[height];
    for (int i = 0; i < (int)height; i++)
      rowPointers[i] = ((png_bytep)dib->GetBits())+(width*i*4);
    png_read_image(png_ptr,rowPointers);
    png_read_end(png_ptr,end_info);
    delete[] rowPointers;

    png_destroy_read_struct(&png_ptr,&info_ptr,&end_info);
    return dib;
  }
  else
  {
    imageFile.SeekToBegin();

    struct jpeg_decompress_struct info;
    struct JPEGErrorInfo error;

    // Initialize the error handling
    info.err = jpeg_std_error(&(error.base));
    error.base.error_exit = errorJPEGExit;
    error.base.output_message = outputJPEGMessage;
    if (setjmp(error.errorJump))
    {
      jpeg_destroy_decompress(&info);
      return NULL;
    }

    // Set up the decompression
    jpeg_create_decompress(&info);
    jpeg_stdio_src(&info,imageFile.m_pStream);

    // Read the image attributes
    jpeg_read_header(&info,TRUE);
    jpeg_calc_output_dimensions(&info);
    int width = info.output_width;
    int height = info.output_height;

    // Force RGB output
    info.out_color_space = JCS_RGB;

    // Create a bitmap
    HDC dc = ::GetDC(NULL);
    CDibSection* dib = new CDibSection();
    BOOL created = dib->CreateBitmap(dc,width,height);
    ::ReleaseDC(NULL,dc);
    if (!created)
    {
      jpeg_destroy_decompress(&info);
      return NULL;
    }

    // Get an output buffer
    JSAMPARRAY buffer = (*info.mem->alloc_sarray)
      ((j_common_ptr)&info,JPOOL_IMAGE,width*3,1);

    // Read in the image
    jpeg_start_decompress(&info);
    while ((int)info.output_scanline < height)
    {
      jpeg_read_scanlines(&info,buffer,1);

      BYTE* pixelRow = ((BYTE*)dib->GetBits())+(width*(info.output_scanline-1)*4);
      for (int i = 0; i < width; i++)
      {
        pixelRow[(i*4)+0] = (*buffer)[(i*3)+2];
        pixelRow[(i*4)+1] = (*buffer)[(i*3)+1];
        pixelRow[(i*4)+2] = (*buffer)[(i*3)+0];
        pixelRow[(i*4)+3] = 0xFF;
      }
    }
    jpeg_finish_decompress(&info);
    jpeg_destroy_decompress(&info);
    return dib;
  }
}
Exemplo n.º 16
0
CSize InformApp::GetImageSize(const char* path)
{
  CSize size(0,0);

  // Check if it's a PNG file
  CStdioFile imageFile;
  if (!imageFile.Open(path,CFile::modeRead|CFile::typeBinary))
    return size;
  png_byte fileHeader[8];
  imageFile.Read(fileHeader,8);
  bool isPNG = (png_sig_cmp(fileHeader,0,8) == 0);

  if (isPNG)
  {
    png_structp png_ptr = png_create_read_struct
      (PNG_LIBPNG_VER_STRING,(png_voidp)NULL,NULL,NULL);
    if (png_ptr == NULL)
      return size;
    png_infop info_ptr = png_create_info_struct(png_ptr);
    if (info_ptr == NULL)
    {
      png_destroy_read_struct(&png_ptr,(png_infopp)NULL,(png_infopp)NULL);
      return size;
    }
    png_infop end_info = png_create_info_struct(png_ptr);
    if (end_info == NULL)
    {
      png_destroy_read_struct(&png_ptr,&info_ptr,(png_infopp)NULL);
      return size;
    }
    if (setjmp(png_jmpbuf(png_ptr)))
    {
      png_destroy_read_struct(&png_ptr,&info_ptr,&end_info);
      return size;
    }

    png_init_io(png_ptr,imageFile.m_pStream);
    png_set_sig_bytes(png_ptr,8);
    png_read_info(png_ptr,info_ptr);

    size.cx = png_get_image_width(png_ptr,info_ptr);
    size.cy = png_get_image_height(png_ptr,info_ptr);

    png_destroy_read_struct(&png_ptr,&info_ptr,&end_info);
    return size;
  }
  else
  {
    imageFile.SeekToBegin();

    struct jpeg_decompress_struct info;
    struct JPEGErrorInfo error;

    info.err = jpeg_std_error(&(error.base));
    error.base.error_exit = errorJPEGExit;
    error.base.output_message = outputJPEGMessage;
    if (setjmp(error.errorJump))
    {
      jpeg_destroy_decompress(&info);
      return size;
    }

    jpeg_create_decompress(&info);
    jpeg_stdio_src(&info,imageFile.m_pStream);

    jpeg_read_header(&info,TRUE);
    jpeg_calc_output_dimensions(&info);

    size.cx = info.output_width;
    size.cy = info.output_height;

    jpeg_destroy_decompress(&info);
    return size;
  }
}
Exemplo n.º 17
0
BOOL CI18n::LoadLanguage(CString strLanguage)
{

	ENTRY_TRACE(_T("CI18n::LoadLanguage(%s)"), strLanguage);

	CString strFilepath;

	strFilepath.Format(_T("%s\\%s.txt"), g_sSettings.GetWorkingDir() + "\\languages", strLanguage);

	CStdioFile fFile;
	CFileException e;
	CString strText	= "";
	sections  sMode = COMMENT;
	
	TRY{

		if(!fFile.Open(strFilepath, CFile::modeRead|CFile::shareDenyWrite|CFile::typeText, &e)){

			LTRACE(_T("Failed to open language file %s"), strFilepath);
			return FALSE;
		}
		fFile.SeekToBegin();
		
		while(fFile.ReadString(strText)){

			strText.TrimLeft();
			strText.TrimRight();
			
			if(strText == _T("START"))      sMode = DIALOG_SEC;
			else if(strText == _T("END"))        sMode = COMMENT;
			else if(strText == _T("INFO_START")) sMode = LANGUAGE_HEADER;
			else if(strText == _T("INFO_END"))   sMode = COMMENT;
			
			if(!strText.IsEmpty() && (strText.Left(1) == _T("#"))){


				switch(sMode){

				case DIALOG_SEC:
					m_viItems.push_back(GetI18nItem(Ascii2Unicode(strText)));
					break;
				case LANGUAGE_HEADER:

					if(strText.Left(10) == _T("#LANGUAGE#")){

						m_strLanguageName = strText.Mid(11, strText.GetLength() - 11);
						m_strLanguageName.TrimLeft();
						m_strLanguageName.TrimRight();
						m_strLanguageName = m_strLanguageName.Mid(1, m_strLanguageName.GetLength() - 2);
					}
					else if(strText.Left(10) == _T("#CODEPAGE#")){

						m_strCodepage = strText.Mid(11, strText.GetLength() - 11);
						m_strCodepage.TrimLeft();
						m_strCodepage.TrimRight();						
						m_strCodepage = m_strCodepage.Mid(1, m_strCodepage.GetLength() - 2);
						m_dwCodePageID = _ttoi(m_strCodepage);
						
					}
					else if(strText.Left(8) == _T("#AUTHOR#")){

						m_strAuthor = strText.Mid(8, strText.GetLength() - 8);
						m_strAuthor.TrimLeft();
						m_strAuthor.TrimRight();						
						m_strAuthor = m_strAuthor.Mid(1, m_strAuthor.GetLength() - 2);
					}
					break;
				}
			}
		}

		fFile.Close();
	}
	CATCH( CFileException, e )
	{

	   #ifdef _DEBUG
		  afxDump << "File could not be opened " << e->m_cause << "\n";
	   #endif

	   m_bLoaded = FALSE;
	   m_strLoadedLang = "";
	}
Exemplo n.º 18
0
void CCountGen::OnBnClickedButton1()
{
	CString strAcc="";
	CString strPwd="";
	CString strPhone = "";
	GetDlgItemText(IDC_EDIT_PICSAVENAME,strPhone);
	strPhone.Trim();
	if (strPhone == "")
	{
		MessageBox("每IP账号数不能为空,请一定填写!");
		return;
	}
	g_iFreshCount = atoi(strPhone);
	if (SaveParams() < 0)
	{
		return;
	}
	CString strRecommandPhone = "";
	int   lines   =   0;   
	CStdioFile   file;
	CString   cstr;
	CFileException   fe;
	CString strFilePath = "";
	char szFilter[]="Text files(*.txt)|*.txt";
	CFileDialog dlg(1,NULL,NULL,NULL,szFilter); 
	if(dlg.DoModal()==IDOK) 
	{
		strFilePath = dlg.GetPathName();
	}
	if (strFilePath=="")
	{
		return;
	}
	if(file.Open(strFilePath,CFile::modeRead,&fe))   
	{ 
		file.SeekToBegin();
		int idx1=0;
		int idx2=0;
		srand(time(NULL));
		while (file.ReadString(cstr))
		{
			cstr+=",";
			strAcc = "";
			strPwd = "";
			//strPhone = "";
			strRecommandPhone = "";
			idx2 =cstr.Find(",");
			if (idx2==-1)
			{
				continue;
			}
			strAcc = cstr.Left(idx2);
			cstr = cstr.Right(cstr.GetLength()-idx2-1);
			idx2 =cstr.Find(",");
			if (idx2==-1)
			{
				continue;
			}
			strPwd = cstr.Left(idx2);

			map<CString,int>::iterator it = m_mapOldAcc.find(strAcc+strPwd);
			if (it != m_mapOldAcc.end())
			{
				CString strShow = "";
				strShow.Format("%s,%s 已经对此账号做过处理",strAcc,strPwd);
				CUserMessagePump *pMsgPump = NULL;
				pMsgPump = CUserMessagePump::GetInstance();
				if (!pMsgPump)
				{
					return;
				}
				pMsgPump->AddToMessagePump(USERWINDOWMSG_1,strShow);
				continue;
			}
// 			cstr = cstr.Right(cstr.GetLength()-idx2-1);
// 			idx2 =cstr.Find(",");
// 			if (idx2==-1)
// 			{
// 				continue;
// 			}
			//strPhone = cstr.Left(idx2);
			//已经找到所有需要的数据
			if (strAcc !="" && strPwd != "" && strPhone != "")
			{
				int nCount = m_pList->GetItemCount();
				CString listIndex = "";
				int iIsExist = 0;
				for (int i=0;i<nCount;i++)
				{
					if (strAcc == m_pList->GetItemText(i,1) && strPwd == m_pList->GetItemText(i,2))
					{
						CString strShow = "";
						strShow.Format("%s,%s 重复导入",strAcc,strPwd);
						CUserMessagePump *pMsgPump = NULL;
						pMsgPump = CUserMessagePump::GetInstance();
						if (!pMsgPump)
						{
							return;
						}
						pMsgPump->AddToMessagePump(USERWINDOWMSG_1,strShow);
						iIsExist = 1;
						break;
					}
				}
				if (iIsExist == 1)
				{
					continue;
				}

				RegisterPack rgPack;
				rgPack.strAcc = strAcc;					//卡号
				rgPack.strPwd = strPwd;					//密码
				rgPack.strNickName = strPhone;			//充值账号

				AddRegisterPack(rgPack);
				nCount = m_pList->GetItemCount();
				listIndex.Format("%d",nCount);
				m_pList->InsertItem(nCount,"",0);
				m_pList->SetItemText(nCount,0,listIndex);
				m_pList->SetItemText(nCount,1,strAcc);
				m_pList->SetItemText(nCount,2,strPwd);							
			}
		}
		file.Close();
	}
	PostMessage(WM_CLOSE,0,0);
}
void CXunJianDlg::OnOK() 
{
	try{
	pList= (CListBox *)GetDlgItem(IDC_HOSTLIST);
	/*if( pList->GetTextLen(0)>15 || pList->GetTextLen(0)<7 )
	{
		MessageBox("主机列表文件未加载,请重新选择!");
		return;
	}*/

	_GUID clsid;
	IUnknown *pUnk;
	IDispatch *pDisp;
	LPDISPATCH lpDisp;

	_Application app;
	Workbooks xj_books;
	_Workbook xj_book;
	Worksheets xj_sheets;
	_Worksheet xj_sheet;
	Range range;
	Range unionRange;
	Range cols;

	Font font;
//	COleVariant background;

	COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

	::CLSIDFromProgID(L"Excel.Application",&clsid); // from registry
	if(GetActiveObject(clsid, NULL,&pUnk) == S_OK)
	{
		VERIFY(pUnk->QueryInterface(IID_IDispatch,(void**) &pDisp) == S_OK);
		app.AttachDispatch(pDisp);
		pUnk->Release();
	} 
	else
	{  
		if(!app.CreateDispatch("Excel.Application"))
		{
			MessageBox("Excel program not found");     
			app.Quit();     
			return;
		}
	}

	xj_books=app.GetWorkbooks();
	xj_book=   xj_books.Add(covOptional);
	xj_sheets= xj_book.GetSheets();
	xj_sheet=  xj_sheets.GetItem(COleVariant((short)1));

	int i;
	Range item;
	range=xj_sheet.GetRange(COleVariant("A1"),COleVariant("F1"));
	for(i= 0; i < 6; i++)
	{
		item.AttachDispatch(range.GetItem(COleVariant((long)1),COleVariant((long)i+1)).pdispVal);
		item.SetValue2(COleVariant(PROJ[i]));
	}  //描绘第一行目录

	//range=xj_sheet.GetRange(COleVariant("A1"),COleVariant("F1"));
	lpDisp=range.GetInterior();
	Interior   cellinterior;
	cellinterior.AttachDispatch(lpDisp);
	cellinterior.SetColor(COleVariant((long)0xc0c0c0));  //设置背景色为灰色
	cellinterior.ReleaseDispatch();
	//range=xj_sheet.GetRange(COleVariant("A1"),COleVariant("F1"));
	range.SetHorizontalAlignment(COleVariant((long)-4108)); //全部居中
	Borders bord;
	bord=range.GetBorders();
	bord.SetLineStyle(COleVariant((short)1));  //设置边框
	//range=xj_sheet.GetRange(COleVariant("A1"),COleVariant("F1"));
	cols=range.GetEntireColumn();
	cols.AutoFit();  //自动调整

/**************************表格初始绘画完成************************************/

	long usedRowNum; //行计数
	CString handleFile;
	CString hostFileName,hostip;
	bool error = false;
	CString infos,info;
	ExcelFile excelFile;
	ReadTxt xj_txt;
	xj_HostCount=pList->GetCount();
	for(int n_host=0;n_host<xj_HostCount;n_host++)  //主循环,一个文件一次循环。
	{		
		pList->GetText(n_host,hostFileName);
		hostip = hostFileName;
		handleFile = hostFileName + _T(" 正在处理...");
		pList->DeleteString(n_host);
		pList->InsertString(n_host,handleFile);
		pList->SetCurSel(n_host);
		pList->UpdateWindow();

		hostFileName = xj_FilePath + hostFileName;
		hostFileName += _T(".txt");
		CStdioFile hostFile;
		if(!hostFile.Open(hostFileName,CFile::modeRead,0))
		{  //记录不存在文件名
			handleFile.Replace("正在处理...","失败!");
			error = true;
			pList->DeleteString(n_host);
			pList->InsertString(n_host,handleFile);
			pList->UpdateWindow();
			continue;
		}
		usedRowNum = excelFile.GetRowCount(xj_sheet);
		range.AttachDispatch(xj_sheet.GetCells());

		//info.Format( _T("%d"), n_host+1);
		info = xj_txt.ReadHostName(&hostFile,COMMAND[0],COMMAND[1]);  //获取节点名称
		range.SetItem(COleVariant(usedRowNum+1),COleVariant(long(1)),COleVariant(info));

		int portCount = 0;   //端口数目,不包括7/1
		CString nSend, nRecv;
		float n_Send,n_Recv;

		while(hostFile.ReadString(info))
			if(info.Find( COMMAND[4]) > -1) break;
		while( hostFile.ReadString(info) && info.Find( "[local]" ) == -1 )  //端口号和流量
		{
			if( info.Find( "/" ) == -1 || info.Find( "7/1" ) > -1 ) continue;

			info.Replace( "ethernet","");
			info = _T("'") + info;
			infos = info;

			while( hostFile.ReadString(info) )
				if( info.Find( "send bit rate" ) > -1 ) break;
			nSend = info.Mid( 60 );
			hostFile.ReadString(info);
			nRecv = info.Mid( 60 );
			nSend.Trim();
			nRecv.Trim();
			n_Send = (float)atof(nSend);
			n_Recv = (float)atof(nRecv);

			if( n_Send < 1000 && n_Recv < 1000 ) continue;
			portCount++;
			range.SetItem(COleVariant(usedRowNum+portCount),COleVariant(long(2)),COleVariant(infos.Trim()));
			range.SetItem(COleVariant(usedRowNum+portCount),COleVariant(long(4)),COleVariant((n_Send>n_Recv)?nSend:nRecv));
		}

		hostFile.SeekToBegin();
		infos = xj_txt.ReadLine(&hostFile,"ubscriber Address");  //历史在线最大用户数
		if( infos == _T("") ) info = _T("0");
		else
		{
			int token = 0;
			for(i = 0; i < 5 ; i++) info = infos.Tokenize(" ",token);
		}
		range.SetItem(COleVariant(usedRowNum+1),COleVariant(long(6)),COleVariant(info.Trim()));  

		hostFile.Close();

		if(portCount > 1)
		{
			unionRange.AttachDispatch(range.GetItem(COleVariant(usedRowNum+1),COleVariant((long)1)).pdispVal);
			unionRange.AttachDispatch(unionRange.GetResize(COleVariant((long)portCount),COleVariant((long)1)));
			unionRange.Merge(COleVariant((long)0));  //节点名称单元格合并

			unionRange.AttachDispatch(range.GetItem(COleVariant(usedRowNum+1),COleVariant((long)6)).pdispVal);
			unionRange.AttachDispatch(unionRange.GetResize(COleVariant((long)portCount),COleVariant((long)1)));
			unionRange.Merge(COleVariant((long)0)); 			
			//历史最大用户数合并
		}

		unionRange.AttachDispatch(range.GetItem(COleVariant(usedRowNum+1),COleVariant((long)1)).pdispVal);
		unionRange.AttachDispatch(unionRange.GetResize(COleVariant((long)portCount),COleVariant((long)6)));
		unionRange.SetRowHeight(COleVariant(13.5));
		bord = unionRange.GetBorders();
		bord.SetLineStyle(COleVariant((short)1));  //设置边框



		handleFile.Replace("正在处理...","已完成");
		pList->DeleteString(n_host);
		pList->InsertString(n_host,handleFile);
		pList->UpdateWindow();
	}

	CTime time;
	time = time.GetCurrentTime();
	infos = time.Format("%Y%m%d%H%M%S");  //time.Format();
	info = _T("巡检报表") + infos + _T(".xlsx");
	info = xj_FilePath + info;
	info.Replace("\\\\","\\");

	xj_book.SaveAs(COleVariant(info),covOptional,covOptional,covOptional,covOptional,covOptional,0,covOptional,covOptional,covOptional,covOptional,covOptional);
	
	if(error == true )
	{
		MessageBox("巡检报表已完成,已保存到\r\n" + info + "\r\n有文件打开错误,点击\"确定\"返回查看","有文件打开错误!",MB_OK|MB_ICONWARNING);
		app.Quit();
	}
	else 
	{
		if(MessageBox("巡检报表已完成,已保存到\r\n" + info + "\r\n点击\"确定\"打开文件查看","生成报表完成",MB_OKCANCEL) == IDOK)
		{
			app.SetVisible(TRUE);
			app.SetUserControl(TRUE);
		}
		else app.Quit();
	}
}
catch (CFileException* e)
    {
        e->ReportError();
        e->Delete();
    }
	//CDialog::OnOK();
}
Exemplo n.º 20
0
void CAppealDlg::OnOK()
{
    // TODO: 在此添加专用代码和/或调用基类
    CBcfFile fMsg(CBcfFile::GetAppPath()+"ClientMessage.bcf");

    POSITION pos = m_FileListCtrl.GetFirstSelectedItemPosition();
    if (pos == NULL)
    {
        //AFCMessageBox(fMsg.GetKeyVal("AppealDlg","SelectAppealGame","请选择要投诉的游戏"));
        DUIMessageBox(m_hWnd,MB_ICONINFORMATION|MB_OK,"系统提示",false,fMsg.GetKeyVal("AppealDlg","SelectAppealGame","请选择要投诉的游戏"));

        return;
    }
    int iItem = m_FileListCtrl.GetNextSelectedItem(pos);
    //m_FileListCtrl
    if (iItem < 0)
    {
        return;
    }
    CString strComent = "";
    GetDlgItem(IDC_EDIT_APPEAL_CONTENT)->GetWindowText(strComent);
    if (strComent == "")
    {
        //AFCMessageBox(fMsg.GetKeyVal("AppealDlg","AppealReason","请写明要投诉的游戏的原因!"));
        DUIMessageBox(m_hWnd,MB_ICONINFORMATION|MB_OK,"系统提示",false,fMsg.GetKeyVal("AppealDlg","AppealReason","请写明要投诉的游戏的原因!"));
        return;
    }
    list<RecordFileStruct>::iterator iter = m_fileList.begin();
    int iIndex = 0;
    for (; iter!=m_fileList.end();)
    {

        if (iIndex == iItem)
        {
            break;

        }
        else
        {
            iter++;
        }
        iIndex++;

    }

    RecordFileStruct record = *iter;
    int iRet = record.strWholeName.Find(record.strFileName);

    CString szPath = record.strWholeName.Mid(0,iRet);


    //CString szInfoFile = szPath + m_strUserName + "_";

    m_strInfoFileName = m_strUserName + "_";

    CString szFileName =  record.strFileName.Mid(0,record.strFileName.Find("."));
    m_strInfoFileName += szFileName;
    m_strInfoFileName += ".txt";

    m_strInfoFileWholeName = szPath + m_strInfoFileName;




    CStdioFile file;
    if (file.Open(m_strInfoFileWholeName,CFile::modeCreate | CFile::modeReadWrite) == false)
    {
        //AFCMessageBox(fMsg.GetKeyVal("AppealDlg","AppealError","投诉过程出错,请稍后再试!"));
        DUIMessageBox(m_hWnd,MB_ICONINFORMATION|MB_OK,"系统提示",false,fMsg.GetKeyVal("AppealDlg","AppealError","投诉过程出错,请稍后再试!"));
        //wushuqun 2009.5.22
        return;

    }
    file.SeekToBegin();
    file.WriteString(m_strUserName);
    file.WriteString("\n");
    file.WriteString(fMsg.GetKeyVal("AppealDlg","AppealContent","投诉内容:"));
    file.WriteString("\n");
    file.WriteString(strComent);
    file.WriteString("\n");

    GetDlgItem(IDC_EDIT_PHONE_NUM)->GetWindowText(strComent);
    if (strComent != "")
    {
        file.WriteString(fMsg.GetKeyVal("AppealDlg","Telephone","联系电话:"));
        file.WriteString(strComent);
        file.WriteString("\n");

    }
    GetDlgItem(IDC_EDIT_APPEAL_EMAIL)->GetWindowText(strComent);
    if (strComent != "")
    {
        file.WriteString(fMsg.GetKeyVal("AppealDlg","Email","Email:"));
        file.WriteString(strComent);
        file.WriteString("\n");
    }
    file.Close();





    CString strRemotName = m_strUserName + "_" +record.strFileName;


    CStringArray csa2;
    csa2.SetSize(0,6);
    csa2.Add(m_strFtpAddress);
    csa2.Add(m_strFtpUserName);
    csa2.Add(m_strFtpPwd);
    csa2.Add(strRemotName);
    csa2.Add(record.strWholeName);
    int  b=UploadFile(&csa2,this->m_hWnd,WM_USER+1);
    //wushuqun 2009.5.22
    if (b>0)
    {
        //AFCMessageBox(fMsg.GetKeyVal("AppealDlg","SendAppealError","投诉文件上传失败!"));
        DUIMessageBox(m_hWnd,MB_ICONINFORMATION|MB_OK,"系统提示",false,fMsg.GetKeyVal("AppealDlg","SendAppealError","投诉文件上传失败!"));

    }
    CDialog::OnOK();
}