Subversion Repositories Kolibri OS

Rev

Rev 485 | Rev 589 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
474 diamond 1
delete_file_worker:
2
; in: ecx=flags: 1=deleting directory
3
; out: eax=0 - OK, eax=1 - retry, eax=2 - skip, eax=-1 - cancel,
4
;      PF, ZF, CF and SF set accordingly to 'cmp eax,2' (or 'cmp al,2')
5
        push    ebx
6
        push    70
7
        pop     eax
8
        mov     ebx, delinfo
517 diamond 9
        int     0x40
474 diamond 10
        pop     ebx
11
        test    eax, eax
12
        jz      .ret
13
        cmp     [del_bSkipAll], 0
14
        jz      @f
15
        push    2
16
        pop     eax
17
        jmp     .ret
18
@@:
19
        push    execdata
20
        push    aCannotDeleteFolder
21
        test    cl, 1
22
        jnz     @f
23
        mov     dword [esp], aCannotDeleteFile
24
@@:
25
        call    get_error_msg
26
        push    eax
27
        mov     eax, esp
28
        push    DeleteErrorBtn
29
        push    4
30
        push    eax
31
        push    3
32
        push    -1
33
        push    -1
34
        push    aError
35
        call    SayErr
36
        add     esp, 3*4
37
        cmp     al, -1
38
        jz      @f
39
        inc     eax
40
        cmp     al, 4   ; "cancel" button
41
        jnz     @f
42
        or      eax, -1
43
@@:
44
        cmp     al, 3   ; "skip all" button
45
        jnz     .ret
46
        mov     [del_bSkipAll], 1
47
        dec     eax
48
.ret:
49
        cmp     al, 2
50
        ret
51
 
52
delete_file:
53
; in: eax->BDFE block
54
; out: CF and ZF not set <=> cancel job ("ja cancel_label")
55
        pushad
56
        mov     [del_dir_stack_ptr], del_dir_stack
57
        lea     esi, [ebp + panel1_dir - panel1_data]
58
        mov     edi, execdata
59
@@:
60
        lodsb
61
        test    al, al
62
        jz      @f
63
        stosb
64
        jmp     @b
65
@@:
66
        mov     esi, [esp+28]
67
        mov     ecx, esi
68
        add     esi, 40
69
        mov     al, '/'
70
        stosb
71
.l1:
72
        lodsb
73
        cmp     edi, execdataend
74
        jb      @f
75
        call    panels_OnKey.bigfilename
76
        popad
77
        ret
78
@@:
79
        stosb
80
        test    al, al
81
        jnz     .l1
82
        mov     ecx, [esp+28]
83
        test    byte [ecx], 10h
84
        jnz     .delete_dir
85
.retrydel:
86
        xor     ecx, ecx
87
        call    delete_file_worker
88
        jae     @f
89
        jp      .retrydel
90
@@:
91
        popad
92
        ret
93
 
94
.delete_dir:
95
; recursive delete of directory
96
        xor     ebp, ebp        ; ebp will contain number of undeletable items
97
.return_from_recursion:
98
        mov     ebx, dirinfo
99
        mov     [ebx+dirinfo.first-dirinfo], ebp
100
        mov     [ebx+dirinfo.size-dirinfo], del_dir_query_size
101
        mov     [ebx+dirinfo.dirdata-dirinfo], del_dir_query_area
102
        mov     [ebx+dirinfo.name-dirinfo], execdata
103
        push    70
104
        pop     eax
517 diamond 105
        int     0x40
474 diamond 106
; if we get read error, the best available action is try to delete directory itself
107
        test    eax, eax
108
        jz      @f
109
        cmp     eax, 6
110
        jnz     .do_delete_dir
111
@@:
112
; loop through a directory and delete items
113
        mov     edx, del_dir_query_area+32
114
        imul    ebx, 304
115
        add     ebx, edx
116
.delete_dir_entry_loop:
117
        cmp     edx, ebx
517 diamond 118
        jb      .do_delete_dir_entry
119
        cmp     ebx, del_dir_query_area+32+304*del_dir_query_size
120
        jnz     .delete_dir_entry_done
121
        jmp     .return_from_recursion
122
.do_delete_dir_entry:
474 diamond 123
; ignore special entries "." and ".."
124
        inc     ebp
125
        cmp     word [edx+40], '.'
126
        jz      .delete_dir_entry_continue
127
        cmp     word [edx+40], '..'
128
        jnz     @f
129
        cmp     byte [edx+42], 0
130
        jz      .delete_dir_entry_continue
131
@@:
132
        dec     ebp
133
        mov     esi, execdata
134
@@:
135
        lodsb
