[JEDI.NET-commits] main/run Jedi.IO.IniFiles.pas,1.1,1.2
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2005-01-23 11:07:01
|
Update of /cvsroot/jedidotnet/main/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9926/main/run Modified Files: Jedi.IO.IniFiles.pas Log Message: * Used new resource static classes. * Fixed a number of bugs Index: Jedi.IO.IniFiles.pas =================================================================== RCS file: /cvsroot/jedidotnet/main/run/Jedi.IO.IniFiles.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Jedi.IO.IniFiles.pas 22 Jan 2005 17:59:14 -0000 1.1 --- Jedi.IO.IniFiles.pas 23 Jan 2005 11:06:48 -0000 1.2 *************** *** 92,96 **** ReturnType: Integer; Version: Integer; - class var rm: ResourceManager; {$ENDREGION} {$REGION 'Return type constants'} --- 92,95 ---- *************** *** 127,131 **** {$REGION 'protected methods'} strict protected - class constructor Create; constructor Create(IniFile: IniFileBase; iterationType, returnType: Integer; section: string); function SectionImpl: string; virtual; abstract; --- 126,129 ---- *************** *** 318,323 **** strict private FCount: Integer; - protected - class var rm: ResourceManager; strict protected KeyType: Integer; --- 316,319 ---- *************** *** 328,333 **** {$ENDREGION 'Internal data'} {$REGION 'Constructors'} - strict private - class constructor Create; public constructor Create(IniFile: MemoryIniFileBase; keyType: Integer); overload; --- 324,327 ---- *************** *** 471,475 **** {$REGION 'Constructors'} public ! constructor Create(path: string); {$ENDREGION} {$REGION 'Data'} --- 465,470 ---- {$REGION 'Constructors'} public ! constructor Create(path: string); overload; ! constructor Create(path: string; autoReloadInterval, autoFlushInterval: Integer); overload; {$ENDREGION} {$REGION 'Data'} *************** *** 519,522 **** --- 514,524 ---- procedure WriteImpl(section, key, value: string); override; {$ENDREGION} + {$REGION 'Public interface'} + public + procedure FullReload; + procedure Flush; + procedure Reload; overload; + procedure Reload(fileOverridesChanges: Boolean); overload; + {$ENDREGION} {$REGION 'Protected methods'} strict protected *************** *** 526,530 **** function NeedFlush: Boolean; function NeedReload: Boolean; ! procedure ReloadImpl; {$ENDREGION} {$REGION 'Property accessors'} --- 528,532 ---- function NeedFlush: Boolean; function NeedReload: Boolean; ! procedure ReloadImpl(fileOverridesChanges: Boolean); {$ENDREGION} {$REGION 'Property accessors'} *************** *** 547,552 **** {$REGION 'implementation uses'} uses ! System.Globalization, ! Jedi.System.Strings; {$ENDREGION} --- 549,553 ---- {$REGION 'implementation uses'} uses ! System.Globalization; {$ENDREGION} *************** *** 554,562 **** constructor BufferedIniFile.Create(path: string); begin inherited Create(True, True); FPath := path; ! ReloadImpl; ! FAutoFlushInterval := 10000; ! FAutoReloadInterval := 1000; FAutoFlushTimer := Timer.Create(AutoFlushHandler, nil, FAutoFlushInterval, FAutoFlushInterval); FAutoReloadTimer := Timer.Create(AutoReloadHandler, nil, FAutoReloadInterval, FAutoReloadInterval); --- 555,568 ---- constructor BufferedIniFile.Create(path: string); begin + Create(path, 10000, 1000); + end; + + constructor BufferedIniFile.Create(path: string; autoReloadInterval, autoFlushInterval: Integer); + begin inherited Create(True, True); FPath := path; ! ReloadImpl(True); ! Self.AutoFlushInterval := autoFlushInterval; ! Self.AutoReloadInterval := autoReloadInterval; FAutoFlushTimer := Timer.Create(AutoFlushHandler, nil, FAutoFlushInterval, FAutoFlushInterval); FAutoReloadTimer := Timer.Create(AutoReloadHandler, nil, FAutoReloadInterval, FAutoReloadInterval); *************** *** 589,593 **** try if NeedReload then ! ReloadImpl; finally Monitor.Exit(Self); --- 595,599 ---- try if NeedReload then ! ReloadImpl(False); finally Monitor.Exit(Self); *************** *** 644,648 **** sw: StreamWriter; begin ! sw := StreamWriter.Create(&File.Open(FPath, FileMode.CreateNew, FileAccess.Write, FileShare.Read)); SaveImpl(sw, True, ';'); sw.Close; --- 650,654 ---- sw: StreamWriter; begin ! sw := StreamWriter.Create(&File.Open(FPath, FileMode.Create, FileAccess.Write, FileShare.Read)); SaveImpl(sw, True, ';'); sw.Close; *************** *** 650,653 **** --- 656,665 ---- end; + procedure BufferedIniFile.Flush; + begin + if HasChanges then + FlushImpl; + end; + function BufferedIniFile.GetEnumerator(iteratorType, returnType: Integer; sect: string): IIniFileEnumerator; begin *************** *** 700,704 **** end; ! procedure BufferedIniFile.ReloadImpl; var sr: StreamReader; --- 712,735 ---- end; ! procedure BufferedIniFile.FullReload; ! begin ! ClearImpl; ! if NeedReload then ! ReloadImpl(True); ! end; ! ! procedure BufferedIniFile.Reload; ! begin ! if NeedReload then ! ReloadImpl(False); ! end; ! ! procedure BufferedIniFile.Reload(fileOverridesChanges: Boolean); ! begin ! if NeedReload then ! ReloadImpl(fileOverridesChanges); ! end; ! ! procedure BufferedIniFile.ReloadImpl(fileOverridesChanges: Boolean); var sr: StreamReader; *************** *** 707,711 **** begin sr := StreamReader.Create(&File.Open(FPath, FileMode.Open, FileAccess.Read, FileShare.Read)); ! LoadImpl(sr, ['#', ';', ''''], False, False); FLastWrite := &File.GetLastWriteTimeUtc(FPath); sr.Close; --- 738,742 ---- begin sr := StreamReader.Create(&File.Open(FPath, FileMode.Open, FileAccess.Read, FileShare.Read)); ! LoadImpl(sr, ['#', ';', ''''], False, fileOverridesChanges); FLastWrite := &File.GetLastWriteTimeUtc(FPath); sr.Close; *************** *** 715,722 **** procedure BufferedIniFile.set_AutoFlushInterval(value: Integer); begin if value <> FAutoFlushInterval then begin FAutoFlushInterval := value; ! FAutoFlushTimer.Change(value, value); end; end; --- 746,757 ---- procedure BufferedIniFile.set_AutoFlushInterval(value: Integer); begin + if value < Timeout.Infinite then + raise ArgumentOutOfRangeException.Create('AutoFlushInterval', + MscorlibResources.GetResourceString('ArgumentOutOfRange_NeedNonNegOrNegative1')); if value <> FAutoFlushInterval then begin FAutoFlushInterval := value; ! if Assigned(FAutoFlushTimer) then ! FAutoFlushTimer.Change(value, value); end; end; *************** *** 724,731 **** procedure BufferedIniFile.set_AutoReloadInterval(value: Integer); begin if value <> FAutoReloadInterval then begin FAutoReloadInterval := value; ! FAutoReloadTimer.Change(value, value); end; end; --- 759,770 ---- procedure BufferedIniFile.set_AutoReloadInterval(value: Integer); begin + if value < Timeout.Infinite then + raise ArgumentOutOfRangeException.Create('AutoReloadInterval', + MscorlibResources.GetResourceString('ArgumentOutOfRange_NeedNonNegOrNegative1')); if value <> FAutoReloadInterval then begin FAutoReloadInterval := value; ! if Assigned(FAutoReloadTimer) then ! FAutoReloadTimer.Change(value, value); end; end; *************** *** 1108,1116 **** {$REGION 'IniFileBase.IniFileEnumerator'} - class constructor IniFileBase.IniFileEnumerator.Create; - begin - rm := ResourceManager.Create('mscorlib', TypeOf(System.String).Assembly); - end; - constructor IniFileBase.IniFileEnumerator.Create(IniFile: IniFileBase; iterationType, returnType: Integer; section: string); --- 1147,1150 ---- *************** *** 1136,1142 **** begin if (Version <> IniFile.Version) then ! raise InvalidOperationException.Create(rm.GetString('InvalidOperation_EnumFailedVersion')); if not Current then ! raise InvalidOperationException.Create(rm.GetString('InvalidOperation_EnumOpCantHappen')); Result := SectionImpl; end; --- 1170,1176 ---- begin if (Version <> IniFile.Version) then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumFailedVersion')); if not Current then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumOpCantHappen')); Result := SectionImpl; end; *************** *** 1145,1151 **** begin if (Version <> IniFile.Version) then ! raise InvalidOperationException.Create(rm.GetString('InvalidOperation_EnumFailedVersion')); if not Current then ! raise InvalidOperationException.Create(rm.GetString('InvalidOperation_EnumOpCantHappen')); Result := KeyImpl; end; --- 1179,1185 ---- begin if (Version <> IniFile.Version) then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumFailedVersion')); if not Current then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumOpCantHappen')); Result := KeyImpl; end; *************** *** 1154,1160 **** begin if (Version <> IniFile.Version) then ! raise InvalidOperationException.Create(rm.GetString('InvalidOperation_EnumFailedVersion')); if not Current then ! raise InvalidOperationException.Create(rm.GetString('InvalidOperation_EnumOpCantHappen')); Result := ValueImpl; end; --- 1188,1194 ---- begin if (Version <> IniFile.Version) then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumFailedVersion')); if not Current then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumOpCantHappen')); Result := ValueImpl; end; *************** *** 1163,1169 **** begin if (Version <> IniFile.Version) then ! raise InvalidOperationException.Create(rm.GetString('InvalidOperation_EnumFailedVersion')); if not Current then ! raise InvalidOperationException.Create(rm.GetString('InvalidOperation_EnumOpCantHappen')); case ReturnType of ReturnSectionKeyAndValue: --- 1197,1203 ---- begin if (Version <> IniFile.Version) then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumFailedVersion')); if not Current then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumOpCantHappen')); case ReturnType of ReturnSectionKeyAndValue: *************** *** 1185,1189 **** begin if (Version <> IniFile.Version) then ! raise InvalidOperationException.Create(rm.GetString('InvalidOperation_EnumFailedVersion')); Result := MoveNextImpl; Current := Result; --- 1219,1223 ---- begin if (Version <> IniFile.Version) then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumFailedVersion')); Result := MoveNextImpl; Current := Result; *************** *** 1193,1197 **** begin if (Version <> IniFile.Version) then ! raise InvalidOperationException.Create(rm.GetString('InvalidOperation_EnumFailedVersion')); Current := False; ResetImpl; --- 1227,1231 ---- begin if (Version <> IniFile.Version) then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumFailedVersion')); Current := False; ResetImpl; *************** *** 1338,1342 **** function MemoryIniFileBase.HasSectionImpl(section: string): Boolean; begin ! if not Assigned(section) or (section = '') then Result := FSections.Contains(section) else --- 1372,1376 ---- function MemoryIniFileBase.HasSectionImpl(section: string): Boolean; begin ! if Assigned(section) and (section <> '') then Result := FSections.Contains(section) else *************** *** 1560,1571 **** function MemoryIniFileBase.KeyOrValueList.Add(value: &Object): Integer; begin ! raise NotSupportedException.Create(MemoryIniFileBase.KeyValueDictionary.rm.GetString( ! 'NotSupported_ReadOnlyCollection')); end; procedure MemoryIniFileBase.KeyOrValueList.Clear; begin ! raise NotSupportedException.Create(MemoryIniFileBase.KeyValueDictionary.rm.GetString( ! 'NotSupported_ReadOnlyCollection')); end; --- 1594,1603 ---- function MemoryIniFileBase.KeyOrValueList.Add(value: &Object): Integer; begin ! raise NotSupportedException.Create(MscorlibResources.GetResourceString('NotSupported_ReadOnlyCollection')); end; procedure MemoryIniFileBase.KeyOrValueList.Clear; begin ! raise NotSupportedException.Create(MscorlibResources.GetResourceString('NotSupported_ReadOnlyCollection')); end; *************** *** 1586,1597 **** raise ArgumentNullException.Create('array'); if &array.Rank <> 1 then ! raise ArgumentException.Create(MemoryIniFileBase.KeyValueDictionary.rm.GetString( ! 'Arg_RankMultiDimNotSupported')); if (index < &array.GetLowerBound(0)) or (index > &array.GetUpperBound(0)) then ! raise ArgumentOutOfRangeException.Create('index', MemoryIniFileBase.KeyValueDictionary.rm.GetString( ! 'Arg_IndexOutOfRangeException')); tempCount := get_Count; if (index + tempCount - 1) > &array.GetUpperBound(0) then ! raise ArgumentException.Create(MemoryIniFileBase.KeyValueDictionary.rm.GetString('Arg_ArrayPlusOffTooSmall')); enum := GetEnumerator; while enum.MoveNext do --- 1618,1627 ---- raise ArgumentNullException.Create('array'); if &array.Rank <> 1 then ! raise ArgumentException.Create(MscorlibResources.GetResourceString('Arg_RankMultiDimNotSupported')); if (index < &array.GetLowerBound(0)) or (index > &array.GetUpperBound(0)) then ! raise ArgumentOutOfRangeException.Create('index', MscorlibResources.GetResourceString('Arg_IndexOutOfRangeException')); tempCount := get_Count; if (index + tempCount - 1) > &array.GetUpperBound(0) then ! raise ArgumentException.Create(MscorlibResources.GetResourceString('Arg_ArrayPlusOffTooSmall')); enum := GetEnumerator; while enum.MoveNext do *************** *** 1650,1683 **** procedure MemoryIniFileBase.KeyOrValueList.Insert(index: Integer; value: &Object); begin ! raise NotSupportedException.Create(MemoryIniFileBase.KeyValueDictionary.rm.GetString( ! 'NotSupported_ReadOnlyCollection')); end; procedure MemoryIniFileBase.KeyOrValueList.Remove(value: &Object); begin ! raise NotSupportedException.Create(MemoryIniFileBase.KeyValueDictionary.rm.GetString( ! 'NotSupported_ReadOnlyCollection')); end; procedure MemoryIniFileBase.KeyOrValueList.RemoveAt(index: Integer); begin ! raise NotSupportedException.Create(MemoryIniFileBase.KeyValueDictionary.rm.GetString( ! 'NotSupported_ReadOnlyCollection')); end; procedure MemoryIniFileBase.KeyOrValueList.set_Item(index: Integer; value: &Object); begin ! raise NotSupportedException.Create(MemoryIniFileBase.KeyValueDictionary.rm.GetString( ! 'NotSupported_ReadOnlyCollection')); end; {$ENDREGION} {$REGION 'MemoryIniFileBase.KeyValueDictionary'} - - class constructor MemoryIniFileBase.KeyValueDictionary.Create; - begin - rm := ResourceManager.Create('mscorlib', TypeOf(System.String).Assembly); - end; - constructor MemoryIniFileBase.KeyValueDictionary.Create(IniFile: MemoryIniFileBase; keyType: Integer); begin --- 1680,1703 ---- procedure MemoryIniFileBase.KeyOrValueList.Insert(index: Integer; value: &Object); begin ! raise NotSupportedException.Create(MscorlibResources.GetResourceString('NotSupported_ReadOnlyCollection')); end; procedure MemoryIniFileBase.KeyOrValueList.Remove(value: &Object); begin ! raise NotSupportedException.Create(MscorlibResources.GetResourceString('NotSupported_ReadOnlyCollection')); end; procedure MemoryIniFileBase.KeyOrValueList.RemoveAt(index: Integer); begin ! raise NotSupportedException.Create(MscorlibResources.GetResourceString('NotSupported_ReadOnlyCollection')); end; procedure MemoryIniFileBase.KeyOrValueList.set_Item(index: Integer; value: &Object); begin ! raise NotSupportedException.Create(MscorlibResources.GetResourceString('NotSupported_ReadOnlyCollection')); end; {$ENDREGION} {$REGION 'MemoryIniFileBase.KeyValueDictionary'} constructor MemoryIniFileBase.KeyValueDictionary.Create(IniFile: MemoryIniFileBase; keyType: Integer); begin *************** *** 1701,1710 **** procedure MemoryIniFileBase.KeyValueDictionary.Add(key, value: &Object); begin ! raise NotSupportedException.Create(rm.GetString('NotSupported_ReadOnlyCollection')); end; procedure MemoryIniFileBase.KeyValueDictionary.Clear; begin ! raise NotSupportedException.Create(rm.GetString('NotSupported_ReadOnlyCollection')); end; --- 1721,1730 ---- procedure MemoryIniFileBase.KeyValueDictionary.Add(key, value: &Object); begin ! raise NotSupportedException.Create(MscorlibResources.GetResourceString('NotSupported_ReadOnlyCollection')); end; procedure MemoryIniFileBase.KeyValueDictionary.Clear; begin ! raise NotSupportedException.Create(MscorlibResources.GetResourceString('NotSupported_ReadOnlyCollection')); end; *************** *** 1723,1732 **** raise ArgumentNullException.Create('array'); if &array.Rank <> 1 then ! raise ArgumentException.Create(rm.GetString('Arg_RankMultiDimNotSupported')); if (index < &array.GetLowerBound(0)) or (index > &array.GetUpperBound(0)) then ! raise ArgumentOutOfRangeException.Create('index', rm.GetString('Arg_IndexOutOfRangeException')); tempCount := get_Count; if (index + tempCount - 1) > &array.GetUpperBound(0) then ! raise ArgumentException.Create(rm.GetString('Arg_ArrayPlusOffTooSmall')); enum := GetDictionaryEnumerator; while enum.MoveNext do --- 1743,1752 ---- raise ArgumentNullException.Create('array'); if &array.Rank <> 1 then ! raise ArgumentException.Create(MscorlibResources.GetResourceString('Arg_RankMultiDimNotSupported')); if (index < &array.GetLowerBound(0)) or (index > &array.GetUpperBound(0)) then ! raise ArgumentOutOfRangeException.Create('index', MscorlibResources.GetResourceString('Arg_IndexOutOfRangeException')); tempCount := get_Count; if (index + tempCount - 1) > &array.GetUpperBound(0) then ! raise ArgumentException.Create(MscorlibResources.GetResourceString('Arg_ArrayPlusOffTooSmall')); enum := GetDictionaryEnumerator; while enum.MoveNext do *************** *** 1880,1889 **** procedure MemoryIniFileBase.KeyValueDictionary.Remove(key: &Object); begin ! raise NotSupportedException.Create(rm.GetString('NotSupported_ReadOnlyCollection')); end; procedure MemoryIniFileBase.KeyValueDictionary.set_Item(key, value: &Object); begin ! raise NotSupportedException.Create(rm.GetString('NotSupported_ReadOnlyCollection')); end; --- 1900,1909 ---- procedure MemoryIniFileBase.KeyValueDictionary.Remove(key: &Object); begin ! raise NotSupportedException.Create(MscorlibResources.GetResourceString('NotSupported_ReadOnlyCollection')); end; procedure MemoryIniFileBase.KeyValueDictionary.set_Item(key, value: &Object); begin ! raise NotSupportedException.Create(MscorlibResources.GetResourceString('NotSupported_ReadOnlyCollection')); end; *************** *** 1943,1951 **** begin if (FVersion <> FKeyValueDictionary.IniFile.Version) then ! raise InvalidOperationException.Create(MemoryIniFileBase.KeyValueDictionary.rm.GetString( ! 'InvalidOperation_EnumFailedVersion')); if (FIndex < 0) or (FIndex >= IDictionary(FKeyValueDictionary).Count) then ! raise InvalidOperationException.Create(MemoryIniFileBase.KeyValueDictionary.rm.GetString( ! 'InvalidOperation_EnumOpCantHappen')); Result := FKeyValueDictionary.GetDictionaryEntry(FIndex); end; --- 1963,1969 ---- begin if (FVersion <> FKeyValueDictionary.IniFile.Version) then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumFailedVersion')); if (FIndex < 0) or (FIndex >= IDictionary(FKeyValueDictionary).Count) then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumOpCantHappen')); Result := FKeyValueDictionary.GetDictionaryEntry(FIndex); end; *************** *** 1964,1969 **** begin if (FVersion <> FKeyValueDictionary.IniFile.Version) then ! raise InvalidOperationException.Create(MemoryIniFileBase.KeyValueDictionary.rm.GetString( ! 'InvalidOperation_EnumFailedVersion')); Inc(FIndex); Result := FIndex < IDictionary(FKeyValueDictionary).Count; --- 1982,1986 ---- begin if (FVersion <> FKeyValueDictionary.IniFile.Version) then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumFailedVersion')); Inc(FIndex); Result := FIndex < IDictionary(FKeyValueDictionary).Count; *************** *** 1975,1980 **** begin if (FVersion <> FKeyValueDictionary.IniFile.Version) then ! raise InvalidOperationException.Create(MemoryIniFileBase.KeyValueDictionary.rm.GetString( ! 'InvalidOperation_EnumFailedVersion')); FIndex := -1; end; --- 1992,1996 ---- begin if (FVersion <> FKeyValueDictionary.IniFile.Version) then ! raise InvalidOperationException.Create(MscorlibResources.GetResourceString('InvalidOperation_EnumFailedVersion')); FIndex := -1; end; *************** *** 2021,2040 **** procedure MemoryIniFile.Save(path: string); begin ! SaveImpl(StreamWriter.Create(path), True, #0); end; procedure MemoryIniFile.Save(path: string; commentChar: Char); begin ! SaveImpl(StreamWriter.Create(path), True, commentChar); end; procedure MemoryIniFile.Save(path: string; emptyLineBetweenSections: Boolean); begin ! SaveImpl(StreamWriter.Create(path), emptyLineBetweenSections, #0); end; procedure MemoryIniFile.Save(path: string; commentChar: Char; emptyLineBetweenSections: Boolean); begin ! SaveImpl(StreamWriter.Create(path), emptyLineBetweenSections, commentChar); end; --- 2037,2063 ---- procedure MemoryIniFile.Save(path: string); begin ! Save(path, #0, True); end; procedure MemoryIniFile.Save(path: string; commentChar: Char); begin ! Save(path, commentChar, True); end; procedure MemoryIniFile.Save(path: string; emptyLineBetweenSections: Boolean); begin ! Save(path, #0, emptyLineBetweenSections); end; procedure MemoryIniFile.Save(path: string; commentChar: Char; emptyLineBetweenSections: Boolean); + var + sw: StreamWriter; begin ! sw := StreamWriter.Create(path); ! try ! SaveImpl(sw, emptyLineBetweenSections, commentChar); ! finally ! sw.Close; ! end; end; |