BOOL CStaticDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace) // Save the document data to a file // lpszPathName = path name where to save document file // if lpszPathName is NULL then the user will be prompted (SaveAs) // note: lpszPathName can be different than 'm_strPathName' // if 'bReplace' is TRUE will change file name if successful (SaveAs) // if 'bReplace' is FALSE will not change path name (SaveCopyAs) { CString newName = lpszPathName; if (newName.IsEmpty()) { newName = m_strPathName; if (bReplace && newName.IsEmpty()) { newName = m_strTitle; if (newName.IsEmpty()) VERIFY(newName.LoadString(AFX_IDS_UNTITLED)); // check for dubious filename int iBad = newName.FindOneOf(_T(" #%;/\\")); if (iBad != -1) newName.ReleaseBuffer(iBad); // append the default suffix if there is one newName += AfxGetStrategyFileExt( ); } if( !AfxDoPromptFileName(newName, bReplace ? IDS_SAVEFILE : IDS_SAVEFILECOPY, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_ENABLESIZING, FALSE ) ) return FALSE; // don't even attempt to save } CWaitCursor wait; if (!OnSaveDocument(newName)) { if (lpszPathName == NULL) { // be sure to delete the file try { CFile::Remove(newName); } catch(CException *e) { TRACE0("Warning: failed to delete file after failed SaveAs.\n"); if( !e->m_bAutoDelete ) e->Delete(); } } return FALSE; } // reset the title and change the document name if (bReplace) SetPathName(newName); return TRUE; // success }
CString CStkUIApp::GetNextNewStrategyTitle( CString & strExtBuffer, CString strPath ) { CString string; VERIFY( string.LoadString( IDS_STRATEGY_NONAME ) ); CString strExt = AfxGetStrategyFileExt( ); if( !strExt.IsEmpty()) strExtBuffer = strExt; CStringArray astrExistTitle; POSITION pos = GetFirstStrategyPosition(); while( NULL != pos ) { CStrategy * pStrategy = GetNextStrategy( pos ); astrExistTitle.Add( AfxGetFileTitleNoExt(pStrategy->GetPathName()) ); } CFileFind finder; BOOL bWorking = finder.FindFile( AfxGetFilePath( (LPCTSTR)strPath, LPCTSTR("*" + strExt) ) ); while( bWorking ) { bWorking = finder.FindNextFile(); astrExistTitle.Add( finder.GetFileTitle( ) ); } finder.Close(); for( int i=1; ; i++ ) { CString strTemp; strTemp.Format( "%s(%d)", string, i ); BOOL bHas = FALSE; for( int k=0; k<astrExistTitle.GetSize(); k++ ) { if( 0 == strTemp.CompareNoCase( astrExistTitle.ElementAt(k) ) ) { bHas = TRUE; break; } } if( !bHas ) { string = strTemp; break; } } return string; }
int CStkUIApp::OpenDefaultStrategy( ) { CSPStringArray astrStrategyToOpen; // Recent if( m_pRecentFileList ) { for( int i=m_pRecentFileList->GetSize()-1; i>=0; i-- ) { CString strPath = (*m_pRecentFileList)[i]; if( !strPath.IsEmpty() ) astrStrategyToOpen.Add( strPath ); } } // projects CString strExt = AfxGetStrategyFileExt( ); if( !strExt.IsEmpty()) { CFileFind finder; BOOL bWorking = finder.FindFile( AfxGetFilePath( (LPCTSTR)AfxGetProfile().GetProjectPath(), LPCTSTR("*" + strExt) ) ); while( bWorking ) { bWorking = finder.FindNextFile(); CString strPath = finder.GetFilePath(); int i; for( i=0; i<astrStrategyToOpen.GetSize(); i++ ) { if( 0 == strPath.Compare( astrStrategyToOpen.ElementAt(i) ) ) break; } if( i == astrStrategyToOpen.GetSize() ) astrStrategyToOpen.Add( strPath ); } finder.Close(); } AfxGetProfile().SetLastOpenedStrategy( astrStrategyToOpen ); return OpenLastOpenedStrategy( ); }
void CWizardView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { // TODO: Add your specialized code here and/or call the base class if( UPDATE_HINT_WIZARDVIEW != lHint ) { if( ::IsWindow( m_listRecent.GetSafeHwnd() ) ) m_listRecent.Invalidate( ); return; } if( IsWindowVisible() ) SetFocus( ); m_listRecent.DeleteAllItems( ); // insert items CStkUIApp * pApp = AfxGetStkUIApp(); CRecentFileList * pRecent = NULL; if( pApp ) pRecent = pApp->GetRecentFileList( ); CString strOpened; strOpened.LoadString( IDS_STRATEGYOPENED ); CStringArray astrAdded; int count = 0; if( pRecent ) { for( int i=pRecent->GetSize()-1; i>=0; i-- ) { CString strPath = (*pRecent)[i]; if( strPath.IsEmpty() ) continue; if( 0 != access(strPath,0) ) { pRecent->Remove(i); continue; } TCHAR szFullPath[_MAX_PATH]; AfxFullPath( szFullPath, strPath ); strPath = szFullPath; CString strName = CStrategy::GetName( strPath ); BOOL bOpened = pApp->IsFileOpened( strPath ); int nItem = m_listRecent.InsertItem( count, strPath, bOpened ? 1 : 0 ); m_listRecent.SetItemText( nItem, 0, strName ); m_listRecent.SetItemText( nItem, 1, strPath ); if( bOpened ) m_listRecent.SetItemText( nItem, 3, strOpened ); astrAdded.Add( strPath ); CString strTime; CFileStatus status; if( CFile::GetStatus( strPath, status ) ) { strTime = status.m_mtime.Format( "%Y-%m-%d" ); m_listRecent.SetItemText( nItem, 2, strTime ); } count ++; } } CString strExt = AfxGetStrategyFileExt( ); if( !strExt.IsEmpty()) { CFileFind finder; BOOL bWorking = finder.FindFile( AfxGetFilePath( (LPCTSTR)AfxGetProfile().GetProjectPath(), LPCTSTR("*" + strExt) ) ); while( bWorking ) { bWorking = finder.FindNextFile(); CString strPath = finder.GetFilePath(); int i; for( i=0; i<astrAdded.GetSize(); i++ ) { if( 0 == strPath.CompareNoCase( astrAdded.ElementAt(i) ) ) break; } if( i < astrAdded.GetSize() ) continue; CString strName = CStrategy::GetName( strPath ); BOOL bOpened = pApp->IsFileOpened( strPath ); int nItem = m_listRecent.InsertItem( count, strPath, bOpened ? 1 : 0 ); m_listRecent.SetItemText( nItem, 0, strName ); m_listRecent.SetItemText( nItem, 1, strPath ); if( bOpened ) m_listRecent.SetItemText( nItem, 3, strOpened ); CString strTime; CFileStatus status; if( CFile::GetStatus( strPath, status ) ) { strTime = status.m_mtime.Format( "%Y-%m-%d" ); m_listRecent.SetItemText( nItem, 2, strTime ); } count ++; if( count >= 256 ) break; } finder.Close(); } m_listRecent.Invalidate( ); }