MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / EditSaveFile

Function EditSaveFile

src/Edit.c:1302–1457  ·  view source on GitHub ↗

============================================================================= EditSaveFile()

Source from the content-addressed store, hash-verified

1300// EditSaveFile()
1301//
1302BOOL EditSaveFile (
1303 HWND hwnd,
1304 LPCWSTR pszFile,
1305 int iEncoding,
1306 BOOL *pbCancelDataLoss,
1307 BOOL bSaveCopy )
1308{
1309 HANDLE hFile;
1310 BOOL bWriteSuccess;
1311 char *lpData;
1312 DWORD cbData;
1313 DWORD dwBytesWritten;
1314 *pbCancelDataLoss = FALSE;
1315 hFile = CreateFile ( pszFile,
1316 GENERIC_WRITE,
1317 FILE_SHARE_READ | FILE_SHARE_WRITE,
1318 NULL,
1319 OPEN_ALWAYS,
1320 FILE_ATTRIBUTE_NORMAL,
1321 NULL );
1322 dwLastIOError = GetLastError();
1323 // failure could be due to missing attributes (2k/XP)
1324 if ( hFile == INVALID_HANDLE_VALUE ) {
1325 DWORD dwAttributes = GetFileAttributes ( pszFile );
1326 if ( dwAttributes != INVALID_FILE_ATTRIBUTES ) {
1327 dwAttributes = dwAttributes & ( FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM );
1328 hFile = CreateFile ( pszFile,
1329 GENERIC_WRITE,
1330 FILE_SHARE_READ | FILE_SHARE_WRITE,
1331 NULL,
1332 OPEN_ALWAYS,
1333 FILE_ATTRIBUTE_NORMAL | dwAttributes,
1334 NULL );
1335 dwLastIOError = GetLastError();
1336 }
1337 }
1338 if ( hFile == INVALID_HANDLE_VALUE ) {
1339 return FALSE;
1340 }
1341 // ensure consistent line endings
1342 if ( bFixLineEndings ) {
1343 SendMessage ( hwnd, SCI_CONVERTEOLS, SendMessage ( hwnd, SCI_GETEOLMODE, 0, 0 ), 0 );
1344 EditFixPositions ( hwnd );
1345 }
1346 // strip trailing blanks
1347 if ( bAutoStripBlanks ) {
1348 EditStripTrailingBlanks ( hwnd, TRUE );
1349 }
1350 // get text
1351 cbData = ( int ) SendMessage ( hwnd, SCI_GETLENGTH, 0, 0 );
1352 lpData = GlobalAlloc ( GPTR, cbData + 1 );
1353 SendMessage ( hwnd, SCI_GETTEXT, GlobalSize ( lpData ), ( LPARAM ) lpData );
1354 if ( cbData == 0 ) {
1355 bWriteSuccess = SetEndOfFile ( hFile );
1356 dwLastIOError = GetLastError();
1357 } else {
1358 // FIXME: move checks in front of disk file access
1359 /*if ((mEncoding[iEncoding].uFlags & NCP_UNICODE) == 0 && (mEncoding[iEncoding].uFlags & NCP_UTF8_SIGN) == 0) {

Callers 1

FileIOFunction · 0.85

Calls 3

EditFixPositionsFunction · 0.85
EditStripTrailingBlanksFunction · 0.85
InfoBoxFunction · 0.85

Tested by

no test coverage detected