/*================================================================= * Function ID : WriteDeviceLog * Input : char* cpath, char* str * Output : void * Author : DengJun * Date : Apr 2005 * Return : void * Description : * Notice : 写插入数据库时不成功的SQL语句 * : cpath-->路径 ucpID-->设备ID号 str-->日志内容 *=================================================================*/ void CMyLog::WriteDeviceMaxMoney(char* cpath, char* ucpID,char* msg) { FileBase mfile; CData m_Data; char pszFileName[128]; char lpBuffer[2048]; BYTE str[30]; memset(str, 0x00,sizeof str); memset(lpBuffer, 0x00,sizeof lpBuffer); memset(pszFileName,0x00,sizeof pszFileName); if( !strlen(msg) ) return ; m_Data.trim(cpath); CheckIsChangeYear(cpath); if( strlen(cpath) ) { strcpy(pszFileName,cpath); strcat(pszFileName,"\\"); } strcat(pszFileName,"Sql"); memcpy(pszFileName+strlen(pszFileName),(char*)m_Data.GetSysTime(),8); strcat(pszFileName,".txt"); if( !m_Data.FileIsExist(pszFileName) ) { CreateDirectory(cpath,NULL); } memset(lpBuffer,0x00,sizeof lpBuffer); strcpy(lpBuffer,msg); mfile.AddLineToFile(pszFileName,lpBuffer,strlen(lpBuffer)); return ; }
virtual struct dirent *readdir() { FileBase *ptr = FileBase::get(n); if (ptr == NULL) return NULL; /* Increment n, so next readdir gets the next item */ n++; /* Setup cur entry and return a pointer to it */ std::strncpy(cur_entry.d_name, ptr->getName(), NAME_MAX); return &cur_entry; }
template<class FileBase> inline bytevector FileRead(FileBase& ifile, size_t chunk, const string& filename) { bytevector data(chunk); ifile.read(data.data(), chunk); size_t nread = ifile.gcount(); if ( nread < data.size() ) data.resize(nread); if ( data.empty() ) throw Source::ReadEOF(filename); return data; }
TFW_BEGIN_NS //////////////////////////////////////////////////////////////////////////// // 静的関数 #if SUPPORT_EXTLIB_LPNG /*---------------------------------------------------------------------*//** ファイル読み込みコールバック関数 **//*---------------------------------------------------------------------*/ static void cbFileRead(png_structp png, png_bytep data, png_size_t length) { FileBase* file = (FileBase*)png_get_io_ptr(png); file->read(data, (u32)length); }
/*================================================================= * Function ID : SMT_GetLastInvoiceNo * Input : char* cpath, char* str * Output : void * Author : DengJun * Date : Apr 2005 * Return : void * Description : * Notice : * : *=================================================================*/ bool CMyLog::SMT_GetLastInvoiceNo(char* sID, int *nInvoiceNo ) { char sValue[20]; char sKeyName[20]; int nValue=0; CData cData; FileBase mfile; memset(sValue,0,sizeof sValue); memset(sKeyName,0,sizeof sKeyName); cData.BcdToAsc((byte*)sID,4,(byte*)sKeyName); g_CriticalSectionLock.Lock(); if( g_WriteFileLock ) { g_CriticalSectionLock.Unlock(); return false; } g_WriteFileLock=true; GetPrivateProfileString(sKeyName, "NO", "-1",sValue,sizeof(sValue),g_sCommRec); if( atoi(sValue)==-1 ) { memset(sValue,0,sizeof sValue); sprintf(sValue,"[%s]",sKeyName); mfile.AddLineToFile(g_sCommRec,sValue,strlen(sValue)); memset(sValue,0,sizeof sValue); strcpy(sValue,"NO=1"); mfile.AddLineToFile(g_sCommRec,sValue,strlen(sValue)); *nInvoiceNo=0; } else { *nInvoiceNo=atol(sValue); if( *nInvoiceNo>=65535 ) nValue=-1; else nValue=*nInvoiceNo; sprintf(sValue,"%ld",++nValue); WritePrivateProfileString(sKeyName, "NO",sValue,g_sCommRec); } g_WriteFileLock=false; g_CriticalSectionLock.Unlock(); return true; }
/*================================================================= * Function ID : WriteDeviceData * Input : char* cpath, char* msg * Output : void * Author : DengJun * Date : Apr 2006 * Return : void * Description : * Notice : 写设备的日志 * : cpath-->路径 ucpID-->设备ID号 msg-->数据内容 *=================================================================*/ bool CMyLog::WriteDeviceData(char* cpath, char* ucpID,char* msg) { FileBase mfile; CData m_Data; char pszFileName[128]; char lpBuffer[1024]; BYTE str[30]; memset(str, 0x00,sizeof str); memset(lpBuffer, 0x00,sizeof lpBuffer); memset(pszFileName,0x00,sizeof pszFileName); m_Data.trim(cpath); CheckIsChangeYear(cpath); if( strlen(cpath) ) { strcpy(pszFileName,cpath); strcat(pszFileName,"\\"); } strcat(pszFileName,"Data"); memcpy(pszFileName+strlen(pszFileName),(char*)m_Data.GetSysTime(),8); strcat(pszFileName,"_"); strcat(pszFileName,(char*)m_Data.BcdToAsc((BYTE*)ucpID,4,str)); strcat(pszFileName,".txt"); if( !m_Data.FileIsExist(pszFileName) ) { CreateDirectory(cpath,NULL); } memset(lpBuffer,0x00,sizeof lpBuffer); strcat(lpBuffer,(char*)m_Data.GetSysTime()); strcat(lpBuffer,","); strcat(lpBuffer,msg); if( mfile.AddLineToFile(pszFileName,lpBuffer,strlen(lpBuffer)) ) { return false; } return true; }
/*================================================================= * Function ID : SMT_UpBeforeFile * Input : void * Output : void * Author : * Date : 2006 2 * Return : void * Description : 前置启动将当天前的文件的记录全部上传 * Notice : *=================================================================*/ bool CSmartCommunicationDlg::SMT_UpBeforeFile(XDHANDLE nHandler) { int nTimeOut=20000; int nErrCode=0; char sErrMsg[256]; char sTempPath[256]; char sBakPath[256]; char sData[256],sMsg[1024]; FILE *fpt=NULL; FileBase mfile; vector<CString> VFileName; vector<CString> VFileContent; //文件内容 CString sFileContent; memset(sMsg, 0,sizeof sMsg); memset(sData, 0,sizeof sData ); memset(sErrMsg, 0,sizeof sErrMsg); memset(sTempPath,0,sizeof sTempPath); memset(sBakPath, 0,sizeof sBakPath); VFileName.clear(); //清除所有文件名 VFileContent.clear(); //保存文件内容 SMT_GetAllFileName(VFileName); //获取不是当天产生的文件 if( VFileName.empty() ) return false; for( int i=0; i<VFileName.size(); i++ ) //将还未上传的文件记录全部上传 { memset(sTempPath,0,sizeof sTempPath); memset(sBakPath, 0,sizeof sBakPath); strcpy(sTempPath,m_DealPath); strcat(sTempPath,"\\"); strcat(sTempPath,VFileName[i].GetBuffer(100)); strcpy(sBakPath,m_DealPath); strcat(sBakPath,"\\Bak\\Bak_"); strcat(sBakPath,VFileName[i].GetBuffer(100)); //remove(sBakPath); if( (fpt=mfile.OpenFile(sTempPath,"r"))==NULL) { continue; } //得到该文件的所有记录 while( mfile.FileEOF(fpt)==0) { memset(sData,0,sizeof sData); if( fgets(sData,128,fpt) !=NULL ) { if( !g_StartFlag ) { mfile.CloseFile(fpt); return true; } sFileContent=sData; VFileContent.push_back(sFileContent); } } mfile.CloseFile(fpt); int nCount=VFileContent.size(); bool bStatus=false; //上传该文件的记录 for( int j=0; j<nCount; j++ ) { bStatus=false; for( int k=0; i<10; k++ ) //一条记录如果上传10次还不成功,则全部重新上传 { if( !g_StartFlag ) { VFileContent.clear(); return true; //收到系统退出命令 } memset(sData,0,sizeof sData); strcpy(sData,VFileContent[j].GetBuffer(100)); if( !g_CInterface.SMT_UpDealRecord(nHandler,sData,nTimeOut,&nErrCode,sErrMsg) ) { sprintf(sMsg,"上传文件名%s的第%ld条记录到金仕达失败(%ld,%s)",VFileName[i].GetBuffer(100),j+1,nErrCode,sErrMsg); if( g_IniFilePara.bWriteDebugLog ) WriteLog(sErrMsg); if( g_IniFilePara.bWriteDebugLog ) AddString(sMsg); Sleep(5000); continue; } bStatus=true; break; } if( !bStatus ) { WriteLog(sErrMsg); VFileContent.clear(); Sleep(1000); return false; } Sleep(50); mfile.AddLineToFile(sBakPath,sData,strlen(sData)-1); } SMT_DeleteFile(VFileName[i].GetBuffer(100)); VFileContent.clear(); if( !g_StartFlag ) return true; //收到系统退出命令 } if( !VFileName.empty() ) VFileName.clear(); return true; }
bool CSmartCommunicationDlg::Init() { char CurPath[256],CreatePath[256],CurDate[30]; CData mData; char buf[128],str[8]; FileBase mfile; DWORD nTime=0; int nLen=0; memset(g_sCommRec, 0,sizeof g_sCommRec); memset(&g_IniFilePara, 0,sizeof g_IniFilePara); memset(g_PathIniFileName, 0,sizeof g_PathIniFileName); memset(g_SaveBlackList, 0,sizeof g_SaveBlackList); memset(g_SaveAssistantList,0,sizeof g_SaveAssistantList); memset(str, 0x00,sizeof str); memset(CurDate, 0x00,sizeof CurDate); memset(m_DealPath, 0x00,sizeof m_DealPath); memset(CurPath, 0x00,sizeof CurPath); memset(CreatePath, 0x00,sizeof CreatePath); memset(m_ErrMsg, 0x00,sizeof m_ErrMsg); memset(m_CurPath, 0x00,sizeof m_CurPath); strcpy(CurPath,mData.GetCurPath()); memcpy(CurDate,mData.GetSysTime(),6); g_nSaveAssistantVer=0; g_WriteFileLock =false; //文件锁 g_VLinkIP.clear(); strcpy(g_sCommRec,CurPath); strcat(g_sCommRec,"\\SmartCommRec.ini"); //上传交易数据明细 strcpy(m_DealPath,CurPath); strcat(m_DealPath,"\\Deal"); CreateDirectory(m_DealPath,NULL); strcpy(g_PathIniFileName,CurPath); strcat(g_PathIniFileName,"\\system.ini"); //日志路径 memset(CreatePath,0x00,sizeof CreatePath); strcpy(CreatePath,CurPath); strcat(CreatePath,"\\Log"); CreateDirectory(CreatePath,NULL); strcat(CreatePath,"\\"); strcat(CreatePath,CurDate); CreateDirectory(CreatePath,NULL); strcpy(m_CurPath,CreatePath); //系统日志 strcat(CreatePath,"\\Sys"); CreateDirectory(CreatePath,NULL); if( !g_VSmartPos.empty()) g_VSmartPos.clear(); if( !g_LTcpsmart.empty()) g_LTcpsmart.clear(); nRateDeveice = 0; m_BtRate.EnableWindow(FALSE); m_edit_devicetotal.SetWindowText(""); m_edit_devicerate.SetWindowText(""); m_edit_devicesuccess.SetWindowText(""); //延时时间1 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SLEEP","TIME1",buf); mData.trim(buf); if( !strlen(buf) ) SMT_WAITFORTIME1=35; else SMT_WAITFORTIME1=atol(buf); //延时时间2 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SLEEP","TIME2",buf); mData.trim(buf); if( !strlen(buf) ) SMT_WAITFORTIME2=25; else SMT_WAITFORTIME2=atol(buf); //延时时间3 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SLEEP","TIME3",buf); mData.trim(buf); if( !strlen(buf) ) SMT_WAITFORTIME3=350; else SMT_WAITFORTIME3=atol(buf); //调试日志开关 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SLEEP","LOG",buf); mData.trim(buf); if( !strlen(buf) ) g_IniFilePara.bWriteDebugLog=false; else g_IniFilePara.bWriteDebugLog=true; memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","MONEY","MAX",buf); mData.trim(buf); //记录上传的时间间隔 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SLEEP","UPRECORD",buf); mData.trim(buf); g_IniFilePara.lUpRecordWaitTime=atol(buf); if( g_IniFilePara.lUpRecordWaitTime<=0 ) { g_IniFilePara.lUpRecordWaitTime=1000; } //前置注册号 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SMARTFRONTREG","REGNO",buf); mData.trim(buf); g_IniFilePara.lFrontRegNo=atol(buf); if( !g_IniFilePara.lFrontRegNo ) g_IniFilePara.lFrontRegNo=39001; //密钥 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SMARTFRONTREG","KEY",buf); mData.trim(buf); strcpy(g_IniFilePara.sKey,buf); //前置功能号 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SMARTFRONTREG","MAINFUN",buf); mData.trim(buf); g_IniFilePara.lMainFunc=atol(buf); if( g_IniFilePara.lMainFunc<=0) g_IniFilePara.lMainFunc=6000; g_CInterface.m_mainfunc=g_IniFilePara.lMainFunc; //设置更新黑名当时间1 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SMARTFRONTREG","DownBlacktime1",buf); mData.trim(buf); g_IniFilePara.DownBlacktime1=atol(buf); if(!g_IniFilePara.DownBlacktime1) g_IniFilePara.DownBlacktime1=0; //设置更新黑名当时间2 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SMARTFRONTREG","DownBlacktime2",buf); mData.trim(buf); g_IniFilePara.DownBlacktime2=atol(buf); if(!g_IniFilePara.DownBlacktime2) g_IniFilePara.DownBlacktime2=0; //查询标志 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","DEVICEQUERYCMD","COUNT",buf); mData.trim(buf); if( atol(buf)>0 ) { g_IniFilePara.bWaterQueryFlag=true; } else { g_IniFilePara.bWaterQueryFlag=false; } //创建金仕达连接数 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SMARTFRONTCOUNT","COUNT",buf); mData.trim(buf); g_IniFilePara.lCreateConCount=atol(buf); g_IniFilePara.lCreateConCount=atol(buf); if( g_IniFilePara.lCreateConCount<4) { g_IniFilePara.lCreateConCount=4; } //IP memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SMARTFRONTREG","HostName",buf); mData.trim(buf); strcpy(g_IniFilePara.sHostIP,buf); strcpy(m_ServerIP,g_IniFilePara.sHostIP); //端口号 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SMARTFRONTREG","ServerPort",buf); mData.trim(buf); g_IniFilePara.lHostPort=atol(buf); m_ServerPort=g_IniFilePara.lHostPort; if( m_ServerPort<=0 ) { m_ServerPort=4000; g_IniFilePara.lHostPort=4000; } //等待多长时间向金仕达取任务 memset(buf,0,sizeof buf); mfile.GetProfileStr("system.ini","SLEEP","QUERY",buf); mData.trim(buf); g_IniFilePara.lGetTaskWaitTime=atol(buf); if( g_IniFilePara.lGetTaskWaitTime<300 ) { g_IniFilePara.lGetTaskWaitTime=300; } return true; }