Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
exilon committed Oct 22, 2020
2 parents fc3f4ee + 8de90cc commit 42d0550
Show file tree
Hide file tree
Showing 12 changed files with 2,269 additions and 42 deletions.
87 changes: 53 additions & 34 deletions Quick.Amazon.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Author : Kike Pérez
Version : 1.4
Created : 18/11/2016
Modified : 21/02/2018
Modified : 11/09/2020
This file is part of QuickLib: https://github.com/exilon/QuickLib
Expand All @@ -29,6 +29,8 @@

unit Quick.Amazon;

{$i QuickLib.inc}

interface

uses
Expand Down Expand Up @@ -111,7 +113,9 @@ TQuickAmazon = class
function ListBuckets(var amResponseInfo : TAmazonResponseInfo) : TStrings;
function CreateBucket(amBucket : string; amBucketRegion : TAmazonRegion; amACLType : TAmazonACLAccess; var amResponseInfo : TAmazonResponseInfo) : Boolean;
function DeleteBucket(amBucket : string; amBucketRegion : TAmazonRegion; var amResponseInfo : TAmazonResponseInfo) : Boolean;
{$IFNDEF DELPHISYDNEY_UP}
class function GetAWSRegion(Region: TAmazonRegion): string; overload;
{$ENDIF}
class function GetAWSRegion(const Region : string) : TAmazonRegion; overload;
end;

