============================================================================= FileSave()
| 5582 | // |
| 5583 | // |
| 5584 | BOOL FileSave ( BOOL bSaveAlways, BOOL bAsk, BOOL bSaveAs, BOOL bSaveCopy , BOOL bDeleteOld ) |
| 5585 | { |
| 5586 | WCHAR tchFile[MAX_PATH]; |
| 5587 | BOOL fSuccess = FALSE; |
| 5588 | BOOL bCancelDataLoss = FALSE; |
| 5589 | BOOL bIsEmptyNewFile = FALSE; |
| 5590 | if ( lstrlen ( szCurFile ) == 0 ) { |
| 5591 | int cchText = ( int ) SendMessage ( hwndEdit, SCI_GETLENGTH, 0, 0 ); |
| 5592 | if ( cchText == 0 ) { |
| 5593 | bIsEmptyNewFile = TRUE; |
| 5594 | } else if ( cchText < 1023 ) { |
| 5595 | char tchText[2048]; |
| 5596 | SendMessage ( hwndEdit, SCI_GETTEXT, ( WPARAM ) 2047, ( LPARAM ) tchText ); |
| 5597 | StrTrimA ( tchText, " \t\n\r" ); |
| 5598 | if ( lstrlenA ( tchText ) == 0 ) { |
| 5599 | bIsEmptyNewFile = TRUE; |
| 5600 | } |
| 5601 | } |
| 5602 | } |
| 5603 | if ( !bSaveAlways && ( !bModified && iEncoding == iOriginalEncoding || bIsEmptyNewFile ) && !bSaveAs ) { |
| 5604 | return TRUE; |
| 5605 | } |
| 5606 | if ( bAsk ) { |
| 5607 | // File or "Untitled" ... |
| 5608 | WCHAR tch[MAX_PATH]; |
| 5609 | if ( lstrlen ( szCurFile ) ) { |
| 5610 | lstrcpy ( tch, szCurFile ); |
| 5611 | } else { |
| 5612 | GetString ( IDS_UNTITLED, tch, COUNTOF ( tch ) ); |
| 5613 | } |
| 5614 | switch ( MsgBox ( MBYESNOCANCEL, IDS_ASK_SAVE, tch ) ) { |
| 5615 | case IDCANCEL: |
| 5616 | return FALSE; |
| 5617 | case IDNO: |
| 5618 | return TRUE; |
| 5619 | } |
| 5620 | } |
| 5621 | // Read only... |
| 5622 | if ( !bSaveAs && !bSaveCopy && lstrlen ( szCurFile ) ) { |
| 5623 | DWORD dwFileAttributes = GetFileAttributes ( szCurFile ); |
| 5624 | if ( dwFileAttributes != INVALID_FILE_ATTRIBUTES ) { |
| 5625 | bReadOnly = ( dwFileAttributes & FILE_ATTRIBUTE_READONLY ); |
| 5626 | } |
| 5627 | if ( bReadOnly ) { |
| 5628 | SetWindowTitle ( hwndMain, uidsAppTitle, fIsElevated, IDS_UNTITLED, szCurFile, |
| 5629 | iPathNameFormat, bModified || iEncoding != iOriginalEncoding, |
| 5630 | IDS_READONLY, bReadOnly, szTitleExcerpt ); |
| 5631 | if ( MsgBox ( MBYESNOWARN, IDS_READONLY_SAVE, szCurFile ) == IDYES ) { |
| 5632 | bSaveAs = TRUE; |
| 5633 | } else { |
| 5634 | return FALSE; |
| 5635 | } |
| 5636 | } |
| 5637 | } |
| 5638 | // Save As... |
| 5639 | if ( bSaveAs || bSaveCopy || lstrlen ( szCurFile ) == 0 ) { |
| 5640 | WCHAR tchInitialDir[MAX_PATH] = L""; |
| 5641 | if ( bSaveCopy && lstrlen ( tchLastSaveCopyDir ) ) { |
no test coverage detected