INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Tips -N- Tricks

How can I automatically backup and restore data files? by ChrisRChamberlain
Posted: 20 Jul 00 (Edited 17 Oct 03)

If you need a simple way to supplement normal backup procedures and ensure a user's data, (single user or workstation), can be automatically restored in the event of a system crash or other problem, try the following:-

Place CABARC.exe and EXTRACT.exe, both available from http://support.microsoft.com/default.aspx?scid=kb%3Ben-..., (file named CAB-SDK.exe), in the folder containing your databases, tables, etc.

If you are likely to have more than one application running, rename CABARC.exe to CABARCn.exe, EXTRACT.exe to EXTRACTn.exe, where you make n to be the identification number of an application, so that you can detemine which copy is in use.

As the user quits the application a .CAB file is created, overwriting the previous one. The .CAB file is only created if the application shuts down correctly.

Both CABARC.exe and EXTRACT.exe will run hidden, so a user will be unable to interfere with their execution.

When an error is caused by corrupted data files, the files are extracted from the .CAB file.

The RepairData code is best placed in a dedicated form, the function of which is to explain to the user that they will need to start the application again.

* Top of MAIN.prg
* The initial code is to determine if CABARC is still running,
* and if so quit the application

SET LIBRARY TO foxtools.fll

* Register the Windows API functions that will be called

mGetWinTxt = RegFn("GetWindowText", "I@CI", "I")
mGetWindow = RegFn("GetWindow", "II", "I")
mIsWinVis =  RegFn("IsWindowVisible", "I", "I")

* Get the HWND (handle) to the main FoxPro window

foxhwnd = MAINHWND()

* Produce a list of all windows

hwndNext = CallFn(mGetWindow,foxhwnd,0)
lCabFile = .F.
DO WHILE hwndNext <> 0
    IF (hwndnext <> foxhwnd) AND ;
        CallFn(mGetWindow,hwndnext,4) = 0

        Stuffer = SPACE(64)
        x = CallFn(mGetWinTxt,hwndnext,@Stuffer,64)
        IF [CABARC] $ UPPER(Stuffer)
            lCabFile = .T.
            EXIT
        ENDIF
    ENDIF
    hwndNext = CallFn(mGetWindow,hwndnext,2)
ENDDO

IF lCabFile
    MESSAGEBOX([This application is still shutting down from the last session.],;
    0 + 48 + 0    ,;
    [Access denied])
    QUIT
ENDIF

* OK to proceed

ON ERROR DO RepairData
DO OpenDatabases   && Open databases, tables etc
ON ERROR DO ErrorTrap WITH ;
    SYS(16) ,;
    LINENO() ,;
    ERROR() ,;
    MESSAGE(1)    ,;
    MESSAGE()  && Default error handler
* Normal code here    
*    
* Place this code to be the last lines of MAIN.prg

SET DEFA TO SYS(5)+SYS(2003)+[\tables\]
lcProg2Run = [cabarc n tables.cab *.dbc *.dbf *.cdx *.fpt]
DECLARE INTEGER WinExec IN kernel32 ;
    STRING lpCmdLine ,;
    INTEGER uCmdShow
IF !WinExec(lcProg2Run, 0) > 31
    * MESSAGEBOX()
ENDIF
QUIT    

***************************
* Procedure: RepairData
*    Syntax: Do RepairData
***************************
PROC RepairData

SET RESOURCE OFF            
CLOSE ALL
* MESSAGEBOX([There has been a error etc])
SET DEFA TO SYS(5)+ SYS(2003)+[\tables\]
lcProg2Run = [extract /y tables.cab *.*]
DECLARE INTEGER WinExec IN kernel32 ;
    STRING lpCmdLine ,;
    INTEGER uCmdShow
IF !WinExec(lcProg2Run, 0) > 31
    * MESSAGEBOX()
ENDIF
QUIT

* DISCLAIMER
* This Code is as is.  There is no warranty expressed or
* implied.  Use this code at your own risk.

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close