Opkman: Implemented support for multiple repositories.

git-svn-id: trunk@53961 -
This commit is contained in:
balazs 2017-01-17 11:12:56 +00:00
parent 91877feb80
commit 7b78ebab89
7 changed files with 94 additions and 52 deletions

View File

@ -41,7 +41,7 @@ const
cLocalRepositoryUpdate = 'update'; cLocalRepositoryUpdate = 'update';
cLocalRepositoryConfig = 'config'; cLocalRepositoryConfig = 'config';
cLocalRepositoryConfigFile = 'options.xml'; cLocalRepositoryConfigFile = 'options.xml';
cLocalRepositoryUpdatesFile = 'updates.xml'; cLocalRepositoryUpdatesFile = 'updates_%s.xml';
cExcludedFilesDef = '*.,*.a,*.o,*.ppu,*.compiled,*.bak,*.or,*.rsj,*.~,*.exe,*.dbg,*.zip,*.json'; cExcludedFilesDef = '*.,*.a,*.o,*.ppu,*.compiled,*.bak,*.or,*.rsj,*.~,*.exe,*.dbg,*.zip,*.json';
cExcludedFoldersDef = 'lib,backup,updates,compiled,.git,.svn'; cExcludedFoldersDef = 'lib,backup,updates,compiled,.git,.svn';
cHelpPage = 'http://wiki.freepascal.org/Online_Package_Manager'; cHelpPage = 'http://wiki.freepascal.org/Online_Package_Manager';
@ -174,6 +174,7 @@ resourcestring
rsMainFrm_rsMessageNoPackage = 'No packages to show.'; rsMainFrm_rsMessageNoPackage = 'No packages to show.';
rsMainFrm_rsMessageParsingJSON = 'Parsing JSON. Please wait...'; rsMainFrm_rsMessageParsingJSON = 'Parsing JSON. Please wait...';
rsMainFrm_rsMessageDownload = 'Downloading package list. Please wait...'; rsMainFrm_rsMessageDownload = 'Downloading package list. Please wait...';
rsMainFrm_rsMessageChangingRepository = 'Changing repository. Please wait...';
rsMainFrm_rsMessageNoRepository0 = 'Remote package repository not configured.' + sLineBreak + 'Do you wish to configure it now?'; rsMainFrm_rsMessageNoRepository0 = 'Remote package repository not configured.' + sLineBreak + 'Do you wish to configure it now?';
rsMainFrm_rsMessageError0 = 'Cannot download package list. Error message:'; rsMainFrm_rsMessageError0 = 'Cannot download package list. Error message:';
rsMainFrm_rsMessageError1 = 'Invalid JSON file.'; rsMainFrm_rsMessageError1 = 'Invalid JSON file.';
@ -368,7 +369,7 @@ resourcestring
rsRepositories_Confirmation0 = 'Delete selected repository "%s" ?'; rsRepositories_Confirmation0 = 'Delete selected repository "%s" ?';
rsRepositories_InputBox_Caption0 = 'Add repository'; rsRepositories_InputBox_Caption0 = 'Add repository';
rsRepositories_InputBox_Caption1 = 'Edit repository'; rsRepositories_InputBox_Caption1 = 'Edit repository';
rsRepositories_InputBox_Text = 'Type the repository name:'; rsRepositories_InputBox_Text = 'Type the repository address:';
implementation implementation

View File

