From b72ce63d2068787e1262f7d61b84a7f60884fc1e Mon Sep 17 00:00:00 2001 From: Guille Polito Date: Wed, 7 Feb 2024 12:15:33 +0100 Subject: [PATCH] Revert "Revert "Remove UIManager dependencies from Compression."" --- .../BaselineOfBasicTools.class.st | 1 + src/Compression/ZipArchive.class.st | 34 +++++++------------ src/System-Spec/Archive.extension.st | 14 ++++++++ src/System-Spec/GZipReadStream.extension.st | 27 +++++++++++++++ .../StPharoApplication.extension.st | 7 ++++ src/System-Spec/ZipArchive.extension.st | 18 ++++++++++ src/System-Spec/package.st | 1 + 7 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 src/System-Spec/Archive.extension.st create mode 100644 src/System-Spec/GZipReadStream.extension.st create mode 100644 src/System-Spec/StPharoApplication.extension.st create mode 100644 src/System-Spec/ZipArchive.extension.st create mode 100644 src/System-Spec/package.st diff --git a/src/BaselineOfBasicTools/BaselineOfBasicTools.class.st b/src/BaselineOfBasicTools/BaselineOfBasicTools.class.st index 388f2279e97..90c251437fa 100644 --- a/src/BaselineOfBasicTools/BaselineOfBasicTools.class.st +++ b/src/BaselineOfBasicTools/BaselineOfBasicTools.class.st @@ -75,6 +75,7 @@ BaselineOfBasicTools >> baseline: spec [ with: [ spec requires: #( 'Tool-Diff' 'MonticelloGUI' ) ]. spec package: 'System-Sources-Tests'. "<= Not sure this one should be here but it is where the classes were loaded before been extracted from Tests package." spec package: 'System-Announcements-Tests'. "<= Not sure this one should be here but it is where the classes were loaded before been extracted from Tests package." + spec package: 'System-Spec'. spec package: 'RPackage-Tests'. spec package: 'Monticello-Tests'. spec package: 'MonticelloGUI-Tests'. diff --git a/src/Compression/ZipArchive.class.st b/src/Compression/ZipArchive.class.st index 1f4739f4c60..d7fd07e98db 100644 --- a/src/Compression/ZipArchive.class.st +++ b/src/Compression/ZipArchive.class.st @@ -41,16 +41,6 @@ ZipArchive class >> compressionStored [ ^CompressionStored ] -{ #category : 'file in/out' } -ZipArchive class >> extractAllIn: aFileReferenceOrFileName [ - "Service method to extract all contents of a zip." - | directory | - directory := (UIManager default chooseDirectoryFrom: aFileReferenceOrFileName asFileReference) ifNil: [^ self]. - ^ (self new) - readFrom: aFileReferenceOrFileName; - extractAllTo: directory -] - { #category : 'file in/out' } ZipArchive class >> extractFrom: aZipFile to: aDirectory [ @@ -148,8 +138,8 @@ ZipArchive >> extractAllTo: aDirectory [ ZipArchive >> extractAllTo: aDirectory informing: job [ "Extract all elements to the given directory; notifying user via UI on progress and if existing files exist" - | job1 barValue | - job1 := job ifNil: [ DummySystemProgressItem new ]. + | barValue | + barValue := 0. self members select: #isDirectory thenDo: [ :entry | | dir shouldUpdateInfos lastUpdate | @@ -157,24 +147,24 @@ ZipArchive >> extractAllTo: aDirectory informing: job [ (shouldUpdateInfos := (Time millisecondsSince: lastUpdate) >= 100) ifTrue: [ lastUpdate := Time millisecondClockValue. - job1 title: 'Creating ' , entry fileName ]. + job title: 'Creating ' , entry fileName ]. dir := (entry fileName findTokens: '/') inject: aDirectory into: [ :base :part | base / part ]. dir ensureCreateDirectory. barValue := barValue + 1. - shouldUpdateInfos ifTrue: [ job1 currentValue: barValue ] ]. + shouldUpdateInfos ifTrue: [ job currentValue: barValue ] ]. self members reject: #isDirectory thenDo: [ :entry | | shouldUpdateInfos lastUpdate | lastUpdate := 0. (shouldUpdateInfos := (Time millisecondsSince: lastUpdate) >= 100) ifTrue: [ lastUpdate := Time millisecondClockValue. - job1 title: 'Extracting ' , entry fileName ]. + job title: 'Extracting ' , entry fileName ]. entry extractInDirectory: aDirectory. barValue := barValue + 1. shouldUpdateInfos ifTrue: [ - job1 currentValue: barValue. + job currentValue: barValue. lastUpdate := Time millisecondClockValue ] ]. ^ self ] @@ -183,8 +173,8 @@ ZipArchive >> extractAllTo: aDirectory informing: job [ ZipArchive >> extractAllTo: aDirectory informing: aBar overwrite: allOverwrite [ "Extract all elements to the given directory. Informs user when a file exists and set to overwrite" - | bar overwriteAll barValue | - bar := aBar ifNil: [ DummySystemProgressItem new ]. + | overwriteAll barValue | + overwriteAll := allOverwrite. barValue := 0. self members select: #isDirectory thenDo: [ :entry | @@ -193,24 +183,24 @@ ZipArchive >> extractAllTo: aDirectory informing: aBar overwrite: allOverwrite [ (shouldUpdateInfos := (Time millisecondsSince: lastUpdate) >= 100) ifTrue: [ lastUpdate := Time millisecondClockValue. - bar label: 'Creating ' , entry fileName ]. + aBar label: 'Creating ' , entry fileName ]. dir := (entry fileName findTokens: '/') inject: aDirectory into: [ :base :part | base / part ]. dir ensureCreateDirectory. barValue := barValue + 1. - shouldUpdateInfos ifTrue: [ bar value: barValue ] ]. + shouldUpdateInfos ifTrue: [ aBar value: barValue ] ]. self members reject: #isDirectory thenDo: [ :entry | | shouldUpdateInfos lastUpdate | lastUpdate := 0. (shouldUpdateInfos := (Time millisecondsSince: lastUpdate) >= 100) ifTrue: [ lastUpdate := Time millisecondClockValue. - bar label: 'Extracting ' , entry fileName ]. + aBar label: 'Extracting ' , entry fileName ]. entry extractInDirectory: aDirectory. barValue := barValue + 1. shouldUpdateInfos ifTrue: [ - bar value: barValue. + aBar value: barValue. lastUpdate := Time millisecondClockValue ] ] ] diff --git a/src/System-Spec/Archive.extension.st b/src/System-Spec/Archive.extension.st new file mode 100644 index 00000000000..d4c26ca0ee4 --- /dev/null +++ b/src/System-Spec/Archive.extension.st @@ -0,0 +1,14 @@ +Extension { #name : 'Archive' } + +{ #category : '*System-Spec' } +Archive class >> application [ + + ^ StPharoApplication current +] + +{ #category : '*System-Spec' } +Archive class >> openDirectoryDialog [ + "Answer a new instance of " + + ^ self application openDirectoryDialog +] diff --git a/src/System-Spec/GZipReadStream.extension.st b/src/System-Spec/GZipReadStream.extension.st new file mode 100644 index 00000000000..8aca867e257 --- /dev/null +++ b/src/System-Spec/GZipReadStream.extension.st @@ -0,0 +1,27 @@ +Extension { #name : 'GZipReadStream' } + +{ #category : '*System-Spec' } +GZipReadStream class >> openWithContents: contentsString label: titleString [ + "Open a text viewer on contentsString and window label titleString" + + SpTextPresenter new + text: contentsString; + open; + withWindowDo: [ : w | + w + title: titleString; + extent: 600 @ 800 ] +] + +{ #category : '*System-Spec' } +GZipReadStream class >> viewContents: fullFileName [ + "Open the decompressed contents of the .gz file with the given name." + + | file | + (file := fullFileName asFileReference) binaryReadStreamDo: [ :aStream | + self with: aStream do: [ :aGzStream | + self + openWithContents: aGzStream upToEnd + label: 'Decompressed contents of: ' , file basename ] ] + +] diff --git a/src/System-Spec/StPharoApplication.extension.st b/src/System-Spec/StPharoApplication.extension.st new file mode 100644 index 00000000000..cb8f765b5e6 --- /dev/null +++ b/src/System-Spec/StPharoApplication.extension.st @@ -0,0 +1,7 @@ +Extension { #name : 'StPharoApplication' } + +{ #category : '*System-Spec' } +StPharoApplication >> openDirectoryDialog [ + + ^ StOpenDirectoryDialog new +] diff --git a/src/System-Spec/ZipArchive.extension.st b/src/System-Spec/ZipArchive.extension.st new file mode 100644 index 00000000000..bb44338a622 --- /dev/null +++ b/src/System-Spec/ZipArchive.extension.st @@ -0,0 +1,18 @@ +Extension { #name : 'ZipArchive' } + +{ #category : '*System-Spec' } +ZipArchive class >> extractAllIn: aFileReferenceOrFileName [ + "Service method to extract all contents of a zip. + Example: + ZipArchive extractAllIn: 'my_file.zip' + " + | directory | + + directory := (self openDirectoryDialog + currentDirectory: FileSystem workingDirectory; + openModal) ifNil: [ ^ self ]. + + ^ self new + readFrom: aFileReferenceOrFileName; + extractAllTo: directory +] diff --git a/src/System-Spec/package.st b/src/System-Spec/package.st new file mode 100644 index 00000000000..c91182fd82c --- /dev/null +++ b/src/System-Spec/package.st @@ -0,0 +1 @@ +Package { #name : 'System-Spec' }