* Save preferences to FoxPro Resource file
FUNCTION SavePrefs()
LOCAL nSelect
LOCAL lSuccess
LOCAL nMemoWidth
LOCAL nCnt
LOCAL cData
LOCAL i
LOCAL oOptionCollection
LOCAL ARRAY aFileList[1]
LOCAL ARRAY FOXREF_OPTIONS[1]
LOCAL ARRAY FOXREF_LOOKFOR_MRU[10]
LOCAL ARRAY FOXREF_FOLDER_MRU[10]
LOCAL ARRAY FOXREF_FILETYPES_MRU[10]
IF !(SET("RESOURCE") == "ON")
RETURN .F.
ENDIF
=ACOPY(THIS.aLookForMRU, FOXREF_LOOKFOR_MRU)
=ACOPY(THIS.aReplaceMRU, FOXREF_REPLACE_MRU)
=ACOPY(THIS.aFolderMRU, FOXREF_FOLDER_MRU)
=ACOPY(THIS.aFileTypesMRU, FOXREF_FILETYPES_MRU)
oOptionCollection = CREATEOBJECT("Collection")
* Add any properties you want to save to
* the resource file to this collection
WITH oOptionCollection
.Add(THIS.Comments, "Comments")
.Add(THIS.MatchCase, "MatchCase")
.Add(THIS.WholeWordsOnly, "WholeWordsOnly")
.Add(THIS.Wildcards, "Wildcards")
.Add(THIS.ProjectHomeDir, "ProjectHomeDir")
.Add(THIS.SubFolders, "SubFolders")
.Add(THIS.OverwritePrior, "OverwritePrior")
.Add(THIS.FileTypes, "FileTypes")
.Add(THIS.IncludeDefTable, "IncludeDefTable")
.Add(THIS.CodeOnly, "CodeOnly")
.Add(THIS.FormProperties, "FormProperties")
.Add(THIS.AutoProjectHomeDir, "AutoProjectHomeDir")
.Add(THIS.ConfirmReplace, "ConfirmReplace")
.Add(THIS.BackupOnReplace, "BackupOnReplace")
.Add(THIS.DisplayReplaceLog, "DisplayReplaceLog")
.Add(THIS.PreserveCase, "PreserveCase")
.Add(THIS.BackupStyle, "BackupStyle")
.Add(THIS.ShowRefsPerLine, "ShowRefsPerLine")
.Add(THIS.ShowFileTypeHistory, "ShowFileTypeHistory")
.Add(THIS.ShowDistinctMethodLine, "ShowDistinctMethodLine")
.Add(THIS.SortMostRecentFirst, "SortMostRecentFirst")
.Add(THIS.FontString, "FontString")
.Add(THIS.FoxRefDirectory, "FoxRefDirectory")
ENDWITH
DIMENSION FOXREF_OPTIONS[MAX(oOptionCollection.Count, 1), 2]
FOR i = 1 TO oOptionCollection.Count
FOXREF_OPTIONS[m.i, 1] = oOptionCollection.GetKey(m.i)
FOXREF_OPTIONS[m.i, 2] = oOptionCollection.Item(m.i)
ENDFOR
nSelect = SELECT()
lSuccess = .F.
* make sure Resource file exists and is not read-only
TRY
nCnt = ADIR(aFileList, SYS(2005))
CATCH
nCnt = 0
ENDTRY
IF nCnt > 0 AND ATCC('R', aFileList[1, 5]) == 0
IF !USED("FoxResource")
USE (SYS(2005)) IN 0 SHARED AGAIN ALIAS FoxResource
ENDIF
IF USED("FoxResource") AND !ISREADONLY("FoxResource")
nMemoWidth = SET('MEMOWIDTH')
SET MEMOWIDTH TO 255
SELECT FoxResource
LOCATE FOR UPPER(ALLTRIM(type)) == "PREFW" AND UPPER(ALLTRIM(id)) == RESOURCE_ID AND EMPTY(name)
IF !FOUND()
APPEND BLANK IN FoxResource
REPLACE ;
Type WITH "PREFW", ;
ID WITH RESOURCE_ID, ;
ReadOnly WITH .F. ;
IN FoxResource
ENDIF
IF !FoxResource.ReadOnly
SAVE TO MEMO Data ALL LIKE FOXREF_*
REPLACE ;
Updated WITH DATE(), ;
ckval WITH VAL(SYS(2007, FoxResource.Data)) ;
IN FoxResource
lSuccess = .T.
ENDIF
SET MEMOWIDTH TO (nMemoWidth)
USE IN FoxResource
ENDIF
ENDIF
SELECT (nSelect)
RETURN lSuccess
ENDFUNC