// upgrade fisier
// fata de functia UpgrFile() 
// -creeaza fisierul pe baza unei structuri, nu pe baza unui fisier de referinta
// -operatii mai sigure, test dupa fiecare operatie
// 
// Parmetri:
// xx_aStr  -structura pentru noul fisier,
// xx_sfile -aliasul fisierului,
// xx_ifile -indexul fisierului (in tabelele sistem),
// xx_fM    -fisierul de manevra (numai numele),  

// fisier de manevra cu cale de acces
xx_fpM := h_FilePathes[xx_ifile]+xx_fM

// sterge fisierele de manevra
#IF ! h_SafeErase(xx_fpM+".DBF")
    h_PutLine("Stergere nereusita: "+h_FilePathes[xx_ifile]+xx_fpM+".DBF")
    #DO FUABANDN.TXT
#ENDIF
#IF h_FileEx(xx_fpM+".DBT") .AND. ! h_SafeErase(xx_fpM+".DBT")
    h_PutLine("Stergere nereusita: "+xx_fpM+".DBT")
    #DO FUABANDN.TXT
#ENDIF

// redenumire fisier
#IF (FRename(h_FileNames[xx_ifile]+".DBF", xx_fpM+".DBF") != 0)
    h_PutLine("Eroare "+LTrim(Str(FError(),5))+", redenumire "+h_UserNames[xx_ifile])
    #DO FUABANDN.TXT
#ENDIF
#IF h_FileEx(h_FileNames[xx_ifile]+".DBT") .and. ;
    (FRename(h_FileNames[xx_ifile]+".DBT", xx_fpM+".DBT") != 0)
    h_PutLine("Eroare "+LTrim(Str(FError(),5))+", redenumire (memo) "+h_UserNames[xx_ifile])
    #DO FUABANDN.TXT
#ENDIF

DbCreate(h_FileNames[xx_ifile]+".DBF",xx_aStr)
#IF ! h_FileEx(h_FileNames[xx_ifile]+".DBF")
    h_PutLine("Creare fisier nereusita: "+h_FileNames[xx_ifile]+".DBF")
    #DO FUABANDN.TXT
#ENDIF

#IF ! h_UseAlias(xx_sfile)
    #DO FUABANDN.TXT
#ENDIF
__dbZap()
__dbApp( (xx_fpM+".DBF"), { },,,,, .F., )
index_file(xx_sfile)
h_CloseAlias(xx_sfile)

#IF "linux"$lower(h_build())
    h_Chmod(h_FileNames[xx_ifile]+".DBF",CtoN("111111101",2))
    #IF h_FileEx(h_FileNames[xx_ifile]+".DBT")
        h_Chmod(h_FileNames[xx_ifile]+".DBT",CtoN("111111101",2))
    #ENDIF
#ENDIF 

#IF ! h_SafeErase (xx_fpM+".DBF")
    h_PutLine("Stergere nereusita: "+xx_fpM+".DBF")
    #DO FUABANDN.TXT
#ENDIF
#IF ! h_SafeErase (xx_fpM+".DBT")
    h_PutLine("Stergere nereusita: "+xx_fpM+".DBT")
    #DO FUABANDN.TXT
#ENDIF

#RETURN