@ -32,7 +32,7 @@ uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, contnrs, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, contnrs,
StdCtrls, ExtCtrls, Buttons, Menus, ComCtrls, IDECommands, LazFileUtils, StdCtrls, ExtCtrls, Buttons, Menus, ComCtrls, IDECommands, LazFileUtils,
LCLIntf, fpjson, opkman_VirtualTrees, opkman_downloader, opkman_installer, LCLIntf, fpjson, opkman_VirtualTrees, opkman_downloader, opkman_installer,
PackageIntf, Clipbrd; PackageIntf, Clipbrd, md5;
type type
@ -111,7 +111,7 @@ type
procedure EnableDisableControls(const AEnable: Boolean); procedure EnableDisableControls(const AEnable: Boolean);
procedure SetupMessage(const AMessage: String = ''); procedure SetupMessage(const AMessage: String = '');
procedure SetupControls; procedure SetupControls;
procedure GetPackageList; procedure GetPackageList(const ARepositoryHasChanged: Boolean = False);
procedure DoOnChecking(Sender: TObject; const AIsAllChecked: Boolean); procedure DoOnChecking(Sender: TObject; const AIsAllChecked: Boolean);
procedure DoOnChecked(Sender: TObject); procedure DoOnChecked(Sender: TObject);
procedure DoOnJSONProgress(Sender: TObject); procedure DoOnJSONProgress(Sender: TObject);
@ -123,7 +123,8 @@ type
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;
function Install(var AInstallStatus: TInstallStatus; var ANeedToRebuild: Boolean): TModalResult; function Install(var AInstallStatus: TInstallStatus; var ANeedToRebuild: Boolean): TModalResult;
function UpdateP(const ADstDir: String; var ADoExtract: Boolean): TModalResult; function UpdateP(const ADstDir: String; var ADoExtract: Boolean): TModalResult;
procedure TerminateUpdates; procedure StartUpdates;
procedure StopUpdates;
public public
procedure ShowOptions(const AActivePageIndex: Integer = 0); procedure ShowOptions(const AActivePageIndex: Integer = 0);
end; end;
@ -154,10 +155,7 @@ begin
PackageDownloader := TPackageDownloader.Create(Options.RemoteRepository[Options.ActiveRepositoryIndex]); PackageDownloader := TPackageDownloader.Create(Options.RemoteRepository[Options.ActiveRepositoryIndex]);
PackageDownloader.OnJSONProgress := @DoOnJSONProgress; PackageDownloader.OnJSONProgress := @DoOnJSONProgress;
PackageDownloader.OnJSONDownloadCompleted := @DoOnJSONDownloadCompleted; PackageDownloader.OnJSONDownloadCompleted := @DoOnJSONDownloadCompleted;
Updates := TUpdates.Create(LocalRepositoryUpdatesFile); StartUpdates;
Updates.OnUpdate := @DoOnUpdate;
Updates.StartUpdate;
Updates.PauseUpdate;
InstallPackageList := TObjectList.Create(True); InstallPackageList := TObjectList.Create(True);
FHintTimeOut := Application.HintHidePause; FHintTimeOut := Application.HintHidePause;
Application.HintHidePause := 1000000; Application.HintHidePause := 1000000;
@ -166,7 +164,18 @@ begin
{$ENDIF} {$ENDIF}
end; end;
procedure TMainFrm.TerminateUpdates; procedure TMainFrm.StartUpdates;
var
FileName: String;
begin
FileName := Format(LocalRepositoryUpdatesFile, [MD5Print(MD5String(Options.RemoteRepository[Options.ActiveRepositoryIndex]))]);
Updates := TUpdates.Create(FileName);
Updates.OnUpdate := @DoOnUpdate;
Updates.StartUpdate;
Updates.PauseUpdate;
end;
procedure TMainFrm.StopUpdates;
begin begin
if Assigned(Updates) then if Assigned(Updates) then
begin begin
@ -178,7 +187,7 @@ end;
procedure TMainFrm.FormDestroy(Sender: TObject); procedure TMainFrm.FormDestroy(Sender: TObject);
begin begin
TerminateUpdates; StopUpdates;
PackageDownloader.Free; PackageDownloader.Free;
SerializablePackages.Free; SerializablePackages.Free;
VisualTree.Free; VisualTree.Free;
@ -199,13 +208,22 @@ begin
GetPackageList; GetPackageList;
end; end;
procedure TMainFrm.GetPackageList; procedure TMainFrm.GetPackageList(const ARepositoryHasChanged: Boolean = False);
begin begin
Updates.PauseUpdate;
Caption := rsLazarusPackageManager; Caption := rsLazarusPackageManager;
EnableDisableControls(False);
VisualTree.VST.Clear; VisualTree.VST.Clear;
VisualTree.VST.Invalidate; VisualTree.VST.Invalidate;
EnableDisableControls(False); if ARepositoryHasChanged then
begin
SetupMessage(rsMainFrm_rsMessageChangingRepository);
Sleep(1500);
StopUpdates;
SerializablePackages.Clear;
StartUpdates;
end
else
Updates.PauseUpdate;
SetupMessage(rsMainFrm_rsMessageDownload); SetupMessage(rsMainFrm_rsMessageDownload);
PackageDownloader.DownloadJSON(10000); PackageDownloader.DownloadJSON(10000);
end; end;
@ -304,7 +322,6 @@ begin
end; end;
end; end;
procedure TMainFrm.DoOnJSONDownloadCompleted(Sender: TObject; AJSON: TJSONStringType; AErrTyp: TErrorType; const AErrMsg: String = ''); procedure TMainFrm.DoOnJSONDownloadCompleted(Sender: TObject; AJSON: TJSONStringType; AErrTyp: TErrorType; const AErrMsg: String = '');
begin begin
case AErrTyp of case AErrTyp of
@ -357,14 +374,17 @@ begin
end; end;
procedure TMainFrm.ShowOptions(const AActivePageIndex: Integer = 0); procedure TMainFrm.ShowOptions(const AActivePageIndex: Integer = 0);
var
OldIndex: Integer;
begin begin
OptionsFrm := TOptionsFrm.Create(MainFrm); OptionsFrm := TOptionsFrm.Create(MainFrm);
try try
OptionsFrm.SetupControls(AActivePageIndex); OptionsFrm.SetupControls(AActivePageIndex);
OldIndex := Options.ActiveRepositoryIndex;
if OptionsFrm.ShowModal = mrOk then if OptionsFrm.ShowModal = mrOk then
begin begin
tbRefresh.Enabled := Trim(Options.RemoteRepository[Options.ActiveRepositoryIndex]) <> ''; tbRefresh.Enabled := Trim(Options.RemoteRepository[Options.ActiveRepositoryIndex]) <> '';
GetPackageList; GetPackageList(OldIndex <> Options.ActiveRepositoryIndex);
end; end;
finally finally
OptionsFrm.Free; OptionsFrm.Free;

