︙ | | | ︙ | |
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
option -leftdirvariable -default "" -configuremethod SetDirOption
option -rightdirvariable -default "" -configuremethod SetDirOption
option -statusvar -default ""
option -changelist -default ""
variable AfterId ""
variable PauseBgProcessing 0
variable ScheduledRestart 0
variable AfterTime 1
variable IdleQueue {}
variable IdleQueueArr
variable leftMark ""
variable rightMark ""
|
>
|
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
option -leftdirvariable -default "" -configuremethod SetDirOption
option -rightdirvariable -default "" -configuremethod SetDirOption
option -statusvar -default ""
option -changelist -default ""
variable AfterId ""
variable DebugCh ""
variable PauseBgProcessing 0
variable ScheduledRestart 0
variable AfterTime 1
variable IdleQueue {}
variable IdleQueueArr
variable leftMark ""
variable rightMark ""
|
︙ | | | ︙ | |
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
}
method ReStart {} {
# Delete all idle processing
if {$AfterId ne ""} {
after cancel $AfterId
}
set AfterId ""
set IdleQueue {}
set ScheduledRestart 0
array unset IdleQueueArr
set protect {left 0 right 0}
# Directory Diff only supports one plugin.
|
>
>
>
>
>
>
|
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
}
method ReStart {} {
# Delete all idle processing
if {$AfterId ne ""} {
after cancel $AfterId
}
if {$DebugCh ne ""} {
close $DebugCh
set DebugCh ""
}
# Uncomment to activate debug logging
#set DebugCh [open ~/dirdiff.log a]
set AfterId ""
set IdleQueue {}
set ScheduledRestart 0
array unset IdleQueueArr
set protect {left 0 right 0}
# Directory Diff only supports one plugin.
|
︙ | | | ︙ | |
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
|
if {[info exists IdleQueueArr($node)]} { return }
lappend IdleQueue $node
set IdleQueueArr($node) 1
if {$AfterId eq ""} {
set AfterId [after $AfterTime [mymethod UpdateIdle]]
}
}
method UpdateIdle {} {
set AfterId "X"
if {$PauseBgProcessing} {
set AfterId [after 200 [mymethod UpdateIdle]]
return
}
set pre [clock clicks -milliseconds]
set errors {}
while {[llength $IdleQueue] > 0} {
set node [lindex $IdleQueue 0]
set IdleQueue [lrange $IdleQueue 1 end]
unset IdleQueueArr($node)
if {[$tree rowattrib $node type] ne "directory"} {
set sts [catch {$self UpdateFileNode $node} err]
} else {
set sts [catch {$self UpdateDirNode $node} err]
}
if {$sts} {
lappend errors $node $err
break
}
# Work for at least 20 ms to keep things efficient
set post [clock clicks -milliseconds]
if {($post - $pre) > 20} break
}
#if {($post - $pre) > 1000} {
#puts "[expr $post - $pre] ms for [$tree set $node leftfull]"
#}
# Update the status variable to track progress
if {$options(-statusvar) ne ""} {
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
|
if {[info exists IdleQueueArr($node)]} { return }
lappend IdleQueue $node
set IdleQueueArr($node) 1
if {$AfterId eq ""} {
set AfterId [after $AfterTime [mymethod UpdateIdle]]
}
}
# Debug logging
method Dlog {msg} {
if {$DebugCh ne ""} {
puts $DebugCh "[clock clicks -milliseconds] $msg"
flush $DebugCh
}
}
method UpdateIdle {} {
$self Dlog UpdateIdle
set AfterId "X"
if {$PauseBgProcessing} {
$self Dlog Pause
set AfterId [after 200 [mymethod UpdateIdle]]
return
}
set pre [clock clicks -milliseconds]
set errors {}
set count 0
while {[llength $IdleQueue] > 0} {
set node [lindex $IdleQueue 0]
# Always make a pause before a large file
if {[$tree rowattrib $node type] ne "directory"} {
if {[$tree rowattrib $node largefile]} {
if {$count > 0} {
$self Dlog "New Lap for large file"
break
}
}
}
incr count
set IdleQueue [lrange $IdleQueue 1 end]
unset IdleQueueArr($node)
if {[$tree rowattrib $node type] ne "directory"} {
set sts [catch {$self UpdateFileNode $node} err]
} else {
set sts [catch {$self UpdateDirNode $node} err]
}
if {$sts} {
lappend errors $node $err
break
}
# Work for at least 50 ms to keep things efficient
set post [clock clicks -milliseconds]
if {($post - $pre) > 50} break
}
#if {($post - $pre) > 1000} {
#puts "[expr $post - $pre] ms for [$tree set $node leftfull]"
#}
# Update the status variable to track progress
if {$options(-statusvar) ne ""} {
|
︙ | | | ︙ | |
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
|
set statusvar ""
set AfterId ""
return
}
}
if {[llength $IdleQueue] > 0} {
set leftfull [$tree rowattrib $node leftfull]
set rightfull [$tree rowattrib $node rightfull]
if {$leftfull ne ""} {
set statusvar $leftfull
} else {
set statusvar $rightfull
}
set AfterId [after $AfterTime [mymethod UpdateIdle]]
} else {
set statusvar ""
set AfterId ""
}
}
method SetNodeStatus {node status} {
variable color
|
>
|
|
>
>
|
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
|
set statusvar ""
set AfterId ""
return
}
}
if {[llength $IdleQueue] > 0} {
set node [lindex $IdleQueue 0]
set leftfull [$tree rowattrib $node leftfull]
set rightfull [$tree rowattrib $node rightfull]
if {$leftfull ne ""} {
set statusvar "$leftfull ($count)"
} else {
set statusvar "$rightfull ($count)"
}
$self Dlog Reschedule
set AfterId [after $AfterTime [mymethod UpdateIdle]]
} else {
$self Dlog DONE
set statusvar ""
set AfterId ""
}
}
method SetNodeStatus {node status} {
variable color
|
︙ | | | ︙ | |
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
|
#puts "Dir [$tree set $node leftfull] already done"
return
}
$tree delete [$tree childkeys $node]
set leftfull [$tree rowattrib $node leftfull]
set rightfull [$tree rowattrib $node rightfull]
$self CompareDirs $leftfull $rightfull $node
}
method UpdateFileNode {node} {
set leftfull [$tree rowattrib $node leftfull]
set rightfull [$tree rowattrib $node rightfull]
# If a -changelist is given, some higher level optimisation has already
# figured out what has changed, so the processing time can be cut down.
if {[llength $options(-changelist)]} {
if {$rightfull ni $options(-changelist)} {
#puts "$rightfull equal since not in change list"
$self SetNodeStatus $node equal
return
|
>
>
|
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
|
#puts "Dir [$tree set $node leftfull] already done"
return
}
$tree delete [$tree childkeys $node]
set leftfull [$tree rowattrib $node leftfull]
set rightfull [$tree rowattrib $node rightfull]
#$self Dlog "UpdateDirNode $leftfull"
$self CompareDirs $leftfull $rightfull $node
}
method UpdateFileNode {node} {
set leftfull [$tree rowattrib $node leftfull]
set rightfull [$tree rowattrib $node rightfull]
#$self Dlog "UpdateFileNode $leftfull"
# If a -changelist is given, some higher level optimisation has already
# figured out what has changed, so the processing time can be cut down.
if {[llength $options(-changelist)]} {
if {$rightfull ni $options(-changelist)} {
#puts "$rightfull equal since not in change list"
$self SetNodeStatus $node equal
return
|
︙ | | | ︙ | |
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
|
if {$df1 ne ""} {
set type $type1
set name [file tail $df1]
} else {
set type $type2
set name [file tail $df2]
}
if {$type eq "directory"} {
set values [list $name \
"" "" \
"" \
"" ""]
} else {
set values [list $name \
$size1 $time1 \
"" \
$size2 $time2]
}
set id [$tree insertchild $node end $values]
$tree rowattrib $id type $type
$tree rowattrib $id status unknown
$tree rowattrib $id leftfull $df1
$tree rowattrib $id rightfull $df2
if {$type ne "directory"} {
if {$type eq "link"} {
$tree cellconfigure $id,structure -image $::img(link)
} else {
$tree cellconfigure $id,structure -image $::img(file)
$tree cellconfigure $id,command -window [mymethod addCmdCol]
}
|
>
>
>
>
>
>
|
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
|
if {$df1 ne ""} {
set type $type1
set name [file tail $df1]
} else {
set type $type2
set name [file tail $df2]
}
set largeFile 0
if {$type eq "directory"} {
set values [list $name \
"" "" \
"" \
"" ""]
} else {
set values [list $name \
$size1 $time1 \
"" \
$size2 $time2]
# TODO: Configurable large file value?
if {$size1 > 1000000 && $size2 > 1000000} {
set largeFile 1
}
}
set id [$tree insertchild $node end $values]
$tree rowattrib $id type $type
$tree rowattrib $id status unknown
$tree rowattrib $id leftfull $df1
$tree rowattrib $id rightfull $df2
$tree rowattrib $id largefile $largeFile
if {$type ne "directory"} {
if {$type eq "link"} {
$tree cellconfigure $id,structure -image $::img(link)
} else {
$tree cellconfigure $id,structure -image $::img(file)
$tree cellconfigure $id,command -window [mymethod addCmdCol]
}
|
︙ | | | ︙ | |