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