-------------------------------------------------------------------------------------
                      [BUG/PRB.] VFP 9.0 FIX - ALWAYS COPY FILES ON DISK IN THE COPY FILE COMMAND
                                September 2024
                 -------------------------------------------------------------------------------------
                                     CCB



1. BUG:

     In vfp9 (and vfp6, vfp7, vfp8), if the file on disk exists and the file in the compiled executable file does not exist,
     it copies the file on disk to the destination file,
     if the file on disk exists and the file in the compiled executable file exists,
     it copies the file in the compiled executable file to the destination file.

     In VFP Advanced, if we enable always copying files on disk in the COPY FILE command,
     if the file on disk exists, it always copies the file on disk to the destination file.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Label6d6c7f ::
             pushd 0100h                                                     ;0x006d6c7f :        6800010000
             lea eax ,  dword ptr [ ebp - 52 ]                               ;0x006d6c84 :        8d45cc
             push eax                                                        ;0x006d6c87 :        50
             lea eax ,  dword ptr [ ebp - 48 ]                               ;0x006d6c88 :        8d45d0
             push eax                                                        ;0x006d6c8b :        50
             lea eax ,  dword ptr [ ebp - 16 ]                               ;0x006d6c8c :        8d45f0
             push eax                                                        ;0x006d6c8f :        50
             push edi                                                        ;0x006d6c90 :        57
             push ebx                                                        ;0x006d6c91 :        53
             call Fun42cd23                                                  ;0x006d6c92 :        e88c60d5ff


     ;
     ;                 --------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - ALWAYS COPY FILES ON DISK IN THE COPY FILE COMMAND
     ;                                September 2024
     ;                 --------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; Always copy files on disk in the COPY FILE command.
     ;
     ; 2024/9/9, by ccb
     ;

             cmp dword ptr vfpa_sys9169_data,00h
             je Label6d6c97
             IF VFPA_VERSION GE 101
             cmp dword ptr [ esp + 2ECh ] , offset Label6d6fd3 ;; Fun6d6e05 .. ; proc near
             jne Label6d6c97
             ELSE
             cmp dword ptr [ esp + 2DCh ] , offset Label6d6fd3 ;; Fun6d6e05 .. ; proc near
             jne Label6d6c97
             ENDIF
             xor eax , eax


     Label6d6c97 ::
             test eax , eax                                                  ;0x006d6c97 :        85c0
             jne Label6d6ce6                                                 ;0x006d6c99 :        754b
             lea eax ,  dword ptr [ ebp + 0F8h ]                             ;0x006d6c9b :        8d85f8000000
             push eax                                                        ;0x006d6ca1 :        50
             push edi                                                        ;0x006d6ca2 :        57
             call  FindFirstFileA                              ;0x006d6ca3 :        ff152c719100
             push eax                                                        ;0x006d6ca9 :        50
             call  FindClose                                   ;0x006d6caa :        ff1528719100
             push ebx                                                        ;0x006d6cb0 :        53
             push esi                                                        ;0x006d6cb1 :        56
             push edi                                                        ;0x006d6cb2 :        57
             call  CopyFileA                                   ;0x006d6cb3 :        ff1524719100
             test eax , eax                                                  ;0x006d6cb9 :        85c0
             jne Label6d6cc6                                                 ;0x006d6cbb :        7509
             pushd 066h                                                      ;0x006d6cbd :        6a66
             mov ecx , esi                                                   ;0x006d6cbf :        8bce
             call Fun44d388                                                  ;0x006d6cc1 :        e8c266d7ff

     Label6d6cc6 ::
             mov  eax , dword ptr [ ebp + 0F8h ]                             ;0x006d6cc6 :        8b85f8000000
             test al , 01h                                                   ;0x006d6ccc :        a801
             je Label6d6cdb                                                  ;0x006d6cce :        740b
             and eax , 0FFFFFFFEh                                            ;0x006d6cd0 :        83e0fe
             push eax                                                        ;0x006d6cd3 :        50
             push esi                                                        ;0x006d6cd4 :        56
             call  SetFileAttributesA                          ;0x006d6cd5 :        ff1520719100

     Label6d6cdb ::
             mov  eax , dword ptr [ ebp + 0118h ]                            ;0x006d6cdb :        8b8518010000
             jmp Label6d6ded                                                 ;0x006d6ce1 :        e907010000


4. APPLIES TO:

     VFP 6.0.8167.0
     VFP 6.0.8961.0 (SP5)

     VFP 7.0.0.9262
     VFP 7.0.0.9465 (SP1)

     VFP 8.0.0.2521
     VFP 8.0.0.3117 (SP1)

     VFP 9.0.0.2412
     VFP 9.0.0.3504 (SP1)
     VFP 9.0.0.4611 (SP2)
     VFP 9.0.0.5015 (SP2)
     VFP 9.0.0.5411 (SP2)
     VFP 9.0.0.5721 (SP2)
     VFP 9.0.0.5815 (SP2)
     VFP 9.0.0.6303 (SP2)
     VFP 9.0.0.6602 (SP2)
     VFP 9.0.0.7423 (SP2)

     The bug has been fixed in VFP Advanced.

     IMPORTANT NOTE:
     In vfp9 (and vfp6, vfp7, vfp8), we can use the EXECSCRIPT() function to execute the COPY FILE command to copy files on disk, for example,
     =EXECSCRIPT("COPY FILE test.txt TO test2.txt") && it always copies the file test.txt on disk to the destination file test2.txt.
     and then there is no the bug.

     In Visual FoxPro all versions, we can use the FILETOSTR() function and the STRTOFILE() function to copy files in the compiled executable file, for example,
     =STRTOFILE(FILETOSTR("test.txt),"test2.txt") && it can copy the file test.txt in the compiled executable file (or on disk) to the destination file test2.txt.


5. REFERENCE WEBSITES:

     1, baiyujia.com:
     http://www.baiyujia.com
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix346.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix35.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix249.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix250.asp

     2, foxite.com:
     https://www.foxite.com/archives/copy-file-from-project-to-file-0000144448.htm
     https://www.foxite.com/archives/vfp-bug-or-me-0000250008.htm


6. OTHER:

     For reference only, there is no guarantees.

     Any questions or suggestions, please send me an email at ccb2000@163.com.