1585
|
1 |
"{ Package: 'stx:libtool2' }"
|
|
2 |
|
|
3 |
FileOperations subclass:#Copy
|
1588
|
4 |
instanceVariableNames:'colOfCopiedFiles'
|
1585
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Interface-Support'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!Copy class methodsFor:'actions'!
|
|
12 |
|
|
13 |
copyFile:aSourceFile to:aDestFile
|
|
14 |
"delete current selected files/directories
|
|
15 |
"
|
|
16 |
|
|
17 |
|instance|
|
|
18 |
|
|
19 |
instance := self new.
|
|
20 |
instance copyFile:aSourceFile to:aDestFile.
|
|
21 |
^ instance
|
|
22 |
!
|
|
23 |
|
|
24 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning
|
|
25 |
"delete current selected files/directories
|
|
26 |
"
|
|
27 |
|
|
28 |
|instance|
|
|
29 |
|
|
30 |
instance := self new.
|
|
31 |
instance copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning.
|
|
32 |
^ instance
|
|
33 |
!
|
|
34 |
|
|
35 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning copyFileIfSame:copy
|
|
36 |
"delete current selected files/directories
|
|
37 |
"
|
|
38 |
|
|
39 |
|instance|
|
|
40 |
|
|
41 |
instance := self new.
|
|
42 |
instance copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning copyFileIfSame:copy.
|
|
43 |
^ instance
|
1588
|
44 |
!
|
|
45 |
|
|
46 |
copyFiles:aColOfSourceFiles to:aDirectory
|
|
47 |
"delete current selected files/directories
|
|
48 |
"
|
|
49 |
|
|
50 |
|instance|
|
|
51 |
|
|
52 |
instance := self new.
|
|
53 |
instance copyFiles:aColOfSourceFiles to:aDirectory.
|
|
54 |
^ instance
|
|
55 |
!
|
|
56 |
|
|
57 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning
|
|
58 |
"delete current selected files/directories
|
|
59 |
"
|
|
60 |
|
|
61 |
|instance|
|
|
62 |
|
|
63 |
instance := self new.
|
|
64 |
instance copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning.
|
|
65 |
^ instance
|
|
66 |
!
|
|
67 |
|
|
68 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:copy
|
|
69 |
"delete current selected files/directories
|
|
70 |
"
|
|
71 |
|
|
72 |
|instance|
|
|
73 |
|
|
74 |
instance := self new.
|
|
75 |
instance copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:copy.
|
|
76 |
^ instance
|
|
77 |
! !
|
|
78 |
|
|
79 |
!Copy methodsFor:'accessing'!
|
|
80 |
|
|
81 |
colOfCopiedFiles
|
|
82 |
"return the value of the instance variable 'colOfCopiedFiles' (automatically generated)"
|
|
83 |
|
|
84 |
colOfCopiedFiles isNil ifTrue:[
|
|
85 |
colOfCopiedFiles := OrderedCollection new.
|
|
86 |
].
|
|
87 |
^ colOfCopiedFiles
|
1585
|
88 |
! !
|
|
89 |
|
|
90 |
!Copy methodsFor:'actions'!
|
|
91 |
|
|
92 |
copyFile:aSourceFile to:aDestFile
|
|
93 |
"defete current selected files/directories
|
|
94 |
"
|
|
95 |
|
|
96 |
self copyFile:aSourceFile to:aDestFile withOverWriteWarning:true
|
|
97 |
!
|
|
98 |
|
|
99 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning
|
|
100 |
"copy to
|
|
101 |
"
|
|
102 |
|
1588
|
103 |
self copyFile:aSourceFile to:aDestFile withOverWriteWarning:true copyFileIfSame:true
|
1585
|
104 |
!
|
|
105 |
|
|
106 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning copyFileIfSame:copy
|
|
107 |
"copy to
|
|
108 |
"
|
|
109 |
|
1588
|
110 |
|newFile fileString targetDirectory targetIsDirectory sourceIsDirectory suffix|
|
1585
|
111 |
|
1588
|
112 |
sourceIsDirectory := aSourceFile isDirectory.
|
|
113 |
targetIsDirectory := aDestFile isDirectory.
|
|
114 |
targetIsDirectory ifTrue:[
|
|
115 |
targetDirectory := aDestFile.
|
|
116 |
newFile := aDestFile construct:(aSourceFile baseName).
|
|
117 |
] ifFalse:[
|
|
118 |
targetDirectory := aDestFile directory.
|
|
119 |
newFile := aDestFile.
|
|
120 |
].
|
|
121 |
"/ do not copy if destination directory doest exist.
|
|
122 |
(targetDirectory exists not) ifTrue:[
|
|
123 |
DialogBox warn:'cant copy to not existing directory ', targetDirectory asString.
|
1585
|
124 |
result := false.
|
|
125 |
^ self
|
|
126 |
].
|
1588
|
127 |
(newFile exists) ifTrue:[
|
1585
|
128 |
((newFile asString = aSourceFile asString) and:[copy]) ifTrue:[
|
|
129 |
[newFile exists] whileTrue:[
|
1588
|
130 |
suffix := newFile suffix.
|
|
131 |
fileString := newFile baseName withoutSuffix, self class copyMoveIfExistSuffixString, '.', suffix.
|
|
132 |
newFile := targetDirectory construct:fileString.
|
1585
|
133 |
].
|
|
134 |
] ifFalse:[
|
|
135 |
overWriteWarning ifTrue:[
|
|
136 |
(self fileExistDialogFor:newFile) ifFalse:[
|
|
137 |
result := false.
|
|
138 |
^ self.
|
|
139 |
]
|
|
140 |
] ifFalse:[
|
|
141 |
result := false.
|
|
142 |
^ self.
|
|
143 |
]
|
|
144 |
].
|
|
145 |
].
|
|
146 |
Error handle:[:ex|
|
|
147 |
"was not able to copy it"
|
|
148 |
WarningBox warn:'on copy file - ', ex errorString.
|
|
149 |
self errorString:('on copy file - ', ex description asString).
|
|
150 |
result := false.
|
|
151 |
] do:[
|
1588
|
152 |
sourceIsDirectory ifTrue:[
|
1585
|
153 |
OperatingSystem recursiveCopyDirectory:(aSourceFile pathName)
|
|
154 |
to:newFile.
|
1588
|
155 |
] ifFalse:[
|
|
156 |
aSourceFile copyTo:newFile.
|
1585
|
157 |
].
|
|
158 |
DirectoryContents flushCachedDirectory:(aSourceFile directory).
|
|
159 |
result := true.
|
|
160 |
].
|
1588
|
161 |
!
|
|
162 |
|
|
163 |
copyFiles:aColOfSourceFiles to:aDirectory
|
|
164 |
|
|
165 |
^ self copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:true.
|
|
166 |
!
|
|
167 |
|
|
168 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning
|
|
169 |
|
|
170 |
^ self copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:true.
|
|
171 |
!
|
|
172 |
|
|
173 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:copy
|
|
174 |
|
|
175 |
|
|
176 |
|newFile suffix fileString sourceIsDirectory askResult|
|
|
177 |
|
|
178 |
(aDirectory exists not) ifTrue:[
|
|
179 |
DialogBox warn:'cant copy to not existing directory ', aDirectory asString.
|
|
180 |
result := false.
|
|
181 |
^ self
|
|
182 |
].
|
|
183 |
(aDirectory isDirectory not) ifTrue:[
|
|
184 |
DialogBox warn:'destination ', aDirectory asString, ' is not a directory'.
|
|
185 |
result := false.
|
|
186 |
^ self
|
|
187 |
].
|
|
188 |
aColOfSourceFiles do:[: filename |
|
|
189 |
newFile := aDirectory construct:(filename baseName).
|
|
190 |
sourceIsDirectory := filename isDirectory.
|
|
191 |
(newFile exists) ifTrue:[
|
|
192 |
askResult := true.
|
|
193 |
((newFile asString = filename asString) and:[copy]) ifTrue:[
|
|
194 |
[newFile exists] whileTrue:[
|
|
195 |
suffix := newFile suffix.
|
|
196 |
fileString := newFile baseName withoutSuffix, self class copyMoveIfExistSuffixString, '.', suffix.
|
|
197 |
newFile := aDirectory construct:fileString.
|
|
198 |
].
|
|
199 |
] ifFalse:[
|
|
200 |
overWriteWarning ifTrue:[
|
|
201 |
askResult := (self fileExistDialogFor:newFile withCancel:true).
|
|
202 |
askResult isNil ifTrue:[
|
|
203 |
result := false.
|
|
204 |
^ self.
|
|
205 |
]
|
|
206 |
]
|
|
207 |
].
|
|
208 |
].
|
|
209 |
askResult ifTrue:[
|
|
210 |
Error handle:[:ex|
|
|
211 |
"was not able to copy it"
|
|
212 |
result := false.
|
|
213 |
self errorString:('on copy file - ', ex description asString).
|
|
214 |
( Dialog
|
|
215 |
confirm:('error on copy file - ', ex description asString)
|
|
216 |
title:'Copy'
|
|
217 |
yesLabel:'Continue'
|
|
218 |
noLabel:'Abort') ifFalse:[
|
|
219 |
^ self.
|
|
220 |
].
|
|
221 |
] do:[
|
|
222 |
sourceIsDirectory ifTrue:[
|
|
223 |
OperatingSystem recursiveCopyDirectory:(filename asString)
|
|
224 |
to:(newFile asString).
|
|
225 |
] ifFalse:[
|
|
226 |
filename copyTo:newFile.
|
|
227 |
].
|
|
228 |
].
|
|
229 |
self colOfCopiedFiles add:filename
|
|
230 |
]
|
|
231 |
].
|
|
232 |
DirectoryContents flushCachedDirectory:aDirectory.
|
|
233 |
result := true.
|
1585
|
234 |
! !
|
|
235 |
|
|
236 |
!Copy class methodsFor:'documentation'!
|
|
237 |
|
|
238 |
version
|
|
239 |
^ '$Header$'
|
|
240 |
! !
|