*!* capp *!* #INCLUDE COMUN.H #INCLUDE SECURITY.H #DEFINE CRLF CHR(13) + CHR(10) *** ==================== CAPP ============================ *** Define Class cApp As Custom oSettings = Null lError = .F. cErrorMessage = '' oLog = Null oTrace = Null lWriteLog = .F. && .T. = scrie in log pe disc * Procedure Init *Set Procedure To "app.prg" Additive This.oSettings = Newobject("Settings","app.prg") && CREATEOBJECT("Settings") This.oLog = Iif(Type('goLog') = 'O', goLog, Createobject("Log")) Endproc && INIT * Procedure ProcessError(toHash) Declare laErrors[1] LOCAL loHash IF TYPE('toHash') = 'O' loHash = toHash ELSE loHash = GetHash() ENDIF lnErrorLines = Aerror(laErrors) lnError = Iif(loHash.HasProperty("nError"), loHash.GetValue("nError"), Transform(laErrors(1)) + ' ' + Transform(laErrors(5))) lcMethod = loHash.GetValue("cMethod") lnLine = loHash.GetValue("nLine") lcError = Iif(loHash.HasProperty("cError"), loHash.GetValue("cError"), Transform(laErrors(2))) lcCode = Iif(loHash.HasProperty("cCode"), loHash.GetValue("cCode"), Message(1) ) lcCallStack = GetCallStack() lcUserMessage = loHash.GetValue("cUserMessage") This.cErrorMessage = lcUserMessage + CRLF + CRLF + ; 'Eroarea nr: ' + Transform(lnError) + CRLF + ; 'Eroarea: ' + Transform(lcError) + CRLF + ; 'Procedura: ' + Transform(lcMethod) + CRLF + ; 'Linia: ' + Transform(lnLine) + CRLF + ; 'Codul: ' + Transform(lcCode) + CRLF + ; lcCallStack This.lError = .T. This.Log(This.cErrorMessage) *!* MESSAGEBOX(THIS.cErrorMessage,0+16,'Eroare') *!* IF MESSAGEBOX(THIS.cErrorMessage + CRLF + 'Doriti sa iesiti?',16+4,'Eroare') = 6 *!* IF _vfp.StartMode = 0 *!* SET STEP ON *!* ELSE *!* RETURN TO MASTER *!* ENDIF *!* ENDIF Endproc && ProcessError * Procedure Log Lparameters tcMessage, toTrace LOCAL loTrace IF this.oSettings.lWriteLog This.oLog.WriteLog(tcMessage) ENDIF loTrace = This.oTrace *!* 03.03.2010 IF TYPE('toTrace') = 'O' toTrace.Trace(tcMessage) ELSE IF TYPE('loTrace') = 'O' loTrace.Trace(tcMessage) ENDIF ENDIF *!* 03.03.2010 ^ Endproc && Log * Function Gethost Local lcValue lcValue = This.oSettings.GetValue("HOST") Return lcValue Endfunc && GetHost * Function GetUser Local lcValue lcValue = This.oSettings.GetValue("USER") Return lcValue Endfunc && GetUser * Function GetPassword Local lcValue lcValue = This.oSettings.GetValue("PASSWORD") Return lcValue Endfunc && GetPassword * Function GetConnectionString Local lcValue lcValue = This.oSettings.GetValue("CONNECTIONSTRING") Return lcValue Endfunc && GetConnectionString * Function GetError Return This.cErrorMessage Endfunc && GetError * Function HasError Return This.lError Endfunc && HasError * Function IsLoggedIn Return .T. && RETURN THIS.oSettings.GetValue("IdUtilizator") > 0 Endfunc && IsLoggedIn Function ShowError Return Messagebox(This.cErrorMessage + CRLF + 'Doriti sa iesiti?',16+4,'Eroare') Endfunc && ShowError Enddefine && cAPP *** ==================== cSETTINGS ============================ *** Define Class cSETTINGS As Custom cIniFile = '' cAppPath = '' cIniText = '' Proc Init Local lcApppath, lcApplicationFile If Type('gcAppPath') = 'C' lcApppath = gcAppPath Else lcApppath = Addbs(Justpath(Sys(16, 0))) If 'PROGRAME'$Upper(lcApppath) lcApppath = Strtran(lcApppath, 'PROGRAME\','') Endif Endif This.cAppPath = lcApppath This.cIniFile = This.cAppPath + 'settings.ini' This.InitSettings() This.ReadSettings() Endproc Procedure InitSettings Local lcInifile, lcIniText lcIniText = This.cIniText lcInifile = This.cIniFile If Empty(lcInifile) Return Endif IF !FILE(lcInifile) Strtofile(lcIniText, lcInifile) ENDIF Endproc && InitSettings Procedure ReadSettings Endproc && ReadSettings *========================================== Procedure SetVariable Lparameters tcSection, tcVarname, tuValue Local lcSection, lcVarname, lcValue lcSection = Lower(Alltrim(tcSection)) lcVarname = Lower(Alltrim(tcVarname)) lcValue = Transform(tuValue) SetIni(This.cIniFile, lcSection, lcVarname, lcValue) Endproc && SetVariable *========================================== Procedure ReadVariable Lparameters tcSection, tcVarname Local lcSection, lcVarname, lcValue lcSection = Lower(Alltrim(tcSection)) lcVarname = Lower(Alltrim(tcVarname)) lcValue = GetIni(This.cIniFile, lcSection, lcVarname) lcValue = Nvl(lcValue, '') Return lcValue Endproc && ReadVariable Function GetValue Lparameters tcSetting Local lcSetting, luValue lcSetting = "THIS." + tcSetting luValue = '' If Type(lcSetting) # 'U' luValue = &lcSetting Endif Return luValue Endfunc Procedure SetValue Lparameters tcSetting, tuValue Local lcSetting, luValue lcSetting = "THIS." + tcSetting luValue = tuValue If Type(lcSetting) # 'U' &lcSetting = luValue Endif Endproc Function DecryptPassword As Character Lparameters tcPassword Local lcPassword lcPassword = Alltrim(Strconv(Alltrim(m.tcPassword),14)) lcPassword = This.EncryptDecrypt(m.lcPassword, ENCRYPTKEY, "decrypt","blowfish") Return m.lcPassword Endfunc *!* EncryptDecrypt *!* EX: EncryptDecrypt("text to encrypt", "encrypt key", "encrypt") *!* EX: EncryptDecrypt("text to decrypt", "decrypt key", "decrypt") *!* EX: EncryptDecrypt("text to encrypt", "encrypt key", "encrypt","blowfish") Function EncryptDecrypt Lparameters tcText, tcPassword, tcMode, tcAlgorithm && tcMode : ENCRYPT/DECRYPT Local lcAlgorithm,lcReturn, lcString, lcPWD Local loException As Exception m.lcString = tcText m.lcPWD = tcPassword m.lcReturn = "" lcAlgorithm = "" If Type('tcAlgorithm') = 'C' lcAlgorithm = tcAlgorithm Endif If lcAlgorithm = "blowfish" If Upper(Alltrim(Transform(tcMode))) = "ENCRYPT" lcReturn=Encrypt(m.lcString, m.lcPWD,4,0) Else Try lcReturn=decrypt(m.lcString, Alltrim(m.lcPWD),4,0) Catch To loException If loException.ErrorNo=2028 golog.Log("S-a incercat decriptarea unui text care nu a fost generat cu algoritmul de criptare selectat.",Program()) Else golog.Log(loException.Message,Program()) Endif Endtry Endif Endif *!* 18.03.2008 : am scos chr(0) de la sfarsitul textului decriptat If At(Chr(0),m.lcReturn) > 0 And Upper(Alltrim(Transform(tcMode))) != "ENCRYPT" m.lcReturn = Substr(m.lcReturn, 1, At(Chr(0),m.lcReturn)-1) Endif *!* 18.03.2008 Return m.lcReturn Endfunc && EncryptDecrypt Enddefine && cSETTINGS