author | Stefan Vogel <sv@exept.de> |
Wed, 04 Dec 2013 15:23:14 +0100 | |
changeset 13703 | 43a4a2599e17 |
parent 13345 | ef9354aa1ab9 |
child 13738 | 07e534de96bd |
permissions | -rw-r--r-- |
6168 | 1 |
" |
2 |
COPYRIGHT (c) 2003 by eXept Software AG |
|
7637 | 3 |
All Rights Reserved |
6168 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
6618 | 12 |
"{ Package: 'stx:libtool' }" |
3841 | 13 |
|
14 |
Object subclass:#FileOperation |
|
11444 | 15 |
instanceVariableNames:'errorString result actionForAll' |
3975
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
16 |
classVariableNames:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
17 |
poolDictionaries:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
18 |
category:'Interface-Support' |
3841 | 19 |
! |
20 |
||
3842 | 21 |
FileOperation subclass:#Copy |
6374 | 22 |
instanceVariableNames:'copiedFiles newFiles' |
3975
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
23 |
classVariableNames:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
24 |
poolDictionaries:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
25 |
privateIn:FileOperation |
3842 | 26 |
! |
27 |
||
7634 | 28 |
FileOperation::Copy subclass:#CopyCorrupted |
7637 | 29 |
instanceVariableNames:'' |
7634 | 30 |
classVariableNames:'' |
31 |
poolDictionaries:'' |
|
32 |
privateIn:FileOperation |
|
33 |
! |
|
34 |
||
3842 | 35 |
FileOperation subclass:#Create |
3975
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
36 |
instanceVariableNames:'createdFile' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
37 |
classVariableNames:'LastCreatedDirectory LastCreatedFile' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
38 |
poolDictionaries:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
39 |
privateIn:FileOperation |
3842 | 40 |
! |
41 |
||
42 |
FileOperation subclass:#Delete |
|
3975
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
43 |
instanceVariableNames:'fileName' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
44 |
classVariableNames:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
45 |
poolDictionaries:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
46 |
privateIn:FileOperation |
3842 | 47 |
! |
48 |
||
6168 | 49 |
FileOperation::Delete subclass:#Erase |
50 |
instanceVariableNames:'' |
|
51 |
classVariableNames:'' |
|
52 |
poolDictionaries:'' |
|
53 |
privateIn:FileOperation |
|
54 |
! |
|
55 |
||
3842 | 56 |
FileOperation subclass:#Move |
6374 | 57 |
instanceVariableNames:'movedFiles' |
3975
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
58 |
classVariableNames:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
59 |
poolDictionaries:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
60 |
privateIn:FileOperation |
3842 | 61 |
! |
62 |
||
63 |
FileOperation subclass:#Rename |
|
3975
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
64 |
instanceVariableNames:'renamedFiles' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
65 |
classVariableNames:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
66 |
poolDictionaries:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
67 |
privateIn:FileOperation |
3842 | 68 |
! |
69 |
||
6168 | 70 |
!FileOperation class methodsFor:'documentation'! |
71 |
||
72 |
copyright |
|
73 |
" |
|
74 |
COPYRIGHT (c) 2003 by eXept Software AG |
|
7637 | 75 |
All Rights Reserved |
6168 | 76 |
|
77 |
This software is furnished under a license and may be used |
|
78 |
only in accordance with the terms of that license and with the |
|
79 |
inclusion of the above copyright notice. This software may not |
|
80 |
be provided or otherwise made available to, or used by, any |
|
81 |
other person. No title to or ownership of the software is |
|
82 |
hereby transferred. |
|
83 |
" |
|
84 |
! ! |
|
3841 | 85 |
|
7634 | 86 |
!FileOperation class methodsFor:'instance creation'! |
87 |
||
88 |
copyCorruptedFile:aSourceFile to:aDestFile |
|
7637 | 89 |
^ CopyCorrupted |
90 |
copyFile:aSourceFile to:aDestFile |
|
7634 | 91 |
|
92 |
"Created: / 07-02-2007 / 18:41:24 / cg" |
|
93 |
! |
|
5961 | 94 |
|
95 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarningBoolean copyFileIfSame:copyIfSameBoolean |
|
7637 | 96 |
^ Copy |
97 |
copyFile:aSourceFile to:aDestFile |
|
98 |
withOverWriteWarning:overWriteWarningBoolean |
|
99 |
copyFileIfSame:copyIfSameBoolean |
|
5961 | 100 |
! |
101 |
||
102 |
copyFiles:aColOfSourceFiles to:aDirectory |
|
103 |
^ Copy copyFiles:aColOfSourceFiles to:aDirectory |
|
104 |
! |
|
105 |
||
106 |
createDirectoryIn:aDirectory |
|
107 |
^ Create createDirectoryIn:aDirectory |
|
108 |
! |
|
109 |
||
110 |
createDirectoryIn:aDirectory initialAnswer:defaultAnswer |
|
111 |
^ Create createDirectoryIn:aDirectory initialAnswer:defaultAnswer |
|
112 |
! |
|
113 |
||
114 |
createFileIn:aDirectory |
|
115 |
^ Create createFileIn:aDirectory |
|
116 |
! |
|
117 |
||
118 |
createHardLinkIn:dir |
|
119 |
^ Create createHardLinkIn:dir |
|
120 |
! |
|
121 |
||
6151 | 122 |
createLinkIn:dir soft:soft |
123 |
^ Create createLinkIn:dir soft:soft |
|
124 |
! |
|
125 |
||
5961 | 126 |
createSoftLinkIn:dir |
127 |
^ Create createSoftLinkIn:dir |
|
128 |
! |
|
129 |
||
130 |
deleteFiles:colOfFiles confirm:confirm |
|
131 |
^ Delete deleteFiles:colOfFiles confirm:confirm |
|
132 |
! |
|
133 |
||
6168 | 134 |
eraseFiles:colOfFiles confirm:confirm |
135 |
^ Erase deleteFiles:colOfFiles confirm:confirm |
|
136 |
! |
|
137 |
||
5961 | 138 |
moveFile:aSourceFile to:aDestFile |
6168 | 139 |
^ Move moveFile:aSourceFile to:aDestFile |
5961 | 140 |
! |
141 |
||
142 |
moveFiles:aCollectionOfFiles to:aDestDirectory |
|
6168 | 143 |
^ Move moveFiles:aCollectionOfFiles to:aDestDirectory |
5961 | 144 |
! |
145 |
||
146 |
renameFile:filename to:newFileString |
|
6168 | 147 |
^ Rename renameFile:filename to:newFileString |
5961 | 148 |
! |
149 |
||
150 |
renameFiles:aCollectionofFilenames |
|
6168 | 151 |
^ Rename renameFiles:aCollectionofFilenames |
5961 | 152 |
! ! |
153 |
||
3841 | 154 |
!FileOperation class methodsFor:'defaults'! |
155 |
||
6168 | 156 |
suffixForCopyOverExistingFile |
3841 | 157 |
^ '.copy' |
158 |
! ! |
|
159 |
||
160 |
!FileOperation methodsFor:'accessing'! |
|
161 |
||
162 |
errorString |
|
163 |
^ errorString |
|
164 |
! |
|
165 |
||
166 |
errorString:something |
|
167 |
errorString := something. |
|
168 |
! |
|
169 |
||
170 |
result |
|
171 |
^ result |
|
172 |
! |
|
173 |
||
174 |
result:something |
|
175 |
result := something. |
|
176 |
! ! |
|
177 |
||
7634 | 178 |
!FileOperation methodsFor:'dialogs & helpers'! |
179 |
||
180 |
checkDirectoryExists:aDirectory |
|
181 |
aDirectory exists ifFalse:[ |
|
9663
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
182 |
(Dialog confirm:(FileBrowser classResources |
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
183 |
stringWithCRs:'Non-existing directory: %1\\Create?' |
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
184 |
with:aDirectory asString) |
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
185 |
) ifFalse:[ |
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
186 |
^ false |
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
187 |
]. |
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
188 |
aDirectory recursiveMakeDirectory. |
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
189 |
aDirectory exists ifFalse:[ |
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
190 |
Dialog warn:(FileBrowser classResources |
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
191 |
string:'Failed to create directory: %1'). |
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
192 |
^ false |
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
193 |
]. |
7634 | 194 |
]. |
195 |
aDirectory isDirectory ifFalse:[ |
|
9663
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
196 |
Dialog warn:('Not a directory: %1' bindWith:aDirectory asString). |
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
197 |
^ false |
7634 | 198 |
]. |
199 |
^ true |
|
200 |
||
201 |
"Created: / 07-02-2007 / 18:30:49 / cg" |
|
9663
7837d4646761
changed: #checkDirectoryExists:
Claus Gittinger <cg@exept.de>
parents:
9650
diff
changeset
|
202 |
"Modified: / 09-12-2010 / 08:45:45 / cg" |
7634 | 203 |
! |
3841 | 204 |
|
6168 | 205 |
fileExistsDialogForNewFile:newFile oldFile:oldFile withCancel:withCancel |
4701 | 206 |
"return true, if the file should be moved/copied. |
207 |
Ask user if oldFile exists." |
|
208 |
||
6168 | 209 |
^ self fileExistsDialogForNewFile:newFile oldFile:oldFile withCancel:withCancel withRemoveIfSame:false. |
5862 | 210 |
! |
211 |
||
6168 | 212 |
fileExistsDialogForNewFile:newFile oldFile:oldFile withCancel:withCancel withRemoveIfSame:withRemoveIfSame |
5862 | 213 |
"return true, if the file should be moved/copied. |
214 |
If oldFile exists, ask user. |
|
215 |
If withRemoveIfSame is true, two additional possible values are returned: |
|
8557 | 216 |
#removeSource and #removeDestination. |
5862 | 217 |
" |
218 |
||
11444 | 219 |
^ self |
220 |
fileExistsDialogForNewFile:newFile oldFile:oldFile withCancel:withCancel withRemoveIfSame:withRemoveIfSame |
|
221 |
withAllAction:false |
|
222 |
||
223 |
"Modified: / 20-03-2012 / 11:44:51 / cg" |
|
224 |
! |
|
225 |
||
226 |
fileExistsDialogForNewFile:newFile oldFile:oldFile withCancel:withCancel withRemoveIfSame:withRemoveIfSame withAllAction:withAllAction |
|
227 |
"return true, if the file should be moved/copied. |
|
228 |
If oldFile exists, ask user. |
|
229 |
If withRemoveIfSame is true, two additional possible values are returned: |
|
230 |
#removeSource and #removeDestination. |
|
231 |
" |
|
232 |
||
233 |
|msg oldSize newSize sameContents resources sourceType destType labels values default olderOrNewer |
|
234 |
forAllHolder answer| |
|
4701 | 235 |
|
236 |
newFile exists ifFalse:[ ^ true ]. |
|
237 |
oldSize := oldFile fileSize. |
|
238 |
newSize := newFile fileSize. |
|
239 |
||
5888 | 240 |
sameContents := false. |
241 |
||
242 |
newFile isDirectory ifTrue:[ |
|
8557 | 243 |
oldFile isDirectory ifTrue:[ |
244 |
"/ could (should?) recursively look for same contents here... |
|
245 |
]. |
|
5888 | 246 |
] ifFalse:[ |
8557 | 247 |
oldFile isDirectory ifFalse:[ |
248 |
sameContents := oldSize = newSize and:[oldFile sameContentsAs:newFile]. |
|
249 |
] |
|
5888 | 250 |
]. |
251 |
||
8557 | 252 |
resources := AbstractFileBrowser classResources. |
253 |
||
5888 | 254 |
"/ for now: |
255 |
oldFile isDirectory ~~ newFile isDirectory ifTrue:[ |
|
8557 | 256 |
Dialog warn:(resources string:'Will not overwrite directory with file and vice versa.'). |
257 |
^ false. |
|
5888 | 258 |
]. |
259 |
||
260 |
sourceType := newFile isDirectory ifTrue:'directory' ifFalse:'file'. |
|
261 |
destType := oldFile isDirectory ifTrue:'directory' ifFalse:'file'. |
|
3841 | 262 |
|
4701 | 263 |
sameContents ifTrue:[ |
9512
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
264 |
msg := 'Overwrite existing destination %7:\\ %1\ size: %3 of %2\\with %8 source (same contents):\\ %4\ size: %6 of %5'. |
4701 | 265 |
] ifFalse:[ |
9512
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
266 |
msg := 'Overwrite existing destination %7:\\ %1\ size: %3 of %2\\with %8 source:\\ %4\ size: %6 of %5'. |
4701 | 267 |
]. |
4587 | 268 |
|
9512
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
269 |
olderOrNewer := newFile modificationTime < oldFile modificationTime |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
270 |
ifTrue:[ 'newer' ] |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
271 |
ifFalse:[ 'older' ]. |
7637 | 272 |
msg := resources |
8557 | 273 |
stringWithCRs:msg |
274 |
withArgs:(Array |
|
275 |
with:newFile asString allBold |
|
276 |
with:(newFile modificationTime printStringFormat:'%(Day)-%(mon)-%(year) %h:%m:%s') |
|
277 |
with:newSize |
|
278 |
with:oldFile asString allBold |
|
279 |
with:(oldFile modificationTime printStringFormat:'%(Day)-%(mon)-%(year) %h:%m:%s') |
|
280 |
with:oldSize |
|
9512
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
281 |
with:destType |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
282 |
with:(resources string:olderOrNewer) ). |
4701 | 283 |
|
5862 | 284 |
(sameContents and:[withRemoveIfSame]) ifTrue:[ |
9512
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
285 |
labels := #( 'No' 'Remove Destination' 'Remove Source' 'Yes'). |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
286 |
values := #( false #removeDestination #removeSource true ). |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
287 |
withCancel ifTrue:[ |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
288 |
labels := #('Cancel') , labels. |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
289 |
values := #( nil ) , values. |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
290 |
]. |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
291 |
default := #removeSource. |
5862 | 292 |
] ifFalse:[ |
9512
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
293 |
labels := #( 'No' 'Yes'). |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
294 |
values := #( false true ). |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
295 |
withCancel ifTrue:[ |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
296 |
labels := #('Cancel') , labels. |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
297 |
values := #( nil ) , values. |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
298 |
]. |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
299 |
default := false. |
5862 | 300 |
]. |
9512
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
301 |
|
11444 | 302 |
forAllHolder := false asValue. |
303 |
Dialog aboutToOpenBoxNotificationSignal handle:[:ex | |
|
13345
ef9354aa1ab9
aboutToOpenBoxNotificationSignal semantic change (for Jan)
Claus Gittinger <cg@exept.de>
parents:
12726
diff
changeset
|
304 |
|box| |
ef9354aa1ab9
aboutToOpenBoxNotificationSignal semantic change (for Jan)
Claus Gittinger <cg@exept.de>
parents:
12726
diff
changeset
|
305 |
|
11444 | 306 |
withAllAction ifTrue:[ |
13345
ef9354aa1ab9
aboutToOpenBoxNotificationSignal semantic change (for Jan)
Claus Gittinger <cg@exept.de>
parents:
12726
diff
changeset
|
307 |
box := ex box. |
ef9354aa1ab9
aboutToOpenBoxNotificationSignal semantic change (for Jan)
Claus Gittinger <cg@exept.de>
parents:
12726
diff
changeset
|
308 |
box addVerticalSpace:10. |
ef9354aa1ab9
aboutToOpenBoxNotificationSignal semantic change (for Jan)
Claus Gittinger <cg@exept.de>
parents:
12726
diff
changeset
|
309 |
box verticalPanel |
11444 | 310 |
add:(CheckBox |
311 |
label:'Same action for all' |
|
312 |
model:forAllHolder). |
|
313 |
]. |
|
314 |
] do:[ |
|
315 |
answer := OptionBox |
|
9512
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
316 |
request:msg |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
317 |
label:(resources string:'Overwrite existing file') |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
318 |
image:(YesNoBox iconBitmap) |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
319 |
buttonLabels:(resources array:labels) |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
320 |
values:values |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
321 |
default:default |
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
322 |
onCancel:nil. |
11444 | 323 |
]. |
324 |
(withAllAction and:[answer notNil]) ifTrue:[ |
|
325 |
actionForAll := answer |
|
326 |
]. |
|
327 |
^ answer |
|
9512
fc8df478d3f1
changed: #fileExistsDialogForNewFile:oldFile:withCancel:withRemoveIfSame:
Claus Gittinger <cg@exept.de>
parents:
9501
diff
changeset
|
328 |
|
11444 | 329 |
"Created: / 20-03-2012 / 11:44:34 / cg" |
3841 | 330 |
! ! |
331 |
||
6285 | 332 |
!FileOperation methodsFor:'queries'! |
333 |
||
334 |
isErase |
|
335 |
^ false |
|
336 |
! ! |
|
337 |
||
3842 | 338 |
!FileOperation::Copy class methodsFor:'actions'! |
339 |
||
340 |
copyFile:aSourceFile to:aDestFile |
|
341 |
|instance| |
|
342 |
||
343 |
instance := self new. |
|
344 |
instance copyFile:aSourceFile to:aDestFile. |
|
345 |
^ instance |
|
346 |
! |
|
347 |
||
348 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning |
|
349 |
|instance| |
|
350 |
||
351 |
instance := self new. |
|
352 |
instance copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning. |
|
353 |
^ instance |
|
354 |
! |
|
355 |
||
5961 | 356 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarningBoolean copyFileIfSame:copyIfSameBoolean |
3842 | 357 |
|instance| |
358 |
||
359 |
instance := self new. |
|
5961 | 360 |
instance copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarningBoolean copyFileIfSame:copyIfSameBoolean. |
3842 | 361 |
^ instance |
362 |
! |
|
363 |
||
364 |
copyFiles:aColOfSourceFiles to:aDirectory |
|
365 |
|instance| |
|
366 |
||
367 |
instance := self new. |
|
368 |
instance copyFiles:aColOfSourceFiles to:aDirectory. |
|
369 |
^ instance |
|
370 |
! |
|
371 |
||
372 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning |
|
373 |
|instance| |
|
374 |
||
375 |
instance := self new. |
|
376 |
instance copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning. |
|
377 |
^ instance |
|
378 |
! |
|
379 |
||
380 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:copy |
|
381 |
|instance| |
|
382 |
||
383 |
instance := self new. |
|
384 |
instance copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:copy. |
|
385 |
^ instance |
|
386 |
! ! |
|
387 |
||
388 |
!FileOperation::Copy methodsFor:'accessing'! |
|
389 |
||
390 |
colOfCopiedFiles |
|
6373 | 391 |
"obsolete - bad name" |
392 |
||
393 |
^ self collectionOfCopiedFiles |
|
394 |
! |
|
395 |
||
396 |
collectionOfCopiedFiles |
|
6374 | 397 |
copiedFiles isNil ifTrue:[ |
7637 | 398 |
copiedFiles := OrderedCollection new. |
3842 | 399 |
]. |
6374 | 400 |
^ copiedFiles |
401 |
! |
|
402 |
||
403 |
collectionOfNewFiles |
|
404 |
newFiles isNil ifTrue:[ |
|
7637 | 405 |
newFiles := OrderedCollection new. |
6374 | 406 |
]. |
407 |
^ newFiles |
|
3842 | 408 |
! ! |
409 |
||
410 |
!FileOperation::Copy methodsFor:'actions'! |
|
411 |
||
412 |
copyFile:aSourceFile to:aDestFile |
|
413 |
self copyFile:aSourceFile to:aDestFile withOverWriteWarning:true |
|
414 |
! |
|
415 |
||
416 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning |
|
417 |
self copyFile:aSourceFile to:aDestFile withOverWriteWarning:true copyFileIfSame:true |
|
418 |
! |
|
419 |
||
6373 | 420 |
copyFiles:aColOfSourceFiles to:aDirectory |
7637 | 421 |
^ self copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:true. |
6373 | 422 |
! |
423 |
||
7637 | 424 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning |
6373 | 425 |
^ self copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:true. |
426 |
! ! |
|
427 |
||
428 |
!FileOperation::Copy methodsFor:'actions-basic'! |
|
429 |
||
7634 | 430 |
basicCopy:aSourceFile to:newFile |
431 |
aSourceFile isDirectory ifTrue:[ |
|
8289
8dcce3984b27
fixed recursive directory copy
Claus Gittinger <cg@exept.de>
parents:
7637
diff
changeset
|
432 |
aSourceFile recursiveCopyTo:newFile. |
8dcce3984b27
fixed recursive directory copy
Claus Gittinger <cg@exept.de>
parents:
7637
diff
changeset
|
433 |
"/ OperatingSystem recursiveCopyDirectory:(aSourceFile pathName) to:(newFile pathName). |
7634 | 434 |
] ifFalse:[ |
8289
8dcce3984b27
fixed recursive directory copy
Claus Gittinger <cg@exept.de>
parents:
7637
diff
changeset
|
435 |
aSourceFile copyTo:newFile. |
7634 | 436 |
]. |
3842 | 437 |
|
7634 | 438 |
"Created: / 07-02-2007 / 18:35:52 / cg" |
439 |
! |
|
440 |
||
441 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarningBoolean copyFileIfSame:copyIfSameBoolean |
|
442 |
|newFile fileString targetDirectory suffix| |
|
443 |
||
444 |
aDestFile isDirectory ifTrue:[ |
|
13703 | 445 |
targetDirectory := aDestFile. |
446 |
newFile := aDestFile construct:(aSourceFile baseName). |
|
3842 | 447 |
] ifFalse:[ |
13703 | 448 |
targetDirectory := aDestFile directory. |
449 |
newFile := aDestFile. |
|
3842 | 450 |
]. |
7634 | 451 |
|
3842 | 452 |
"/ do not copy if destination directory doest exist. |
7634 | 453 |
(self checkDirectoryExists:targetDirectory) ifFalse:[ |
13703 | 454 |
result := false. |
455 |
^ self |
|
3842 | 456 |
]. |
457 |
(newFile exists) ifTrue:[ |
|
13703 | 458 |
((newFile asString = aSourceFile asString) and:[copyIfSameBoolean]) ifTrue:[ |
459 |
[newFile exists] whileTrue:[ |
|
460 |
suffix := newFile suffix. |
|
461 |
fileString := newFile baseName withoutSuffix, self class suffixForCopyOverExistingFile, '.', suffix. |
|
462 |
newFile := targetDirectory construct:fileString. |
|
463 |
]. |
|
464 |
] ifFalse:[ |
|
465 |
overWriteWarningBoolean ifTrue:[ |
|
466 |
(self fileExistsDialogForNewFile:newFile oldFile:aSourceFile withCancel:false withRemoveIfSame:false) ifFalse:[ |
|
467 |
result := false. |
|
468 |
^ self. |
|
469 |
] |
|
470 |
] ifFalse:[ |
|
471 |
result := false. |
|
472 |
^ self. |
|
473 |
] |
|
474 |
]. |
|
3842 | 475 |
]. |
13703 | 476 |
StreamError handle:[:ex| |
477 |
"was not able to copy it" |
|
478 |
newFile remove. |
|
479 |
WarningBox warn:'on copy file - ', ex description. |
|
480 |
self errorString:('on copy file - ', ex description asString). |
|
481 |
result := false. |
|
482 |
^ self |
|
3842 | 483 |
] do:[ |
13703 | 484 |
self basicCopy:aSourceFile to:newFile. |
3842 | 485 |
]. |
4006
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
486 |
DirectoryContents flushCachedDirectoryFor:(aSourceFile directory). |
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
487 |
result := true. |
7634 | 488 |
|
489 |
"Modified: / 07-02-2007 / 18:36:02 / cg" |
|
3842 | 490 |
! |
491 |
||
492 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:copy |
|
7634 | 493 |
|newFile suffix fileString doCopy| |
3842 | 494 |
|
7634 | 495 |
"/ do not copy if destination directory doest exist. |
496 |
(self checkDirectoryExists:aDirectory) ifFalse:[ |
|
7637 | 497 |
result := false. |
498 |
^ self |
|
3842 | 499 |
]. |
6374 | 500 |
|
501 |
aColOfSourceFiles do:[:filename | |
|
7637 | 502 |
newFile := aDirectory construct:(filename baseName). |
503 |
doCopy := true. |
|
504 |
(newFile exists) ifTrue:[ |
|
505 |
((newFile asString = filename asString) and:[copy]) ifTrue:[ |
|
506 |
[newFile exists] whileTrue:[ |
|
507 |
suffix := newFile suffix. |
|
508 |
fileString := newFile withoutSuffix baseName, self class suffixForCopyOverExistingFile. |
|
509 |
suffix notEmpty ifTrue:[ |
|
510 |
fileString := fileString, '.', suffix. |
|
511 |
]. |
|
512 |
newFile := aDirectory construct:fileString. |
|
513 |
]. |
|
514 |
] ifFalse:[ |
|
515 |
overWriteWarning ifTrue:[ |
|
516 |
doCopy := (self fileExistsDialogForNewFile:newFile oldFile:filename withCancel:(aColOfSourceFiles size > 1) withRemoveIfSame:false). |
|
517 |
doCopy isNil ifTrue:[ |
|
518 |
" abort pressed " |
|
519 |
result := false. |
|
520 |
^ self. |
|
521 |
] |
|
522 |
] |
|
523 |
]. |
|
524 |
]. |
|
525 |
doCopy ifTrue:[ |
|
526 |
Error handle:[:ex| |
|
527 |
|msg| |
|
7634 | 528 |
|
7637 | 529 |
msg := 'on copy file - ', ex description asString. |
530 |
"was not able to copy it" |
|
531 |
result := false. |
|
532 |
self errorString:msg. |
|
533 |
( Dialog |
|
534 |
confirm:('Error ',msg) |
|
535 |
title:'Copy' |
|
536 |
yesLabel:'Continue' |
|
537 |
noLabel:'Abort') ifTrue:[ |
|
538 |
ex proceed. |
|
539 |
] ifFalse:[ |
|
540 |
^ self. |
|
541 |
]. |
|
542 |
] do:[ |
|
543 |
self basicCopy:filename to:newFile |
|
544 |
]. |
|
545 |
self collectionOfCopiedFiles add:filename. |
|
546 |
self collectionOfNewFiles add:newFile. |
|
547 |
] |
|
3842 | 548 |
]. |
4006
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
549 |
DirectoryContents flushCachedDirectoryFor:aDirectory. |
3842 | 550 |
result := true. |
7634 | 551 |
|
552 |
"Modified: / 07-02-2007 / 18:36:54 / cg" |
|
553 |
! ! |
|
554 |
||
555 |
!FileOperation::CopyCorrupted methodsFor:'actions-basic'! |
|
556 |
||
557 |
basicCopy:aSourceFile to:newFile |
|
558 |
aSourceFile isDirectory ifTrue:[ |
|
7637 | 559 |
newFile makeDirectory. |
560 |
aSourceFile directoryContentsDo:[:eachFileOrDirectory | |
|
561 |
self basicCopy:(aSourceFile construct:eachFileOrDirectory) to:(newFile construct:eachFileOrDirectory) |
|
562 |
]. |
|
7634 | 563 |
] ifFalse:[ |
7637 | 564 |
self basicCopyFile:aSourceFile to:newFile. |
7634 | 565 |
]. |
566 |
||
567 |
"Created: / 07-02-2007 / 18:39:03 / cg" |
|
568 |
! |
|
569 |
||
570 |
basicCopyFile:sourceFile to:destFile |
|
571 |
"this is a copy which is tolerant w.r.t. read errors. |
|
572 |
Wheneven a read fails, a number of retries is performed |
|
573 |
(with smaller buffer sizes) and, a block of zeros is eventually written. |
|
574 |
This allows for partially corrupted data to be read from a tape or disk." |
|
575 |
||
576 |
|in in2 out doWrite doRead fileSize offset buffer bufferSize nRead nWritten nSingle |
|
577 |
lostStart lostEnd seekFailed| |
|
578 |
||
9501 | 579 |
buffer := ByteArray new:(self bufferSize). |
7634 | 580 |
bufferSize := buffer size. |
581 |
offset := 0. |
|
582 |
fileSize := sourceFile fileSize. |
|
583 |
in := sourceFile readStream binary. |
|
584 |
out := destFile writeStream binary. |
|
585 |
||
586 |
doWrite := [:n | |
|
8557 | 587 |
nWritten := out nextPutBytes:n from:buffer startingAt:1. |
588 |
offset := offset + nWritten. |
|
589 |
nWritten ~= n ifTrue:[ |
|
590 |
self error:'Write error'. |
|
591 |
]. |
|
592 |
]. |
|
7634 | 593 |
|
594 |
doRead := [:n | |
|
8557 | 595 |
ReadError handle:[:ex | |
596 |
nRead := 0. |
|
597 |
in position:offset. |
|
598 |
] do:[ |
|
599 |
nRead := in nextBytes:n into:buffer startingAt:1. |
|
600 |
]. |
|
601 |
]. |
|
7634 | 602 |
|
603 |
[ |
|
8557 | 604 |
[offset < fileSize] whileTrue:[ |
605 |
doRead value:(bufferSize min:(fileSize - offset)). |
|
606 |
nRead > 0 ifTrue:[ |
|
607 |
lostStart notNil ifTrue:[ |
|
608 |
Transcript showCR:'CORRUPT: ',(lostStart printString),' .. ',(lostEnd printString). |
|
609 |
lostStart := nil. |
|
610 |
]. |
|
611 |
doWrite value:nRead. |
|
612 |
]. |
|
7634 | 613 |
|
8557 | 614 |
nRead == (bufferSize min:(fileSize - offset)) ifTrue:[ |
615 |
bufferSize < buffer size ifTrue:[ |
|
616 |
bufferSize := bufferSize * 2. |
|
617 |
]. |
|
618 |
] ifFalse:[ |
|
619 |
nRead == 0 ifTrue:[ |
|
620 |
"/ try reading single blocks for a while... |
|
9501 | 621 |
nSingle := self defectBlockRetryCount. |
8557 | 622 |
[ |
9501 | 623 |
nSingle > 0 |
8557 | 624 |
and:[ |
9501 | 625 |
doRead value:(self defectBlockCopySize). |
8557 | 626 |
nRead > 0] |
627 |
] whileTrue:[ |
|
628 |
lostStart notNil ifTrue:[ |
|
629 |
Transcript showCR:'CORRUPT: ',(lostStart printString),' .. ',(lostEnd printString). |
|
630 |
lostStart := nil. |
|
631 |
]. |
|
9501 | 632 |
Transcript showCR:'single block at ',offset printString, 'size=',nRead printString. |
8557 | 633 |
doWrite value:nRead. |
634 |
nSingle := nSingle - 1. |
|
635 |
]. |
|
7634 | 636 |
|
8557 | 637 |
nRead == 0 ifTrue:[ |
638 |
in2 := sourceFile readStream binary. |
|
639 |
Error handle:[:ex | |
|
640 |
] do:[ |
|
641 |
in2 position:0. |
|
642 |
in2 nextBytes:buffer size into:buffer startingAt:1. |
|
643 |
]. |
|
644 |
seekFailed := false. |
|
645 |
Error handle:[:ex | |
|
646 |
seekFailed := true. |
|
647 |
] do:[ |
|
648 |
in2 position:offset. |
|
649 |
]. |
|
650 |
seekFailed ifTrue:[ |
|
9501 | 651 |
buffer atAllPut:0. |
8557 | 652 |
Transcript showCR:'bad seek at ',offset printString. |
9501 | 653 |
doWrite value:(self defectBlockCopySize). |
8557 | 654 |
] ifFalse:[ |
655 |
in close. |
|
656 |
in := in2. |
|
9501 | 657 |
doRead value:(self defectBlockCopySize). |
8557 | 658 |
nRead > 0 ifTrue:[ |
7634 | 659 |
Transcript showCR:'single after reopen at ',offset printString. |
8557 | 660 |
doWrite value:nRead. |
661 |
] ifFalse:[ |
|
662 |
lostStart isNil ifTrue:[ |
|
663 |
lostStart := lostEnd := offset. |
|
664 |
] ifFalse:[ |
|
665 |
lostEnd := offset. |
|
666 |
]. |
|
9501 | 667 |
buffer atAllPut:0. |
7634 | 668 |
Transcript showCR:'bad at ',offset printString. |
9501 | 669 |
doWrite value:(self defectBlockCopySize). |
670 |
bufferSize := (self defectBlockCopySize). |
|
8557 | 671 |
]. |
672 |
] |
|
673 |
] |
|
674 |
]. |
|
675 |
]. |
|
676 |
Transcript showCR:offset. |
|
677 |
]. |
|
7634 | 678 |
] ensure:[ |
8557 | 679 |
in close. |
680 |
out close. |
|
7634 | 681 |
]. |
682 |
lostStart notNil ifTrue:[ |
|
8557 | 683 |
Transcript showCR:'CORRUPT: ',(lostStart printString),' .. ',(lostEnd printString). |
684 |
lostStart := nil. |
|
7634 | 685 |
]. |
686 |
||
687 |
"Created: / 07-02-2007 / 18:40:32 / cg" |
|
9501 | 688 |
"Modified: / 21-06-2010 / 14:25:22 / cg" |
689 |
! ! |
|
690 |
||
691 |
!FileOperation::CopyCorrupted methodsFor:'defaults'! |
|
692 |
||
693 |
bufferSize |
|
694 |
^ 1024*1024*1 |
|
695 |
||
696 |
"Created: / 21-06-2010 / 14:20:35 / cg" |
|
697 |
! |
|
698 |
||
699 |
defectBlockCopySize |
|
700 |
"/ ^ 256 |
|
9650 | 701 |
^ 128*1024 |
9501 | 702 |
|
703 |
"Created: / 21-06-2010 / 14:22:23 / cg" |
|
9650 | 704 |
"Modified: / 27-11-2010 / 18:06:10 / cg" |
9501 | 705 |
! |
706 |
||
707 |
defectBlockRetryCount |
|
9650 | 708 |
^ 1 |
9501 | 709 |
|
710 |
"Created: / 21-06-2010 / 14:24:45 / cg" |
|
9650 | 711 |
"Modified: / 27-11-2010 / 18:05:19 / cg" |
3842 | 712 |
! ! |
713 |
||
714 |
!FileOperation::Create class methodsFor:'actions'! |
|
715 |
||
3863 | 716 |
createDirectoryIn:aDirectory |
3842 | 717 |
|
718 |
|instance| |
|
719 |
||
720 |
instance := self new. |
|
3863 | 721 |
instance createDirectoryIn:aDirectory. |
3842 | 722 |
^ instance |
723 |
! |
|
724 |
||
5961 | 725 |
createDirectoryIn:aDirectory initialAnswer:defaultAnswer |
726 |
||
727 |
|instance| |
|
728 |
||
729 |
instance := self new. |
|
730 |
instance createDirectoryIn:aDirectory initialAnswer:defaultAnswer. |
|
731 |
^ instance |
|
732 |
! |
|
733 |
||
3863 | 734 |
createFileIn:aFile |
3842 | 735 |
|
736 |
|instance| |
|
737 |
||
738 |
instance := self new. |
|
3863 | 739 |
instance createFileIn:aFile. |
3842 | 740 |
^ instance |
3877 | 741 |
! |
742 |
||
743 |
createHardLinkIn:aFile |
|
744 |
"create an new hard link in a files directory" |
|
745 |
||
6151 | 746 |
^ self createLinkIn:aFile soft:false |
747 |
! |
|
748 |
||
749 |
createLinkIn:aFile soft:soft |
|
750 |
"create an new soft or hard link in a files directory" |
|
751 |
||
3877 | 752 |
|instance| |
753 |
||
754 |
instance := self new. |
|
6151 | 755 |
instance createLinkIn:aFile soft:soft. |
3877 | 756 |
^ instance |
757 |
! |
|
758 |
||
759 |
createSoftLinkIn:aFile |
|
760 |
"create an new soft link in a files directory" |
|
761 |
||
6151 | 762 |
^ self createLinkIn:aFile soft:true |
3842 | 763 |
! ! |
764 |
||
3863 | 765 |
!FileOperation::Create methodsFor:'accessing'! |
766 |
||
767 |
createdFile |
|
768 |
^ createdFile |
|
769 |
! |
|
770 |
||
771 |
createdFile:something |
|
772 |
createdFile := something. |
|
3842 | 773 |
! ! |
774 |
||
775 |
!FileOperation::Create methodsFor:'actions'! |
|
776 |
||
3863 | 777 |
createDirectoryIn:startDirectory |
4522 | 778 |
|defaultDirectory| |
3863 | 779 |
|
4522 | 780 |
"/ stupid - that one already exists |
781 |
"/ LastCreatedDirectory notNil ifTrue:[ |
|
782 |
"/ defaultDirectory := LastCreatedDirectory baseName. |
|
783 |
"/ ]. |
|
7637 | 784 |
|
4522 | 785 |
^ self createDirectoryIn:startDirectory initialAnswer:defaultDirectory |
786 |
! |
|
787 |
||
6373 | 788 |
createHardLinkIn:aFile |
789 |
"create an new hard link in a files directory" |
|
790 |
||
791 |
self createLinkIn:aFile soft:false. |
|
792 |
! |
|
793 |
||
794 |
createSoftLinkIn:aFile |
|
795 |
"create an new soft link in a files directory" |
|
796 |
||
797 |
self createLinkIn:aFile soft:true. |
|
798 |
! |
|
799 |
||
800 |
operationError:msg |
|
801 |
self result:false. |
|
802 |
Dialog warn:msg. |
|
803 |
self errorString:msg. |
|
804 |
! ! |
|
805 |
||
806 |
!FileOperation::Create methodsFor:'actions-basic'! |
|
807 |
||
4522 | 808 |
createDirectoryIn:startDirectory initialAnswer:initialAnswerArg |
4584 | 809 |
|resources initialAnswer msg startBaseName newName newDir| |
810 |
||
811 |
resources := AbstractFileBrowser classResources. |
|
3842 | 812 |
|
3863 | 813 |
startBaseName := startDirectory baseName. |
4522 | 814 |
initialAnswer := initialAnswerArg. |
815 |
(startDirectory construct:initialAnswer) exists ifTrue:[ |
|
7637 | 816 |
initialAnswer := nil. |
3863 | 817 |
]. |
7084 | 818 |
newName := Dialog |
7637 | 819 |
request:(resources string:'Create New Directory in %1:' with:startBaseName allBold) |
820 |
initialAnswer:initialAnswer |
|
821 |
okLabel:(resources string:'Create') |
|
822 |
title:(resources string:'Create Directory') |
|
823 |
onCancel:[ |
|
824 |
self result:false. |
|
825 |
^ self |
|
826 |
]. |
|
3863 | 827 |
newName isEmpty ifTrue:[ |
7637 | 828 |
self result:false. |
829 |
^ self |
|
3863 | 830 |
]. |
4522 | 831 |
newDir := startDirectory construct:newName. |
832 |
newDir exists ifTrue:[ |
|
7637 | 833 |
Dialog warn:(newName, ' already exists.'). |
834 |
result := false. |
|
835 |
^ self |
|
3842 | 836 |
]. |
837 |
||
4522 | 838 |
newDir makeDirectory ifFalse:[ |
7637 | 839 |
msg := errorString := ('cannot create directory '', newName,'' !!') , '(', (OperatingSystem lastErrorString) , ')'. |
840 |
errorString := msg. |
|
841 |
Dialog warn:errorString. |
|
842 |
result := false. |
|
843 |
^ self |
|
3842 | 844 |
]. |
4522 | 845 |
self createdFile:newDir. |
846 |
LastCreatedDirectory := newDir. |
|
3842 | 847 |
result := true. |
7084 | 848 |
|
849 |
"Modified: / 05-09-2006 / 11:52:48 / cg" |
|
3842 | 850 |
! |
851 |
||
3863 | 852 |
createFileIn:aFile |
3842 | 853 |
"create an empty file" |
854 |
||
4584 | 855 |
|resources aStream msg file directory newName defaultFile| |
856 |
||
857 |
resources := AbstractFileBrowser classResources. |
|
3842 | 858 |
|
3863 | 859 |
aFile isDirectory ifTrue:[ |
7637 | 860 |
directory := aFile |
3863 | 861 |
] ifFalse:[ |
7637 | 862 |
directory := aFile directory. |
863 |
file := aFile |
|
3863 | 864 |
]. |
865 |
LastCreatedFile isNil ifTrue:[ |
|
7637 | 866 |
defaultFile := aFile baseName. |
3863 | 867 |
] ifFalse:[ |
7637 | 868 |
defaultFile := LastCreatedFile baseName. |
3842 | 869 |
]. |
3863 | 870 |
newName := Dialog |
7637 | 871 |
request:(resources string:'Create New File in %1:' with:directory baseName allBold) |
872 |
initialAnswer:defaultFile |
|
873 |
okLabel:(resources string:'Create') |
|
874 |
title:(resources string:'Create File') |
|
875 |
onCancel:[ |
|
876 |
self result:false. |
|
877 |
^ self |
|
878 |
]. |
|
3863 | 879 |
newName isEmpty ifTrue:[ |
7637 | 880 |
self result:false. |
3842 | 881 |
] ifFalse:[ |
7637 | 882 |
| newFile | |
883 |
newFile := directory construct:newName. |
|
884 |
newFile exists ifTrue:[ |
|
885 |
(Dialog |
|
886 |
confirm:(newName, ' already exists truncate ?') |
|
887 |
yesLabel:('Truncate') |
|
888 |
noLabel:('Cancel')) |
|
889 |
ifFalse:[ |
|
890 |
self result:false. |
|
891 |
^ self |
|
892 |
]. |
|
893 |
]. |
|
894 |
FileStream openErrorSignal handle:[:ex| |
|
895 |
msg := ('Cannot create file '', newName,'' !!') , '(' , (FileStream lastErrorString) , ')'. |
|
896 |
errorString := msg. |
|
897 |
self result:false. |
|
898 |
^ Dialog warn:errorString |
|
899 |
] do:[ |
|
900 |
aStream := newFile newReadWriteStream. |
|
901 |
]. |
|
902 |
aStream close. |
|
903 |
self createdFile:newFile. |
|
904 |
LastCreatedFile := newFile. |
|
905 |
self result:true. |
|
3842 | 906 |
]. |
3877 | 907 |
! |
908 |
||
909 |
createLinkIn:aFile soft:symbolic |
|
4788 | 910 |
"ask for the link target; |
911 |
then, create an new soft or hard link in aFile's directory" |
|
3877 | 912 |
|
4788 | 913 |
|resources newPath oldPath box string if1 if2| |
4584 | 914 |
|
915 |
resources := AbstractFileBrowser classResources. |
|
3877 | 916 |
|
10383 | 917 |
newPath := (aFile isDirectory ifTrue:[ aFile ] ifFalse:[ aFile directory ]) asValue. |
918 |
oldPath := aFile asValue. |
|
3877 | 919 |
|
920 |
box := Dialog new. |
|
4585 | 921 |
box label:'Create Link'. |
922 |
||
923 |
string := 'Create ', (symbolic ifTrue:['Symbolic'] ifFalse:['Hard']) ,' Link from:'. |
|
4584 | 924 |
(box addTextLabel:(resources string:string)) adjust:#left. |
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
925 |
if1 := box addFilenameInputFieldOn:oldPath in:nil tabable:true. |
4584 | 926 |
(box addTextLabel:(resources string:'to:')) adjust:#left. |
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
927 |
if2 := box addFilenameInputFieldOn:newPath in:nil value tabable:true. |
3877 | 928 |
|
929 |
box addAbortAndOkButtons. |
|
930 |
||
6250
5b0673ccff1c
refactored intention revealing code:
Claus Gittinger <cg@exept.de>
parents:
6185
diff
changeset
|
931 |
aFile isDirectory ifFalse:[ |
10383 | 932 |
box focusOnField:if1. |
3877 | 933 |
]. |
934 |
box showAtPointer. |
|
935 |
||
4788 | 936 |
box accepted ifFalse:[ |
10383 | 937 |
self result:false. |
4788 | 938 |
] ifTrue:[ |
10383 | 939 |
self doCreateLinkFrom:(oldPath value) to:(newPath value) soft:symbolic. |
3877 | 940 |
]. |
10383 | 941 |
|
942 |
"Modified: / 24-07-2011 / 08:24:14 / cg" |
|
3877 | 943 |
! |
944 |
||
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
945 |
doCreateLinkFrom:oldPath to:newPathArg soft:symbolic |
4788 | 946 |
"actually create a soft or hard link" |
947 |
||
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
948 |
|resources err newPath newPathFile oldPathFile| |
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
949 |
|
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
950 |
newPath := newPathArg. |
4788 | 951 |
|
952 |
resources := AbstractFileBrowser classResources. |
|
953 |
||
954 |
(oldPath size == 0) ifTrue:[ |
|
7637 | 955 |
self operationError:'Missing source'. |
956 |
^ self. |
|
4788 | 957 |
]. |
958 |
(newPath size == 0) ifTrue:[ |
|
7637 | 959 |
self operationError:'Missing link name (target)'. |
960 |
^ self. |
|
4788 | 961 |
]. |
962 |
||
963 |
newPathFile := newPath asFilename. |
|
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
964 |
oldPathFile := oldPath asFilename. |
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
965 |
|
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
966 |
newPathFile exists ifTrue:[ |
7637 | 967 |
newPathFile isDirectory ifTrue:[ |
968 |
newPathFile := newPathFile construct:(oldPathFile baseName). |
|
969 |
newPath := newPathFile name. |
|
970 |
]. |
|
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
971 |
]. |
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
972 |
|
4788 | 973 |
newPathFile exists ifTrue:[ |
7637 | 974 |
self operationError:(resources string:'%1 already exists' with:newPath allBold). |
975 |
^ self. |
|
4788 | 976 |
]. |
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
977 |
oldPathFile exists ifFalse:[ |
7637 | 978 |
symbolic ifTrue:[ |
979 |
oldPathFile isAbsolute ifTrue:[ |
|
980 |
self operationError:(resources string:'%1 does not exist' with:oldPath allBold). |
|
981 |
^ self. |
|
982 |
]. |
|
983 |
(newPathFile directory construct:oldPath) exists ifFalse:[ |
|
984 |
Dialog warn:(resources string:'%1 does not exist (Warning only)' with:oldPath allBold). |
|
985 |
]. |
|
986 |
] ifFalse:[ |
|
987 |
self operationError:(resources string:'%1 does not exist' with:oldPath allBold). |
|
988 |
^ self. |
|
989 |
]. |
|
4788 | 990 |
]. |
991 |
((symbolic not) and:[oldPathFile isDirectory]) ifTrue:[ |
|
7637 | 992 |
self operationError:(resources string:'%1 is a directory' with:oldPath allBold). |
993 |
^ self. |
|
4788 | 994 |
]. |
995 |
ErrorSignal handle:[:ex | |
|
7637 | 996 |
err := ex errorString. |
997 |
self operationError:err. |
|
4788 | 998 |
] do:[ |
7637 | 999 |
symbolic ifTrue:[ |
1000 |
OperatingSystem createSymbolicLinkFrom:oldPath to:newPath. |
|
1001 |
] ifFalse:[ |
|
1002 |
OperatingSystem createHardLinkFrom:oldPath to:newPath |
|
1003 |
]. |
|
1004 |
self createdFile:newPathFile. |
|
1005 |
self result:true. |
|
4788 | 1006 |
]. |
3842 | 1007 |
! ! |
1008 |
||
1009 |
!FileOperation::Delete class methodsFor:'actions'! |
|
1010 |
||
1011 |
deleteFile:aFileOrDirectory |
|
6168 | 1012 |
"delete aFileOrDirectory" |
3842 | 1013 |
|
1014 |
|instance| |
|
1015 |
||
1016 |
instance := self new. |
|
1017 |
instance deleteFile:aFileOrDirectory. |
|
1018 |
^ instance |
|
1019 |
! |
|
1020 |
||
6168 | 1021 |
deleteFiles:aCollectionOfFiles |
1022 |
^ self deleteFiles:aCollectionOfFiles confirm:true |
|
5081 | 1023 |
! |
1024 |
||
6168 | 1025 |
deleteFiles:aCollectionOfFiles confirm:confirm |
1026 |
"delete aCollectionOfFiles" |
|
3842 | 1027 |
|
1028 |
|instance| |
|
1029 |
||
1030 |
instance := self new. |
|
6168 | 1031 |
instance deleteFiles:aCollectionOfFiles confirm:confirm. |
3842 | 1032 |
^ instance |
1033 |
! ! |
|
1034 |
||
1035 |
!FileOperation::Delete methodsFor:'actions'! |
|
1036 |
||
6373 | 1037 |
deleteFiles:colOfFiles |
1038 |
^ self deleteFiles:colOfFiles confirm:true. |
|
1039 |
! |
|
1040 |
||
1041 |
eraseFilesContentsBeforeRemoving:file |
|
1042 |
"intentionally left blank" |
|
1043 |
! ! |
|
1044 |
||
1045 |
!FileOperation::Delete methodsFor:'actions-basic'! |
|
1046 |
||
3842 | 1047 |
deleteFile:aFileOrDirectory |
1048 |
| file isDirectory | |
|
1049 |
||
1050 |
aFileOrDirectory notNil ifTrue:[ |
|
7637 | 1051 |
file := aFileOrDirectory asFilename. |
3842 | 1052 |
|
7637 | 1053 |
isDirectory := file isDirectory. |
3842 | 1054 |
|
7637 | 1055 |
Error handle:[:ex| |
1056 |
"was not able to remove it" |
|
1057 |
Dialog warn:(ex description). |
|
1058 |
self errorString:(ex description). |
|
1059 |
result := false. |
|
1060 |
^ self. |
|
1061 |
] do:[ |
|
1062 |
isDirectory ifTrue:[ |
|
1063 |
file recursiveRemove |
|
1064 |
] ifFalse:[ |
|
1065 |
self eraseFilesContentsBeforeRemoving:file. |
|
1066 |
file remove |
|
1067 |
]. |
|
1068 |
]. |
|
1069 |
"/ flush parent directory or directory |
|
3842 | 1070 |
]. |
4006
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
1071 |
DirectoryContents flushCachedDirectoryFor:(file directory). |
3842 | 1072 |
result := true. |
5746
a505fc181e11
warning string (backslash in pc-filename)
Claus Gittinger <cg@exept.de>
parents:
5687
diff
changeset
|
1073 |
|
a505fc181e11
warning string (backslash in pc-filename)
Claus Gittinger <cg@exept.de>
parents:
5687
diff
changeset
|
1074 |
"Modified: / 17-03-2004 / 12:42:02 / cg" |
3842 | 1075 |
! |
1076 |
||
5081 | 1077 |
deleteFiles:colOfFiles confirm:confirm |
9576 | 1078 |
|resources answer nFilesToDelete ask labels values fileTypeString msg lbls vals dontAskForNonEmptyDirectory |
1079 |
nFilesDone| |
|
5081 | 1080 |
|
7051 | 1081 |
dontAskForNonEmptyDirectory := false. |
5081 | 1082 |
ask := confirm. |
4584 | 1083 |
resources := AbstractFileBrowser classResources. |
3842 | 1084 |
|
4701 | 1085 |
nFilesToDelete := colOfFiles size. |
9576 | 1086 |
nFilesDone := 0. |
4408
8c0c80b68ae7
ask again, if dir is not empty
Claus Gittinger <cg@exept.de>
parents:
4395
diff
changeset
|
1087 |
colOfFiles do:[:filenameOrString | |
9576 | 1088 |
|filename doDelete skip| |
4665
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
1089 |
|
9576 | 1090 |
filename := filenameOrString asFilename. |
1091 |
skip := false. |
|
1092 |
fileTypeString := ''. |
|
1093 |
filename isSymbolicLink ifTrue:[ |
|
1094 |
fileTypeString := 'symbolic link '. |
|
1095 |
] ifFalse:[ |
|
1096 |
filename exists ifFalse:[ |
|
1097 |
(Dialog |
|
1098 |
confirm:('%1 does not exist.' bindWith:filename asString allBold) |
|
1099 |
yesLabel:(resources string:'Proceed') |
|
1100 |
noLabel:(resources string:'Cancel')) |
|
1101 |
ifFalse:[ |
|
1102 |
^ self. |
|
1103 |
]. |
|
1104 |
skip := true. |
|
1105 |
] |
|
1106 |
]. |
|
1107 |
skip ifFalse:[ |
|
1108 |
ask ifTrue:[ |
|
1109 |
nFilesToDelete = 1 ifTrue:[ |
|
1110 |
labels := #('No' 'Yes'). |
|
1111 |
values := #(#no #yes). |
|
1112 |
] ifFalse:[ |
|
1113 |
labels := #('Cancel' 'No' 'Yes' 'Yes to All' ). |
|
1114 |
values := #(#cancel #no #yes #yesToAll). |
|
1115 |
]. |
|
1116 |
msg := self isErase ifTrue:'Really erase' ifFalse:'Really delete'. |
|
1117 |
msg := msg , |
|
1118 |
(nFilesToDelete = 1 |
|
1119 |
ifTrue:'\\%1%2 ?' |
|
1120 |
ifFalse:'\\%1%2 \\(%3 files alltogether)'). |
|
1121 |
answer := Dialog |
|
1122 |
confirmWithCancel:(resources |
|
1123 |
stringWithCRs:msg |
|
1124 |
with:fileTypeString |
|
1125 |
with:(filename asString allBold) |
|
1126 |
with:nFilesToDelete) |
|
1127 |
labels:(resources array:labels) |
|
1128 |
values:values |
|
1129 |
default:(values indexOf:#yes). |
|
1130 |
] ifFalse:[ |
|
1131 |
answer := #yesToAll. |
|
1132 |
]. |
|
5673 | 1133 |
|
9576 | 1134 |
answer == #cancel ifTrue:[ |
1135 |
^ self. |
|
1136 |
]. |
|
5673 | 1137 |
|
9576 | 1138 |
answer == #yesToAll ifTrue:[ |
1139 |
ask := false. |
|
1140 |
answer := #yes. |
|
1141 |
]. |
|
4408
8c0c80b68ae7
ask again, if dir is not empty
Claus Gittinger <cg@exept.de>
parents:
4395
diff
changeset
|
1142 |
|
9576 | 1143 |
answer == #yes ifTrue:[ |
1144 |
doDelete := true. |
|
1145 |
filename isSymbolicLink ifFalse:[ |
|
1146 |
dontAskForNonEmptyDirectory ifFalse:[ |
|
1147 |
filename isNonEmptyDirectory ifTrue:[ |
|
1148 |
colOfFiles size == 1 ifTrue:[ |
|
1149 |
lbls := #('Cancel' 'Remove'). |
|
1150 |
vals := #(false true). |
|
1151 |
] ifFalse:[ |
|
1152 |
lbls := #('Cancel All' 'Keep' 'Remove' 'Remove All'). |
|
1153 |
vals := #(nil false true #removeAll). |
|
1154 |
]. |
|
1155 |
doDelete := Dialog |
|
1156 |
confirmWithCancel:(resources |
|
1157 |
stringWithCRs:'Directory ''%1'' is not empty\remove anyway ?' |
|
1158 |
with:filename pathName allBold) |
|
1159 |
labels:( resources array:lbls ) |
|
1160 |
values:vals |
|
1161 |
default:(vals indexOf:true). |
|
1162 |
doDelete == nil ifTrue:[ |
|
1163 |
^ self |
|
1164 |
]. |
|
1165 |
doDelete == #removeAll ifTrue:[ |
|
1166 |
dontAskForNonEmptyDirectory := true. |
|
1167 |
doDelete := true. |
|
1168 |
]. |
|
1169 |
]. |
|
1170 |
]. |
|
1171 |
]. |
|
1172 |
doDelete ifTrue:[ |
|
1173 |
ProgressNotification progressPercentage:(nFilesDone / nFilesToDelete)*100. |
|
1174 |
self deleteFile:filename. |
|
1175 |
nFilesDone := nFilesDone + 1. |
|
1176 |
ProgressNotification progressPercentage:(nFilesDone / nFilesToDelete)*100. |
|
1177 |
] |
|
1178 |
]. |
|
1179 |
]. |
|
3842 | 1180 |
]. |
7051 | 1181 |
|
9576 | 1182 |
"Modified: / 11-10-2010 / 13:08:20 / cg" |
6168 | 1183 |
! ! |
1184 |
||
6373 | 1185 |
!FileOperation::Erase methodsFor:'actions-basic'! |
6168 | 1186 |
|
1187 |
eraseFilesContentsBeforeRemoving:file |
|
7634 | 1188 |
"fill file with zeros (to be really erased from the disk). |
1189 |
We use this, if the file contains security relevant data (such as crypto-keys)" |
|
6168 | 1190 |
|
1191 |
|writeStream fileSize remaining buffer bufferSize nWritten| |
|
1192 |
||
1193 |
fileSize := file fileSize. |
|
1194 |
writeStream := file asFilename readWriteStream. |
|
8293 | 1195 |
[ |
1196 |
remaining := fileSize. |
|
1197 |
bufferSize := 8192. |
|
1198 |
buffer := ByteArray new:bufferSize. |
|
6168 | 1199 |
|
8293 | 1200 |
[remaining > 0] whileTrue:[ |
1201 |
nWritten := writeStream |
|
1202 |
nextPutBytes:(bufferSize min:remaining) |
|
1203 |
from:buffer. |
|
1204 |
remaining := remaining - nWritten. |
|
1205 |
ProgressNotification progressPercentage:(1 - (remaining / fileSize))*100. |
|
1206 |
]. |
|
1207 |
] ensure:[ |
|
1208 |
writeStream close. |
|
6168 | 1209 |
]. |
7634 | 1210 |
|
1211 |
"Modified: / 07-02-2007 / 18:20:21 / cg" |
|
3842 | 1212 |
! ! |
1213 |
||
6285 | 1214 |
!FileOperation::Erase methodsFor:'queries'! |
1215 |
||
1216 |
isErase |
|
1217 |
^ true |
|
1218 |
! ! |
|
1219 |
||
3842 | 1220 |
!FileOperation::Move class methodsFor:'actions'! |
1221 |
||
1222 |
moveFile:aSourceFile to:aDestFile |
|
1223 |
|instance| |
|
1224 |
||
1225 |
instance := self new. |
|
1226 |
instance moveFile:aSourceFile to:aDestFile. |
|
1227 |
^ instance |
|
1228 |
! |
|
1229 |
||
1230 |
moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning |
|
1231 |
|instance| |
|
1232 |
||
1233 |
instance := self new. |
|
1234 |
instance moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning. |
|
1235 |
^ instance |
|
1236 |
! |
|
1237 |
||
1238 |
moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:move |
|
1239 |
|instance| |
|
1240 |
||
1241 |
instance := self new. |
|
1242 |
instance moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:move. |
|
1243 |
^ instance |
|
1244 |
! |
|
1245 |
||
1246 |
moveFiles:aColOfSourceFiles to:aDirectory |
|
1247 |
|instance| |
|
1248 |
||
1249 |
instance := self new. |
|
1250 |
instance moveFiles:aColOfSourceFiles to:aDirectory. |
|
1251 |
^ instance |
|
1252 |
! |
|
1253 |
||
1254 |
moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning |
|
1255 |
|instance| |
|
1256 |
||
1257 |
instance := self new. |
|
1258 |
instance moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning. |
|
1259 |
^ instance |
|
1260 |
! |
|
1261 |
||
1262 |
moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:move |
|
1263 |
|instance| |
|
1264 |
||
1265 |
instance := self new. |
|
1266 |
instance moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:move. |
|
1267 |
^ instance |
|
1268 |
! ! |
|
1269 |
||
1270 |
!FileOperation::Move methodsFor:'accessing'! |
|
1271 |
||
1272 |
colOfMovedFiles |
|
6373 | 1273 |
"obsolete - bad name" |
1274 |
||
1275 |
^ self collectionOfMovedFiles |
|
1276 |
! |
|
1277 |
||
1278 |
collectionOfMovedFiles |
|
6374 | 1279 |
movedFiles isNil ifTrue:[ |
7637 | 1280 |
movedFiles := OrderedCollection new. |
3842 | 1281 |
]. |
6374 | 1282 |
^ movedFiles |
3842 | 1283 |
! ! |
1284 |
||
1285 |
!FileOperation::Move methodsFor:'actions'! |
|
1286 |
||
1287 |
moveFile:aSourceFile to:aDestFile |
|
1288 |
||
1289 |
^ self moveFile:aSourceFile to:aDestFile withOverWriteWarning:true. |
|
1290 |
! |
|
1291 |
||
1292 |
moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning |
|
1293 |
||
1294 |
^ self moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:true |
|
1295 |
! |
|
1296 |
||
6373 | 1297 |
moveFiles:aColOfSourceFiles to:aDirectory |
1298 |
||
1299 |
^ self moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:true |
|
1300 |
! |
|
1301 |
||
1302 |
moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning |
|
1303 |
||
1304 |
^ self moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:true |
|
1305 |
! ! |
|
1306 |
||
1307 |
!FileOperation::Move methodsFor:'actions-basic'! |
|
1308 |
||
3842 | 1309 |
moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:move |
1310 |
||
5862 | 1311 |
|newFile fileString targetDirectory targetIsDirectory suffix doMove| |
3842 | 1312 |
|
1313 |
targetIsDirectory := aDestFile isDirectory. |
|
1314 |
targetIsDirectory ifTrue:[ |
|
8361 | 1315 |
targetDirectory := aDestFile. |
1316 |
newFile := aDestFile construct:(aSourceFile baseName). |
|
3842 | 1317 |
] ifFalse:[ |
8361 | 1318 |
targetDirectory := aDestFile directory. |
1319 |
newFile := aDestFile. |
|
3842 | 1320 |
]. |
1321 |
"/ do not copy if destination directory doest exist. |
|
6250
5b0673ccff1c
refactored intention revealing code:
Claus Gittinger <cg@exept.de>
parents:
6185
diff
changeset
|
1322 |
targetDirectory exists ifFalse:[ |
8361 | 1323 |
Dialog warn:'Cannot move to non-existing directory ', targetDirectory asString. |
1324 |
result := false. |
|
1325 |
^ self |
|
3842 | 1326 |
]. |
1327 |
(newFile exists) ifTrue:[ |
|
8361 | 1328 |
((newFile asString = aSourceFile asString) and:[move]) ifTrue:[ |
1329 |
[newFile exists] whileTrue:[ |
|
1330 |
suffix := newFile suffix. |
|
1331 |
fileString := newFile baseName withoutSuffix, self class suffixForCopyOverExistingFile, '.', suffix. |
|
1332 |
newFile := targetDirectory construct:fileString. |
|
1333 |
]. |
|
1334 |
] ifFalse:[ |
|
1335 |
overWriteWarning ifTrue:[ |
|
1336 |
doMove := self fileExistsDialogForNewFile:newFile oldFile:aSourceFile withCancel:false withRemoveIfSame:true. |
|
1337 |
doMove == #removeSource ifTrue:[ |
|
8397
921162bfd791
Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents:
8361
diff
changeset
|
1338 |
self shouldImplement. |
8361 | 1339 |
result := false. |
1340 |
^ self. |
|
1341 |
]. |
|
1342 |
doMove == #removeDestination ifTrue:[ |
|
8397
921162bfd791
Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents:
8361
diff
changeset
|
1343 |
self shouldImplement. |
8361 | 1344 |
result := false. |
1345 |
^ self. |
|
1346 |
]. |
|
1347 |
doMove == true ifFalse:[ |
|
1348 |
result := false. |
|
1349 |
^ self. |
|
1350 |
]. |
|
5862 | 1351 |
|
8361 | 1352 |
] ifFalse:[ |
1353 |
result := false. |
|
1354 |
^ self. |
|
1355 |
] |
|
1356 |
]. |
|
3842 | 1357 |
]. |
1358 |
Error handle:[:ex| |
|
8361 | 1359 |
"was not able to copy it" |
13703 | 1360 |
WarningBox warn:'Error in move file operation: ', ex description. |
1361 |
self errorString:('Error in move file operation- ', ex description asString). |
|
8361 | 1362 |
result := false. |
1363 |
^ self |
|
3842 | 1364 |
] do:[ |
8361 | 1365 |
aSourceFile moveTo:newFile. |
3842 | 1366 |
]. |
4006
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
1367 |
DirectoryContents flushCachedDirectoryFor:(aSourceFile directory). |
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
1368 |
result := true. |
3842 | 1369 |
! |
1370 |
||
1371 |
moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:move |
|
1372 |
||
5862 | 1373 |
|newFile suffix fileString doMove doRemoveSource doRemoveDestination| |
3842 | 1374 |
|
5854
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1375 |
aDirectory exists ifFalse:[ |
11444 | 1376 |
(Dialog confirm:(FileBrowser classResources |
1377 |
stringWithCRs:'Non-existing directory "%1" .\Create ?' |
|
1378 |
with:aDirectory asString allBold)) ifFalse:[ |
|
1379 |
result := false. |
|
1380 |
^ self |
|
1381 |
]. |
|
1382 |
aDirectory makeDirectory. |
|
1383 |
aDirectory exists ifFalse:[ |
|
1384 |
Dialog warn:(FileBrowser classResources |
|
1385 |
stringWithCRs:'Cannot create directory "%1" !!\Create ?.' |
|
1386 |
with:aDirectory asString allBold). |
|
1387 |
result := false. |
|
1388 |
^ self |
|
1389 |
] |
|
3842 | 1390 |
]. |
5788 | 1391 |
(aDirectory isDirectory) ifFalse:[ |
11444 | 1392 |
Dialog warn:('Destination %1 is not a directory.' bindWith:aDirectory asString allBold). |
1393 |
result := false. |
|
1394 |
^ self |
|
3842 | 1395 |
]. |
1396 |
aColOfSourceFiles do:[: filename | |
|
11444 | 1397 |
newFile := aDirectory construct:filename baseName. |
5790 | 1398 |
|
11444 | 1399 |
doMove := true. |
1400 |
doRemoveSource := false. |
|
1401 |
doRemoveDestination := false. |
|
5862 | 1402 |
|
11444 | 1403 |
(newFile exists) ifTrue:[ |
1404 |
((newFile asString = filename asString) and:[move]) ifTrue:[ |
|
1405 |
[newFile exists] whileTrue:[ |
|
1406 |
suffix := newFile suffix. |
|
1407 |
fileString := newFile withoutSuffix baseName , self class suffixForCopyOverExistingFile, '.', suffix. |
|
1408 |
newFile := aDirectory construct:fileString. |
|
1409 |
]. |
|
1410 |
] ifFalse:[ |
|
1411 |
overWriteWarning ifTrue:[ |
|
1412 |
(doMove := actionForAll) isNil ifTrue:[ |
|
1413 |
doMove := self |
|
1414 |
fileExistsDialogForNewFile:newFile oldFile:filename |
|
1415 |
withCancel:(aColOfSourceFiles size > 1) withRemoveIfSame:true |
|
1416 |
withAllAction: true. |
|
1417 |
doMove isNil ifTrue:[ "/ cancel |
|
1418 |
result := false. |
|
1419 |
^ self. |
|
1420 |
]. |
|
1421 |
]. |
|
1422 |
(doMove == #removeSource) ifTrue:[ |
|
1423 |
doRemoveSource := true. |
|
1424 |
doMove := false |
|
1425 |
] ifFalse:[ |
|
1426 |
(doMove == #removeDestination) ifTrue:[ |
|
1427 |
doRemoveDestination := true. |
|
1428 |
doMove := false |
|
1429 |
] |
|
1430 |
] |
|
1431 |
] |
|
1432 |
]. |
|
1433 |
]. |
|
4522 | 1434 |
|
11444 | 1435 |
(doMove or:[doRemoveSource or:[doRemoveDestination]]) ifTrue:[ |
1436 |
Error handle:[:ex| |
|
1437 |
"was not able to copy it" |
|
1438 |
|descriptionString| |
|
5862 | 1439 |
|
11444 | 1440 |
result := false. |
1441 |
descriptionString := ex description asString. |
|
1442 |
self errorString:(' Error in Move-File Operation:', descriptionString). |
|
1443 |
( Dialog |
|
1444 |
confirm:(' Error in Move-File Operation: ', descriptionString) |
|
1445 |
title:'Move' |
|
1446 |
yesLabel:'Continue' |
|
1447 |
noLabel:'Abort' |
|
1448 |
) ifFalse:[ |
|
1449 |
^ self. |
|
1450 |
]. |
|
1451 |
] do:[ |
|
1452 |
doRemoveSource ifTrue:[ |
|
1453 |
filename remove |
|
1454 |
] ifFalse:[ |
|
1455 |
doRemoveDestination ifTrue:[ |
|
1456 |
newFile remove |
|
1457 |
] ifFalse:[ |
|
1458 |
filename moveTo:newFile. |
|
1459 |
] |
|
1460 |
] |
|
1461 |
]. |
|
1462 |
self collectionOfMovedFiles add:filename |
|
1463 |
] |
|
3842 | 1464 |
]. |
4006
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
1465 |
DirectoryContents flushCachedDirectoryFor:aDirectory. |
3842 | 1466 |
result := true. |
11444 | 1467 |
|
1468 |
"Modified: / 20-03-2012 / 11:53:35 / cg" |
|
3842 | 1469 |
! ! |
1470 |
||
1471 |
!FileOperation::Rename class methodsFor:'actions'! |
|
1472 |
||
1473 |
renameFile:oldFile to:newName |
|
1474 |
|instance| |
|
1475 |
||
1476 |
instance := self new. |
|
1477 |
instance renameFile:oldFile to:newName. |
|
1478 |
^ instance |
|
1479 |
! |
|
1480 |
||
7637 | 1481 |
renameFiles:aColOfFiles |
3842 | 1482 |
|instance| |
1483 |
||
1484 |
instance := self new. |
|
1485 |
instance renameFiles:aColOfFiles. |
|
1486 |
^ instance |
|
1487 |
! ! |
|
1488 |
||
1489 |
!FileOperation::Rename methodsFor:'accessing'! |
|
1490 |
||
1491 |
renamedFiles |
|
1492 |
renamedFiles isNil ifTrue:[ |
|
7637 | 1493 |
renamedFiles := OrderedCollection new. |
3842 | 1494 |
]. |
1495 |
^ renamedFiles |
|
1496 |
! ! |
|
1497 |
||
6373 | 1498 |
!FileOperation::Rename methodsFor:'actions-basic'! |
3842 | 1499 |
|
1500 |
renameFile:oldFile to:newName |
|
1501 |
"rename a file (or directory)" |
|
1502 |
||
7334
e0bd092badd1
care for same-name rename on OS which is not filename-case-sensitive
Claus Gittinger <cg@exept.de>
parents:
7084
diff
changeset
|
1503 |
|newFile msg resources sameFile| |
3842 | 1504 |
|
1505 |
(oldFile isNil or:[newName isNil]) ifTrue:[ |
|
12726 | 1506 |
result := false. |
1507 |
^ self. |
|
3842 | 1508 |
]. |
1509 |
(oldFile asString isBlank or:[newName isBlank]) ifTrue:[ |
|
12726 | 1510 |
result := false. |
1511 |
^ self. |
|
3842 | 1512 |
]. |
5656 | 1513 |
newName asFilename isAbsolute ifTrue:[ |
12726 | 1514 |
newFile := newName asFilename. |
5656 | 1515 |
] ifFalse:[ |
12726 | 1516 |
(oldFile baseName = newName) ifTrue:[ |
1517 |
result := false |
|
1518 |
]. |
|
1519 |
newFile := oldFile directory construct:newName. |
|
3842 | 1520 |
]. |
1521 |
||
5656 | 1522 |
oldFile pathName = newFile pathName ifTrue:[ |
12726 | 1523 |
^ self. |
4674
64a49fadc47e
do op if newName is same as old in a rename operation
Claus Gittinger <cg@exept.de>
parents:
4665
diff
changeset
|
1524 |
]. |
7334
e0bd092badd1
care for same-name rename on OS which is not filename-case-sensitive
Claus Gittinger <cg@exept.de>
parents:
7084
diff
changeset
|
1525 |
Filename isCaseSensitive ifFalse:[ |
12726 | 1526 |
sameFile := (oldFile pathName sameAs: newFile pathName) |
7334
e0bd092badd1
care for same-name rename on OS which is not filename-case-sensitive
Claus Gittinger <cg@exept.de>
parents:
7084
diff
changeset
|
1527 |
] ifTrue:[ |
12726 | 1528 |
sameFile := false |
7334
e0bd092badd1
care for same-name rename on OS which is not filename-case-sensitive
Claus Gittinger <cg@exept.de>
parents:
7084
diff
changeset
|
1529 |
]. |
4674
64a49fadc47e
do op if newName is same as old in a rename operation
Claus Gittinger <cg@exept.de>
parents:
4665
diff
changeset
|
1530 |
|
5656 | 1531 |
resources := Dialog classResources. |
1532 |
||
12726 | 1533 |
OsError handle:[:ex| |
1534 |
msg := resources |
|
1535 |
stringWithCRs:'Cannot rename file %1 to %2 !!\\(%3)' |
|
1536 |
with:oldFile baseName |
|
1537 |
with:newName |
|
1538 |
with:(OperatingSystem lastErrorString). |
|
1539 |
Dialog warn:msg. |
|
1540 |
result := false. |
|
1541 |
^ self. |
|
3842 | 1542 |
] do:[ |
12726 | 1543 |
sameFile ifFalse:[ |
1544 |
newFile exists ifTrue:[ |
|
1545 |
(newFile sameContentsAs:oldFile) ifTrue:[ |
|
1546 |
msg := '%1 exists [with same contents] - rename (i.e. overwrite) anyway ?' |
|
1547 |
] ifFalse:[ |
|
1548 |
msg := '%1 exists - rename (i.e. overwrite) anyway ?' |
|
1549 |
]. |
|
1550 |
(Dialog confirmWithCancel:(resources string:msg with:newName allBold) default:false) ifFalse:[ |
|
1551 |
result := false. |
|
1552 |
^ self. |
|
1553 |
] |
|
1554 |
]. |
|
1555 |
]. |
|
1556 |
oldFile renameTo:newFile. |
|
1557 |
self renamedFiles add:newFile. |
|
3842 | 1558 |
]. |
1559 |
result := true. |
|
7334
e0bd092badd1
care for same-name rename on OS which is not filename-case-sensitive
Claus Gittinger <cg@exept.de>
parents:
7084
diff
changeset
|
1560 |
|
e0bd092badd1
care for same-name rename on OS which is not filename-case-sensitive
Claus Gittinger <cg@exept.de>
parents:
7084
diff
changeset
|
1561 |
"Modified: / 21-09-2006 / 18:32:12 / cg" |
3842 | 1562 |
! |
1563 |
||
7637 | 1564 |
renameFiles:aColOfFiles |
5827 | 1565 |
|resources queryBox b lastNewName lastOldName initialText oldName newName renameAll doRename| |
4584 | 1566 |
|
1567 |
resources := AbstractFileBrowser classResources. |
|
5827 | 1568 |
renameAll := false. |
3842 | 1569 |
|
1570 |
queryBox := FilenameEnterBox new. |
|
4584 | 1571 |
queryBox okText:(resources string:'Rename'). |
5827 | 1572 |
|
3842 | 1573 |
aColOfFiles size > 1 ifTrue:[ |
7637 | 1574 |
b := queryBox addAbortButtonLabelled:(resources string:'Cancel All'). |
1575 |
b action:[^ self]. |
|
1576 |
queryBox addButton:(Button label:(resources string:'Rename All') action:[renameAll := true. queryBox okPressed]) before:(queryBox okButton). |
|
3842 | 1577 |
]. |
5827 | 1578 |
aColOfFiles do:[:oldFile | |
7637 | 1579 |
oldName := oldFile baseName asString. |
1580 |
lastNewName notNil ifTrue:[ |
|
1581 |
initialText := FileBrowser goodRenameDefaultForFile:oldName lastOld:lastOldName lastNew:lastNewName. |
|
1582 |
]. |
|
1583 |
doRename := false. |
|
1584 |
(renameAll and:[initialText notNil]) ifTrue:[ |
|
1585 |
doRename := true. |
|
1586 |
newName := initialText. |
|
1587 |
] ifFalse:[ |
|
1588 |
queryBox title:(resources string:'Rename %1 to:' with:(oldName allBold)). |
|
1589 |
queryBox initialText:(initialText ? oldName). |
|
1590 |
queryBox action:[:newEnteredName | newName := newEnteredName. doRename := true.]. |
|
1591 |
queryBox show "showAtPointer". |
|
1592 |
"/ queryBox accepted ifFalse:[self halt]. |
|
1593 |
]. |
|
1594 |
doRename ifTrue:[ |
|
1595 |
(self renameFile:oldFile to:newName asString) ifTrue:[ |
|
1596 |
result := true |
|
1597 |
]. |
|
1598 |
lastOldName := oldName. |
|
1599 |
lastNewName := newName. |
|
1600 |
]. |
|
3842 | 1601 |
] |
1602 |
! ! |
|
1603 |
||
3841 | 1604 |
!FileOperation class methodsFor:'documentation'! |
1605 |
||
1606 |
version |
|
13703 | 1607 |
^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.93 2013-12-04 14:23:14 stefan Exp $' |
9501 | 1608 |
! |
1609 |
||
1610 |
version_CVS |
|
13703 | 1611 |
^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.93 2013-12-04 14:23:14 stefan Exp $' |
3841 | 1612 |
! ! |
12726 | 1613 |