136
        test    al, al
137
        jnz     @b
138
        mov     byte [esi-1], '/'
139
        mov     edi, esi
140
        lea     esi, [edx+40]
141
@@:
142
        cmp     edi, execdataend
143
        jae     .fullname_big
144
        lodsb
145
        stosb
146
        test    al, al
147
        jnz     @b
148
        test    byte [edx], 10h
149
        jnz     .entry_is_folder
150
.retry2:
151
        xor     ecx, ecx
152
        call    delete_file_worker
153
        ja      .cancel
154
        jz      .skip
155
        jp      .retry2
156
        jmp     .restore_name
157
.entry_is_folder:
158
; allocate new item in directory stack
159
        mov     eax, [del_dir_stack_ptr]
160
        mov     [eax], ebp
161
        add     eax, 4
162
        mov     [del_dir_stack_ptr], eax
163
; do recursive deleting
164
        jmp     .delete_dir
165
.fullname_big:
166
; we will just ignore such files and continue - in real life this situation can not happen
167
        inc     ebp
168
        mov     esi, execdataend-1
169
        jmp     .do_restore_name
170
.skip:
171
        inc     ebp
172
.restore_name:
173
        mov     esi, execdata
174
@@:
175
        lodsb
176
        test    al, al
177
        jnz     @b
178
        dec     esi
179
        dec     esi
180
.do_restore_name:
517 diamond 181
        call    delete_last_name
474 diamond 182
.delete_dir_entry_continue:
183
        add     edx, 304
184
        jmp     .delete_dir_entry_loop
185
.delete_dir_entry_done:
186
.do_delete_dir:
187
        mov     cl, 1
188
        call    delete_file_worker
189
        ja      .cancel
190
        jz      @f
191
        jp      .delete_dir
192
@@:
193
; al=0 - OK, al=2 - skip this directory
194
; return to previous directory
195
; pop item from directory stack
196
        mov     ecx, [del_dir_stack_ptr]
197
        cmp     ecx, del_dir_stack
198
        jbe     .done
199
        sub     ecx, 4
200
        mov     [del_dir_stack_ptr], ecx
201
        mov     ebp, [ecx]
202
        cmp     al, 2
203
        sbb     ebp, -1
204
; restore prev directory name
205
        mov     esi, execdata
517 diamond 206
        call    delete_last_name_from_end
207
        jmp     .return_from_recursion
208
.done:
209
.cancel:
210
        mov     [dirinfo.first], 0      ; do not destroys flags
211
        popad
212
        ret
213
 
214
makedir:
215
; create directory with name from CopyDestEditBuf+12
216
; destroys eax
217
        push    ebx
218
        push    70
219
        pop     eax
220
        mov     ebx, mkdirinfo
221
        int     0x40
222
        pop     ebx
223
        test    eax, eax
224
        jz      .ret
225
        cmp     dword [esp+8], DeleteErrorBtn
226
        jnz     @f
227
        cmp     [copy_bSkipAll], 0
228
        jz      @f
229
        push    1
230
        pop     eax
231
        jmp     .ret
474 diamond 232
@@:
517 diamond 233
        push    dword CopyDestEditBuf+12
234
        push    dword aCannotMakeFolder
235
        call    get_error_msg
236
        push    eax
237
        mov     eax, esp
238
        push    dword [eax+20]
239
        push    dword [eax+16]
240
        push    eax
241
        push    3
242
        push    -1
243
        push    -1
244
        push    dword aError
245
        call    SayErr
246
        add     esp, 3*4
247
        test    eax, eax
248
        jz      makedir
249
.ret:
250
        ret     8
251
 
252
copy_file_worker:
253
; in: execdata = source name, CopyDestEditBuf+12 = destination name, edx = BDFE block for source
254
; out: CF and ZF not set <=> cancel job ("ja cancel_label")
255
; destroys eax,esi,edi
256
        push    CopyDestEditBuf+12+513
257
        cmp     [bDestIsFolder], 0
258
        jz      .noaddtoname
259
        mov     esi, CopyDestEditBuf+12
260
@@:
474 diamond 261
        lodsb
262
        test    al, al
263
        jnz     @b
517 diamond 264
        mov     byte [esi-1], '/'
265
        pop     edi
266
        push    esi
267
        mov     edi, esi
268
        lea     esi, [edx+40]
269
@@:
270
        cmp     edi, CopyDestEditBuf+12+513
271
        jae     .overflow
272
        lodsb
273
        stosb
274
        test    al, al
275
        jnz     @b
276
        jmp     .noaddtoname
277
.overflow:
278
.ret_zf:
279
        pop     esi