View File

@ -157,6 +157,8 @@ begin
FRemoteRepository.Text := FXML.GetValue('RemoteRepository/Value', '') FRemoteRepository.Text := FXML.GetValue('RemoteRepository/Value', '')
else else
FRemoteRepository.Text := FXML.GetValue('General/RemoteRepository/Value', ''); FRemoteRepository.Text := FXML.GetValue('General/RemoteRepository/Value', '');
if Trim(FRemoteRepository.Text) = '' then
FRemoteRepository.Add(cRemoteRepository);
FActiveRepositoryIndex := FXML.GetValue('General/ActiveRepositoryIndex/Value', 0); FActiveRepositoryIndex := FXML.GetValue('General/ActiveRepositoryIndex/Value', 0);
FForceDownloadAndExtract := FXML.GetValue('General/ForceDownloadAndExtract/Value', True); FForceDownloadAndExtract := FXML.GetValue('General/ForceDownloadAndExtract/Value', True);
FDeleteZipAfterInstall := FXML.GetValue('General/DeleteZipAfterInstall/Value', True); FDeleteZipAfterInstall := FXML.GetValue('General/DeleteZipAfterInstall/Value', True);
@ -215,6 +217,8 @@ end;
procedure TOptions.LoadDefault; procedure TOptions.LoadDefault;
begin begin
FRemoteRepository.Clear;
FRemoteRepositoryTmp.Clear;
FRemoteRepository.Add(cRemoteRepository); FRemoteRepository.Add(cRemoteRepository);
FActiveRepositoryIndex := 0; FActiveRepositoryIndex := 0;
FForceDownloadAndExtract := True; FForceDownloadAndExtract := True;

View File

