mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-22 22:09:43 +01:00
Opkman: Preparing OPM for the integration with the build in Package Manager. Step2.
git-svn-id: trunk@56451 -
This commit is contained in:
parent
597f1091fc
commit
bda79565c0
@ -33,7 +33,7 @@ uses
|
|||||||
// IdeIntf
|
// IdeIntf
|
||||||
LazIDEIntf, PackageIntf, PackageLinkIntf, PackageDependencyIntf,
|
LazIDEIntf, PackageIntf, PackageLinkIntf, PackageDependencyIntf,
|
||||||
// OPM
|
// OPM
|
||||||
opkman_timer, opkman_downloader;
|
opkman_timer, opkman_downloader, opkman_serializablepackages;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -41,29 +41,46 @@ type
|
|||||||
|
|
||||||
TOPMInterfaceEx = class(TOPMInterface)
|
TOPMInterfaceEx = class(TOPMInterface)
|
||||||
private
|
private
|
||||||
|
FOPMPackageLinks: TList;
|
||||||
FWaitForIDE: TThreadTimer;
|
FWaitForIDE: TThreadTimer;
|
||||||
procedure DoWaitForIDE(Sender: TObject);
|
procedure DoWaitForIDE(Sender: TObject);
|
||||||
|
procedure DoUpdatePackageLinks(Sender: TObject);
|
||||||
procedure InitOPM;
|
procedure InitOPM;
|
||||||
|
procedure SynchronizePackages;
|
||||||
|
function IsInList(const AName, AURL: String): Boolean;
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
public
|
public
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses opkman_serializablepackages, opkman_common, opkman_options;
|
uses opkman_common, opkman_options;
|
||||||
|
|
||||||
{ TOPMMain }
|
{ TOPMInterfaceEx }
|
||||||
|
|
||||||
constructor TOPMInterfaceEx.Create;
|
constructor TOPMInterfaceEx.Create;
|
||||||
begin
|
begin
|
||||||
|
FOPMPackageLinks := TList.Create;
|
||||||
FWaitForIDE := TThreadTimer.Create;
|
FWaitForIDE := TThreadTimer.Create;
|
||||||
FWaitForIDE.Interval := 100;
|
FWaitForIDE.Interval := 100;
|
||||||
FWaitForIDE.OnTimer := @DoWaitForIDE;
|
FWaitForIDE.OnTimer := @DoWaitForIDE;
|
||||||
FWaitForIDE.StartTimer;
|
FWaitForIDE.StartTimer;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
destructor TOPMInterfaceEx.Destroy;
|
||||||
|
begin
|
||||||
|
FOPMPackageLinks.Clear;
|
||||||
|
FOPMPackageLinks.Free;
|
||||||
|
PackageDownloader.Free;
|
||||||
|
SerializablePackages.Free;
|
||||||
|
Options.Free;
|
||||||
|
InstallPackageList.Free;
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TOPMInterfaceEx.DoWaitForIDE(Sender: TObject);
|
procedure TOPMInterfaceEx.DoWaitForIDE(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
if Assigned(LazarusIDE) and Assigned(PackageEditingInterface) then
|
if Assigned(LazarusIDE) and Assigned(PackageEditingInterface) then
|
||||||
@ -79,19 +96,65 @@ begin
|
|||||||
InitLocalRepository;
|
InitLocalRepository;
|
||||||
Options := TOptions.Create(LocalRepositoryConfigFile);
|
Options := TOptions.Create(LocalRepositoryConfigFile);
|
||||||
SerializablePackages := TSerializablePackages.Create;
|
SerializablePackages := TSerializablePackages.Create;
|
||||||
|
SerializablePackages.OnUpdatePackageLinks := @DoUpdatePackageLinks;
|
||||||
PackageDownloader := TPackageDownloader.Create(Options.RemoteRepository[Options.ActiveRepositoryIndex]);
|
PackageDownloader := TPackageDownloader.Create(Options.RemoteRepository[Options.ActiveRepositoryIndex]);
|
||||||
InstallPackageList := TObjectList.Create(True);
|
InstallPackageList := TObjectList.Create(True);
|
||||||
PackageDownloader.DownloadJSON(Options.ConTimeOut*1000);
|
PackageDownloader.DownloadJSON(Options.ConTimeOut*1000);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TOPMInterfaceEx.Destroy;
|
procedure TOPMInterfaceEx.DoUpdatePackageLinks(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
PackageDownloader.Free;
|
SynchronizePackages;
|
||||||
SerializablePackages.Free;
|
|
||||||
Options.Free;
|
|
||||||
InstallPackageList.Free;
|
|
||||||
inherited Destroy;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TOPMInterfaceEx.IsInList(const AName, AURL: String): Boolean;
|
||||||
|
var
|
||||||
|
I: Integer;
|
||||||
|
PackageLink: TPackageLink;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
for I := 0 to FOPMPackageLinks.Count - 1 do
|
||||||
|
begin
|
||||||
|
PackageLink := TPackageLink(FOPMPackageLinks.Items[I]);
|
||||||
|
if (UpperCase(PackageLink.Name) = UpperCase(AName)) and (UpperCase(PackageLink.LPKUrl) = UpperCase(AURL)) then
|
||||||
|
begin
|
||||||
|
Result := True;
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TOPMInterfaceEx.SynchronizePackages;
|
||||||
|
var
|
||||||
|
I, J: Integer;
|
||||||
|
MetaPackage: TMetaPackage;
|
||||||
|
LazPackage: TLazarusPackage;
|
||||||
|
PackageLink: TPackageLink;
|
||||||
|
URL, Name: String;
|
||||||
|
Version: TPkgVersion;
|
||||||
|
begin
|
||||||
|
for I := 0 to SerializablePackages.Count - 1 do
|
||||||
|
begin
|
||||||
|
MetaPackage := SerializablePackages.Items[I];
|
||||||
|
for J := 0 to MetaPackage.LazarusPackages.Count - 1 do
|
||||||
|
begin
|
||||||
|
LazPackage := TLazarusPackage(MetaPackage.LazarusPackages.Items[J]);
|
||||||
|
URL := Options.RemoteRepository[Options.ActiveRepositoryIndex] + MetaPackage.RepositoryFileName;
|
||||||
|
Name := StringReplace(LazPackage.Name, '.lpk', '', [rfReplaceAll, rfIgnoreCase]);
|
||||||
|
Version := Lazpackage.Version;
|
||||||
|
if not IsInList(Name, URL) then
|
||||||
|
begin
|
||||||
|
PackageLink := PkgLinks.AddOnlineLink(Url, Name, Version);
|
||||||
|
PackageLink.Name := Name;
|
||||||
|
PackageLink.LPLFileDate := MetaPackage.RepositoryDate;
|
||||||
|
PackageLink.LPKFilename := Options.LocalRepositoryPackages + MetaPackage.PackageBaseDir + LazPackage.PackageRelativePath + LazPackage.Name;
|
||||||
|
PackageLink.LPKUrl := URL;
|
||||||
|
FOPMPackageLinks.Add(PackageLink);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|||||||
@ -154,7 +154,6 @@ type
|
|||||||
procedure DoOnJSONProgress(Sender: TObject);
|
procedure DoOnJSONProgress(Sender: TObject);
|
||||||
procedure DoOnJSONDownloadCompleted(Sender: TObject; AJSON: TJSONStringType; AErrTyp: TErrorType; const AErrMsg: String = '');
|
procedure DoOnJSONDownloadCompleted(Sender: TObject; AJSON: TJSONStringType; AErrTyp: TErrorType; const AErrMsg: String = '');
|
||||||
procedure DoOnProcessJSON(Sender: TObject);
|
procedure DoOnProcessJSON(Sender: TObject);
|
||||||
procedure DoOnUpdate(Sender: TObject);
|
|
||||||
function IsSomethingChecked(const AResolveDependencies: Boolean = True): Boolean;
|
function IsSomethingChecked(const AResolveDependencies: Boolean = True): Boolean;
|
||||||
function Download(const ADstDir: String; var ADoExtract: Boolean): TModalResult;
|
function Download(const ADstDir: String; var ADoExtract: Boolean): TModalResult;
|
||||||
function Extract(const ASrcDir, ADstDir: String; var ADoOpen: Boolean; const AIsUpdate: Boolean = False): TModalResult;
|
function Extract(const ASrcDir, ADstDir: String; var ADoOpen: Boolean; const AIsUpdate: Boolean = False): TModalResult;
|
||||||
@ -198,7 +197,6 @@ var
|
|||||||
begin
|
begin
|
||||||
FileName := Format(LocalRepositoryUpdatesFile, [MD5Print(MD5String(Options.RemoteRepository[Options.ActiveRepositoryIndex]))]);
|
FileName := Format(LocalRepositoryUpdatesFile, [MD5Print(MD5String(Options.RemoteRepository[Options.ActiveRepositoryIndex]))]);
|
||||||
Updates := TUpdates.Create(FileName);
|
Updates := TUpdates.Create(FileName);
|
||||||
Updates.OnUpdate := @DoOnUpdate;
|
|
||||||
Updates.StartUpdate;
|
Updates.StartUpdate;
|
||||||
Updates.PauseUpdate;
|
Updates.PauseUpdate;
|
||||||
end;
|
end;
|
||||||
@ -401,27 +399,6 @@ begin
|
|||||||
Application.ProcessMessages;
|
Application.ProcessMessages;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMainFrm.DoOnUpdate(Sender: TObject);
|
|
||||||
var
|
|
||||||
I, J: Integer;
|
|
||||||
MetaPkg: TMetaPackage;
|
|
||||||
LazarusPkg: TLazarusPackage;
|
|
||||||
begin
|
|
||||||
VisualTree.UpdatePackageUStatus;
|
|
||||||
// Pass the online package info as package links to IDE.
|
|
||||||
for I := 0 to SerializablePackages.Count - 1 do
|
|
||||||
begin
|
|
||||||
MetaPkg := SerializablePackages.Items[I];
|
|
||||||
for J := 0 to MetaPkg.LazarusPackages.Count - 1 do
|
|
||||||
begin
|
|
||||||
LazarusPkg := TLazarusPackage(MetaPkg.LazarusPackages.Items[J]);
|
|
||||||
//DebugLn(['OPM DoOnUpdate: Package.Name=', MetaPkg.Name,
|
|
||||||
// ', Package.DisplayName=', MetaPkg.DisplayName]);
|
|
||||||
PkgLinks.AddOnlineLink(MetaPkg.DownloadZipURL, MetaPkg.Name, LazarusPkg.Version);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TMainFrm.ShowOptions(const AActivePageIndex: Integer = 0);
|
procedure TMainFrm.ShowOptions(const AActivePageIndex: Integer = 0);
|
||||||
var
|
var
|
||||||
OldIndex: Integer;
|
OldIndex: Integer;
|
||||||
|
|||||||
@ -241,6 +241,7 @@ type
|
|||||||
FMetaPackages: TCollection;
|
FMetaPackages: TCollection;
|
||||||
FLastError: String;
|
FLastError: String;
|
||||||
FOnProcessJSON: TNotifyEvent;
|
FOnProcessJSON: TNotifyEvent;
|
||||||
|
FOnUpdatePackageLinks: TNotifyEvent;
|
||||||
function GetCount: Integer;
|
function GetCount: Integer;
|
||||||
function GetDownloadCount: Integer;
|
function GetDownloadCount: Integer;
|
||||||
function GetExtractCount: Integer;
|
function GetExtractCount: Integer;
|
||||||
@ -291,6 +292,7 @@ type
|
|||||||
property Items[Index: Integer]: TMetaPackage read GetItem write SetItem;
|
property Items[Index: Integer]: TMetaPackage read GetItem write SetItem;
|
||||||
property LastError: String read FlastError;
|
property LastError: String read FlastError;
|
||||||
property OnProcessJSON: TNotifyEvent read FOnProcessJSON write FOnProcessJSON;
|
property OnProcessJSON: TNotifyEvent read FOnProcessJSON write FOnProcessJSON;
|
||||||
|
property OnUpdatePackageLinks: TNotifyEvent read FOnUpdatePackageLinks write FOnUpdatePackageLinks;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -939,6 +941,9 @@ begin
|
|||||||
finally
|
finally
|
||||||
Parser.Free;
|
Parser.Free;
|
||||||
end;
|
end;
|
||||||
|
if Result then
|
||||||
|
if Assigned(FOnUpdatePackageLinks) then
|
||||||
|
FOnUpdatePackageLinks(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TSerializablePackages.LazarusPackagesToJSON(AMetaPackage: TMetaPackage;
|
function TSerializablePackages.LazarusPackagesToJSON(AMetaPackage: TMetaPackage;
|
||||||
|
|||||||
@ -112,7 +112,6 @@ type
|
|||||||
FPaused: Boolean;
|
FPaused: Boolean;
|
||||||
function GetUpdateInfo(const AURL: String; var AJSON: TJSONStringType): Boolean;
|
function GetUpdateInfo(const AURL: String; var AJSON: TJSONStringType): Boolean;
|
||||||
procedure DoOnTimer(Sender: TObject);
|
procedure DoOnTimer(Sender: TObject);
|
||||||
procedure DoOnUpdate;
|
|
||||||
procedure Load;
|
procedure Load;
|
||||||
procedure Save;
|
procedure Save;
|
||||||
procedure AssignPackageData(AMetaPackage: TMetaPackage);
|
procedure AssignPackageData(AMetaPackage: TMetaPackage);
|
||||||
@ -127,8 +126,6 @@ type
|
|||||||
procedure StartUpdate;
|
procedure StartUpdate;
|
||||||
procedure StopUpdate;
|
procedure StopUpdate;
|
||||||
procedure PauseUpdate;
|
procedure PauseUpdate;
|
||||||
published
|
|
||||||
property OnUpdate: TNotifyEvent read FOnUpdate write FOnUpdate;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -311,7 +308,6 @@ begin
|
|||||||
MetaPkg.HasUpdate := HasUpdate;
|
MetaPkg.HasUpdate := HasUpdate;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
Synchronize(@DoOnUpdate);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TUpdates.Save;
|
procedure TUpdates.Save;
|
||||||
@ -497,12 +493,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TUpdates.DoOnUpdate;
|
|
||||||
begin
|
|
||||||
if Assigned(FOnUpdate) then
|
|
||||||
FOnUpdate(Self);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TUpdates.Execute;
|
procedure TUpdates.Execute;
|
||||||
var
|
var
|
||||||
I: Integer;
|
I: Integer;
|
||||||
@ -538,8 +528,6 @@ begin
|
|||||||
else
|
else
|
||||||
FHTTPClient.Terminate;
|
FHTTPClient.Terminate;
|
||||||
end;
|
end;
|
||||||
if Assigned(FOnUpdate) and (not FNeedToBreak) and (not FPaused) then
|
|
||||||
Synchronize(@DoOnUpdate);
|
|
||||||
finally
|
finally
|
||||||
FBusyUpdating := False;
|
FBusyUpdating := False;
|
||||||
FNeedToUpdate := False;
|
FNeedToUpdate := False;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user