AutoHotkey: Auto-Delete BAK-files created by TC's File-Compare-Editor: Difference between revisions

From TotalcmdWiki
Jump to navigation Jump to search
(updated for TC 7.50 (tested up to beta 10))
(Updated new control names and double backup files (tested up to public beta 7))
Line 1: Line 1:
<pre>
<pre>
; ////////////////////////////////////////////////////////////////////////////
; ////////////////////////////////////////////////////////////////////////////
; // TC_CompareEditor_AutoDelBak.ahk v0.12
; // TC_CompareEditor_AutoDelBak.ahk v0.13
; // (W) StatusQuo 2008-2009 for TC 7.0x, TC 7.50 (tested up to beta 10)
; // (W) StatusQuo 2008-2009 for TC 7.0x, TC 7.50 (tested up to public beta 7)
; //--------------------------------------------------------------------------
; //--------------------------------------------------------------------------
; // Auto-deletes *.bak-files created by TC's File-Compare-Editor  
; // Auto-deletes *.bak-files created by TC's File-Compare-Editor  
Line 25: Line 25:
{
{
WinWaitActive, ahk_class TFileCompForm
WinWaitActive, ahk_class TFileCompForm
ControlGetText, sFNLeft , TAltEdit.UnicodeClass2 ; TC7.50
ControlGetText, sFNLeft , TAltEdit2 ; TC7.50 public beta 7
ControlGetText, sFNRight, TAltEdit.UnicodeClass1 ; TC7.50
ControlGetText, sFNRight, TAltEdit1 ; TC7.50 public beta 7
if ( (sFNLeft = "") and (sFNRight = "") )
if ( (sFNLeft = "") and (sFNRight = "") )
{
{
Line 32: Line 32:
ControlGetText, sFNRight, TEdit1 ; TC7.0x up to 7.04a
ControlGetText, sFNRight, TEdit1 ; TC7.0x up to 7.04a
}
}
sBakLeft := sFNLeft  . ".bak"
sBakLeft   := sFNLeft  . ".bak"
sBakRight := sFNRight . ".bak"
sBakRight := sFNRight . ".bak"
sBakLeft2  := sFNLeft  . ".bk2"
sBakRight2 := sFNRight . ".bk2"
SetTitleMatchMode, Slow ; needed for TC 7.50
SetTitleMatchMode, Slow ; needed for TC 7.50
Loop ; wait for compare-editor to close
Loop ; wait for compare-editor to close
Line 45: Line 47:
boFileDeleted := "0"
boFileDeleted := "0"
if not ( f_DelBak( sBakLeft  ) = "10")
if not ( f_DelBak( sBakLeft  ) = "10")
f_DelBak( sBakRight )
if not ( f_DelBak( sBakLeft2 ) = "10")
if not ( f_DelBak( sBakRight ) = "10")
f_DelBak( sBakRight2 )
if not (boFileDeleted = "0") ; no reread if nothing was deleted
if not (boFileDeleted = "0") ; no reread if nothing was deleted
{
{

Revision as of 20:38, 9 July 2009

	; ////////////////////////////////////////////////////////////////////////////
	; // TC_CompareEditor_AutoDelBak.ahk v0.13
	; // (W) StatusQuo 2008-2009 for TC 7.0x, TC 7.50 (tested up to public beta 7)
	; //--------------------------------------------------------------------------
	; // Auto-deletes *.bak-files created by TC's File-Compare-Editor 
	; // (after confirmation)
	; //
	; // Full support is only included for a single instance of TC's compare window -
	; // for now, to have the BAK files of multiple instances deleted, you have to 
	; // close the compare windows in the same order you opened them
	; // (first close the one which was opened first).
	; ////////////////////////////////////////////////////////////////////////////
	
	; http://www.ghisler.ch/wiki/index.php?title=AutoHotkey:_Auto-Delete_BAK-files_created_by_TC%27s_File-Compare-Editor
	
	#SingleInstance, Force

	; #Persistent
	; SetTimer, l_TC_AutoDelBak
	; Return

	Loop
l_TC_AutoDelBak:
	{
		WinWaitActive, ahk_class TFileCompForm
		ControlGetText, sFNLeft , TAltEdit2	; TC7.50 public beta 7
		ControlGetText, sFNRight, TAltEdit1	; TC7.50 public beta 7
		if ( (sFNLeft = "") and (sFNRight = "") )
		{
			ControlGetText, sFNLeft , TEdit2	; TC7.0x up to 7.04a
			ControlGetText, sFNRight, TEdit1	; TC7.0x up to 7.04a
		}
		sBakLeft   := sFNLeft  . ".bak"
		sBakRight  := sFNRight . ".bak"
		sBakLeft2  := sFNLeft  . ".bk2"
		sBakRight2 := sFNRight . ".bk2"
		SetTitleMatchMode, Slow	; needed for TC 7.50
		Loop	; wait for compare-editor to close
		{
			Sleep, 500	; save CPU time
			IfWinNotExist, ahk_class TFileCompForm, %sFNLeft%
			IfWinNotExist, ahk_class TFileCompForm, %sFNRight%
				Break
		}
		SetTitleMatchMode, Fast	; back to standard; needed for TC 7.50
		boFileDeleted := "0"
		if not ( f_DelBak( sBakLeft  ) = "10")
		if not ( f_DelBak( sBakLeft2 ) = "10")
		if not ( f_DelBak( sBakRight ) = "10")
			f_DelBak( sBakRight2 )
		if not (boFileDeleted = "0")	; no reread if nothing was deleted
		{
			; Sleep, 200
			PostMessage, 1075, 540,,, ahk_class TTOTAL_CMD	; cm_RereadSource
		}
	}
	Return
	
f_DelBak( sFNBak )
{
	global boFileDeleted
	IfNotExist, %sFNBak%
		Return
	MsgBox, 35,, Delete Backup file?`n`n%sFNBak%
	IfMsgBox, Cancel
		Return, 10
	IfMsgBox, Yes
	{
		FileRecycle, %sFNBak%
		boFileDeleted := "1"
	}
}

Back to AutoHotkey