@ -22,7 +22,7 @@ object OptionsFrm: TOptionsFrm
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 39 ClientHeight = 39
ClientWidth = 525 ClientWidth = 525
TabOrder = 0 TabOrder = 1
object bOk: TButton object bOk: TButton
Left = 332 Left = 332
Height = 25 Height = 25
@ -61,19 +61,20 @@ object OptionsFrm: TOptionsFrm
ActivePage = tsGeneral ActivePage = tsGeneral
Align = alClient Align = alClient
TabIndex = 0 TabIndex = 0
TabOrder = 1 TabOrder = 0
object tsGeneral: TTabSheet object tsGeneral: TTabSheet
Caption = 'General' Caption = 'General'
ClientHeight = 297 ClientHeight = 297
ClientWidth = 517 ClientWidth = 517
object pnGeneral: TPanel object pnGeneral: TPanel
Left = 0 Left = 0
Height = 297 Height = 296
Top = 0 Top = 0
Width = 517 Width = 517
Align = alClient Align = alClient
BorderSpacing.Bottom = 1
BevelOuter = bvNone BevelOuter = bvNone
ClientHeight = 297 ClientHeight = 296
ClientWidth = 517 ClientWidth = 517
Color = clBtnFace Color = clBtnFace
ParentColor = False ParentColor = False
@ -89,7 +90,7 @@ object OptionsFrm: TOptionsFrm
object cbForceDownloadExtract: TCheckBox object cbForceDownloadExtract: TCheckBox
Left = 15 Left = 15
Height = 19 Height = 19
Top = 70 Top = 75
Width = 235 Width = 235
Caption = ' Force download and extract of packages' Caption = ' Force download and extract of packages'
ParentShowHint = False ParentShowHint = False
@ -115,9 +116,9 @@ object OptionsFrm: TOptionsFrm
ParentColor = False ParentColor = False
end end
object cbCheckForUpdates: TComboBox object cbCheckForUpdates: TComboBox
Left = 16 Left = 15
Height = 23 Height = 23
Top = 168 Top = 170
Width = 209 Width = 209
ItemHeight = 15 ItemHeight = 15
ItemIndex = 0 ItemIndex = 0
@ -136,37 +137,51 @@ object OptionsFrm: TOptionsFrm
object lbLastUpdate: TLabel object lbLastUpdate: TLabel
Left = 240 Left = 240
Height = 15 Height = 15
Top = 171 Top = 173
Width = 64 Width = 64
Caption = 'Last update:' Caption = 'Last update:'
ParentColor = False ParentColor = False
end end
object bOpen: TButton object pnRepositories: TPanel
Left = 476 Left = 15
Height = 25 Height = 26
Top = 31 Top = 31
Width = 27 Width = 489
Anchors = [akTop, akRight]
Caption = '...'
OnClick = bOpenClick
TabOrder = 3
end
object cbRemoteRepository: TComboBox
Left = 16
Height = 23
Top = 32
Width = 457
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
ItemHeight = 15 AutoSize = True
Style = csDropDownList BevelOuter = bvNone
TabOrder = 4 ClientHeight = 26
ClientWidth = 489
TabOrder = 3
object cbRemoteRepository: TComboBox
Left = 1
Height = 23
Top = 1
Width = 456
Align = alClient
BorderSpacing.Around = 1
ItemHeight = 15
Style = csDropDownList
TabOrder = 0
end
object bOpen: TButton
Left = 458
Height = 25
Top = 0
Width = 31
Align = alRight
BorderSpacing.Bottom = 1
Caption = '...'
OnClick = bOpenClick
TabOrder = 1
end
end end
end end
end end
object tsProxy: TTabSheet object tsProxy: TTabSheet
Caption = 'Proxy' Caption = 'Proxy'
ClientHeight = 297 ClientHeight = 286
ClientWidth = 517 ClientWidth = 519
object pnProxy: TPanel object pnProxy: TPanel
Left = 0 Left = 0
Height = 297 Height = 297
@ -273,8 +288,8 @@ object OptionsFrm: TOptionsFrm
end end
object tsFolders: TTabSheet object tsFolders: TTabSheet
Caption = 'Folders' Caption = 'Folders'
ClientHeight = 297 ClientHeight = 286
ClientWidth = 517 ClientWidth = 519
object pnFolders: TPanel object pnFolders: TPanel
Left = 0 Left = 0
Height = 297 Height = 297
@ -364,8 +379,8 @@ object OptionsFrm: TOptionsFrm
end end
object tsProfiles: TTabSheet object tsProfiles: TTabSheet
Caption = 'Profiles' Caption = 'Profiles'
ClientHeight = 297 ClientHeight = 286
ClientWidth = 517 ClientWidth = 519
object pnProfiles: TPanel object pnProfiles: TPanel
Left = 0 Left = 0
Height = 297 Height = 297
@ -505,7 +520,7 @@ object OptionsFrm: TOptionsFrm
Color = clBtnFace Color = clBtnFace
ItemHeight = 0 ItemHeight = 0
ParentShowHint = False ParentShowHint = False
ScrollWidth = 161 ScrollWidth = 179
ShowHint = True ShowHint = True
Sorted = True Sorted = True
TabOrder = 2 TabOrder = 2
@ -593,7 +608,7 @@ object OptionsFrm: TOptionsFrm
Color = clBtnFace Color = clBtnFace
ItemHeight = 0 ItemHeight = 0
ParentShowHint = False ParentShowHint = False
ScrollWidth = 154 ScrollWidth = 159
ShowHint = True ShowHint = True
Sorted = True Sorted = True
TabOrder = 2 TabOrder = 2

