Simpler temp file class
Windows visual diff and merge for files and directories
Brought to you by:
christianlist,
grimmdp
It was error to create TempFileContext class. Yes it made handling MergeDoc temp files simpler, but it just cannot be used elsewhere. And it is just too complex for the simple task it has.
So I created simpler TempFile class which just holds one temp file path. And deletes the temp file when instance gets deleted.
TempFile can (and should) be used everywhere we use temp files to make sure we delete all our temp files.
Original and altered files.
Updated patch.
Logged In: YES
user_id=631874
Originator: YES
Found regression from first patch. There was some weird code that in original form copied temp *files* not just paths or filenames from mergedoc to buffer code. I don't know any reason for such trick so I just removed that. In a kind of replacement I added code for TempFile class to behave similarly by creating a temp file from given file.
Attaching updated patch.
File Added: SimplerTempfiles2.zip
Logged In: YES
user_id=631874
Originator: YES
Committed to SVN trunk.
Completed: At revision: 4929
Logged In: YES
user_id=954028
Originator: NO
This patch causes crash when clicking [File]->[New] menu item.
I think the following fix from the analogy of old TempFileContext::CreateFiles() solves this problem.
Index: TempFile.cpp
--- TempFile.cpp (revision 4937)
+++ TempFile.cpp (working copy)
@@ -77,10 +77,10 @@
temp = env_GetTempFileName(temp.c_str(), pref.c_str(), NULL);
if (!temp.empty())
{
+ m_path = temp;
if (::CopyFile(filepath, temp.c_str(), FALSE))
{
::SetFileAttributes(temp.c_str(), FILE_ATTRIBUTE_NORMAL);
- m_path = temp;
}
}
return temp;
Logged In: YES
user_id=631874
Originator: YES
I'm not sure I like the original logic (even when it was my too). Function's idea is to copy existing file data to used as temp file. So it should succeed only when we really copy the data.
But, scratchpads are again a special case I'm not sure how to handle.
So I think your is good as it fixes the bug (of course!) but I just hope we'd have better logic for handling scratchpads than adding special cases in so many places.
Logged In: YES
user_id=631874
Originator: YES
I committed your patch to SVN trunk with comment about scratchpads.
Completed: At revision: 4943