Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions DN.Character.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
unit DN.Character;

interface

uses
Character;

{$Warnings off}
type
TCharacter = Character.TCharacter;

implementation

end.
61 changes: 61 additions & 0 deletions DN.Package.Gitlab.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.Package.Gitlab;

interface

uses
Classes,
Types,
DN.Types,
DN.Package;

type
TDNGitLabPackage = class;

TGetLicenseCallback = function(const APackage: TDNGitLabPackage; const ALicense: TDNLicense): string of object;

TDNGitLabPackage = class(TDNPackage)
private
FRepoID: string;
FRepoReleases: string;
FDefaultBranch: string;
FRepositoryName: string;
FOnGetLicense: TGetLicenseCallback;
FRepositoryType: string;
FRepository: string;
FRepositoryUser: string;
protected
function GetLicenseText(const AValue: TDNLicense): string; override;
public
property RepoID: string read FRepoID write FRepoID;
property RepoReleases: string read FRepoReleases write FRepoReleases;
property DefaultBranch: string read FDefaultBranch write FDefaultBranch;
property RepositoryName: string read FRepositoryName write FRepositoryName;
property RepositoryType: string read FRepositoryType write FRepositoryType;
property RepositoryUser: string read FRepositoryUser write FRepositoryUser;
property Repository: string read FRepository write FRepository;
property OnGetLicense: TGetLicenseCallback read FOnGetLicense write FOnGetLicense;
end;

implementation

{ TDNGitLabPackage }

function TDNGitLabPackage.GetLicenseText(const AValue: TDNLicense): string;
begin
Result := inherited;
if (Result = '') and not FLicenseTexts.ContainsKey(AValue.LicenseFile) and Assigned(FOnGetLicense) then
begin
Result := FOnGetLicense(Self, AValue);
LicenseText[AValue] := Result;
end;
end;

end.

156 changes: 156 additions & 0 deletions DN.PackageProvider.Folder.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
unit DN.PackageProvider.Folder;

interface

uses
DN.Package.Intf,
DN.PackageProvider;

type
TDNFolderPackageProvider = class(TDNPackageProvider)
private
FPath: string;
procedure ProcessPackagesOfAuthor(const APath, AAuthor: string);
procedure ProcessPackage(const APath, AAuthor, APackage: string);
public
constructor Create(const APath: string);
function Reload: Boolean; override;
function Download(const APackage: IDNPackage; const AVersion: string; const AFolder: string; out AContentFolder: string): Boolean; override;
end;

implementation

uses
IOUtils,
SysUtils,
Classes,
DN.Types,
DN.Version,
DN.Package,
DN.Package.Version,
DN.Package.Dependency,
DN.JsonFile.Info;

const
CNoVersionDir = 'HEAD';

{ TDNFolderPackageProvider }

constructor TDNFolderPackageProvider.Create(const APath: string);
begin
inherited Create();
FPath := APath;
end;

function TDNFolderPackageProvider.Download(const APackage: IDNPackage;
const AVersion, AFolder: string; out AContentFolder: string): Boolean;
var
LPath: string;
begin
LPath := TPath.Combine(TPath.Combine(FPath, APackage.Author), APackage.Name);
if AVersion <> '' then
LPath := TPath.Combine(LPath, AVersion)
else
LPath := TPath.Combine(LPath, CNoVersionDir);

Result := TDirectory.Exists(LPath);
if Result then
begin
TDirectory.Copy(LPath, AFolder);
AContentFolder := AFolder;
end;
end;