280
        and     byte [esi-1], 0         ; ZF=1
281
        ret
282
.noaddtoname:
283
; Íåëüçÿ ñêîïèðîâàòü ôàéë ïîâåðõ ñàìîãî ñåáÿ!
284
        mov     esi, execdata
285
        mov     edi, CopyDestEditBuf+12
286
        push    esi edi
287
        call    strcmpi
288
        pop     edi esi
289
        jnz     @f
290
        push    esi
291
        push    aCannotCopyToSelf
292
        mov     eax, esp
293
        push    ContinueBtn
294
        push    1
295
        push    eax
296
        push    2
297
        push    -1
298
        push    -1
299
        push    aError
300
        call    SayErr
301
        pop     eax
302
        pop     eax
303
        jmp     .ret_zf
304
@@:
305
; Ñîáñòâåííî, êîïèðóåì
306
; esi->source name, edi->destination name
307
        push    ebx
308
        mov     [writeinfo.code], 2
309
        mov     [writeinfo.name], edi
310
        and     dword [writeinfo.first], 0
311
        and     dword [writeinfo.first+4], 0
312
        mov     [writeinfo.data], copy_buffer
313
        mov     ebx, readinfo
314
        and     dword [ebx+readinfo.first-readinfo], 0
315
        and     dword [ebx+readinfo.first+4-readinfo], 0
316
        mov     [ebx+readinfo.size-readinfo], copy_buffer_size
317
        mov     [ebx+readinfo.data-readinfo], copy_buffer
318
        mov     [ebx+readinfo.name-readinfo], esi
319
.copyloop:
320
        mov     ebx, readinfo
321
        push    70
322
        pop     eax
323
        int     0x40
324
        test    eax, eax
325
        jz      .copyreadok
326
        cmp     eax, 6
327
        jz      .copyreadok
328
        cmp     [copy_bSkipAll2], 0
329
        jnz     .copyfailed_del2
330
        push    esi
331
        push    dword aCannotReadFile
332
        call    get_error_msg
333
        push    eax
334
        mov     eax, esp
335
        push    dword DeleteErrorBtn
336
        push    4
337
        push    eax
338
        push    3
339
        push    -1
340
        push    -1
341
        push    dword aError
342
        call    SayErr
343
        add     esp, 3*4
344
        test    eax, eax
345
        jz      .copyloop
346
        jmp     .copyfailed_parseuser
347
.copyreadok:
348
        add     dword [readinfo.first], ebx
349
        adc     dword [readinfo.first+4], 0
350
        mov     [writeinfo.size], ebx
351
        test    ebx, ebx
352
        jnz     .copywrite
353
        cmp     byte [writeinfo.code], 2
354
        jnz     .copydone
355
.copywrite:
356
        mov     ebx, writeinfo
357
        push    70
358
        pop     eax
359
        int     0x40
360
        test    eax, eax
361
        jz      .copywriteok
362
        cmp     [copy_bSkipAll2], 0
363
        jnz     .copyfailed_del2
364
        push    edi
365
        push    dword aCannotWriteFile
366
        call    get_error_msg
367
        push    eax
368
        mov     eax, esp
369
        push    dword DeleteErrorBtn
370
        push    4
371
        push    eax
372
        push    3
373
        push    -1
374
        push    -1
375
        push    dword aError
376
        call    SayErr
377
        add     esp, 3*4
378
        test    eax, eax
379
        jz      .copywrite
380
.copyfailed_parseuser:
381
        cmp     al, 2
382
        jnz     @f
383
        mov     [copy_bSkipAll2], 1
384
        dec     eax
385
@@:
386
        cmp     al, 1
387
        pushf
388
        jmp     .copyfailed
389
.copywriteok:
390
        mov     ecx, [writeinfo.size]
391
        add     dword [writeinfo.first], ecx
392
        adc     dword [writeinfo.first+4], 0
393
        mov     [writeinfo.code], 3
394
        cmp     ecx, copy_buffer_size
395
        jz      .copyloop
396
.copydone:
397
; now try to set attributes from source, ignore errors
398
        mov     edi, attrinfo.attr
399
        mov     esi, edx
400
        push    8
401
        pop     ecx
402
        rep     movsd
403
        mov     ebx, attrinfo
404
        mov     [ebx+attrinfo.name-attrinfo], CopyDestEditBuf+12
405
        inc     dword [ebx]
406
        push    70
407
        pop     eax
408
        push    ebx
409
        int     0x40
410
        pop     ebx
411
        dec     dword [ebx]
412
        xor     eax, eax        ; ZF=1
413
.ret:
414
        pop     ebx
415
        pop     esi
