fix, DUB json, save as utf8 if loaded so, always save new proj as

This commit is contained in:
Basile Burg 2015-11-28 02:05:02 +01:00
parent 640f38a9d9
commit 9a9f74149f
1 changed files with 12 additions and 4 deletions

View File

@ -28,6 +28,7 @@ type
fBasePath: string; fBasePath: string;
fModificationCount: integer; fModificationCount: integer;
fOutputFileName: string; fOutputFileName: string;
fSaveAsUtf8: boolean;
// //
procedure doModified; procedure doModified;
procedure updateFields; procedure updateFields;
@ -99,6 +100,7 @@ const
constructor TCEDubProject.create(aOwner: TComponent); constructor TCEDubProject.create(aOwner: TComponent);
begin begin
inherited; inherited;
fSaveAsUtf8 := true;
fJSON := TJSONObject.Create(); fJSON := TJSONObject.Create();
fProjectSubject := TCEProjectSubject.Create; fProjectSubject := TCEProjectSubject.Create;
fBuildTypes := TStringList.Create; fBuildTypes := TStringList.Create;
@ -161,13 +163,14 @@ begin
fBasePath := extractFilePath(aFilename); fBasePath := extractFilePath(aFilename);
fFilename := aFilename; fFilename := aFilename;
loader.LoadFromFile(fFilename); loader.LoadFromFile(fFilename);
fSaveAsUtf8 := false;
//TODO-cDUB: if loaded as UTF8 it should be saved as well !
// skip BOM, this crashes the parser // skip BOM, this crashes the parser
loader.Read(bom, 4); loader.Read(bom, 4);
if (bom and $BFBBEF) = $BFBBEF then if (bom and $BFBBEF) = $BFBBEF then
loader.Position:= 3 begin
loader.Position:= 3;
fSaveAsUtf8 := true;
end
else if (bom = $FFFE0000) or (bom = $FEFF) then else if (bom = $FFFE0000) or (bom = $FEFF) then
begin begin
// UCS-4 LE/BE not handled by DUB // UCS-4 LE/BE not handled by DUB
@ -216,6 +219,11 @@ begin
try try
fFilename := aFilename; fFilename := aFilename;
str := fJSON.FormatJSON; str := fJSON.FormatJSON;
if fSaveAsUtf8 then
begin
saver.WriteDWord($00BFBBEF);
saver.Position:=saver.Position-1;
end;
saver.Write(str[1], length(str)); saver.Write(str[1], length(str));
saver.SaveToFile(fFilename); saver.SaveToFile(fFilename);
finally finally