'From Squeak3.4beta of ''1 December 2002'' [latest update: #5147] on 16 December 2002 at 5:31:49 pm'! "Change Set: Rel(ative)ZipExtractFix-nk Date: 16 December 2002 Author: Ned Konz Version: 3.4b 16 Dec: This fixes a problem with re-opening a zip in an ArchiveViewer under Windows (by opening zips read-only), as well as fixing extraction with subdirectories under Windows. 13 Dec: This ensures that zip extraction relative to a given directory works properly, and should eliminate the infinite recursion noted on the Mac. It lacks AcornFileDirectory>>relativeNameFor: ; this should be added if necessary before adding to the update stream. "! !ArchiveViewer methodsFor: 'archive operations' stamp: 'nk 12/16/2002 17:27'! extractAllPossibleInDirectory: directory "Answer true if I can extract all the files in the given directory safely. Inform the user as to problems." | conflicts | self canExtractAll ifFalse: [ ^false ]. conflicts _ Set new. self members do: [ :ea | | fullName | fullName _ directory fullNameFor: ea fileName. (ea usesFileNamed: fullName) ifTrue: [ conflicts add: fullName ]. ]. conflicts notEmpty ifTrue: [ | str | str _ WriteStream on: (String new: 200). str nextPutAll: 'The following file(s) are needed by archive members and cannot be overwritten:'; cr. conflicts do: [ :ea | str nextPutAll: ea ] separatedBy: [ str cr ]. self inform: str contents. ^false. ]. conflicts _ Set new. self members do: [ :ea | | fullName | fullName _ directory relativeNameFor: ea fileName. (directory fileExists: fullName) ifTrue: [ conflicts add: fullName ]. ]. conflicts notEmpty ifTrue: [ | str | str _ WriteStream on: (String new: 200). str nextPutAll: 'The following file(s) will be overwritten:'; cr. conflicts do: [ :ea | str nextPutAll: ea ] separatedBy: [ str cr ]. str cr; nextPutAll: 'Is this OK?'. ^PopUpMenu confirm: str contents. ]. ^true. ! ! !ArchiveViewer methodsFor: 'initialization' stamp: 'nk 12/16/2002 17:12'! windowIsClosing archive close.! ! !FileDirectory methodsFor: 'file name utilities' stamp: 'nk 12/13/2002 10:07'! relativeNameFor: aFileName "Return the full name for aFileName, assuming that aFileName is a name relative to me." aFileName isEmpty ifTrue: [ ^pathName ]. ^aFileName first = self pathNameDelimiter ifTrue: [ pathName, aFileName ] ifFalse: [ pathName, self slash, aFileName ] ! ! !DosFileDirectory methodsFor: 'path access' stamp: 'nk 12/13/2002 10:05'! relativeNameFor: path "Return the full name for path, assuming that path is a name relative to me." path isEmpty ifTrue:[^pathName]. (path at: 1) = $\ ifTrue:[ (path size >= 2 and:[(path at: 2) = $\]) ifTrue:[^super relativeNameFor: path allButFirst ]. "e.g., \\pipe\" ^super relativeNameFor: path "e.g., \windows\"]. (path size >= 2 and:[(path at: 2) = $: and:[path first isLetter]]) ifTrue:[^super relativeNameFor: (path copyFrom: 3 to: path size) ]. "e.g., c:" ^pathName, self slash, path! ! !ZipArchive methodsFor: 'archive operations' stamp: 'nk 12/16/2002 17:09'! readFrom: aStreamOrFileName | stream name eocdPosition | stream _ aStreamOrFileName isStream ifTrue: [name _ aStreamOrFileName name. aStreamOrFileName] ifFalse: [StandardFileStream readOnlyFileNamed: (name _ aStreamOrFileName)]. stream binary. eocdPosition _ self class findEndOfCentralDirectoryFrom: stream. eocdPosition <= 0 ifTrue: [self error: 'can''t find EOCD position']. self readEndOfCentralDirectoryFrom: stream. stream position: eocdPosition - centralDirectorySize. self readMembersFrom: stream named: name! ! !ZipArchiveMember methodsFor: 'accessing' stamp: 'nk 12/13/2002 09:42'! extractToFileNamed: aFileName inDirectory: dir | stream fullName fullDir | self isEncrypted ifTrue: [ ^self error: 'encryption unsupported' ]. fullName _ dir relativeNameFor: aFileName. fullDir _ FileDirectory forFileName: fullName. fullDir assureExistence. self isDirectory ifFalse: [ stream _ fullDir forceNewFileNamed: (FileDirectory localNameFor: fullName). self extractTo: stream. stream close. ] ifTrue: [ fullDir assureExistence ] ! !