416
        mov     byte [esi-1], 0
417
        ret
418
.copydone2:
419
        popf
420
        jmp     .ret
421
.copyfailed:
422
        cmp     [bConfirmDeleteIncomplete], 0
423
        jz      .copyfailed_del
424
        cmp     [writeinfo.code], 2
425
        jz      .copydone2
426
        push    dword aIncompleteFile
427
        mov     eax, esp
428
        push    dword DeleteOrKeepBtn
429
        push    2
430
        push    eax
431
        push    1
432
        push    -1
433
        push    -1
434
        push    dword aCopyCaption
435
        call    SayErr
436
        add     esp, 4
437
        test    eax, eax
438
        jnz     .copydone2
439
.copyfailed_del:
440
        mov     ebx, delinfo
441
        push    dword [ebx+21]
442
        mov     dword [ebx+21], edi
443
        push    70
444
        pop     eax
445
        int     0x40
446
; ignore errors
447
        pop     dword [delinfo+21]
448
        jmp     .copydone2
449
.copyfailed_del2:
450
        xor     eax, eax
451
        pushf
452
        jmp     .copyfailed_del
453
 
454
copy_file:
455
; in: eax->BDFE block for source, CopyDestEditBuf+12 contains ASCIIZ full name for destination
456
; out: CF and ZF not set <=> cancel job ("ja cancel_label")
457
        pushad
458
        mov     [copy_dir_stack_ptr], copy_dir_stack
459
        mov     [bNeedRestoreName], 0
460
        lea     esi, [ebp + panel1_dir - panel1_data]
461
        mov     edi, execdata
462
@@:
463
        lodsb
464
        test    al, al
465
        jz      @f
466
        stosb
467
        jmp     @b
468
@@:
469
        mov     esi, [esp+28]
470
        add     esi, 40
471
        mov     al, '/'
472
        stosb
473
.l1:
474
        lodsb
475
        cmp     edi, execdataend
476
        jb      @f
477
        call    panels_OnKey.bigfilename
478
        popad
479
        ret
480
@@:
481
        stosb
482
        test    al, al
483
        jnz     .l1
484
        mov     edx, [esp+28]
485
        test    byte [edx], 10h
486
        jnz     .copy_dir
487
        call    copy_file_worker
488
.popad_ret:
489
        popad
490
        ret
491
 
492
.biiig:
493
        mov     byte [edi-1], 0
494
        jmp     .popad_ret
495
 
496
.copy_dir:
497
; recursive copy of directory
498
        cmp     [bDestIsFolder], 0
499
        mov     [bDestIsFolder], 0
500
        jz      .target_created
501
        mov     [bNeedRestoreName], 1
502
        mov     esi, CopyDestEditBuf+12
503
@@:
504
        lodsb
505
        test    al, al
506
        jnz     @b
507
        mov     byte [esi-1], '/'
508
        mov     edi, esi
509
        lea     esi, [edx+40]
510
@@:
511
        cmp     edi, CopyDestEditBuf+12+513
512
        jae     .biiig
513
        lodsb
514
        stosb
515
        test    al, al
516
        jnz     @b
517
.create_target:
518
.enter_recursion:
519
        push    DeleteErrorBtn
520
        push    4
521
        call    makedir
522
        jz      .target_created
523
        cmp     al, 2
524
        jnz     @f
525
        dec     eax
526
        mov     [copy_bSkipAll], 1
527
@@:
528
        cmp     al, 1
529
        jz      .copy_dir_entry_done
530
        jmp     .cancel
531
.target_created:
532
        xor     ebp, ebp        ; ebp will contain number of copied items
533
.return_from_recursion:
534
.read_retry:
535
        mov     ebx, dirinfo
536
        mov     [ebx+dirinfo.first-dirinfo], ebp
537
        mov     [ebx+dirinfo.size-dirinfo], copy_dir_query_size
538
        mov     [ebx+dirinfo.dirdata-dirinfo], copy_dir_query_area
539
        mov     [ebx+dirinfo.name-dirinfo], execdata
540
        push    70
541
        pop     eax
542
        int     0x40
543
        test    eax, eax
544
        jz      .readok
545
        cmp     eax, 6
546
        jz      .readok
547
; read error
548
        cmp     [copy_bSkipAll], 0
549
        jz      .skip1
550
        push    execdata
551
        push    aCannotReadFolder
552
        call    get_error_msg
553
        push    eax
554
        mov     eax, esp
555
        push    DeleteErrorBtn
556
        push    4
557
        push    eax
558
        push    3
559
        push    -1
560
        push    -1
561
        push    aError
562
        call    SayErr
