checkin from browser
authorClaus Gittinger <cg@exept.de>
Thu, 10 Dec 1998 17:40:28 +0100
changeset 1972 0458592bba46
parent 1971 4b88d5f657cd
child 1973 b9f91a173aa9
checkin from browser
FBrowser.st
FileBrowser.st
--- a/FBrowser.st	Tue Dec 08 15:22:17 1998 +0100
+++ b/FBrowser.st	Thu Dec 10 17:40:28 1998 +0100
@@ -985,6 +985,11 @@
                           #value: #fileFindDuplicates
                       )
                        #(#MenuItem
+                          #label: 'Find All Duplicate Files (recursive)'
+                          #translateLabel: true
+                          #value: #fileFindAllDuplicates
+                      )
+                       #(#MenuItem
                           #label: 'Find a File'
                           #translateLabel: true
                           #value: #fileFindFile
@@ -1026,6 +1031,8 @@
           ) nil
           nil
       )
+
+    "Modified: / 28.11.1998 / 17:48:35 / cg"
 ! !
 
 !FileBrowser methodsFor:'aspects'!
@@ -1537,6 +1544,109 @@
     "Modified: / 18.6.1998 / 15:30:38 / cg"
 !
 
+fileFindAllDuplicates
+    "scan directory and all subdirs for duplicate files"
+
+    |fileNames dir infoDir filesBySize
+     result info dirPrefix|
+
+    (self askIfModified:'contents has not been saved.\\Modifications will be lost when you proceed.'
+              yesButton:'proceed') ifFalse:[^ self].
+
+    self withWaitCursorDo:[
+        result := Dictionary new.
+
+        dir := currentDirectory asFilename.
+        self label:myName , '- gathering file names ...'.
+        fileNames := dir recursiveDirectoryContents.
+        fileNames := fileNames collect:[:fn | dir construct:fn].
+        fileNames := fileNames select:[:fn | fn isDirectory not].
+
+        self label:myName , '- gathering sizes ...'.
+        infoDir := Dictionary new.
+        fileNames do:[:fn |
+            infoDir at:fn put:(fn fileSize)
+        ].
+
+        "/ for each, get the files size.
+        "/ in a first pass, look for files of the same size and
+        "/ compare them ...
+
+        self label:myName , '- preselect possible duplicates ...'.
+        filesBySize := Dictionary new.
+        infoDir keysAndValuesDo:[:fn :sz |
+            |entry|
+
+            entry := filesBySize at:sz ifAbsentPut:[Set new].
+            entry add:fn.
+        ].
+
+        "/ any of same size ?
+
+        self label:myName , '- checking for duplicates ...'.
+        filesBySize do:[:entry |
+            |files|
+
+            entry size > 1 ifTrue:[
+                files := entry asArray.
+                1 to:files size-1 do:[:idx1 |
+                    idx1+1 to:files size do:[:idx2 |
+                        |fn1 fn2|
+
+                        fn1 := files at:idx1.
+                        fn2 := files at:idx2.
+
+"/                        self label:myName , '- checking ' , fn1 baseName , ' vs. ' , fn2 baseName , ' ...'.
+                        (result at:fn2 ifAbsent:nil) ~= fn1 ifTrue:[
+                            "/ compare the files
+                            (fn1 sameContentsAs:fn2) ifTrue:[
+"/                                Transcript show:'Same: '; show:fn1 baseName; show:' and '; showCR:fn2 baseName.
+                                result at:fn1 put:fn2.
+                            ]
+                        ]
+                    ]
+                ]
+            ]
+        ].
+
+        self label:myName , '- sorting ...'.
+        dirPrefix := currentDirectory asFilename pathName.
+        result := result associations.
+        result := result collect:[:assoc |
+                                        |f1 f2|
+
+                                        f1 := assoc key name.
+                                        f2 := assoc value name.
+                                        (f1 startsWith:dirPrefix) ifTrue:[
+                                            f1 := f1 copyFrom:dirPrefix size + 2.
+                                        ].
+                                        (f2 startsWith:dirPrefix) ifTrue:[
+                                            f2 := f2 copyFrom:dirPrefix size + 2.
+                                        ].
+                                        f1 < f2 ifTrue:[
+                                            f2 -> f1
+                                        ] ifFalse:[
+                                            f1 -> f2
+                                        ]
+                                ].
+        result sort:[:f1 :f2 | f2 value < f1 value].
+
+        info := OrderedCollection new.
+        result do:[:assoc |
+            info add:(assoc key , ' same as ' , assoc value)
+        ].
+        info isEmpty ifTrue:[
+            info := 'No duplicate files found.'
+        ].
+    ].
+
+    subView contents:info.
+    self label:myName.
+
+    "Created: / 28.11.1998 / 17:47:53 / cg"
+    "Modified: / 10.12.1998 / 17:13:14 / cg"
+!
+
 fileFindDuplicates
     "scan directory for duplicate files"
 