View File

@ -45,15 +45,15 @@ type
bFoldersDelete: TButton; bFoldersDelete: TButton;
bFoldersEdit: TButton; bFoldersEdit: TButton;
bOk: TButton; bOk: TButton;
bOpen: TButton;
bRestore: TButton; bRestore: TButton;
bFilesAdd: TButton; bFilesAdd: TButton;
bOpen: TButton;
cbProxy: TCheckBox; cbProxy: TCheckBox;
cbForceDownloadExtract: TCheckBox; cbForceDownloadExtract: TCheckBox;
cbDeleteZipAfterInstall: TCheckBox; cbDeleteZipAfterInstall: TCheckBox;
cbCheckForUpdates: TComboBox; cbCheckForUpdates: TComboBox;
cbSelectProfile: TComboBox;
cbRemoteRepository: TComboBox; cbRemoteRepository: TComboBox;
cbSelectProfile: TComboBox;
edLocalRepositoryUpdate: TDirectoryEdit; edLocalRepositoryUpdate: TDirectoryEdit;
edLocalRepositoryPackages: TDirectoryEdit; edLocalRepositoryPackages: TDirectoryEdit;
edLocalRepositoryArchive: TDirectoryEdit; edLocalRepositoryArchive: TDirectoryEdit;
@ -76,6 +76,7 @@ type
lbPassword: TLabel; lbPassword: TLabel;
lbExcludeFiles: TListBox; lbExcludeFiles: TListBox;
lbExcludeFolders: TListBox; lbExcludeFolders: TListBox;
pnRepositories: TPanel;
pnProfilesCaptionLeft: TPanel; pnProfilesCaptionLeft: TPanel;
pnProfilesCaptionLeft1: TPanel; pnProfilesCaptionLeft1: TPanel;
pnProfilesLeftButtons: TPanel; pnProfilesLeftButtons: TPanel;

View File

@ -7,6 +7,7 @@ object RepositoriesFrm: TRepositoriesFrm
Caption = 'RepositoriesFrm' Caption = 'RepositoriesFrm'
ClientHeight = 367 ClientHeight = 367
ClientWidth = 561 ClientWidth = 561
Color = clBtnFace
OnCreate = FormCreate OnCreate = FormCreate
OnDestroy = FormDestroy OnDestroy = FormDestroy
PopupMode = pmExplicit PopupMode = pmExplicit

View File

@ -51,7 +51,7 @@ var
RepositoriesFrm: TRepositoriesFrm; RepositoriesFrm: TRepositoriesFrm;
implementation implementation
uses opkman_const, opkman_common, opkman_options, opkman_optionsfrm; uses opkman_const, opkman_common, opkman_options;
{$R *.lfm} {$R *.lfm}
type type