void CTextPadDlg::OnBnClickedLoadbtn() { // TODO: Add your control notification handler code here char szFilter[] = "(*.txt) | All Files(*.*)|*.*||"; CFileDialog dlg(TRUE, "txt", "*.txt", OFN_HIDEREADONLY, szFilter); if(IDOK == dlg.DoModal()){ CString strPathName = dlg.GetPathName(); CStdioFile fp; CFileException e; if(!fp.Open(strPathName, CFile::modeRead, &e)) { e.ReportError(); return; } CString str = ""; CString tmp = ""; while(fp.ReadString(tmp)){ str += tmp; str += "\r\n"; } UpdateData(FALSE); textpad.SetWindowText(str); fp.Close(); } }
void CTextPadDlg::OnBnClickedSavebtn() { // TODO: Add your control notification handler code here //CFileDialog를 숨긴파일 읽지않고, //같은 이름의 파일이 있을시 물어보는 옵션으로 열기 char szFilter[] = "(*.txt) | All Files(*.*)|*.*||"; CFileDialog dlg(FALSE, "txt", "*.txt", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT , szFilter); if(IDOK == dlg.DoModal()){ CString strPathName = dlg.GetPathName(); CStdioFile fp; CFileException e; if(!fp.Open(strPathName,CFile::modeWrite|CFile::modeCreate, &e)) { e.ReportError(); return; } UpdateData(TRUE); CString str; textpad.GetWindowText(str); str.Replace("\r\n", "\n"); fp.WriteString(str); fp.Close(); } }
void CKmlDlg::convert_all_file() { int i; CString temp; for(i=0;i<NumOfFile;i++) { CFileException ef; try { if(!Fsource.Open(FilePath[i],CFile::modeRead,&ef)) { ef.ReportError(); continue; } IsFSourceOpen = true; kml_filename = FileName[i]; int find = kml_filename.Find("."); kml_filename = kml_filename.Mid(0,find); Convert(); temp.Format("%s OK",FileName[i]); m_check[i].SetWindowText(temp); m_check[i].SetCheck(BST_CHECKED); } catch(CFileException *fe) { fe->ReportError(); fe->Delete(); } } }
bool CCrossDlg::Save(int Sel) { ASSERT(Sel >= 0 && Sel < SELS); CPathStr FileName; GetName(Sel, FileName); CFileDialog fd(FALSE, EXT_PATCH, FileName, OFN_OVERWRITEPROMPT, LDS(IDS_FILTER_PATCH)); if (fd.DoModal() != IDOK) return(FALSE); CStdioFile fp; CFileException e; if (!fp.Open(fd.GetPathName(), CFile::modeCreate | CFile::modeWrite, &e)) { e.ReportError(); return(FALSE); } CPatch Patch; Patch = m_Info[Sel]; // assign parm info m_Frm->GetPatch(Patch); // get master and main info if (!Patch.Write(fp)) return(FALSE); m_Modified[Sel] = FALSE; FileName = fd.GetFileName(); FileName.RemoveExtension(); SetName(Sel, FileName); return(TRUE); }
bool CJobList::DoIO(LPCTSTR Path, DWORD FileMode, DWORD ArchiveMode) { CFile fp; CFileException e; if (!fp.Open(Path, FileMode, &e)) { e.ReportError(); return(FALSE); } TRY { CArchive ar(&fp, ArchiveMode); ar.m_strFileName = fp.GetFileName(); Serialize(ar); } CATCH(CArchiveException, e) { e->ReportError(); return(FALSE); }
bool CPatch::Read(LPCTSTR Path) { CStdioFile fp; CFileException e; if (!fp.Open(Path, CFile::modeRead | CFile::shareDenyWrite, &e)) { e.ReportError(); return(FALSE); } TRY { if (!Read(fp)) { AfxMessageBox(IDS_DOC_BAD_FORMAT); return(FALSE); } } CATCH(CFileException, e) { e->ReportError(); return(FALSE); }
void CKmlDlg::convert_all_file() { int i; CString temp; CKmlDlg::kmlDlg->PostMessage(UWM_PROGRESS, 1, 0); //Show progress for(i = 0; i < NumOfFile; ++i) { CFileException ef; CFile f; try { if(KML_USE_CHECKLISTBOX) { m_fileList.SetCurSel(i); } if(!f.Open(FilePath[i], CFile::modeRead,&ef)) { ef.ReportError(); continue; } kml_filename = FilePath[i]; int find = kml_filename.ReverseFind('.'); kml_filename = kml_filename.Mid(0,find); //Convert(f); Convert2(f); f.Close(); temp.Format("%s OK", FileName[i]); if(KML_USE_CHECKLISTBOX) { //m_fileList.SetCurSel(i); m_fileList.DeleteString(i); m_fileList.InsertString(i, temp); m_fileList.SetCheck(i, BST_CHECKED); } else { m_check[i].SetWindowText(temp); m_check[i].SetCheck(BST_CHECKED); } } catch(CFileException *fe) { fe->ReportError(); fe->Delete(); } } CKmlDlg::kmlDlg->PostMessage(UWM_PROGRESS, 0, 1000); //Hide progress }
BOOL Driver::Open(LPCTSTR filename,CStdioFile &File,UINT nOpenFlags) { CFileException ex; if (!File.Open(filename,nOpenFlags)) { ex.ReportError(); return FALSE; } else { return TRUE; } }
//************************************ // Method: Open // FullName: CRawFileExporter::Open // Access: public // Returns: int // Qualifier: // Parameter: CString in_szFilePath //************************************ int CRawFileExporter::Open( CString in_szFilePath ) { int ret = SV_NORMAL; m_szFilePath = in_szFilePath; CFileException ex; BOOL bflagOpen = m_oFile.Open(m_szFilePath, CFile::modeWrite | CFile::modeCreate, &ex); if(!bflagOpen) { ret = SV_FILEIO_ERROR; ex.ReportError(); m_szFilePath = _T(""); } return ret; }
BOOL CImportFile::Load(const TCHAR *filename) { ASSERT( m_pDesign == NULL ); CFile f; CFileException e; if( !f.Open( filename, CFile::modeRead, &e ) ) { e.ReportError(); return FALSE; } CArchive ar( &f, CArchive::load ); m_pDesign = new CTinyCadMultiDoc; m_pDesign->Serialize( ar ); return TRUE; }
BOOL helper::DumpResourceToFile(LPCSTR lpName, LPCSTR lpType, LPCSTR lpFile) { HRSRC hrsRC = ::FindResource(NULL, lpName, lpType); HGLOBAL hGlobal = ::LoadResource(NULL, hrsRC); LPVOID pData = ::LockResource(hGlobal); DWORD dwLen = ::SizeofResource(NULL, hrsRC); CFile f; CFileException e; if (!f.Open(lpFile, CFile::modeCreate | CFile::modeWrite, &e)) { e.ReportError(); return FALSE; } f.Write(pData, dwLen); f.Close(); return TRUE; }
/** * Load the coding file */ void CCoding::Load() { Clear(); CFileFind finder; if (finder.FindFile(m_Filename)) { finder.Close(); } else { if (!SaveRes(m_Filename)) { ShowError(_T("Can't find encoding file \"") + m_Filename + _T("\"")); return; } } CFileException ex; CFile f; if (f.Open(m_Filename, CFile::modeRead | CFile::shareDenyWrite, &ex)) { char c; CString line; while (f.Read(&c, 1)) { switch (c) { case 10: break; case 13: if (!line.IsEmpty()) { AddCode(line); line.Empty(); } break; default: line += c; } } f.Close(); if (!line.IsEmpty()) { AddCode(line); } } else ex.ReportError(); m_Loaded = TRUE; }
void ToolWnd::OnBvecButton() { CMainFrame * pFrame = (CMainFrame *) AfxGetApp()->m_pMainWnd; CString szFilter = _T("B-vector table (*.txt)|*.txt| All Files (*.*)|*.*|"); CFileDialog dlg (TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT, szFilter, this); if(dlg.DoModal() == IDCANCEL) return; CStdioFile file; CFileException e; CString str, temp; int i = 0; if(!file.Open(dlg.GetPathName() , CFile::modeRead, &e)) { e.ReportError(); return; } for (int i =0; i <3; i++) { for(int j =0; j <15; j++) { if(file.ReadString(str)) { AfxExtractSubString(temp,str, 0,'\n'); BV[i][j] =_ttof(temp); } } } file.Close(); AfxMessageBox(_T("Complete Load B-vec")); }
bool CCrossDlg::Open(int Sel, LPCTSTR Path) { ASSERT(Sel >= 0 && Sel < SELS); if (!SaveCheck(Sel)) return(FALSE); CStdioFile fp; CFileException e; if (!fp.Open(Path, CFile::modeRead | CFile::shareDenyWrite, &e)) { e.ReportError(); return(FALSE); } CPatch Patch; if (!Patch.Read(fp)) return(FALSE); m_Info[Sel] = Patch; UpdateMix(m_PosEdit.GetVal()); CPathStr FileName(PathFindFileName(Path)); FileName.RemoveExtension(); SetName(Sel, FileName); if (Sel == m_Frm->GetEditSel()) // if input is selected for editing m_Frm->SetEditSel(Sel); // refresh parameters dialog return(TRUE); }
void CGetEphemerisDlg::OnBnClickedOk() { m_file.GetWindowText(m_fileName); if(m_fileName.IsEmpty()) { AfxMessageBox("Please create a new file to save Ephemeris data!"); return; } if(Utility::IsFileExist(m_fileName)) { AfxMessageBox("File already exist!"); return; } CFileException ef; try { if(!CGPSDlg::gpsDlg->m_ephmsFile.Open(m_fileName, CFile::modeReadWrite|CFile::modeCreate, &ef)) { //CGPSDlg::gpsDlg->m_ephmsFile.Close(); ef.ReportError(); return; } } catch(CFileException *fe) { fe->ReportError(); fe->Delete(); return; } g_SV = m_ephems.GetCurSel(); AfxBeginThread(GetEphmsThread, (void*)ephType); OnOK(); }
void ModEncrypt::CheckInstallDate() { COleDateTime InsDate, Today; long i , iNum; CFile f,f1; long st; CFileException e; try{ //下面是安装日期记录文件 f.Open(user::gstrWinDir + FileIns,CFile::modeRead); iNum=f.GetLength()/sizeof(time_t) - 1; if(Qsort.sortarray !=NULL) { delete [] Qsort.sortarray; Qsort.sortarray=NULL; } if(Qsort.sortindex!=NULL) { delete [] Qsort.sortindex; Qsort.sortindex=NULL; } Qsort.sortarray=new DATE [iNum]; Qsort.sortindex=new int [iNum]; f.Seek(sizeof(DATE),CFile::begin); for(i=0;i<iNum;i++) { f.Read(&InsDate,sizeof(DATE)); //移动4个字节 Qsort.sortarray[i] = InsDate; Qsort.sortindex[i] = i; } Qsort.QuickSort(0, iNum-1); //最早的安装日期 //MsgBox Qsort.sortarray[1) //最晚的安装日期 //MsgBox Qsort.sortarray[iNum) InsDate=COleDateTime::GetCurrentTime(); f.Close(); SetFileTime(user::gstrWinDir + FileWinCom, user::gstrWinDir + FileIns); DATE tmpD; f.Open(user::gstrWinDir + FileIns,CFile::modeWrite); f.Seek(8,CFile::begin); if( ! FileExists(user::gstrWinDir + FileOutDate) ) { if( UEGetSettingInstallNumber("1", 0) >= INSTALL_NUM ) { //如果安装次数超过 glngUseDemoVersionDays = glngLimitedDemoVersionDays + 1; } else { //如果时间超过,则演示版功能受到限制 if( glngLimitedDemoVersionDays > RUN_DAYS_NUM ) glngLimitedDemoVersionDays = RUN_DAYS_NUM; else if( glngLimitedDemoVersionDays <= 0 ) glngLimitedDemoVersionDays = RUN_DAYS_NUM; else glngLimitedDemoVersionDays = RUN_DAYS_NUM; COleDateTime Date=COleDateTime::GetCurrentTime(); COleDateTime dateTmp = Qsort.sortarray[iNum-1]; if(Date >= dateTmp ) { dateTmp=Qsort.sortarray[0]; if( Date >= dateTmp) { glngUseDemoVersionDays = Date - COleDateTime(Qsort.sortarray[1]); } else { glngUseDemoVersionDays = glngLimitedDemoVersionDays + 1;//因为用户自已调整了时间所以让演示版到期 tmpD=(DATE)InsDate; f.Write(&tmpD,sizeof(DATE)); } } else { glngUseDemoVersionDays = glngLimitedDemoVersionDays + 1;//因为用户自已调整了时间所以让演示版到期 tmpD=(DATE)InsDate; f.Write(&tmpD,sizeof(DATE)); } } if( glngUseDemoVersionDays >= glngLimitedDemoVersionDays ) { f1.Open(user::gstrWinDir + FileOutDate,CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate); Today=COleDateTime::GetCurrentTime(); tmpD=(DATE)Today; f1.Write(&tmpD,sizeof(DATE)); f1.Close(); tmpD=0; st=f.GetLength(); if(st>=16) { st=8; f.Seek(st,CFile::begin); f.Write(&tmpD,sizeof(DATE)); } SetFileTime(user::gstrWinDir + FileWinCom, user::gstrWinDir + FileOutDate); gbLegalUser = FALSE; if( FileExists(user::gstrWinDir + FileFlag) ) DeleteFile(user::gstrWinDir + FileFlag); } else { if( UEGetSettingInstallNumber( "2", 0) >= RUN_NUM ) { //如果运行次数超过 SetFileTime(user::gstrWinDir + FileWinCom, user::gstrWinDir + FileOutDate); gbLegalUser = FALSE; if( FileExists(user::gstrWinDir + FileFlag) ) DeleteFile( user::gstrWinDir + FileFlag); } else { if( UEGetSettingInstallNumber( "2", 0) < 0 ) { UESaveSettingInstallNumber( "2", RUN_NUM); gbLegalUser = FALSE; } else { CopyFile( user::gstrWinDir + FileWinCom, user::gstrWinDir + FileFlag,TRUE); SetFileTime(user::gstrWinDir + FileWinCom, user::gstrWinDir + FileFlag); gbLegalUser = TRUE; } } } } else { gbLegalUser = FALSE; if( FileExists(user::gstrWinDir + FileFlag) ) DeleteFile( user::gstrWinDir + FileFlag); } f.Close(); } catch(CFileException *e) { e->ReportError(); e->Delete(); } }