|
@@ -215,10 +215,12 @@ type
|
|
FStream: TStream;
|
|
FStream: TStream;
|
|
FCacheUpdates: Boolean;
|
|
FCacheUpdates: Boolean;
|
|
FDirty : Boolean;
|
|
FDirty : Boolean;
|
|
|
|
+ FWriteBOM: Boolean;
|
|
procedure FillSectionList(AStrings: TStrings);
|
|
procedure FillSectionList(AStrings: TStrings);
|
|
Procedure DeleteSection(ASection : TIniFileSection);
|
|
Procedure DeleteSection(ASection : TIniFileSection);
|
|
Procedure MaybeDeleteSection(ASection : TIniFileSection);
|
|
Procedure MaybeDeleteSection(ASection : TIniFileSection);
|
|
procedure SetCacheUpdates(const AValue: Boolean);
|
|
procedure SetCacheUpdates(const AValue: Boolean);
|
|
|
|
+ procedure SetWriteBOM(const aWriteBOM: Boolean);
|
|
protected
|
|
protected
|
|
procedure ReadIniValues;
|
|
procedure ReadIniValues;
|
|
procedure MaybeUpdateFile;
|
|
procedure MaybeUpdateFile;
|
|
@@ -241,6 +243,7 @@ type
|
|
procedure UpdateFile; override;
|
|
procedure UpdateFile; override;
|
|
property Stream: TStream read FStream;
|
|
property Stream: TStream read FStream;
|
|
property CacheUpdates : Boolean read FCacheUpdates write SetCacheUpdates;
|
|
property CacheUpdates : Boolean read FCacheUpdates write SetCacheUpdates;
|
|
|
|
+ property WriteBOM: Boolean Read FWriteBOM Write SetWriteBOM;
|
|
end;
|
|
end;
|
|
|
|
|
|
{ TMemIniFile }
|
|
{ TMemIniFile }
|
|
@@ -981,6 +984,9 @@ begin
|
|
// read the ini file values
|
|
// read the ini file values
|
|
slLines.LoadFromStream(FStream, FEncoding);
|
|
slLines.LoadFromStream(FStream, FEncoding);
|
|
FillSectionList(slLines);
|
|
FillSectionList(slLines);
|
|
|
|
+ if FEncoding=nil then
|
|
|
|
+ FEncoding := TEncoding.Default;
|
|
|
|
+ FWriteBOM := (FEncoding.CodePage=CP_UTF16) or (FEncoding.CodePage=CP_UTF16BE); // write BOM for UTF16 by default
|
|
finally
|
|
finally
|
|
slLines.Free;
|
|
slLines.Free;
|
|
end;
|
|
end;
|
|
@@ -1122,6 +1128,13 @@ begin
|
|
FCacheUpdates := AValue;
|
|
FCacheUpdates := AValue;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TIniFile.SetWriteBOM(const aWriteBOM: Boolean);
|
|
|
|
+begin
|
|
|
|
+ if FWriteBOM = aWriteBOM then Exit;
|
|
|
|
+ FWriteBOM := aWriteBOM;
|
|
|
|
+ MaybeUpdateFile;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TIniFile.WriteString(const Section, Ident, Value: String);
|
|
procedure TIniFile.WriteString(const Section, Ident, Value: String);
|
|
var
|
|
var
|
|
oSection: TIniFileSection;
|
|
oSection: TIniFileSection;
|
|
@@ -1324,6 +1337,7 @@ begin
|
|
if (i < FSectionList.Count-1) and not IsComment(Name) then
|
|
if (i < FSectionList.Count-1) and not IsComment(Name) then
|
|
slLines.Add('');
|
|
slLines.Add('');
|
|
end;
|
|
end;
|
|
|
|
+ slLines.WriteBOM := FWriteBOM;
|
|
if FFileName > '' then
|
|
if FFileName > '' then
|
|
begin
|
|
begin
|
|
D:=ExtractFilePath(FFileName);
|
|
D:=ExtractFilePath(FFileName);
|
|
@@ -1363,17 +1377,34 @@ begin
|
|
slLines := TStringList.Create;
|
|
slLines := TStringList.Create;
|
|
try
|
|
try
|
|
// read the ini file values
|
|
// read the ini file values
|
|
- if FEncoding=nil then
|
|
|
|
- slLines.LoadFromFile(FFileName)
|
|
|
|
- else
|
|
|
|
- begin
|
|
|
|
|
|
+ if FEncoding<>nil then
|
|
slLines.DefaultEncoding := FEncoding; // TStrings clones the encoding.
|
|
slLines.DefaultEncoding := FEncoding; // TStrings clones the encoding.
|
|
- slLines.LoadFromFile(FFileName, nil);
|
|
|
|
|
|
+ slLines.Options := slLines.Options + [soPreserveBOM];
|
|
|
|
+ slLines.LoadFromFile(FFileName, nil);
|
|
|
|
+ if (FEncoding=nil) or (FEncoding.CodePage<>slLines.Encoding.CodePage) then
|
|
|
|
+ begin
|
|
|
|
+ if FOwnsEncoding then
|
|
|
|
+ FEncoding.Free;
|
|
|
|
+ if TEncoding.IsStandardEncoding(slLines.Encoding) then
|
|
|
|
+ begin
|
|
|
|
+ FEncoding := slLines.Encoding;
|
|
|
|
+ FOwnsEncoding := False;
|
|
|
|
+ end else
|
|
|
|
+ begin
|
|
|
|
+ FEncoding := slLines.Encoding.Clone;
|
|
|
|
+ FOwnsEncoding := True;
|
|
end;
|
|
end;
|
|
|
|
+ end;
|
|
|
|
+ FWriteBOM := slLines.WriteBOM;
|
|
FillSectionList(slLines);
|
|
FillSectionList(slLines);
|
|
finally
|
|
finally
|
|
slLines.Free;
|
|
slLines.Free;
|
|
end;
|
|
end;
|
|
|
|
+ end else
|
|
|
|
+ begin
|
|
|
|
+ if FEncoding=nil then
|
|
|
|
+ FEncoding := TEncoding.Default;
|
|
|
|
+ FWriteBOM := (FEncoding.CodePage=CP_UTF16) or (FEncoding.CodePage=CP_UTF16BE); // write BOM for UTF16 by default
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|