@@ -6011,5 +6121,5 @@
 !FileBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/Attic/FBrowser.st,v 1.279 1998-12-04 14:53:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Attic/FBrowser.st,v 1.280 1998-12-10 16:40:28 cg Exp $'
 ! !
--- a/FileBrowser.st	Tue Dec 08 15:22:17 1998 +0100
+++ b/FileBrowser.st	Thu Dec 10 17:40:28 1998 +0100
@@ -985,6 +985,11 @@
                           #value: #fileFindDuplicates
                       )
                        #(#MenuItem
+                          #label: 'Find All Duplicate Files (recursive)'
+                          #translateLabel: true
+                          #value: #fileFindAllDuplicates
+                      )
+                       #(#MenuItem
                           #label: 'Find a File'
                           #translateLabel: true
                           #value: #fileFindFile
@@ -1026,6 +1031,8 @@
           ) nil
           nil
       )
+
+    "Modified: / 28.11.1998 / 17:48:35 / cg"
 ! !
 
 !FileBrowser methodsFor:'aspects'!
@@ -1537,6 +1544,109 @@
     "Modified: / 18.6.1998 / 15:30:38 / cg"
 !
 
+fileFindAllDuplicates
+    "scan directory and all subdirs for duplicate files"
+
+    |fileNames dir infoDir filesBySize
+     result info dirPrefix|
+
+    (self askIfModified:'contents has not been saved.\\Modifications will be lost when you proceed.'
+              yesButton:'proceed') ifFalse:[^ self].
+
+    self withWaitCursorDo:[
+        result := Dictionary new.
+
+        dir := currentDirectory asFilename.
+        self label:myName , '- gathering file names ...'.
+        fileNames := dir recursiveDirectoryContents.
+        fileNames := fileNames collect:[:fn | dir construct:fn].
+        fileNames := fileNames select:[:fn | fn isDirectory not].
+
+        self label:myName , '- gathering sizes ...'.
+        infoDir := Dictionary new.
+        fileNames do:[:fn |
+            infoDir at:fn put:(fn fileSize)
+        ].
+
+        "/ for each, get the files size.
+        "/ in a first pass, look for files of the same size and
+        "/ compare them ...
+
+        self label:myName , '- preselect possible duplicates ...'.
+        filesBySize := Dictionary new.
+        infoDir keysAndValuesDo:[:fn :sz |
+            |entry|
+
+            entry := filesBySize at:sz ifAbsentPut:[Set new].
+            entry add:fn.
+        ].
+
+        "/ any of same size ?
+
+        self label:myName , '- checking for duplicates ...'.
+        filesBySize do:[:entry |
+            |files|
+
+            entry size > 1 ifTrue:[
+                files := entry asArray.
+                1 to:files size-1 do:[:idx1 |
+                    idx1+1 to:files size do:[:idx2 |
+                        |fn1 fn2|
+
+                        fn1 := files at:idx1.
+                        fn2 := files at:idx2.
+
+"/                        self label:myName , '- checking ' , fn1 baseName , ' vs. ' , fn2 baseName , ' ...'.
+                        (result at:fn2 ifAbsent:nil) ~= fn1 ifTrue:[
+                            "/ compare the files
+                            (fn1 sameContentsAs:fn2) ifTrue:[
+"/                                Transcript show:'Same: '; show:fn1 baseName; show:' and '; showCR:fn2 baseName.
+                                result at:fn1 put:fn2.
+                            ]
+                        ]
+                    ]
+                ]
+            ]
+        ].
+
+        self label:myName , '- sorting ...'.
+        dirPrefix := currentDirectory asFilename pathName.
+        result := result associations.
+        result := result collect:[:assoc |
+                                        |f1 f2|
+
+                                        f1 := assoc key name.
+                                        f2 := assoc value name.
+                                        (f1 startsWith:dirPrefix) ifTrue:[
+                                            f1 := f1 copyFrom:dirPrefix size + 2.
+                                        ].
+                                        (f2 startsWith:dirPrefix) ifTrue:[
+                                            f2 := f2 copyFrom:dirPrefix size + 2.
+                                        ].
+                                        f1 < f2 ifTrue:[
+                                            f2 -> f1
+                                        ] ifFalse:[
+                                            f1 -> f2
+                                        ]
+                                ].
+        result sort:[:f1 :f2 | f2 value < f1 value].
+
+        info := OrderedCollection new.
+        result do:[:assoc |
+            info add:(assoc key , ' same as ' , assoc value)
+        ].
+        info isEmpty ifTrue:[
+            info := 'No duplicate files found.'
+        ].
+    ].
+
+    subView contents:info.
+    self label:myName.
+
+    "Created: / 28.11.1998 / 17:47:53 / cg"
+    "Modified: / 10.12.1998 / 17:13:14 / cg"
+!
+
 fileFindDuplicates
     "scan directory for duplicate files"
 
@@ -6011,5 +6121,5 @@
 !FileBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.279 1998-12-04 14:53:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.280 1998-12-10 16:40:28 cg Exp $'
 ! !