#include comun\include\security.h

Define Class iniaccess As Custom
	cIniFile=""

	Function Init
		This.cIniFile=shortpath(GetIniPath())
	Endfunc

	Function setCValue
		Lparameters tcSection, tcSetting, tcValue
		Local lcFisierIni
		lcFisierIni = This.cIniFile

	  DECLARE INTEGER WritePrivateProfileString ;
	      IN WIN32API ;
	      STRING cSection,STRING cEntry,STRING cEntry,;
	      STRING cFileName
      
		Return WritePrivateProfileString(tcSection,tcSetting,tcValue,lcFisierIni)
	Endfunc

	Function getCValue As Character
		Lparameters tcSection,tcSetting
		Local lcFisierIni
		lcFisierIni=This.cIniFile
		lcBuffer=Space(255)

	DECLARE INTEGER GetPrivateProfileString ;
	   IN WIN32API ;
	   STRING cSection,;
	   STRING cEntry,;
	   STRING cDefault,;
	   STRING @cRetVal,;
	   INTEGER nSize,;
	   STRING cFileName
   
		GetPrivateProfileString(tcSection,tcSetting,"",@lcBuffer, Len(lcBuffer), lcFisierIni)
		lcBuffer = Strtran(lcBuffer,Chr(0),"")
		lcBuffer = Alltrim(lcBuffer)
		Return lcBuffer
	Endfunc

	Function setUF
		Lparameters cUFvalue
		Return This.setCValue("update","UpdateFrequency",cUFvalue)
	Endfunc

	Function setNetworkPath
		Lparameters cNPvalue
		Return This.setCValue("update","NetworkPath",cNPvalue)
	Endfunc

	Function setURL
		Lparameters cURLvalue
		Return This.setCValue("update","InternetPath",cURLvalue)
	Endfunc

	Function setUsername
		Lparameters cUsername
		Return This.setCValue("update","Username",cUsername)
	Endfunc

	Function setPassword
		Lparameters cPassword
		cPassword=EncryptDecrypt(cPassword, ENCRYPTKEY, "encrypt","blowfish")
		cPassword=Strconv(cPassword,13)
		Return This.setCValue("update","Password",cPassword)
	Endfunc

	Function setPasswordDirect
		Lparameters cPassword
		Return This.setCValue("update","Password",cPassword)
	Endfunc

	Function SetDefault
		Lparameters cDefaultvalue
		Return This.setCValue("update","DefaultPath",cDefaultvalue)
	Endfunc

	Function setLocalExe
		Lparameters cDefaultvalue
		Return This.setCValue("update","exepath",cDefaultvalue)
	Endfunc

	Function setAllowConfirm
		Lparameters cDefaultvalue
		Return This.setCValue("update","AllowConfirm",cDefaultvalue)
	Endfunc

	Function setLastServer
		Lparameters cLastServer
		Return This.setCValue("server","last",cLastServer)
	Endfunc

	Function getUF As Character
		Return This.getCValue("update","UpdateFrequency")
	Endfunc

	Function getNetworkPath As Character
		Return This.getCValue("update","NetworkPath")
	Endfunc

	Function getLocalExe As Character
		Return This.getCValue("update","exepath")
	Endfunc

	Function getURL As Character
		Return This.getCValue("update","InternetPath")
	Endfunc

	Function getDefault As Character
		Return This.getCValue("update","DefaultPath")
	Endfunc

	Function getUsername As Character
		Return This.getCValue("update","Username")
	Endfunc

	Function getPassword As Character
		Local lcParola
		lcParola = This.getCValue("update","Password")
		If Len(lcParola)>0
			lcParola =Alltrim(Strconv(lcParola ,14))
			lcParola = EncryptDecrypt(lcParola, ENCRYPTKEY, "decrypt","blowfish")
		Endif
		Return lcParola
	Endfunc

	Function getPasswordDirect As Character
		Return This.getCValue("update","Password")
	Endfunc

	Function getAllowConfirm As Boolean
		Local lcValoare
		lcValoare = This.getCValue( "update","AllowConfirm")
		If Upper(lcValoare)=Upper("True")
			Return .T.
		Else
			Return .F.
		Endif
	Endfunc

	Function getLastServer As Character
		Return This.getCValue("server","last")
	Endfunc

Enddefine
