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:-
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
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
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.