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