Expand Down Expand Up @@ -228,7 +232,6 @@ function TQuickAmazon.PutObject(amBucket, cFilename, amObjectName : string; amAC
Content : TArray<Byte>;
CloudResponseInfo : TCloudResponseInfo;
begin
Result := False;
AmazonS3 := TAmazonStorage.Create(fconAmazon);
if amBucket = '' then amBucket := '$root';
CloudResponseInfo := TCloudResponseInfo.Create;
Expand Down Expand Up @@ -258,13 +261,16 @@ function TQuickAmazon.PutObject(amBucket : string; cStream : TStream; amObjectNa
try
//AmazonS3.Timeout := fTimeout;
CloudResponseInfo := TCloudResponseInfo.Create;
//CloudResponseInfo.Headers.AddPair();
Content := StreamToArray(cStream);
Result := AmazonS3.UploadObject(amBucket,amObjectName,Content,False,nil,nil,amACLType,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
try
//CloudResponseInfo.Headers.AddPair();
Content := StreamToArray(cStream);
Result := AmazonS3.UploadObject(amBucket,amObjectName,Content,False,nil,nil,amACLType,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
finally
CloudResponseInfo.Free;
end;
finally
AmazonS3.Free;
CloudResponseInfo.Free;
SetLength(Content,0);
Content := nil;
end;
Expand All @@ -278,7 +284,7 @@ function TQuickAmazon.GetObject(amBucket, amObjectName, cFilenameTo : string; va
AmazonS3 : TAmazonStorage;
fs : TFileStream;
CloudResponseInfo : TCloudResponseInfo;
amParams : TAmazonGetObjectOptionals;
//amParams : TAmazonGetObjectOptionals;
begin
Result := False;
if amBucket = '' then amBucket := '$root';
Expand Down Expand Up @@ -309,7 +315,6 @@ function TQuickAmazon.GetObject(amBucket, amObjectName, cFilenameTo : string; va
function TQuickAmazon.GetObject(amBucket, amObjectName : string; var amResponseInfo : TAmazonResponseInfo) : TMemoryStream;
var
AmazonS3 : TAmazonStorage;
fs : TFileStream;
CloudResponseInfo : TCloudResponseInfo;
begin
Result := TMemoryStream.Create;
Expand All @@ -320,14 +325,17 @@ function TQuickAmazon.GetObject(amBucket, amObjectName : string; var amResponseI
//AmazonS3.Timeout := fTimeout;
CloudResponseInfo := TCloudResponseInfo.Create;
try
AmazonS3.GetObject(amBucket,amObjectName,Result,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
except
Result := nil;
try
AmazonS3.GetObject(amBucket,amObjectName,Result,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
except
Result := nil;
end;
finally
CloudResponseInfo.Free;
end;
finally
AmazonS3.Free;
CloudResponseInfo.Free;
end;
end;

Expand Down Expand Up @@ -361,18 +369,20 @@ function TQuickAmazon.DeleteObject(amBucket,amObjectName : string; var amRespons
AmazonS3 : TAmazonStorage;
CloudResponseInfo : TCloudResponseInfo;
begin
Result := False;
if amBucket = '' then amBucket := '$root';
if amObjectName.StartsWith('/') then amObjectName := Copy(amObjectName,2,Length(amObjectName));
AmazonS3 := TAmazonStorage.Create(fconAmazon);
try
//AmazonS3.Timeout := fTimeout;
CloudResponseInfo := TCloudResponseInfo.Create;
Result := AmazonS3.DeleteObject(amBucket,amObjectName,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
try
Result := AmazonS3.DeleteObject(amBucket,amObjectName,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
finally
CloudResponseInfo.Free;
end;
finally
AmazonS3.Free;
CloudResponseInfo.Free;
end;
end;

Expand All @@ -385,7 +395,6 @@ function TQuickAmazon.ListObjects(amBucket : string; amObjectsStartWith : string
CloudResponseInfo : TCloudResponseInfo;
cNextMarker : string;
amParams : TStrings;
a : TAmazonBucketResult;
begin
Result := TAmazonObjects.Create(True);
cNextMarker := '';
Expand Down Expand Up @@ -437,7 +446,6 @@ function TQuickAmazon.ListObjectsNames(amBucket : string; amObjectsStartWith : s
CloudResponseInfo : TCloudResponseInfo;
cNextMarker : string;
amParams : TStrings;
a : TAmazonBucketResult;
begin
Result := TStringList.Create;
cNextMarker := '';
Expand Down Expand Up @@ -510,20 +518,23 @@ function TQuickAmazon.ListBuckets(var amResponseInfo : TAmazonResponseInfo) : TS
try
//AmazonS3.Timeout := fTimeout;
CloudResponseInfo := TCloudResponseInfo.Create;
Buckets := AmazonS3.ListBuckets(CloudResponseInfo);
try
Result.Capacity := Buckets.Count;
for i := 0 to Buckets.Count -1 do
begin
Result.Add(Buckets.Names[i]);
Buckets := AmazonS3.ListBuckets(CloudResponseInfo);
try
Result.Capacity := Buckets.Count;
for i := 0 to Buckets.Count -1 do
begin
Result.Add(Buckets.Names[i]);
end;
amResponseInfo := GetResponseInfo(CloudResponseInfo);
finally
Buckets.Free;
end;
amResponseInfo := GetResponseInfo(CloudResponseInfo);
finally
Buckets.Free;
CloudResponseInfo.Free;
end;
finally
AmazonS3.Free;
CloudResponseInfo.Free;
end;
end;

Expand All @@ -538,11 +549,14 @@ function TQuickAmazon.CreateBucket(amBucket : string; amBucketRegion : TAmazonRe
AmazonS3 := TAmazonStorageService.Create(fconAmazon);
try
CloudResponseInfo := TCloudResponseInfo.Create;
Result := AmazonS3.CreateBucket(amBucket,amACLType,amBucketRegion,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
try
Result := AmazonS3.CreateBucket(amBucket,amACLType,amBucketRegion,CloudResponseInfo);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
finally
CloudResponseInfo.Free;
end;
finally
AmazonS3.Free;
CloudResponseInfo.Free;
end;
end;

Expand All @@ -557,11 +571,14 @@ function TQuickAmazon.DeleteBucket(amBucket : string; amBucketRegion : TAmazonRe
AmazonS3 := TAmazonStorageService.Create(fconAmazon);
try
CloudResponseInfo := TCloudResponseInfo.Create;
Result := AmazonS3.DeleteBucket(amBucket,CloudResponseInfo,amBucketRegion);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
try
Result := AmazonS3.DeleteBucket(amBucket,CloudResponseInfo,amBucketRegion);
amResponseInfo := GetResponseInfo(CloudResponseInfo);
finally
CloudResponseInfo.Free;
end;
finally
AmazonS3.Free;
CloudResponseInfo.Free;
end;
end;

Expand All @@ -570,9 +587,11 @@ class function TQuickAmazon.GetAWSRegion(const Region : string) : TAmazonRegion;
Result := TAmazonStorageService.GetRegionFromString(Region);
end;

{$IFNDEF DELPHISYDNEY_UP}
class function TQuickAmazon.GetAWSRegion(Region: TAmazonRegion): string;
begin
Result := TAmazonStorageService.GetRegionString(Region);
end;
{$ENDIF}

end.
1 change: 1 addition & 0 deletions Quick.AppService.pas
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ constructor TAppService.Create;
fStatus := TSvcStatus.ssStopped;
fCanInstallWithOtherName := False;
fOnExecute := nil;
IsQuickServiceApp := True;
end;

destructor TAppService.Destroy;
Expand Down
22 changes: 21 additions & 1 deletion Quick.Commons.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Author : Kike Pérez
Version : 2.0
Created : 14/07/2017
Modified : 14/07/2020
Modified : 06/08/2020
This file is part of QuickLib: https://github.com/exilon/QuickLib
Expand Down Expand Up @@ -304,6 +304,8 @@ EShellError = class(Exception);
function GetComputerName : string;
//Changes incorrect delims in path
function NormalizePathDelim(const cPath : string; const Delim : Char) : string;
//combine paths normalized with delim
function CombinePaths(const aFirstPath, aSecondPath: string; aDelim : Char): string;
//Removes last segment of a path
function RemoveLastPathSegment(cDir : string) : string;
//returns path delimiter if found
Expand Down Expand Up @@ -386,6 +388,8 @@ EShellError = class(Exception);

var
path : TEnvironmentPath;
//Enabled if QuickService is defined
IsQuickServiceApp : Boolean;

implementation

Expand Down Expand Up @@ -985,6 +989,22 @@ function NormalizePathDelim(const cPath : string; const Delim : Char) : string;
else Result := StringReplace(cPath,'\',Delim,[rfReplaceAll]);
end;

function CombinePaths(const aFirstPath, aSecondPath: string; aDelim : Char): string;
begin
var path1 := NormalizePathDelim(aFirstPath,aDelim);
var path2 := NormalizePathDelim(aSecondPath,aDelim);
if path1.EndsWith(aDelim) then
begin
if path2.StartsWith(aDelim) then Result := path1 + path2.Substring(1)
else Result := path1 + path2;
end
else
begin
if path2.StartsWith(aDelim) then Result := path1 + path2
else result := path1 + aDelim + path2;
end;
end;

function RemoveLastPathSegment(cDir : string) : string;
var
posi : Integer;
Expand Down
20 changes: 20 additions & 0 deletions Quick.Console.pas
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ TConsoleMenu = class
procedure cout(const cMsg : Double; cEventType : TLogEventType); overload;
procedure cout(const cMsg : string; cEventType : TLogEventType); overload;
procedure cout(const cMsg : string; cColor : TConsoleColor); overload;
procedure coutSL(const cMsg : string; cColor : TConsoleColor);
procedure cout(const cMsg : string; params : array of const; cEventType : TLogEventType); overload;
procedure coutXY(x,y : Integer; const cMsg : string; cEventType : TLogEventType); overload;
procedure coutXY(x,y : Integer; const cMsg : string; cColor : TConsoleColor); overload;
Expand Down Expand Up @@ -327,6 +328,25 @@ procedure cout(const cMsg : string; cColor : TConsoleColor);
end;
end;

procedure coutSL(const cMsg : string; cColor : TConsoleColor);
begin
EnterCriticalSection(CSConsole);
try
{$IFDEF MSWINDOWS}
if hStdOut <> 0 then
{$ENDIF}
begin
TextColor(cColor);
{$I-}
Write(cMsg{$IFDEF LINUX} +#13{$ENDIF});
{$I+}
TextColor(LastMode);
end;
finally
LeaveCriticalSection(CSConsole);
end;
end;

procedure cout(const cMsg : string; params : array of const; cEventType : TLogEventType);
begin
cout(Format(cMsg,params),cEventType);
Expand Down
1 change: 1 addition & 0 deletions Quick.Debug.Utils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class function TDebugger.Log: ILogger;

class procedure TDebugger.SetLogger(aLogger: ILogger);
begin
if aLogger = nil then raise Exception.Create('Debugger logger cannot be nil!');
fLogger := aLogger;
fShowTime := False;
end;
Expand Down
Loading

0 comments on commit 42d0550

Please sign in to comment.