procedure TDNFolderPackageProvider.ProcessPackage(const APath, AAuthor,
APackage: string);
var
LVersionPath, LVersionText, LInfoPath: string;
LPackage: TDNPackage;
LPackageVersion: TDNPackageVersion;
LVersion, LHighestVersion: TDNVersion;
LInfo: TInfoFile;
LDependency: TInfoDependency;
LPictureFile: string;
LLicense, LLicenseCopy: TDNLicense;
begin
LHighestVersion := TDNVersion.Create();
LPackage := TDNPackage.Create();
try
LPackage.Author := AAuthor;
LPackage.Name := APackage;
for LVersionPath in TDirectory.GetDirectories(APath) do
begin
LVersionText := ExtractFileName(LVersionPath);
LInfoPath := TPath.Combine(LVersionPath, CInfoFile);
if TDNVersion.TryParse(LVersionText, LVersion) and TFile.Exists(LInfoPath) then
begin
LInfo := TInfoFile.Create();
try
LInfo.LoadFromFile(LInfoPath);
LPackageVersion := TDNPackageVersion.Create();
try
LPackageVersion.Name := LVersion.ToString;
LPackageVersion.Value := LVersion;
LPackageVersion.CompilerMin := LInfo.CompilerMin;
LPackageVersion.CompilerMax := LInfo.CompilerMax;
for LDependency in LInfo.Dependencies do
LPackageVersion.Dependencies.Add(TDNPackageDependency.Create(LDependency.ID, LDependency.Version));
if LHighestVersion.IsEmpty or (LVersion > LHighestVersion) then
begin
LHighestVersion := LVersion;
LPackage.ID := LInfo.ID;
LPackage.CompilerMin := LInfo.CompilerMin;
LPackage.CompilerMax := LInfo.CompilerMax;
LPackage.Platforms := LInfo.Platforms;
for LLicense in LInfo.Licenses do
begin
LLicenseCopy := LLicense;
LLicenseCopy.LicenseFile := TPath.Combine(LVersionPath, LLicense.LicenseFile);
LPackage.Licenses.Add(LLicenseCopy);
if TFile.Exists(LLicenseCopy.LicenseFile) then
LPackage.LicenseText[LLicenseCopy] := TFile.ReadAllText(LLicenseCopy.LicenseFile);
end;
LPictureFile := TPath.Combine(LVersionPath, LInfo.Picture);
end;
finally
LPackage.Versions.Add(LPackageVersion);
end;
finally
LInfo.Free;
end;
end;
end;
if TFile.Exists(LPictureFile) then
LPackage.Picture.LoadFromFile(LPictureFile);
finally
if LPackage.ID <> TGuid.Empty then
Packages.Add(LPackage)
else
LPackage.Free;
end;
end;

procedure TDNFolderPackageProvider.ProcessPackagesOfAuthor(const APath,
AAuthor: string);
var
LDir: string;
begin
for LDir in TDirectory.GetDirectories(APath) do
ProcessPackage(LDir, AAuthor, ExtractFileName(LDir));
end;

function TDNFolderPackageProvider.Reload: Boolean;
var
LDir: string;
begin
Result := False;
Packages.Clear;
if TDirectory.Exists(FPath) then
begin
for LDir in TDirectory.GetDirectories(FPath) do
ProcessPackagesOfAuthor(LDir, ExtractFileName(LDir));
Result := True;
end;
end;

end.
68 changes: 68 additions & 0 deletions DN.PackageProvider.GitLab.State.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.PackageProvider.GitLab.State;

interface

uses
DN.PackageProvider.State,
DN.PackageProvider.State.Intf,
DN.HttpClient.Intf;

type
TDNGitlabPackageProviderState = class(TDNPackageProviderState)
private
FClient: IDNHttpClient;
protected
function GetStatisticCount: Integer; override;
function GetStatisticName(const AIndex: Integer): string; override;
function GetStatisticValue(const AIndex: Integer): string; override;
public
constructor Create(const AClient: IDNHttpClient);
end;

implementation

{ TDNGitlabPackageProviderState }

constructor TDNGitlabPackageProviderState.Create(const AClient: IDNHttpClient);
begin
inherited Create;
FClient := AClient;
end;

function TDNGitlabPackageProviderState.GetStatisticCount: Integer;
begin
Result := 3;
end;

function TDNGitlabPackageProviderState.GetStatisticName(
const AIndex: Integer): string;
begin
case AIndex of
0: Result := 'Ratelimit';
1: Result := 'RateLimit-Remaining';
2: Result := 'RateLimit-Reset';
else
Result := '';
end;
end;

function TDNGitlabPackageProviderState.GetStatisticValue(
const AIndex: Integer): string;
begin
case AIndex of
0: Result := FClient.ResponseHeader['X-RateLimit-Limit'];
1: Result := FClient.ResponseHeader['X-RateLimit-Remaining'];
2: Result := FClient.ResponseHeader['X-RateLimit-Reset'];
else
Result := '';
end;
end;

end.
Loading