mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 10:39:18 +02:00
ide: simplify resource availability check
git-svn-id: trunk@16944 -
This commit is contained in:
parent
0775a9258a
commit
1876e1727f
@ -55,6 +55,8 @@ type
|
|||||||
function GetStream: TStream;
|
function GetStream: TStream;
|
||||||
procedure SetStream(AStream: TStream);
|
procedure SetStream(AStream: TStream);
|
||||||
|
|
||||||
|
function HasAnyLazarusResource: Boolean; override;
|
||||||
|
function HasAnySystemResource: Boolean; override;
|
||||||
function UpdateResources(AResources: TAbstractProjectResources; const MainFilename: string): Boolean; override;
|
function UpdateResources(AResources: TAbstractProjectResources; const MainFilename: string): Boolean; override;
|
||||||
function CreateIconFile: Boolean;
|
function CreateIconFile: Boolean;
|
||||||
|
|
||||||
@ -111,6 +113,16 @@ begin
|
|||||||
IconText := NewIconText;
|
IconText := NewIconText;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TProjectIcon.HasAnyLazarusResource: Boolean;
|
||||||
|
begin
|
||||||
|
Result := IconText <> '';
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TProjectIcon.HasAnySystemResource: Boolean;
|
||||||
|
begin
|
||||||
|
Result := IconText <> '';
|
||||||
|
end;
|
||||||
|
|
||||||
function TProjectIcon.UpdateResources(AResources: TAbstractProjectResources;
|
function TProjectIcon.UpdateResources(AResources: TAbstractProjectResources;
|
||||||
const MainFilename: string): Boolean;
|
const MainFilename: string): Boolean;
|
||||||
var
|
var
|
||||||
@ -134,6 +146,7 @@ begin
|
|||||||
// the preferred way is this:
|
// the preferred way is this:
|
||||||
// RCIcon := sIcon + #$D#$A + GetAsHex;
|
// RCIcon := sIcon + #$D#$A + GetAsHex;
|
||||||
// but it does not work
|
// but it does not work
|
||||||
|
|
||||||
if CreateIconFile then
|
if CreateIconFile then
|
||||||
AResources.AddSystemResource(sIcon + Format(' "%s"', [StringReplace(icoFileName, '\', '\\', [rfReplaceAll])]))
|
AResources.AddSystemResource(sIcon + Format(' "%s"', [StringReplace(icoFileName, '\', '\\', [rfReplaceAll])]))
|
||||||
else
|
else
|
||||||
|
@ -77,8 +77,8 @@ type
|
|||||||
function Regenerate(const AWorkingDir, MainFileName: String): Boolean;
|
function Regenerate(const AWorkingDir, MainFileName: String): Boolean;
|
||||||
function UpdateMainSourceFile(const AFileName: string): Boolean;
|
function UpdateMainSourceFile(const AFileName: string): Boolean;
|
||||||
|
|
||||||
function HasSystemResources: Boolean;
|
function HasSystemResources(CheckLists: Boolean): Boolean;
|
||||||
function HasLazarusResources: Boolean;
|
function HasLazarusResources(CheckLists: Boolean): Boolean;
|
||||||
|
|
||||||
procedure WriteToProjectFile(AConfig: TXMLConfig; Path: String);
|
procedure WriteToProjectFile(AConfig: TXMLConfig; Path: String);
|
||||||
procedure ReadFromProjectFile(AConfig: TXMLConfig; Path: String);
|
procedure ReadFromProjectFile(AConfig: TXMLConfig; Path: String);
|
||||||
@ -127,6 +127,7 @@ end;
|
|||||||
|
|
||||||
function TProjectResources.Update: Boolean;
|
function TProjectResources.Update: Boolean;
|
||||||
begin
|
begin
|
||||||
|
// CheckMode is used only to test whether we have paticular resources
|
||||||
Clear;
|
Clear;
|
||||||
// handle versioninfo
|
// handle versioninfo
|
||||||
Result := VersionInfo.UpdateResources(Self, rcFileName);
|
Result := VersionInfo.UpdateResources(Self, rcFileName);
|
||||||
@ -215,7 +216,7 @@ begin
|
|||||||
Exit;
|
Exit;
|
||||||
|
|
||||||
AStream := nil;
|
AStream := nil;
|
||||||
if HasSystemResources then
|
if HasSystemResources(True) then
|
||||||
begin
|
begin
|
||||||
try
|
try
|
||||||
AStream := TFileStream.Create(UTF8ToSys(rcFileName), fmCreate);
|
AStream := TFileStream.Create(UTF8ToSys(rcFileName), fmCreate);
|
||||||
@ -224,7 +225,7 @@ begin
|
|||||||
AStream.Free;
|
AStream.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
if HasLazarusResources then
|
if HasLazarusResources(True) then
|
||||||
begin
|
begin
|
||||||
try
|
try
|
||||||
AStream := TFileStream.Create(UTF8ToSys(lrsFileName), fmCreate);
|
AStream := TFileStream.Create(UTF8ToSys(lrsFileName), fmCreate);
|
||||||
@ -236,14 +237,24 @@ begin
|
|||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TProjectResources.HasSystemResources: Boolean;
|
function TProjectResources.HasSystemResources(CheckLists: Boolean): Boolean;
|
||||||
begin
|
begin
|
||||||
Result := FSystemResources.Count > 0;
|
if CheckLists then
|
||||||
|
Result := FSystemResources.Count > 0
|
||||||
|
else
|
||||||
|
Result := VersionInfo.HasAnySystemResource or
|
||||||
|
XPManifest.HasAnySystemResource or
|
||||||
|
ProjectIcon.HasAnySystemResource;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TProjectResources.HasLazarusResources: Boolean;
|
function TProjectResources.HasLazarusResources(CheckLists: Boolean): Boolean;
|
||||||
begin
|
begin
|
||||||
Result := FLazarusResources.Count > 0;
|
if CheckLists then
|
||||||
|
Result := FLazarusResources.Count > 0
|
||||||
|
else
|
||||||
|
Result := VersionInfo.HasAnyLazarusResource or
|
||||||
|
XPManifest.HasAnyLazarusResource or
|
||||||
|
ProjectIcon.HasAnyLazarusResource;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TProjectResources.WriteToProjectFile(AConfig: TXMLConfig; Path: String);
|
procedure TProjectResources.WriteToProjectFile(AConfig: TXMLConfig; Path: String);
|
||||||
@ -310,8 +321,7 @@ var
|
|||||||
NamePos, InPos: integer;
|
NamePos, InPos: integer;
|
||||||
begin
|
begin
|
||||||
Result := True;
|
Result := True;
|
||||||
if not Update then
|
|
||||||
Exit;
|
|
||||||
CodeBuf := CodeToolBoss.LoadFile(AFilename, False, False);
|
CodeBuf := CodeToolBoss.LoadFile(AFilename, False, False);
|
||||||
if CodeBuf <> nil then
|
if CodeBuf <> nil then
|
||||||
begin
|
begin
|
||||||
@ -322,7 +332,7 @@ begin
|
|||||||
// update LResources uses
|
// update LResources uses
|
||||||
if CodeToolBoss.FindUnitInAllUsesSections(CodeBuf, LazResourcesUnit, NamePos, InPos) then
|
if CodeToolBoss.FindUnitInAllUsesSections(CodeBuf, LazResourcesUnit, NamePos, InPos) then
|
||||||
begin
|
begin
|
||||||
if not HasLazarusResources then
|
if not HasLazarusResources(False) then
|
||||||
begin
|
begin
|
||||||
if not CodeToolBoss.RemoveUnitFromAllUsesSections(CodeBuf, LazResourcesUnit) then
|
if not CodeToolBoss.RemoveUnitFromAllUsesSections(CodeBuf, LazResourcesUnit) then
|
||||||
begin
|
begin
|
||||||
@ -333,7 +343,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if HasLazarusResources then
|
if HasLazarusResources(False) then
|
||||||
begin
|
begin
|
||||||
if not CodeToolBoss.AddUnitToMainUsesSection(CodeBuf, LazResourcesUnit,'') then
|
if not CodeToolBoss.AddUnitToMainUsesSection(CodeBuf, LazResourcesUnit,'') then
|
||||||
begin
|
begin
|
||||||
@ -349,7 +359,7 @@ begin
|
|||||||
NewTopLine, Filename, false) then
|
NewTopLine, Filename, false) then
|
||||||
begin
|
begin
|
||||||
// there is a resource directive in the source
|
// there is a resource directive in the source
|
||||||
if not HasSystemResources then
|
if not HasSystemResources(False) then
|
||||||
begin
|
begin
|
||||||
if not CodeToolBoss.RemoveDirective(NewCode, NewX,NewY,true) then
|
if not CodeToolBoss.RemoveDirective(NewCode, NewX,NewY,true) then
|
||||||
begin
|
begin
|
||||||
@ -360,7 +370,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if HasSystemResources then
|
if HasSystemResources(False) then
|
||||||
begin
|
begin
|
||||||
if not CodeToolBoss.AddResourceDirective(CodeBuf,
|
if not CodeToolBoss.AddResourceDirective(CodeBuf,
|
||||||
Filename,false,'{$IFDEF WINDOWS}{$R '+Filename+'}{$ENDIF}') then
|
Filename,false,'{$IFDEF WINDOWS}{$R '+Filename+'}{$ENDIF}') then
|
||||||
@ -379,7 +389,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
// there is a resource directive in the source
|
// there is a resource directive in the source
|
||||||
//debugln(['TProjectResources.UpdateMainSourceFile include directive found']);
|
//debugln(['TProjectResources.UpdateMainSourceFile include directive found']);
|
||||||
if not HasLazarusResources then
|
if not HasLazarusResources(False) then
|
||||||
begin
|
begin
|
||||||
if not CodeToolBoss.RemoveDirective(NewCode, NewX,NewY,true) then
|
if not CodeToolBoss.RemoveDirective(NewCode, NewX,NewY,true) then
|
||||||
begin
|
begin
|
||||||
@ -391,7 +401,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if HasLazarusResources then
|
if HasLazarusResources(False) then
|
||||||
begin
|
begin
|
||||||
//debugln(['TProjectResources.UpdateMainSourceFile include directive not found']);
|
//debugln(['TProjectResources.UpdateMainSourceFile include directive not found']);
|
||||||
if not CodeToolBoss.AddIncludeDirective(CodeBuf,
|
if not CodeToolBoss.AddIncludeDirective(CodeBuf,
|
||||||
|
@ -47,6 +47,8 @@ type
|
|||||||
public
|
public
|
||||||
function UpdateResources(AResources: TAbstractProjectResources; const MainFilename: string): Boolean; override;
|
function UpdateResources(AResources: TAbstractProjectResources; const MainFilename: string): Boolean; override;
|
||||||
|
|
||||||
|
function HasAnyLazarusResource: Boolean; override;
|
||||||
|
function HasAnySystemResource: Boolean; override;
|
||||||
property UseManifest: boolean read FUseManifest write SetUseManifest;
|
property UseManifest: boolean read FUseManifest write SetUseManifest;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -94,5 +96,15 @@ begin
|
|||||||
AResources.AddSystemResource(sManifest);
|
AResources.AddSystemResource(sManifest);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TProjectXPManifest.HasAnyLazarusResource: Boolean;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TProjectXPManifest.HasAnySystemResource: Boolean;
|
||||||
|
begin
|
||||||
|
Result := UseManifest;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -84,6 +84,8 @@ type
|
|||||||
procedure SetUseVersionInfo(const AValue: boolean);
|
procedure SetUseVersionInfo(const AValue: boolean);
|
||||||
procedure SetVersionNr(const AValue: integer);
|
procedure SetVersionNr(const AValue: integer);
|
||||||
public
|
public
|
||||||
|
function HasAnyLazarusResource: Boolean; override;
|
||||||
|
function HasAnySystemResource: Boolean; override;
|
||||||
function UpdateResources(AResources: TAbstractProjectResources; const MainFilename: string): Boolean; override;
|
function UpdateResources(AResources: TAbstractProjectResources; const MainFilename: string): Boolean; override;
|
||||||
|
|
||||||
property UseVersionInfo: boolean read FUseVersionInfo write SetUseVersionInfo;
|
property UseVersionInfo: boolean read FUseVersionInfo write SetUseVersionInfo;
|
||||||
@ -511,6 +513,16 @@ begin
|
|||||||
Modified:=true;
|
Modified:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TProjectVersionInfo.HasAnyLazarusResource: Boolean;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TProjectVersionInfo.HasAnySystemResource: Boolean;
|
||||||
|
begin
|
||||||
|
Result := UseVersionInfo;
|
||||||
|
end;
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
FreeAndNil(fHexCharSets);
|
FreeAndNil(fHexCharSets);
|
||||||
FreeAndNil(fHexLanguages);
|
FreeAndNil(fHexLanguages);
|
||||||
|
@ -29,6 +29,8 @@ type
|
|||||||
FOnModified: TNotifyEvent;
|
FOnModified: TNotifyEvent;
|
||||||
procedure SetModified(const AValue: boolean);
|
procedure SetModified(const AValue: boolean);
|
||||||
public
|
public
|
||||||
|
function HasAnyLazarusResource: Boolean; virtual; abstract;
|
||||||
|
function HasAnySystemResource: Boolean; virtual; abstract;
|
||||||
function UpdateResources(AResources: TAbstractProjectResources; const MainFilename: string): Boolean; virtual; abstract;
|
function UpdateResources(AResources: TAbstractProjectResources; const MainFilename: string): Boolean; virtual; abstract;
|
||||||
|
|
||||||
constructor Create; virtual;
|
constructor Create; virtual;
|
||||||
|
Loading…
Reference in New Issue
Block a user