Skip to content

Commit

Permalink
Merge branch 'hotfix' (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpottsoh committed Jun 5, 2018
2 parents 4fd7b1e + 9eab096 commit ad227fb
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Delphi/Project/ExercismCLIInstaller.dproj
Expand Up @@ -109,9 +109,9 @@
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_MajorVer>2</VerInfo_MajorVer>
<VerInfo_AutoIncVersion>true</VerInfo_AutoIncVersion>
<VerInfo_Keys>CompanyName=Exercism;FileDescription=$(MSBuildProjectName);FileVersion=2.0.2.18;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=2.0.2.0;Comments=</VerInfo_Keys>
<VerInfo_Keys>CompanyName=Exercism;FileDescription=$(MSBuildProjectName);FileVersion=2.0.2.19;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=2.0.2.0;Comments=</VerInfo_Keys>
<Icon_MainIcon>img\ExercismCLIInstaller_Icon.ico</Icon_MainIcon>
<VerInfo_Build>18</VerInfo_Build>
<VerInfo_Build>19</VerInfo_Build>
<VerInfo_Release>2</VerInfo_Release>
</PropertyGroup>
<ItemGroup>
Expand Down
19 changes: 0 additions & 19 deletions Delphi/Project/Source/uClientDownloadFrm.dfm
Expand Up @@ -206,25 +206,6 @@ object frmDownload: TfrmDownload
Left = 184
Top = 128
end
object Assets: TRESTResponseDataSetAdapter
Dataset = tableAssets
FieldDefs = <>
Response = RESTResponse1
RootElement = 'assets'
NestedElements = True
Left = 260
Top = 88
end
object tableAssets: TFDMemTable
FetchOptions.AssignedValues = [evMode]
FetchOptions.Mode = fmAll
ResourceOptions.AssignedValues = [rvSilentMode]
ResourceOptions.SilentMode = True
UpdateOptions.AssignedValues = [uvCheckRequired]
UpdateOptions.CheckRequired = False
Left = 320
Top = 96
end
object tmrInstall: TTimer
Enabled = False
Interval = 500
Expand Down
91 changes: 86 additions & 5 deletions Delphi/Project/Source/uClientDownloadFrm.pas
Expand Up @@ -18,6 +18,12 @@ Tos = class
class function Is32BitWindows: Boolean;
end;

IAssetsURL = interface(IInvokable)
['{49E2CFFF-32DB-4CF7-9C63-674206B52BBA}']
function GetAssetsURL: string;
property assets_url: string read GetAssetsURL;
end;

IDownloadURL = interface(IInvokable)
['{049FAAD1-D024-4E96-B7B5-96674D6F56AF}']
function GetUrl: string;
Expand Down Expand Up @@ -45,8 +51,6 @@ TfrmDownload = class(TForm)
RESTClient1: TRESTClient;
RESTRequest1: TRESTRequest;
RESTResponse1: TRESTResponse;
Assets: TRESTResponseDataSetAdapter;
tableAssets: TFDMemTable;
tmrInstall: TTimer;
btnStopDownload: TButton;
Label4: TLabel;
Expand All @@ -72,10 +76,12 @@ TfrmDownload = class(TForm)
FDownloadStream: TStream;
FHTTPResponse: IHTTPResponse;
DownloadVer: IDownloadVer;
AssetsURL: IAssetsURL;
procedure DoEndDownload(const AsyncResult: IAsyncResult);
function DetermineArchitecture(var aStatus: TResultStatus): Boolean;
procedure FetchRESTRequest(var aStatus: TResultStatus);
function FetchDownloadVersion(var aStatus: TResultStatus): IDownloadVer;
function FetchAssetsURL(var aStatus: TResultStatus): IAssetsURL;
function FetchDownloadURL(const aIs32BitWindows: Boolean; var aStatus: TResultStatus): IDownloadURL;
procedure Download_CLI_ZIP(aDownloadURL: IDownloadURL; var aStatus: TResultStatus);
procedure Unzip_CLI(var aStatus: TResultStatus);
Expand All @@ -89,11 +95,21 @@ TfrmDownload = class(TForm)
function ShowClientDownloadForm(const aInstallInfo: TInstallInfo): TResultStatus;
function NewDownloadURL(a32Bit: boolean; aFDMemTable: TFDMemTable): IDownloadURL;
function NewDownloadVer(aFDMemTable: TFDMemTable): IDownloadVer;
function NewAssets(aFDMemTable: TFDMemTable): IAssetsURL;

implementation
uses System.IOUtils, System.Zip, uUpdatePath;
{$R *.dfm}
type
TAssetsURL = class(TInterfacedObject, IAssetsURL)
private
fAssetsUrl: string;
function GetAssetsURL: string;
public
constructor create(aFDMEMTable: TFDMemTable);
property assets_url: string read GetAssetsURL;
end;

TDownloadVer = class(TInterfacedObject, IDownloadVer)
private
FVersion: TArray<integer>;
Expand Down Expand Up @@ -130,6 +146,11 @@ function NewDownloadVer(aFDMemTable: TFDMemTable): IDownloadVer;
result := TDownloadVer.create(aFDMemTable);
end;

function NewAssets(aFDMemTable: TFDMemTable): IAssetsURL;
begin
result := TAssetsURL.Create(aFDMemTable);
end;

class function Tos.Is32BitWindows: Boolean;
begin
result := TOSVersion.Architecture = arIntelX86;
Expand Down Expand Up @@ -237,11 +258,34 @@ function TfrmDownload.FetchDownloadVersion(var aStatus: TResultStatus): IDownloa
end;
end;

function TfrmDownload.FetchAssetsURL(var aStatus: TResultStatus): IAssetsURL;
begin
aStatus := rsCancel;
mStatus.Lines.Add('Fetching Assets Info.');
result := NewAssets(tableRoot);
if not result.Assets_Url.IsEmpty then
begin
mStatus.Lines.Add('Successfully retrieved Assets Info');
aStatus := rsNext;
end
else
begin
result := nil;
mStatus.Lines.Add('Failed to retrieve Assets Info');
if MessageDlg('Unable to retrieve Assets Info. Confirm internet connection then Retry or Cancel.',
mtError, [mbRetry, mbCancel], 0) = mrRetry then
begin
aStatus := rsRepeat;
mStatus.Lines.Add('');
end;
end;
end;

function TfrmDownload.FetchDownloadURL(const aIs32BitWindows: Boolean; var aStatus: TResultStatus): IDownloadURL;
begin
aStatus := rsCancel;
mStatus.Lines.Add('Fetching URL for latest CLI version.');
result := NewDownloadURL(aIs32BitWindows, tableAssets);
result := NewDownloadURL(aIs32BitWindows, tableRoot);
if result.Url <> '' then
begin
mStatus.Lines.Add('Successfully retrieved URL');
Expand Down Expand Up @@ -346,8 +390,17 @@ procedure TfrmDownload.tmrDownloadTimer(Sender: TObject);
0: lIs32BitWindows := DetermineArchitecture(lStatus);
1: FetchRESTRequest(lStatus);
2: DownloadVer := FetchDownloadVersion(lStatus);
3: lDownloadURL := FetchDownloadURL(lIs32BitWindows, lStatus);
4: Download_CLI_ZIP(lDownloadURL, lStatus);
3:
begin
AssetsURL := FetchAssetsURL(lStatus);
if lStatus = rsNext then
begin
RESTClient1.BaseURL := AssetsURL.assets_url;
FetchRESTRequest(lStatus);
end;
end;
4: lDownloadURL := FetchDownloadURL(lIs32BitWindows, lStatus);
5: Download_CLI_ZIP(lDownloadURL, lStatus);
end;//case

case lStatus of
Expand Down Expand Up @@ -512,6 +565,7 @@ constructor TDownloadVer.create(aFDMEMTable: TFDMemTable);
IsFound: boolean;
tag_name_Field: TField;
begin
FTag_Name := '';
if aFDMemTable.FindFirst then
begin
IsFound := false;
Expand Down Expand Up @@ -540,4 +594,31 @@ function TDownloadVer.GetTagName: string;
result := FTag_Name;
end;

{ TAssetsURL }

constructor TAssetsURL.create(aFDMEMTable: TFDMemTable);
var
IsFound: boolean;
assets_url_Field: TField;
begin
fAssetsUrl := '';
if aFDMemTable.FindFirst then
begin
IsFound := false;
repeat
assets_url_Field := aFDMemTable.FindField('assets_url');
if assigned(assets_url_Field) then
begin
IsFound := true;
fAssetsUrl := assets_url_Field.DisplayText;
end;
until IsFound or not aFDMemtable.FindNext;
end;
end;

function TAssetsURL.GetAssetsURL: string;
begin
result := fAssetsUrl;
end;

end.

0 comments on commit ad227fb

Please sign in to comment.