* Put_ini.prg * PURPOSE: Save the value of an item in a INI file. * * USAGE: varible = PUT_INI( 'FILENAME.INI', '[SomeSection]', 'SomeItem', 'SomeValue' ) * * REVISION: Common * * Date Programmer Changes * ---------- ----------- ---------------------------------------------------- * PARAMETERS xinifile,xinisection,xiniitem,xinisetting PRIVATE xreturn,xfilehan,i xreturn = ' ' xfilehan = 0 *--10/18/2001 TCH Visual Foxpro Mods #IF 'VISUAL' $ UPPER(VERSION()) *--Ensure can save if no value sent over to ensure removing values set earlier *--This will leave the key but remove the setting IF PARAMETERS()=4 .and. EMPTY(xIniSetting) xIniSetting=CHR(0)+" " ENDIF #ENDIF IF !EMPTY(xinifile) AND !EMPTY(xinisection) AND !EMPTY(xiniitem) AND !EMPTY(xinisetting) *--10/11/2001 TCH Visual Foxpro Mods #IF 'VISUAL' $ UPPER(VERSION()) *--must ensure path is given to ini file-if not add it -- all inis are in progs IF LEFT(xIniFile,1)<>"\" .and. LEFT(xIniFile,2)<>".." .and. SUBSTR(ALLTRIM(xIniFile),2,1)<>":" xIniFile="\profiler\progs\"+xIniFile ENDIF *--if brackets were included in passed section parameter, strip them out IF LEFT(LTRIM(xIniSection),1)="[" xIniSection=SUBSTR(xIniSection,2,AT(']',xIniSection)-2) ENDIF * WRITEPRIVATEPROFILESTRING win32api Parameters: * xIniSection = pointer to a null-terminated string that specifies the name of the * section to which the string will be copied. * xIniItem = Pointer to the null-terminated string specifying the name of the * key associated with a string. * xIniSetting = Pointer to a null-terminated string to be written to the file. * xIniFile = Pointer to a null-terminated string that specifies the name of the * the initialization file. * Return value is non-zero if successful *--Write the key's string xReturn=' ' DECLARE integer WritePrivateProfileString IN Win32API AS SetINI string,string,string,string IF SetINI(@xIniSection,@xIniItem,@xiniSetting,@xIniFile) # 0 =SetIni(0,0,0,xIniFile) && flush buffer RETURN xReturn ELSE && Return value is zero-could not write entry error! MESSAGEBOX("Could not save information! Please contact the ATI HelpDesk. "; +" Trying to save: "+"File: "+xIniFile+" Section: "+xIniSection; +" Key: "+XiniItem+" Setting: "+ALLTRIM(xIniSetting)+" In: put_ini.prg",16+4096,; "An Error Ocurred Trying to Save to your INI File!",30000) =SetIni(0,0,0,xIniFile) && flush buffer RETURN xReturn ENDIF #ELSE *---Create the file PROFILER.INI if it does not exist. IF FILE(xinifile) xfilehan = FOPEN(xinifile,2) ELSE xfilehan = FCREATE(xinifile) ENDIF IF xfilehan > 0 *---Read file into an array DIMENSION xinilines[1] xinilines[1] = ' ' i = 0 DO WHILE !FEOF(xfilehan) i = i + 1 DIMENSION xinilines[i] xinilines[i] = FGETS(xfilehan) ENDDO *---Move to the begining of the file =FSEEK(xfilehan,0) *---Resize the file =FCHSIZE(xfilehan,0) *---Search for the begining of the section xnewsect = .T. FOR i = 1 TO ALEN(xinilines,1) =FPUTS(xfilehan,xinilines[i]) IF xinilines[i] = xinisection xnewsect = .F. *---Search through this section only FOR i = i+1 TO ALEN(xinilines,1) DO CASE CASE LEFT(xinilines[i],1) = ' ' CASE LEFT(xinilines[i],1) = '[' =FPUTS(xfilehan,xiniitem+'='+xinisetting) =FPUTS(xfilehan,' ') =FPUTS(xfilehan,xinilines[i]) EXIT CASE LEFT(xinilines[i],AT('=',xinilines[i])-1) = xiniitem =FPUTS(xfilehan,xiniitem+'='+xinisetting) EXIT OTHERWISE =FPUTS(xfilehan,xinilines[i]) IF i = ALEN(xinilines,1) =FPUTS(xfilehan,xiniitem+'='+xinisetting) ENDIF ENDCASE NEXT ENDIF NEXT IF xnewsect =FPUTS(xfilehan,' ') =FPUTS(xfilehan,xinisection) =FPUTS(xfilehan,xiniitem+'='+xinisetting) ENDIF =FFLUSH(xfilehan) =FCLOSE(xfilehan) ENDIF #ENDIF ENDIF RETURN xreturn *: EOF: PUT_INI.PRGGET_INI.PRG
*:***************************************************************************** *: *: Procedure file: GET_INI.PRG *:***************************************************************************** * * PURPOSE: Returns the value of an item in a INI file. * * USAGE: varible = GET_INI( 'FILENAME.INI', '[SomeSection]', 'SomeItem' ) * * REVISION: Common * * Date Programmer Changes * ---------- ----------- ---------------------------------------------------- * PARAMETERS xinifile,xinisection,xiniitem PRIVATE xreturn,xfilehan,xiniline xreturn = ' ' xfilehan = 0 *--10/16/2001 TCH Visual Foxpro Mods #IF 'VISUAL' $ UPPER(VERSION()) *--must have valid parameters passed to get information from INI file IF EMPTY(xinifile) OR EMPTY(xinisection) OR EMPTY(xiniitem) RETURN xReturn ENDIF *--must ensure path is given to ini file-if not add it -- all inis are in progs IF LEFT(xIniFile,1)<>"\" .and. LEFT(xIniFile,2)<>".." .and. SUBSTR(ALLTRIM(xIniFile),2,1)<>":" xIniFile="\profiler\progs\"+xIniFile ENDIF *--if brackets were included in passed section parameter, strip them out IF LEFT(LTRIM(xIniSection),1)="[" xIniSection=SUBSTR(xIniSection,2,AT(']',xIniSection)-2) ENDIF *---Create the file <<xinifile>> if it does not exist. IF !FILE(xinifile) RETURN xReturn ENDIF *--Retrieve the section key's string LOCAL lnargs, lcresult, lcdefault, lnbufsize lnargs=PARAMETERS() lcresult=SPACE(255) lnbufsize=LEN(lcResult) lcdefault=' ' DECLARE SHORT GetPrivateProfileString IN WIN32API ; STRING cIniSection, STRING cIniItem, STRING cDefault, ; STRING @cReturnBuffer, INTEGER nBufferSize, STRING cIniFile lnbufsize=GetPrivateProfileString(xInisection, xIniItem, lcdefault, @lcresult, lnbufsize, xIniFile) IF lnbufsize>0 *--Get rid of the null character lcResult = STRTRAN(lcResult,CHR(0),"") IF LEN(ALLTRIM(lcResult))=0 lcResult= ' ' ELSE lcResult=LEFT(lcresult, lnbufsize) ENDIF ELSE lcResult= ' ' ENDIF RETURN lcResult #ELSE IF !EMPTY(xinifile) AND !EMPTY(xinisection) AND !EMPTY(xiniitem) *---Create the file <<xinifile>> if it does not exist. IF FILE(xinifile) xfilehan = FOPEN(xinifile) ELSE xfilehan = FCREATE(xinifile) ENDIF IF xfilehan > 0 *---Search for the begining of the section DO WHILE !FEOF(xfilehan) xiniline = FGETS(xfilehan) IF xiniline = xinisection *---Search through this section only DO WHILE !FEOF(xfilehan) xiniline = FGETS(xfilehan) DO CASE CASE LEFT(xiniline,1) = '[' EXIT CASE LEFT(xiniline,AT('=',xiniline)-1) = xiniitem xreturn = SUBSTR(xiniline,AT('=',xiniline)+1) EXIT ENDCASE ENDDO EXIT ENDIF ENDDO =FCLOSE(xfilehan) ENDIF ENDIF #ENDIF RETURN xreturn *: EOF: GET_INI.PRG