Add better support for command line arguments
Use -g or --gameid to set game id Use -u or --username to set username Use -p or --password to set password
This commit is contained in:
parent
67bf8f70f2
commit
6e8e993aba
@ -1,13 +1,13 @@
|
||||
program downloader;
|
||||
|
||||
uses fphttpclient, base64, opensslsockets, fpjson, jsonparser, SysUtils, process, Classes, libtar;
|
||||
uses fphttpclient, base64, opensslsockets, fpjson, jsonparser, SysUtils, process, Classes, libtar, CustApp;
|
||||
|
||||
var
|
||||
authString: String;
|
||||
gameId: Integer;
|
||||
gameData: TJSONData;
|
||||
client: TFPHTTPClient;
|
||||
tarFile: String;
|
||||
authString, tarFile, errorMsg: String;
|
||||
app: TCustomApplication;
|
||||
|
||||
procedure createFileDir(filePath: AnsiString);
|
||||
var
|
||||
@ -110,11 +110,25 @@ const
|
||||
var
|
||||
username, password: String;
|
||||
|
||||
begin
|
||||
if app.HasOption('u', 'user') then
|
||||
begin
|
||||
username := app.GetOptionValue('u', 'username');
|
||||
end
|
||||
else
|
||||
begin
|
||||
Write('Enter username: ');
|
||||
ReadLn(username);
|
||||
end;
|
||||
if app.HasOption('p', 'password') then
|
||||
begin
|
||||
password := app.GetOptionValue('p', 'password');
|
||||
end
|
||||
else
|
||||
begin
|
||||
Write('Enter password: ');
|
||||
ReadLn(password);
|
||||
end;
|
||||
authString := username + ':' + password;
|
||||
client.AddHeader('Authorization', 'Basic '+base64.EncodeStringBase64(authString));
|
||||
client.AllowRedirect := true;
|
||||
@ -127,9 +141,13 @@ begin
|
||||
end;
|
||||
|
||||
begin
|
||||
if ParamCount > 0 then
|
||||
app := TCustomApplication.Create(nil);
|
||||
errorMsg := app.checkOptions('g:u:p:', 'gameid: username: password:');
|
||||
if (errorMsg = '') then
|
||||
begin
|
||||
gameId := StrToInt(ParamStr(1));
|
||||
if app.HasOption('g', 'gameid') then
|
||||
begin
|
||||
gameId := StrToInt(app.GetOptionValue('g', 'gameid'));
|
||||
client := TFPHTTPClient.Create(nil);
|
||||
if authenticate(client) then
|
||||
begin
|
||||
@ -154,5 +172,10 @@ begin
|
||||
begin
|
||||
WriteLn('No game id was given');
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
WriteLn(errorMsg);
|
||||
end;
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user