---------------------------------------------------------------------------------
                      [ENHANCED] VFP 9.0 FIX - LOCATE FILES IN THE APPLICATION DATA DIRECTORY
                                 January 2024
                 ---------------------------------------------------------------------------------
                                     CCB



1. BUG:

     For VFP 9.0, it will locate the resource file (foxuser.dbf) in the startup directory.
     If it can not find any resource file (foxuser.dbf), it will create the resource file (foxuser.dbf) in the startup directory.

     For some security reasons, the Program Files folder (for example, C:\Program Files) is readonly on Windows Vista or later.
     If we don't run VFP as Administrator, we can't write data to some application data files,
     for example, the resource file (foxuser.dbf), the command window history file (_command.prg) and the task manager file (foxtask.dbf).

     For VFP Advanced, it will locate the resource file (foxuser.dbf) in the Application Data directory.
     If it can not find any resource file (foxuser.dbf), it will create the resource file (foxuser.dbf) in the Application Data directory.
     It will also locate the command window history file (_command.prg) and the task manager file (foxtask.dbf) in the Application Data directory.

     The bug was reported by John Ryan.


2. CAUSE:

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Fun42cc34 :: ; proc near
             push ebp                                                        ;0x0042cc34 :        55
             lea ebp ,  dword ptr [ esp + 0FFFFFEFCh ]                       ;0x0042cc35 :        8dac24fcfeffff
             sub esp , 0184h                                                 ;0x0042cc3c :        81ec84010000
             mov eax ,  dword ptr [ Data937090 ]                             ;0x0042cc42 :        a190709300
             push ebx                                                        ;0x0042cc47 :        53
             push esi                                                        ;0x0042cc48 :        56
             push edi                                                        ;0x0042cc49 :        57
             mov  dword ptr [ ebp + 0100h ] , eax                            ;0x0042cc4a :        898500010000
             mov  eax , dword ptr [ ebp + 0110h ]                            ;0x0042cc50 :        8b8510010000
             mov ebx , ecx                                                   ;0x0042cc56 :        8bd9
             mov  ecx , dword ptr [ ebp + 010Ch ]                            ;0x0042cc58 :        8b8d0c010000
             push eax                                                        ;0x0042cc5e :        50
             push ecx                                                        ;0x0042cc5f :        51
             push edx                                                        ;0x0042cc60 :        52
             push ebx                                                        ;0x0042cc61 :        53
             mov  dword ptr [ ebp - 12 ] , ebx                               ;0x0042cc62 :        895df4
             mov  dword ptr [ ebp - 16 ] , 01h                               ;0x0042cc65 :        c745f001000000
             call Fun42c46b                                                  ;0x0042cc6c :        e8faf7ffff
             mov  eax , dword ptr [ ebp + 0114h ]                            ;0x0042cc71 :        8b8514010000
             test eax , eax                                                  ;0x0042cc77 :        85c0
             jne Label42c764                                                 ;0x0042cc79 :        0f85e5faffff

     Label42cc7f ::


     ;
     ;                 ---------------------------------------------------------------------
     ;                      VFP 9.0 FIX - LOCATE FILE IN THE APPLICATION DATA DIRECTORY
     ;                                  March 2017
     ;                 ---------------------------------------------------------------------
     ;                                     CCB
     ;
     ; For VFP 9.0, it will locate the resource file (foxuser.dbf) in the startup directory.
     ; If it can not find any resource file (foxuser.dbf), it will create the resource file (foxuser.dbf) in the startup directory.
     ;
     ; For VFP Advanced, it will locate the resource file (foxuser.dbf) in the Application Data directory.
     ; If it can not find any resource file (foxuser.dbf), it will create the resource file (foxuser.dbf) in the Application Data directory.
     ;
     ; 2017/3/25, by ccb
     ;

             cmp ebx , offset Data93ba24
             jne Label42cc81

             pushd 05Ch
             push ebx
             call strrchr
             add esp , 08h
             test eax , eax
             jne Label42cc81

             push offset vfpa_locatefiles_foxuser
             push ebx
             call lstrcmpiA
             test eax , eax
             je Label42cc80

             push offset vfpa_locatefiles_foxuser_dbf
             push ebx
             call lstrcmpiA
             test eax , eax
             je Label42cc80

             jmp Label42cc81

     Label42cc80 ::
             push 00h
             push ebx
             call Fun42c9be
             test eax , eax
             jne Label42cc81

             mov  eax , dword ptr [ Data937560 ]
             mov  eax , dword ptr [eax]
             add  eax , dword ptr [ Data9335c0 ]

             push eax
             push ebx
             call lstrcpyA

             push offset vfpa_locatefiles_backslash
             push ebx
             call lstrcatA

             push offset vfpa_locatefiles_foxuser_dbf
             push ebx
             call lstrcatA

             jmp Label42cc86


     Label42cc81 ::
             mov ecx , ebx                                                   ;0x0042cc7f :        8bcb
             call Fun42c8bb                                                  ;0x0042cc81 :        e835fcffff

     Label42cc86 ::
             mov  ecx , dword ptr [ ebp + 0100h ]                            ;0x0042cc86 :        8b8d00010000
             mov  eax , dword ptr [ ebp - 16 ]                               ;0x0042cc8c :        8b45f0
             call Fun42bf1d                                                  ;0x0042cc8f :        e889f2ffff
             pop edi                                                         ;0x0042cc94 :        5f
             pop esi                                                         ;0x0042cc95 :        5e
             pop ebx                                                         ;0x0042cc96 :        5b
             add ebp , 0104h                                                 ;0x0042cc97 :        81c504010000
             mov esp , ebp                                                   ;0x0042cc9d :        8be5
             pop ebp                                                         ;0x0042cc9f :        5d
             ret 010h                                                        ;0x0042cca0 :        c21000


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.


5. REFERENCE WEBSITES:

     1, baiyujia.com:
     http://www.baiyujia.com

     2, microsoft.com:
     https://msdn.microsoft.com/en-us/library/9a1k8t3w(v=vs.80).aspx
     https://social.msdn.microsoft.com/Forums/en-US/182187f6-e317-44b0-8214-9523ca03dc10/deployment-problems-in-vista
     https://social.msdn.microsoft.com/Forums/en-US/e81155f2-863f-4e64-b4c4-5323e9bc4382/proper-location-of-foxuserdbf-in-distributed-application
     https://social.msdn.microsoft.com/Forums/en-US/182187f6-e317-44b0-8214-9523ca03dc10/deployment-problems-in-vista
     https://social.msdn.microsoft.com/Forums/en-US/9a062a10-8952-44c5-b9b6-265f1fc93139/vfp-doesnt-remember-defaults

     3, foxite.com:
     https://www.foxite.com/archives/foxuser-0000318958.htm

     4, tek-tips.com:
     http://www.tek-tips.com/viewthread.cfm?qid=1771909
     http://www.tek-tips.com/viewthread.cfm?qid=1539853


6. OTHER:

     For reference only, there is no guarantees.

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