*** define local variables LOCAL lnFiles, laFiles, lnI, ; lnTables, laTables, lnJ, ; lnExists, laExists, lnK, ; lcOldDeleted, lcOldSafety DIMENSION laFiles[1], laTables[1], laExists[1] *** look for the stage 1 0 byte flag file lnFiles = ADIR(laFiles, "FreshInstallation.flg") IF lnFiles > 0 *** check for tables in Data dir lnFiles = ADIR(laFiles, "Data\*.dbf") IF lnFiles > 0 *** existing tables means that there may be existing data WAIT WINDOW "Reinstall Detected, Converting Data, Please wait ..." NOWAIT *** create if required the temporary dir lnFiles = ADIR(laFiles, "Trashcan", "D") IF lnFiles = 0 MD Trashcan ENDIF CD Trashcan *** empty trashcan lnFiles = ADIR(laFiles, "*.*") FOR lnI = 1 TO lnFiles DELETE FILE (laFiles[lnI, 1]) ENDFOR *** copy to trashcan the vsodbcx generated prg sets lnFiles = ADIR(laFiles, "..\Data\ReGenDBC*.*") FOR lnI = 1 TO lnFiles COPY FILE ("..\Data\" + laFiles[lnI, 1]) TO (laFiles[lnI, 1]) ENDFOR *** execute in trashcan the vsodbcx generated prgs to get a clean copy of the dbcs lnFiles = ADIR(laFiles, "ReGenDBC*.prg") = ASORT(laFiles) FOR lnI = 1 TO lnFiles DO (laFiles[lnI, 1]) WITH , .T. ENDFOR lcOldDeleted = SET("DELETED") SET DELETED OFF *** find out the dbcs lnFiles = ADIR(laFiles, "*.dbc") FOR lnI = 1 TO lnFiles *** open each dbc OPEN DATABASE (laFiles[lnI, 1]) EXCLUSIVE *** get all the table names for the dbc lnTables = ADBOBJECTS(laTables, "TABLE") FOR lnJ = 1 TO lnTables *** open each table IF USED(laTables[lnJ]) SELECT (laTables[lnJ]) ELSE USE (laTables[lnJ]) ENDIF *** if exists a same name table in data dir apped data from it lnExists = ADIR(laExists, "..\Data\" + laTables[lnJ] + ".dbf") IF lnExists > 0 APPEND FROM ("..\Data\" + laTables[lnJ]) ENDIF *** close each table USE ENDFOR *** close each dbc CLOSE DATABASE ENDFOR SET DELETED &lcOldDeleted. CD.. *** create stage 2 flag file = FCLOSE(FCREATE("FreshConversion.flg")) ELSE *** no existing tables means that only the vsodbcx generated prgs are there *** from the installation WAIT WINDOW "Fresh Install Detected, Creating Data, Please wait ..." NOWAIT *** execute here the vsodbcx generated prgs to get a clean copy of the dbcs CD DATA lnFiles = ADIR(laFiles, "ReGenDBC*.prg") = ASORT(laFiles) FOR lnI = 1 TO lnFiles DO (laFiles[lnI, 1]) WITH , .T. ENDFOR CD .. *** execute here the vsodbcx generated prgs to get a clean copy of the dbcs CD Security lnFiles = ADIR(laFiles, "ReGenDBC*.prg") = ASORT(laFiles) FOR lnI = 1 TO lnFiles DO (laFiles[lnI, 1]) WITH , .T. ENDFOR CD.. ENDIF *** clean up CLOSE TABLES ALL CLOSE DATABASES ALL *** remove the stage 1 flag file DELETE FILE FreshInstallation.flg WAIT CLEAR ENDIF *** look for the stage 2 0 byte flag file lnFiles = ADIR(laFiles, "FreshConversion.flg") IF lnFiles > 0 *** data conversion is now complete WAIT WINDOW "Fresh Conversion Detected, Moving Converted Data, Please wait ..." NOWAIT *** create if required the temporary dir *** this should be here anyways but can't predict better safe the error out lnFiles = ADIR(laFiles, "Trashcan", "D") IF lnFiles = 0 MD Trashcan ENDIF CD Trashcan lcOldSafety = SET("SAFETY") SET SAFETY OFF *** find out each and every file in trashcan lnFiles = ADIR(laFiles, "*.*") FOR lnI = 1 TO lnFiles IF laFiles[lnI, 1] # "REGENDBC" *** delete any file which does not belong to vsodbcx generated prg sets *** it seems they are open when they are last run COPY FILE (laFiles[lnI, 1]) TO ("..\Data\" + laFiles[lnI, 1]) DELETE FILE (laFiles[lnI, 1]) ENDIF ENDFOR SET SAFETY &lcOldSafety. CD.. *** remove the stage 2 flag file DELETE FILE FreshConversion.flg WAIT CLEAR ENDIF