--- a/Archiver.st Thu Sep 15 15:12:03 2011 +0200
+++ b/Archiver.st Fri Sep 16 17:27:10 2011 +0200
@@ -110,6 +110,16 @@
other person. No title to or ownership of the software is
hereby transferred.
"
+!
+
+documentation
+"
+ this is a soon to be obsoleted helper class for the fileBrowser.
+ it wrapps OS-specific command line archivers (tar, zip, rar, etc)
+ into a common protocol useful to display an archive's contents.
+
+ do not use for your projects.
+"
! !
!Archiver class methodsFor:'initialization'!
@@ -354,7 +364,13 @@
self fileName isNil ifTrue:[ ^ self].
dir := self fileName directory.
cmd := self getCommandToListFiles:aColOfFiles.
- self executeCommand:cmd directory:dir
+ cmd isNil ifTrue:[
+ errorStream nextPutLine:'No command to list the archive.'.
+ ^ self
+ ].
+ self executeCommand:cmd directory:dir
+
+ "Modified: / 16-09-2011 / 16:33:50 / cg"
!
removeFilesFromArchive:aColOfFiles
@@ -396,7 +412,10 @@
!Archiver methodsFor:'command execution'!
executeCommand:cmd directory:aDirectory
-
+ cmd isNil ifTrue:[
+ errorStream nextPutAll:'No command for archive operation.'.
+ ^ false
+ ].
synchron isNil ifTrue:[synchron := true].
synchron ifTrue:[
@@ -428,6 +447,8 @@
process resume.
^true
]
+
+ "Modified: / 16-09-2011 / 16:32:37 / cg"
!
isValidOutputLine:line
@@ -513,7 +534,12 @@
"/ addFiles to the archive. Synchron command execution answers
"/ a boolean.
cmd := self getCommandToAdd:colOfFiles toArchive:archivInTemp.
- result := self executeCommand:cmd directory:tempDir.
+ cmd isNil ifTrue:[
+ errorStream nextPutAll:'No command to add files.'.
+ result := false
+ ] ifFalse:[
+ result := self executeCommand:cmd directory:tempDir.
+ ].
"/ copy the archive back
(result == true and: [archivInTemp exists]) ifTrue:[
@@ -532,6 +558,8 @@
].
^result == true.
+
+ "Modified: / 16-09-2011 / 16:35:17 / cg"
!
extractFiles:aColOfFilesOrNil to:aDirectory
@@ -539,7 +567,13 @@
execDir := self fileName directory.
cmd := self getCommandToExtractFiles:aColOfFilesOrNil intoDirectory:aDirectory.
+ cmd isNil ifTrue:[
+ errorStream nextPutAll:'No command to extract files.'.
+ ^ self.
+ ].
self executeCommand:cmd directory:execDir.
+
+ "Modified: / 16-09-2011 / 16:35:34 / cg"
!
extractFiles:aColOfFiles withoutDirectoryTo:aDirectory
@@ -566,7 +600,13 @@
|cmd|
cmd := self getCommandToRemoveFiles:aColOfFiles.
- self executeCommand:cmd directory:(self fileName directory).
+ cmd isNil ifTrue:[
+ errorStream nextPutAll:'No command to remove files.'.
+ ^ self.
+ ].
+ self executeCommand:cmd directory:(self fileName directory).
+
+ "Modified: / 16-09-2011 / 16:35:41 / cg"
! !
!Archiver::MultiFileArchive methodsFor:'command strings'!
@@ -1170,11 +1210,44 @@
!Archiver::ZipArchive class methodsFor:'command strings'!
unzipCommand
- ^ 'unzip'
+ |cmdString s cmd|
+
+ OperatingSystem isUNIXlike ifTrue:[
+ ^ 'unzip'
+ ].
+ OperatingSystem isMSWINDOWSlike ifTrue:[
+ cmdString := MIMETypes defaultCommandTemplateToOpenMimeType:'application/x-zip-compressed'.
+ cmdString notEmptyOrNil ifTrue:[
+ s := cmdString readStream.
+ s skipSeparators.
+ s peek == $" ifTrue:[
+ s next.
+ cmd := (s upTo:$")
+ ] ifFalse:[
+ cmd := s upToSeparator.
+ ].
+ ^ cmd
+ ].
+ ].
+ ^ nil
+
+ "
+ self unzipCommand
+ "
+
+ "Modified: / 16-09-2011 / 17:26:18 / cg"
!
zipCommand
- ^ 'zip'
+ OperatingSystem isUNIXlike ifTrue:[
+ ^ 'zip'
+ ].
+ OperatingSystem isMSWINDOWSlike ifTrue:[
+ ^ self unzipCommand.
+ ].
+ ^ nil
+
+ "Modified: / 16-09-2011 / 16:26:00 / cg"
! !
!Archiver::ZipArchive class methodsFor:'queries'!
@@ -1226,78 +1299,110 @@
!Archiver::ZipArchive methodsFor:'command strings'!
getCommandToAdd:aColOfFiles toArchive:archiveFile
- |stream|
-
- " archiveFile exists ifFalse:[^ nil]. "
+ "archiveFile exists ifFalse:[^ nil]."
- stream := WriteStream on:''.
-
- stream nextPutAll:('%1 -r "%2"'
+ OperatingSystem isUNIXlike ifTrue:[
+ ^ String streamContents:[:s |
+ s nextPutAll:('%1 -r "%2"'
bindWith:self class zipCommand
with:archiveFile asString string).
- self
- addDoubleQuotedFilenames:(aColOfFiles collect:[:each | each asFilename baseName])
- toStream:stream.
+ self
+ addDoubleQuotedFilenames:(aColOfFiles collect:[:each | each asFilename baseName])
+ toStream:s.
+ ].
+ ].
- ^ stream contents
+ ^ nil
+
+ "Modified (comment): / 16-09-2011 / 16:27:20 / cg"
!
getCommandToExtractFiles:aColOfFiles intoDirectory:dir
- |stream|
+ |cmd template|
- stream := WriteStream on:''.
+ cmd := self class unzipCommand.
- "/ -o UnzipOverwriteExistingFilesOption
- "/ -d UnzipExtDirectoryOption
+ OperatingSystem isUNIXlike ifTrue:[
+ template := '%1 -o -d "%2" "%3"'
+ ].
+ OperatingSystem isMSDOSlike ifTrue:[
+ self halt.
+ ].
- stream nextPutAll:('%1 -o -d "%2" "%3"'
- bindWith:self class unzipCommand
+ template notNil ifTrue:[
+ ^ String streamContents:[:s |
+ "/ -o UnzipOverwriteExistingFilesOption
+ "/ -d UnzipExtDirectoryOption
+
+ s nextPutAll:(template
+ bindWith:cmd
with:dir asString string
with:self fileName asString).
- self addDoubleQuotedFilenames:aColOfFiles toStream:stream.
- ^ stream contents.
+ self addDoubleQuotedFilenames:aColOfFiles toStream:s.
+ ]
+ ].
+
+ ^ nil.
+
+ "Modified: / 16-09-2011 / 16:38:57 / cg"
!
getCommandToListFiles:aColOfFiles
- |stream|
+ |cmd template|
- stream := WriteStream on:''.
+ cmd := self class unzipCommand.
- "/ -Z ZipInfoOption
- "/ -h ZipHeaderOption
- "/ -t ZipTotalOption
- stream nextPutAll:('%1 -Z -m -h "%2"'
+ OperatingSystem isUNIXlike ifTrue:[
+ "/ -Z ZipInfoOption
+ "/ -h ZipHeaderOption
+ "/ -t ZipTotalOption
+ template := '"%1" -Z -m -h "%2"'
+ ].
+ OperatingSystem isMSDOSlike ifTrue:[
+ self halt.
+ ].
+
+ template notNil ifTrue:[
+ ^ String streamContents:[:s |
+ s nextPutAll:(template
bindWith:self class unzipCommand
with:self fileName asString string).
- aColOfFiles notNil ifTrue:[
- self breakPoint:#ca.
- self
- addDoubleQuotedFilenames:(aColOfFiles collect:[:each | each asFilename baseName])
- toStream:stream.
+ aColOfFiles notNil ifTrue:[
+ self breakPoint:#ca.
+ self
+ addDoubleQuotedFilenames:(aColOfFiles collect:[:each | each asFilename baseName])
+ toStream:s.
+ ].
+ ].
].
- ^ stream contents.
+ ^ nil.
+
+ "Modified: / 16-09-2011 / 17:25:40 / cg"
!
getCommandToRemoveFiles:aColOfFiles
- |stream|
-
- stream := WriteStream on:''.
-
- stream nextPutAll:('%1 -d "%2"'
+ OperatingSystem isUNIXlike ifTrue:[
+ ^ String streamContents:[:s |
+ s nextPutAll:('%1 -d "%2"'
bindWith:self class zipCommand
with:self fileName asString string).
- self addDoubleQuotedFilenames:aColOfFiles toStream:stream.
- ^ stream contents.
+ self addDoubleQuotedFilenames:aColOfFiles toStream:s.
+ ]
+ ].
+
+ ^ nil.
+
+ "Modified: / 16-09-2011 / 16:29:09 / cg"
! !
!Archiver class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Archiver.st,v 1.34 2009-01-13 21:03:16 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Archiver.st,v 1.35 2011-09-16 15:27:10 cg Exp $'
! !
Archiver initialize!