Converter: Backup the original .dfm also when it is used directly for Lazarus. Issue #29631.

git-svn-id: trunk@51632 -
This commit is contained in:
juha 2016-02-15 00:08:08 +00:00
parent d7e4677c9f
commit 5ec79158ce

View File

@ -556,33 +556,40 @@ var
begin begin
Result:=mrOK; Result:=mrOK;
fLFMBuffer:=nil; fLFMBuffer:=nil;
if ADfmFilename<>'' then begin if ADfmFilename<>'' then
begin
Result:=LazarusIDE.DoCloseEditorFile(ADfmFilename,[cfSaveFirst]); Result:=LazarusIDE.DoCloseEditorFile(ADfmFilename,[cfSaveFirst]);
if Result<>mrOK then exit; if Result<>mrOK then exit;
// Save before using .dfm.
Result:=fOwnerConverter.fSettings.MaybeBackupFile(ADfmFilename);
if Result<>mrOK then exit;
end; end;
if fOwnerConverter.fSettings.SameDfmFile then if fOwnerConverter.fSettings.SameDfmFile then
LfmFilename:=ADfmFilename LfmFilename:=ADfmFilename
else else begin
with fOwnerConverter do begin
// Create a form file name based on the unit file name. // Create a form file name based on the unit file name.
LfmFilename:=fSettings.DelphiToLazFilename(fOrigUnitFilename, '.lfm', with fOwnerConverter.fSettings do
LfmFilename:=DelphiToLazFilename(fOrigUnitFilename, '.lfm',
cdtlufRenameLowercase in fFlags); cdtlufRenameLowercase in fFlags);
if ADfmFilename<>'' then begin if ADfmFilename<>'' then
begin
if FileExistsUTF8(LfmFilename) then if FileExistsUTF8(LfmFilename) then
if (FileAgeUTF8(LfmFilename)<FileAgeUTF8(ADfmFilename)) then if (FileAgeUTF8(LfmFilename)<FileAgeUTF8(ADfmFilename)) then
DeleteFileUTF8(LfmFilename); // .lfm is older than .dfm -> remove .lfm DeleteFileUTF8(LfmFilename); // .lfm is older than .dfm -> remove .lfm
if not FileExistsUTF8(LfmFilename) then begin if not FileExistsUTF8(LfmFilename) then
begin
// TODO: update project // TODO: update project
if fSettings.SupportDelphi and not fSettings.SameDfmFile then if fOwnerConverter.fSettings.SupportDelphi then
Result:=CopyFileWithErrorDialogs(ADfmFilename,LfmFilename,[mbAbort]) Result:=CopyFileWithErrorDialogs(ADfmFilename, LfmFilename, [mbAbort])
else else
Result:=fSettings.RenameFile(ADfmFilename,LfmFilename); Result:=RenameFileWithErrorDialogs(ADfmFilename, LfmFilename, [mbAbort]);
if Result<>mrOK then exit; if Result<>mrOK then exit;
end; end;
end; end;
end; end;
// Convert Unit .dfm file to .lfm file (without context type checking) // Convert Unit .dfm file to .lfm file (without context type checking)
if FileExistsUTF8(LfmFilename) then begin if FileExistsUTF8(LfmFilename) then
begin
DFMConverter:=TDFMConverter.Create; DFMConverter:=TDFMConverter.Create;
try try
DFMConverter.Settings:=fOwnerConverter.fSettings; DFMConverter.Settings:=fOwnerConverter.fSettings;
@ -595,18 +602,18 @@ begin
Result:=LoadCodeBuffer(TempLFMBuffer,LfmFilename, Result:=LoadCodeBuffer(TempLFMBuffer,LfmFilename,
[lbfCheckIfText,lbfUpdateFromDisk],true); [lbfCheckIfText,lbfUpdateFromDisk],true);
// Change encoding to UTF-8 // Change encoding to UTF-8
if TempLFMBuffer.DiskEncoding<>EncodingUTF8 then begin if TempLFMBuffer.DiskEncoding<>EncodingUTF8 then
begin
fOwnerConverter.fSettings.AddLogLine(Format(lisConvDelphiChangedEncodingToUTF8, fOwnerConverter.fSettings.AddLogLine(Format(lisConvDelphiChangedEncodingToUTF8,
[TempLFMBuffer.DiskEncoding])); [TempLFMBuffer.DiskEncoding]));
TempLFMBuffer.DiskEncoding:=EncodingUTF8; TempLFMBuffer.DiskEncoding:=EncodingUTF8;
TempLFMBuffer.Save; TempLFMBuffer.Save;
end; end;
// Read form file code in. // Read form file code in.
if not fOwnerConverter.fSettings.SameDfmFile then begin if not fOwnerConverter.fSettings.SameDfmFile then
Result:=LoadCodeBuffer(fLFMBuffer,LfmFilename, Result:=LoadCodeBuffer(fLFMBuffer,LfmFilename,
[lbfCheckIfText,lbfUpdateFromDisk],true); [lbfCheckIfText,lbfUpdateFromDisk],true);
end; end;
end;
end; end;
function TDelphiUnit.ConvertUnitFile: TModalResult; function TDelphiUnit.ConvertUnitFile: TModalResult;