mirror of
				https://github.com/notepad-plus-plus/notepad-plus-plus.git
				synced 2025-11-03 21:14:08 +01:00 
			
		
		
		
	[ENHANCE] (Author: Andreas Jonsson) Improve readability by using RAII to reset events.
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1316 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
		
							parent
							
								
									15542d7c8d
								
							
						
					
					
						commit
						04cd96d11c
					
				@ -835,6 +835,24 @@ bool FileManager::backupCurrentBuffer()
 | 
				
			|||||||
	return result;
 | 
						return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class EventReset
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
						EventReset(HANDLE h)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							_h = h;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						~EventReset()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							::SetEvent(_h);
 | 
				
			||||||
 | 
							::CloseHandle(_h);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
						HANDLE _h;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool FileManager::deleteCurrentBufferBackup()
 | 
					bool FileManager::deleteCurrentBufferBackup()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	HANDLE writeEvent = ::OpenEvent(EVENT_ALL_ACCESS, TRUE, TEXT("nppWrittingEvent"));
 | 
						HANDLE writeEvent = ::OpenEvent(EVENT_ALL_ACCESS, TRUE, TEXT("nppWrittingEvent"));
 | 
				
			||||||
@ -856,6 +874,8 @@ bool FileManager::deleteCurrentBufferBackup()
 | 
				
			|||||||
		::ResetEvent(writeEvent);
 | 
							::ResetEvent(writeEvent);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						EventReset reset(writeEvent); // Will reset event in destructor.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Buffer * buffer = _pNotepadPlus->getCurrentBuffer();
 | 
						Buffer * buffer = _pNotepadPlus->getCurrentBuffer();
 | 
				
			||||||
	bool result = true;
 | 
						bool result = true;
 | 
				
			||||||
	generic_string backupFilePath = buffer->getBackupFileName();
 | 
						generic_string backupFilePath = buffer->getBackupFileName();
 | 
				
			||||||
@ -867,9 +887,7 @@ bool FileManager::deleteCurrentBufferBackup()
 | 
				
			|||||||
		result = (::DeleteFile(file2Delete.c_str()) != 0);
 | 
							result = (::DeleteFile(file2Delete.c_str()) != 0);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// set to signaled state
 | 
						// set to signaled state via destructor EventReset.
 | 
				
			||||||
	::SetEvent(writeEvent);
 | 
					 | 
				
			||||||
	::CloseHandle(writeEvent);
 | 
					 | 
				
			||||||
	return result;
 | 
						return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -894,6 +912,7 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
 | 
				
			|||||||
		::ResetEvent(writeEvent);
 | 
							::ResetEvent(writeEvent);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						EventReset reset(writeEvent); // Will reset event in destructor.
 | 
				
			||||||
	Buffer * buffer = getBufferByID(id);
 | 
						Buffer * buffer = getBufferByID(id);
 | 
				
			||||||
	bool isHidden = false;
 | 
						bool isHidden = false;
 | 
				
			||||||
	bool isSys = false;
 | 
						bool isSys = false;
 | 
				
			||||||
@ -969,9 +988,7 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
 | 
				
			|||||||
			if(error_msg != NULL)
 | 
								if(error_msg != NULL)
 | 
				
			||||||
				*error_msg = TEXT("Failed to save file.\nNot enough space on disk to save file?");
 | 
									*error_msg = TEXT("Failed to save file.\nNot enough space on disk to save file?");
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
			// set to signaled state
 | 
								// set to signaled state via destructor EventReset.
 | 
				
			||||||
			::SetEvent(writeEvent);
 | 
					 | 
				
			||||||
			::CloseHandle(writeEvent);
 | 
					 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -996,9 +1013,7 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			*/
 | 
								*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// set to signaled state
 | 
								// set to signaled state via destructor EventReset.
 | 
				
			||||||
			::SetEvent(writeEvent);
 | 
					 | 
				
			||||||
			::CloseHandle(writeEvent);			
 | 
					 | 
				
			||||||
			return true;	//all done
 | 
								return true;	//all done
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1019,14 +1034,10 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy, g
 | 
				
			|||||||
			::DeleteFile(file2Delete.c_str());
 | 
								::DeleteFile(file2Delete.c_str());
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// set to signaled state
 | 
							// set to signaled state via destructor EventReset.
 | 
				
			||||||
		::SetEvent(writeEvent);
 | 
					 | 
				
			||||||
		::CloseHandle(writeEvent);
 | 
					 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// set to signaled state
 | 
						// set to signaled state via destructor EventReset.
 | 
				
			||||||
	::SetEvent(writeEvent);
 | 
					 | 
				
			||||||
	::CloseHandle(writeEvent);
 | 
					 | 
				
			||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user