563
        add     esp, 3*4
564
        test    al, al
565
        jz      .read_retry
566
        cmp     al, 2
567
        jnz     @f
568
        dec     eax
569
        mov     [copy_bSkipAll], 1
570
@@:
571
        cmp     al, 1
572
        jz      .skip1
573
        jmp     .cancel
574
.readok:
575
; loop through a directory and copy items
576
        mov     edx, copy_dir_query_area+32
577
        imul    ebx, 304
578
        add     ebx, edx
579
.copy_dir_entry_loop:
580
        cmp     edx, ebx
581
        jb      .do_copy_dir_entry
582
        cmp     ebx, copy_dir_query_area+32+copy_dir_query_size*304
583
        jz      .return_from_recursion
584
        jmp     .copy_dir_entry_done
585
.do_copy_dir_entry:
586
        inc     ebp
587
; ignore special entries "." and ".."
588
        cmp     word [edx+40], '.'
589
        jz      .copy_dir_entry_continue
590
        cmp     word [edx+40], '..'
591
        jnz     @f
592
        cmp     byte [edx+42], 0
593
        jz      .copy_dir_entry_continue
594
@@:
595
        mov     esi, execdata
596
@@:
597
        lodsb
598
        test    al, al
599
        jnz     @b
600
        mov     byte [esi-1], '/'
601
        mov     edi, esi
602
        lea     esi, [edx+40]
603
@@:
604
        cmp     edi, execdataend
605
        jae     .fullname_big
606
        lodsb
607
        stosb
608
        test    al, al
609
        jnz     @b
610
        mov     esi, CopyDestEditBuf+12
611
@@:
612
        lodsb
613
        test    al, al
614
        jnz     @b
615
        mov     byte [esi-1], '/'
616
        mov     edi, esi
617
        lea     esi, [edx+40]
618
@@:
619
        cmp     edi, CopyDestEditBuf+513
620
        jae     .fullname2_big
621
        lodsb
622
        stosb
623
        test    al, al
624
        jnz     @b
625
        test    byte [edx], 10h
626
        jnz     .entry_is_folder
627
        call    copy_file_worker
628
        ja      .cancel
629
        jmp     .restore_name
630
.entry_is_folder:
631
; allocate new item in directory stack
632
        mov     eax, [copy_dir_stack_ptr]
633
        mov     [eax], ebp
634
        add     eax, 4
635
        mov     [copy_dir_stack_ptr], eax
636
; do recursive copying
637
        jmp     .enter_recursion
638
.fullname_big:
639
; we will just ignore such files and continue - in real life this situation can not happen
640
        mov     esi, execdataend-1
641
        jmp     .do_restore_name2
642
.fullname2_big:
643
        mov     esi, CopyDestEditBuf+12+512
644
        jmp     .restore_name2
645
.skip1:
646
.restore_name:
647
        mov     esi, CopyDestEditBuf+12
648
@@:
649
        lodsb
650
        test    al, al
651
        jnz     @b
474 diamond 652
        dec     esi
653
        dec     esi
517 diamond 654
.restore_name2:
655
        call    delete_last_name
656
        mov     esi, execdata
474 diamond 657
@@:
658
        lodsb
517 diamond 659
        test    al, al
474 diamond 660
        jnz     @b
517 diamond 661
        dec     esi
662
        dec     esi
663
.do_restore_name2:
664
        call    delete_last_name
665
.copy_dir_entry_continue:
666
        add     edx, 304
667
        jmp     .copy_dir_entry_loop
668
.copy_dir_entry_done:
669
; return to previous directory
670
; pop item from directory stack
671
        mov     ecx, [copy_dir_stack_ptr]
672
        cmp     ecx, copy_dir_stack
673
        jbe     .done
674
        sub     ecx, 4
675
        mov     [copy_dir_stack_ptr], ecx
676
        mov     ebp, [ecx]
677
; restore prev directory name
678
        mov     esi, execdata
679
        call    delete_last_name_from_end
680
        mov     esi, CopyDestEditBuf+12
681
        call    delete_last_name_from_end
474 diamond 682
        jmp     .return_from_recursion
683
.done:
684
.cancel:
685
        mov     [dirinfo.first], 0      ; do not destroys flags
686
        popad
687
        ret
517 diamond 688
 
689
delete_last_name_from_end:
690
        lodsb
691
        test    al, al
692
        jnz     delete_last_name_from_end
693
        dec     esi
694
        dec     esi
695
delete_last_name:
696
        std
697
@@:
698
        lodsb
699
        cmp     al, '/'
700
        jnz     @b
701
        cld
702
        mov     byte [esi+1], 0
703
        ret