void CCheckForUpdatesDlg::FillChangelog(CAutoConfig& versioncheck, bool official) { ProjectProperties pp; pp.lProjectLanguage = -1; if (versioncheck.GetString(_T("tortoisegit.issuesurl"), pp.sUrl)) pp.sUrl = _T("https://tortoisegit.org/issue/%BUGID%"); if (!pp.sUrl.IsEmpty()) { pp.SetCheckRe(_T("[Ii]ssues?:?(\\s*(,|and)?\\s*#?\\d+)+")); pp.SetBugIDRe(_T("(\\d+)")); } m_cLogMessage.Init(pp); CString sChangelogURL; versioncheck.GetString(_T("TortoiseGit.changelogurl"), sChangelogURL); if (sChangelogURL.IsEmpty()) sChangelogURL = _T("https://versioncheck.tortoisegit.org/changelog.txt"); else { CString tmp(sChangelogURL); sChangelogURL.FormatMessage(tmp, TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, m_updateDownloader->m_sWindowsPlatform, m_updateDownloader->m_sWindowsVersion, m_updateDownloader->m_sWindowsServicePack); } CString tempchangelogfile = CTempFiles::Instance().GetTempFilePath(true).GetWinPathString(); DWORD err; if ((err = m_updateDownloader->DownloadFile(sChangelogURL, tempchangelogfile, false)) != ERROR_SUCCESS) { CString msg = _T("Could not load changelog.\r\nError: ") + GetWinINetError(err) + _T(" (on ") + sChangelogURL + _T(")"); ::SendMessage(m_hWnd, WM_USER_FILLCHANGELOG, 0, reinterpret_cast<LPARAM>((LPCTSTR)msg)); return; } if (official) { CString signatureTempfile = CTempFiles::Instance().GetTempFilePath(true).GetWinPathString(); if ((err = m_updateDownloader->DownloadFile(sChangelogURL + SIGNATURE_FILE_ENDING, signatureTempfile, false)) != ERROR_SUCCESS || VerifyIntegrity(tempchangelogfile, signatureTempfile, m_updateDownloader)) { CString error = _T("Could not verify digital signature."); if (err) error += _T("\r\nError: ") + GetWinINetError(err) + _T(" (on ") + sChangelogURL + SIGNATURE_FILE_ENDING + _T(")"); ::SendMessage(m_hWnd, WM_USER_FILLCHANGELOG, 0, reinterpret_cast<LPARAM>((LPCTSTR)error)); DeleteUrlCacheEntry(sChangelogURL); DeleteUrlCacheEntry(sChangelogURL + SIGNATURE_FILE_ENDING); return; } } CString temp; CStdioFile file; if (file.Open(tempchangelogfile, CFile::modeRead | CFile::typeBinary)) { auto buf = std::make_unique<BYTE[]>((UINT)file.GetLength()); UINT read = file.Read(buf.get(), (UINT)file.GetLength()); bool skipBom = read >= 3 && buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF; CGit::StringAppend(&temp, buf.get() + (skipBom ? 3 : 0), CP_UTF8, read - (skipBom ? 3 : 0)); } else temp = _T("Could not open downloaded changelog file."); ::SendMessage(m_hWnd, WM_USER_FILLCHANGELOG, 0, reinterpret_cast<LPARAM>((LPCTSTR)temp)); }
ERRORCODE NodeSimCodeGenerator::GenerateMakeFile(IBMNetWorkGetService* pBmNetWork, ETYPE_BUS eBus, std::string strForCppFile) { std::string strMakeFilePath; std::string strLibFolder; std::string strSimIncludeFolder; GetBusmasterNodeSimualtionFolder(NS_MAKEFILE_FOLDER, strMakeFilePath); GetBusmasterNodeSimualtionFolder(NS_LIB_FOLDER, strLibFolder); GetBusmasterNodeSimualtionFolder(NS_INCLUDE_FOLDER, strSimIncludeFolder); CStdioFile omStdiofile; CStdioFile omStdioMakefile; CFileException omException ; DWORD dwSize = 0; DWORD dwRead = 0; BOOL bFileOpen = FALSE; CString omStrFile = ""; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ext[_MAX_EXT]; _splitpath( strForCppFile.c_str(), drive, dir, fname, ext ); char chAbsPath[MAX_PATH] = {'\0'}; PathCombine(chAbsPath, strMakeFilePath.c_str(), "GCCDLLMakeTemplate"); strMakeFilePath = std::string(chAbsPath); bFileOpen = omStdiofile.Open(strMakeFilePath.c_str(), CFile::modeRead | CFile::typeText, &omException); if(bFileOpen!=FALSE) { CHAR* pcBuff = nullptr; CString omTemp = ""; // Get the size of file dwSize = (DWORD)omStdiofile.GetLength(); //pcBuff = (char*) new char[dwSize]; pcBuff = (char*) new char[dwSize+1]; if(pcBuff!=nullptr) { memset(pcBuff, 0, dwSize); // Read the whole file and put the content to pcBuff; dwRead = omStdiofile.Read(pcBuff,dwSize); // Add end of string; *(pcBuff+dwRead) = '\0'; // copy the content to CString object; omStrFile = pcBuff; // Delete the buffer and initialise it to nullptr delete []pcBuff; pcBuff = nullptr; } //1. NS_LIB Folder omStrFile.Replace("<BUSMASTER_NS_LIB_FOLDER>", strLibFolder.c_str()); //2. Protocol Lib omStrFile.Replace("<PROTOCOL_HELPER_LIB>", GetProtocolLib(eBus).c_str()); //3. DB Object std::string strCheckSum; std::string strDbCachePath; std::string strGccVer; std::string strObjPath =""; std::string strIncPath =""; GetCurrentGccVersion(strGccVer); GetBusMasterDBCachePath(strDbCachePath); int nChannels = 0; pBmNetWork->GetChannelCount(eBus, nChannels); ICluster* pCluster = nullptr; for ( int i = 0; i < nChannels; i++ ) { int nDBCount = 0; pBmNetWork->GetDBServiceCount(eBus, i, nDBCount); for (int nDbIndex = 0; nDbIndex < nDBCount; nDbIndex++) { pBmNetWork->GetDBService(eBus, i, nDbIndex, &pCluster); strObjPath += "\""; strObjPath += strDbCachePath + "\\"; strIncPath += "-include\""; strIncPath += strDbCachePath + "\\"; if (pCluster != nullptr) { pCluster->GetDBFileChecksum(strCheckSum); strObjPath += strCheckSum + "_gcc"; strObjPath += strGccVer + ".obj"; strIncPath += strCheckSum + ".h"; } strObjPath += "\" "; strIncPath += "\" "; } } omStrFile.Replace("<DB_OBJFILES>", strObjPath.c_str()); //4. DB Include omStrFile.Replace("<DB_INCLUDES>", strIncPath.c_str()); //5. FileName omStrFile.Replace("<FILENAME>", fname); //6. BM Includes omStrFile.Replace("<BM_INCLUDES>", strSimIncludeFolder.c_str()); //7. file path char chShortPath[1024]; GetShortPathName(strForCppFile.c_str(), chShortPath, 1024); CString strTemp = chShortPath; strTemp.Replace("\\", "/"); omStrFile.Replace("<FILEPATH>", strTemp); std::strcat(fname, "make"); PathCombine(chAbsPath, drive, dir); char chFullPath[BM_MAX_PATH] = { '\0' }; PathCombine(chFullPath, chAbsPath, fname); std::string strMakeFileName = std::string(chFullPath); bFileOpen = omStdioMakefile.Open(strMakeFileName.c_str(), CFile::modeWrite | CFile::typeText | CFile::modeCreate, &omException); if(bFileOpen!=FALSE) { omStdioMakefile.WriteString(omStrFile); } } return S_OK; }
bool FileMisc::LoadFile(const TCHAR* szPathname, CString& sText) { CStdioFile file; if (file.Open(szPathname, CFile::modeRead | CFile::shareDenyWrite)) { if (file.GetLength()) { // init size CString sTemp(_T('\0'), (int)file.GetLength()); sText = sTemp; CString sLine; int nPos = 0; while (file.ReadString(sLine)) { sText.Insert(nPos, sLine); nPos += sLine.GetLength(); } } return true; } return false; }
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(); }
bool CStringUtils::ReadStringFromTextFile(const CString& path, CString& text) { if (!PathFileExists(path)) return false; try { CStdioFile file; // w/o typeBinary for some files \r gets dropped if (!file.Open(path, CFile::typeBinary | CFile::modeRead | CFile::shareDenyWrite)) return false; CStringA filecontent; UINT filelength = (UINT)file.GetLength(); int bytesread = (int)file.Read(filecontent.GetBuffer(filelength), filelength); filecontent.ReleaseBuffer(bytesread); text = CUnicodeUtils::GetUnicode(filecontent); file.Close(); } catch (CFileException* pE) { text.Empty(); pE->Delete(); } return true; }
int FileMisc::LoadFileLines(LPCTSTR szPathname, CStringArray& aLines, int nLineCount) { int nLinesRead = 0; aLines.RemoveAll(); CStdioFile file; if (file.Open(szPathname, CFile::modeRead | CFile::shareDenyWrite)) { if (file.GetLength()) { if (nLineCount == -1) { nLineCount = INT_MAX; } // read lines CString sLine; while (file.ReadString(sLine) && nLinesRead < nLineCount) { aLines.Add(sLine); nLinesRead++; } } } return nLinesRead; }
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(); }
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; }
void CFileClipboardDlg::ReadFileClipboard(CString szFilename) { CStdioFile fInput; UINT nFileSize; char *szFileData; char *pEnd, *pStart; if (fInput.Open(szFilename, CFile::typeText|CFile::modeRead) == TRUE) { nFileSize = (UINT)fInput.GetLength(); szFileData = (char*)malloc(nFileSize + 1); if (szFileData) { nFileSize = fInput.Read(szFileData, nFileSize); if (nFileSize > 0) { szFileData[nFileSize] = 0; pStart = szFileData; do { pEnd = strchr(pStart, '\n'); if (pEnd) { *pEnd = 0; pEnd++; } if (strlen(pStart) > 0) { m_cFileClipboardList.InsertItem(m_cFileClipboardList.GetItemCount() - 1, pStart); } pStart = pEnd; } while (pStart); } free(szFileData); } fInput.Close(); } }
BOOL CBuildProgram::bCreateMakeFile(CString& omStrMakeFileTemplateName, CString& omStrMakeFileName ) { CStdioFile omStdiofile; CFileException omException ; CString omStrFile = ""; BOOL bReturn = FALSE; DWORD dwSize = 0; DWORD dwRead = 0; BOOL bFileOpen = FALSE; CString omStrErrorMessage = ""; char acErrorMsg[defSIZE_OF_ERROR_BUFFER]; // Open the make file template. TRY { bFileOpen = omStdiofile.Open(omStrMakeFileTemplateName, CFile::modeRead | CFile::typeText, &omException); if(bFileOpen!=FALSE) { CHAR* pcBuff = NULL; CString omTemp = ""; // Get the size of file dwSize = (DWORD)omStdiofile.GetLength(); pcBuff = (char*) new char[dwSize]; if(pcBuff!=NULL) { memset(pcBuff, 0, dwSize); // Read the whole file and put the content to pcBuff; dwRead = omStdiofile.Read(pcBuff,dwSize); // Add end of string; *(pcBuff+dwRead) = '\0'; // copy the content to CString object; omStrFile = pcBuff; // Delete the buffer and initialise it to NULL delete []pcBuff; pcBuff = NULL; char acStrShortPath[1000] ; // Convert long name to short name for GCC compiler dwConvertShortPathName(omStrMakeFileTemplateName,acStrShortPath); omTemp = acStrShortPath; INT nIndex = 0; // Get the path of make file temptate in temp object nIndex = omStrMakeFileTemplateName.ReverseFind('\\'); if(nIndex>=0) { omTemp = omStrMakeFileTemplateName.Left(nIndex); // Replace all occurrence of "<INSTALLDIR>" string with template path omStrFile.Replace("<INSTALLDIR>",omTemp); } // Replace all occurence of <SRCDIR> and <FILENAME> with source // directory and file name respectively. nIndex = omTemp.ReverseFind('\\'); if(nIndex>=0) { nIndex = m_omStrSourceFilename.ReverseFind('.'); if(nIndex>=0) { omTemp = m_omStrSourceFilename.Left(nIndex); // Replace all occurrence of "<INSTALLDIR>" string with template path omStrFile.Replace("<INPUTFILE>",omTemp); } omTemp = m_omStrSourceFilename; omTemp.Replace('\\', '/'); omTemp.Replace(" ", "\\ "); omStrFile.Replace("<CPPFILE>", omTemp); bReturn = TRUE; } } omStdiofile.Close(); } else { // Get the exception error message omException.GetErrorMessage(acErrorMsg,sizeof(acErrorMsg)); // make file template open error notification // AfxMessageBox(acErrorMsg ,MB_ICONERROR| MB_SYSTEMMODAL|MB_OK,0); m_omStrArray.Add(acErrorMsg); bAddString(m_omStrArray); } if(bReturn == TRUE) { bFileOpen = omStdiofile.Open( omStrMakeFileName, CFile::modeCreate | CFile::modeWrite, &omException); if(bFileOpen!=FALSE) { //AfxMessageBox(omStrFile); omStdiofile.WriteString(omStrFile); omStdiofile.Close(); } else { // Get the exception error message omException.GetErrorMessage(acErrorMsg,sizeof(acErrorMsg)); //AfxMessageBox(acErrorMsg , // MB_ICONERROR| MB_SYSTEMMODAL|MB_OK, // 0); m_omStrArray.Add(acErrorMsg); bAddString(m_omStrArray); bReturn = FALSE; } } } CATCH_ALL(pomE) { if(pomE != NULL ) { // Get the exception error message pomE->GetErrorMessage(acErrorMsg,sizeof(acErrorMsg)); omStrErrorMessage = acErrorMsg; //Display the error //AfxMessageBox(omStrErrorMessage , // MB_ICONERROR| MB_SYSTEMMODAL|MB_OK,0); m_omStrArray.Add(acErrorMsg); bAddString(m_omStrArray); pomE->Delete(); } bReturn = FALSE; } END_CATCH_ALL return bReturn; }
/***************************************************************************** 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; }
BOOL CComputeCheckSum::bGetCheckSum(CString &omStrConfigFileName, UCHAR* pucCheckSum, UCHAR* pucCheckSumInFile) { CStdioFile omStdiofile; CFileException omException ; DWORD dwSize = 0; DWORD dwRead = 0; BOOL bReturn = FALSE; BOOL bFileOpen = FALSE; CString omStrErrorMessage = _T(""); TCHAR acErrorMsg[defSIZE_OF_ERROR_BUFFER]; // Open the configration file. TRY { bFileOpen = omStdiofile.Open(omStrConfigFileName, CFile::modeRead | CFile::typeBinary, &omException); if(bFileOpen!=FALSE) { UCHAR *pucBuff = NULL; // Get the size of file dwSize = (DWORD)omStdiofile.GetLength(); if( dwSize > 0) { 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 - 1, pucCheckSum); // Get the check sum stored in file ( Last byte ) *pucCheckSumInFile = pucBuff[dwSize-1]; delete [] pucBuff; pucBuff = NULL; } } omStdiofile.Close(); bReturn = TRUE; } else { // Get the exception error message omException.GetErrorMessage(acErrorMsg,sizeof(acErrorMsg)); // configuration file open error notification //AfxMessageBox(acErrorMsg ,MB_ICONERROR| MB_SYSTEMMODAL|MB_OK,nZERO); MessageBox(NULL,acErrorMsg, defPROJECT_NAME,MB_OK|MB_ICONERROR|MB_TOPMOST); } } CATCH_ALL(pomE) { if(pomE != NULL ) { // Get the exception error message pomE->GetErrorMessage(acErrorMsg,sizeof(acErrorMsg)); //Display the error //AfxMessageBox(acErrorMsg ,MB_ICONERROR| MB_SYSTEMMODAL|MB_OK,nZERO); MessageBox(NULL,acErrorMsg, defPROJECT_NAME,MB_OK|MB_ICONERROR|MB_TOPMOST); } } END_CATCH_ALL return bReturn; }
BOOL CFraseSPSToXML::read_file_rec(CString strPath) { CString str1,str2; CString str_header_type; CString str_line ; CString str_point; CString str_type; int m_list = 0; int flag = 0; m_icnt_rec = 0; double intvl = 0; m_vecLine.clear(); CStdioFile file; memset(&rec_file[0], 0, ARRAY_SIZE*sizeof(rec_file_struct)); if (FALSE == file.Open(strPath, CFile::modeRead)) { return FALSE; } while (file.GetPosition()<file.GetLength()) { file.ReadString(str1); str2 = str1.GetAt(0); if (str2 == FLAG_R) { str_line = _T(""); str_point = _T(""); str_type = _T(""); str_line = readbyte(1, 17, str1); if (_tstoi(str_line) != rec_file[m_icnt_rec].lineName) //如果测线号有变,则数组位置递增(起始位置为1),测点号为下限 { m_vecLine.push_back(0); m_icnt_rec++; rec_file[m_icnt_rec].lineName = _tstoi(str_line); rec_file[m_icnt_rec].type = _tstoi(readbyte(27, 28, str1)); str_point = readbyte(17, 25, str1); rec_file[m_icnt_rec].point_lower = _tstof(str_point); } else //否则测点号上限不断更新 { str_point = readbyte(17, 25, str1); if (rec_file[m_icnt_rec].point_upper == 0) //该测线上第二个点,计算间隔 { rec_file[m_icnt_rec].interval = _tstof(str_point) - rec_file[m_icnt_rec].point_lower; rec_file[m_icnt_rec].point_upper = _tstof(str_point); } else { intvl = _tstof(str_point) - rec_file[m_icnt_rec].point_upper; //同测线上,间隔不等 if (intvl != rec_file[m_icnt_rec].interval) { m_icnt_rec++; rec_file[m_icnt_rec].lineName = _tstoi(str_line); rec_file[m_icnt_rec].type = _tstoi(readbyte(27, 28, str1)); rec_file[m_icnt_rec].point_lower = _tstof(str_point); } else rec_file[m_icnt_rec].point_upper = _tstof(str_point); } } rec_file[m_icnt_rec].count++; m_vecLine[m_icnt_rec - 1] = rec_file[m_icnt_rec].count; } else if (str2 == _T('H')) { str_header_type = _T(""); str_header_type = readbyte(1, 4, str1); if (str_header_type == HEADER_INSTRUMENT_TYPE) { m_str_instr_type = _T(""); m_str_instr_type = readbyte(32, 33, str1); } else if (str_header_type == HEADER_REC_TYPE) { m_str_rec_type = _T(""); m_str_rec_type = readbyte(32, 34, str1); } if (str_header_type == HEADER_SHOT_TYPE) { m_str_shot_type = _T(""); m_str_shot_type = readbyte(32, 34, str1); } } else break; } return TRUE; }
BOOL CFraseSPSToXML::read_file_comm(CString strPath) { CStdioFile file; CString str1, str2, str_header_type; double shot_line; double shot_point; m_icnt_comm = 0; memset(&comm_file[0], 0, ARRAY_SIZE*sizeof(comm_file_struct)); if (FALSE == file.Open(strPath, CFile::modeRead)) { return FALSE; } while (file.GetPosition()<file.GetLength()) { file.ReadString(str1); str2 = str1.GetAt(0); if (str2 == FLAG_X) { shot_line = _tstoi(readbyte(13, 29, str1)); shot_point = _tstof(readbyte(29, 37, str1)); if (comm_file[m_icnt_comm].shot_lineName!=0 && comm_file[m_icnt_comm].shot_point!=0) { if (comm_file[m_icnt_comm].shot_lineName != shot_line || comm_file[m_icnt_comm].shot_point != shot_point) { m_icnt_comm++; comm_file[m_icnt_comm].shot_lineName = shot_line; comm_file[m_icnt_comm].shot_point = shot_point; } } else { m_icnt_comm++; comm_file[m_icnt_comm].shot_lineName = shot_line; comm_file[m_icnt_comm].shot_point = shot_point; } comm_file[m_icnt_comm].rec_line_num ++; comm_file[m_icnt_comm].rec_point_index[comm_file[m_icnt_comm].rec_line_num-1]= _tstoi(readbyte(37, 38, str1)); comm_file[m_icnt_comm].record_channel_lower[comm_file[m_icnt_comm].rec_line_num-1] = _tstoi(readbyte(38, 42, str1)); comm_file[m_icnt_comm].record_channel_upper[comm_file[m_icnt_comm].rec_line_num-1] = _tstoi(readbyte(42, 46, str1)); comm_file[m_icnt_comm].record_channel_interval[comm_file[m_icnt_comm].rec_line_num-1] = _tstoi(readbyte(46, 47, str1)); comm_file[m_icnt_comm].rec_lineName[comm_file[m_icnt_comm].rec_line_num-1] = _tstoi(readbyte(47, 63, str1)); comm_file[m_icnt_comm].rec_point_lower[comm_file[m_icnt_comm].rec_line_num-1] = _tstof(readbyte(63, 71, str1)); comm_file[m_icnt_comm].rec_point_upper[comm_file[m_icnt_comm].rec_line_num-1] = _tstof(readbyte(71, 79, str1)); comm_file[m_icnt_comm].channel_lower[comm_file[m_icnt_comm].rec_line_num-1] = (int)((comm_file[m_icnt_comm].rec_point_lower[comm_file[m_icnt_comm].rec_line_num-1] - rec_file[comm_file[m_icnt_comm].rec_line_num].point_lower)/rec_file[comm_file[m_icnt_comm].rec_line_num].interval + 1); comm_file[m_icnt_comm].channel_upper[comm_file[m_icnt_comm].rec_line_num-1] = (int)((comm_file[m_icnt_comm].rec_point_upper[comm_file[m_icnt_comm].rec_line_num-1] - rec_file[comm_file[m_icnt_comm].rec_line_num].point_lower)/rec_file[comm_file[m_icnt_comm].rec_line_num].interval + 1); } else if (str2 == _T('H')) { str_header_type = _T(""); str_header_type = readbyte(1, 4, str1); if (str_header_type == HEADER_INSTRUMENT_TYPE) { m_str_instr_type = _T(""); m_str_instr_type = readbyte(32, 33, str1); } else if (str_header_type == HEADER_REC_TYPE) { m_str_rec_type = _T(""); m_str_rec_type = readbyte(32, 34, str1); } if (str_header_type == HEADER_SHOT_TYPE) { m_str_shot_type = _T(""); m_str_shot_type = readbyte(32, 34, str1); } } else break; } return TRUE; }
void OnCfg2Bin(CString strSrcFile, CString strDstFile, BOOL bForce) { CFile out; CStdioFile in; CString strRead; char * p; BOOL bSettings = TRUE; int iItem; if (!PromptOverwriteFile(strDstFile, bForce)) return; if (!in.Open(strSrcFile, CFile::modeRead)) { #ifndef __GNUC__ wprintf(_T("Can not open source file %s"), strSrcFile); #else printf("Can not open source file %s", strSrcFile.c_str()); #endif return; } if (!out.Open(strDstFile, CFile::modeCreate|CFile::modeWrite)) { #ifndef __GNUC__ wprintf(_T("Can not create destination file %s"), strDstFile); #else printf("Can not create destination file %s", strDstFile.c_str()); #endif in.Close(); return; } #ifndef __GNUC__ AfxGetApp()->BeginWaitCursor(); #endif p = (char *)malloc(SETTINGS_FILE_SIZE); memset(p, 0, SETTINGS_FILE_SIZE); iItem = 0; #ifndef __GNUC__ while (in.ReadString(strRead)) { #else while (!in.eof()) { std::getline(in, strRead); strRead.TrimRight(); #endif if (!strRead.GetLength()) { continue; } if (strRead.GetAt(0) == '[') { strRead.MakeLower(); if (strRead.Left(10) == "[settings]") { bSettings = TRUE; } else if (strRead.Left(10) == "[digitmap]") { bSettings = FALSE; } continue; } else if (strRead.Left(12) == "ENDOFCONFIG=") { break; } else { if (bSettings) { AR168CompareCfg((char *)p, strRead); } else { if (iItem < DIGITMAP_ENTRY_NUM) { if (AR168CompareMap((char *)(p + OPT_DIGIT_MAP), strRead, iItem)) { iItem++; } } } } } out.Write(p, SETTINGS_FILE_SIZE); #ifndef __GNUC__ AfxGetApp()->EndWaitCursor(); #endif free(p); in.Close(); out.Close(); } void OnBin2H(CString strSrcFile, CString strDstFile, BOOL bForce, int iAddressOffset, int iConvertLength) { CFile in; CStdioFile out; CString strAnswer, strName; CString strOut, strItem; TCHAR drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; char * p; int iLength, i, j; if (!PromptOverwriteFile(strDstFile, bForce)) return; if (!in.Open(strSrcFile, CFile::modeRead)) { #ifndef __GNUC__ wprintf(_T("Can not open source file %s"), strSrcFile); #else printf("Can not open source file %s", strSrcFile.c_str()); #endif return; } if (!out.Open(strDstFile, CFile::modeCreate|CFile::modeWrite)) { #ifndef __GNUC__ wprintf(_T("Can not create destination file %s"), strDstFile); #else printf("Can not create destination file %s", strDstFile.c_str()); #endif in.Close(); return; } iLength = (int)in.GetLength(); p = (char *)malloc(iLength); in.Read(p, iLength); if (iConvertLength == 0) { iConvertLength = iLength; } #ifndef __GNUC__ _wsplitpath(strDstFile, drive, dir, fname, ext); #else strcpy(fname,basename(strDstFile)); #endif strName = fname; strName.MakeUpper(); #ifndef __GNUC__ strOut.Format(_T("#define DATA_%s_SIZE\t\t%d\n"), strName, iConvertLength); #else { char buff[511]; sprintf(buff, _T("#define DATA_%s_SIZE\t\t%d\n"), strName.c_str(), iConvertLength); strOut = buff; } #endif out.WriteString(strOut); #ifndef __GNUC__ strOut.Format(_T("const unsigned char _c_%s[DATA_%s_SIZE] = {\n"), fname, strName); #else { char buff[511]; sprintf(buff, _T("const unsigned char _c_%s[DATA_%s_SIZE] = {\n"), fname, strName.c_str()); strOut = buff; } #endif out.WriteString(strOut); for (i = iAddressOffset; i < iAddressOffset+iConvertLength; i += FRAME_LEN) { strOut = _T(""); for (j = 0; j < FRAME_LEN; j ++) { if (i+j < iAddressOffset+iConvertLength) { #ifndef __GNUC__ strItem.Format(_T("0x%02x"), (unsigned char)p[i+j]); #else { char buff[511]; sprintf(buff, _T("0x%02x"), (unsigned char)p[i+j]); strItem = buff; } #endif strOut += strItem; } if (i+j < ((iAddressOffset+iConvertLength) - 1)) { strOut += _T(", "); } } strOut += _T("\n"); out.WriteString(strOut); } #ifndef __GNUC__ strOut.Format(_T("};\n")); #else { char buff[511]; sprintf(buff, _T("};\n")); strOut = buff; } #endif out.WriteString(strOut); free(p); in.Close(); out.Close(); }