2010-03-31 18:22:46 -04:00
|
|
|
{
|
|
|
|
This file is part of the Mufasa Macro Library (MML)
|
|
|
|
Copyright (c) 2009 by Raymond van Venetië and Merlijn Wajer
|
|
|
|
|
|
|
|
MML is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
MML is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with MML. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
See the file COPYING, included in this distribution,
|
|
|
|
for details about the copyright.
|
|
|
|
|
|
|
|
extensions.inc for the Mufasa Macro Library
|
|
|
|
}
|
|
|
|
|
2010-04-05 07:56:20 -04:00
|
|
|
type
|
|
|
|
TStringArray = array of string;
|
2010-04-18 11:14:19 -04:00
|
|
|
function ext_UnTar(const Input : string; var Content : TStringArray) : boolean;
|
2010-04-05 07:56:20 -04:00
|
|
|
var
|
|
|
|
Stream : TStringStream;
|
|
|
|
begin
|
|
|
|
result := false;
|
|
|
|
try
|
|
|
|
Stream := TStringStream.Create(Input);
|
|
|
|
content := UnTar(Stream);
|
|
|
|
result := (length(content) > 0);
|
|
|
|
finally
|
|
|
|
stream.free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function ext_UnTarEx(const Input : string;const outputdir : string; overwrite : boolean): boolean;
|
|
|
|
var
|
|
|
|
Stream : TStringStream;
|
2010-04-16 10:03:26 -04:00
|
|
|
Untarrer : TUntarThread;
|
2010-04-05 07:56:20 -04:00
|
|
|
begin
|
|
|
|
result := false;
|
|
|
|
try
|
|
|
|
Stream := TStringStream.Create(Input);
|
2010-04-16 10:03:26 -04:00
|
|
|
Untarrer := TUntarThread.Create(stream,outputdir,overwrite);
|
|
|
|
Untarrer.Resume;
|
|
|
|
while Untarrer.Finished = false do
|
|
|
|
begin
|
|
|
|
Application.ProcessMessages;
|
|
|
|
sleep(25);
|
|
|
|
end;
|
|
|
|
result := Untarrer.Result;
|
2010-04-05 07:56:20 -04:00
|
|
|
finally
|
2010-04-16 10:03:26 -04:00
|
|
|
Untarrer.Free;
|
2010-04-05 07:56:20 -04:00
|
|
|
stream.free;
|
|
|
|
end;
|
|
|
|
end;
|
2010-04-18 11:14:19 -04:00
|
|
|
function ext_DecompressBZip2(const input: string;var output : string; const BlockSize: Cardinal): boolean;
|
2010-04-05 07:56:20 -04:00
|
|
|
var
|
|
|
|
Stream : TStringStream;
|
2010-04-16 10:03:26 -04:00
|
|
|
Decompress : TDecompressThread;
|
2010-04-05 07:56:20 -04:00
|
|
|
MS : TMemoryStream;
|
|
|
|
begin
|
|
|
|
result := false;
|
|
|
|
try
|
|
|
|
Stream := TStringStream.Create(Input);
|
2010-04-16 10:03:26 -04:00
|
|
|
Decompress := TDecompressThread.Create(Stream);
|
|
|
|
Decompress.Resume;
|
|
|
|
while Decompress.Finished = false do
|
|
|
|
begin
|
|
|
|
Application.ProcessMessages;
|
|
|
|
sleep(25);
|
|
|
|
end;
|
|
|
|
ms := Decompress.Result;
|
2010-04-05 07:56:20 -04:00
|
|
|
if ms.size > 0 then
|
|
|
|
begin
|
|
|
|
ms.Position:= 0;
|
|
|
|
SetLength(output,ms.Size);
|
|
|
|
MS.Read(output[1],MS.size);
|
|
|
|
result := true;
|
|
|
|
end;
|
2010-04-16 10:03:26 -04:00
|
|
|
ms.free;
|
2010-04-05 07:56:20 -04:00
|
|
|
finally
|
|
|
|
stream.free;
|
2010-04-16 10:03:26 -04:00
|
|
|
Decompress.Free;
|
2010-04-05 07:56:20 -04:00
|
|
|
end;
|
|
|
|
end;
|
2010-03-31 18:22:46 -04:00
|
|
|
|
2010-04-05 07:56:20 -04:00
|
|
|
function ext_GetPage(const url : string) : string;
|
2010-03-31 18:22:46 -04:00
|
|
|
var
|
|
|
|
t: TDownloadThread;
|
|
|
|
begin
|
2010-04-05 07:56:20 -04:00
|
|
|
result := '';
|
|
|
|
try
|
2010-04-18 11:14:19 -04:00
|
|
|
t := TDownloadThread.Create(url,@result);
|
2010-04-05 07:56:20 -04:00
|
|
|
t.Resume;
|
|
|
|
while not t.done do
|
|
|
|
begin
|
|
|
|
Application.ProcessMessages;
|
|
|
|
Sleep(25);
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
mDebugLn('Exception in GetPage in Extensions: ' + e.message);
|
2010-03-31 18:22:46 -04:00
|
|
|
end;
|
|
|
|
end;
|
2010-04-11 15:42:42 -04:00
|
|
|
|
|
|
|
function ext_MessageDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
|
|
|
|
begin
|
|
|
|
result := MessageDlg(acaption,amsg,dlgtype,buttons,helpctx);
|
|
|
|
end;
|
2010-05-20 05:12:20 -04:00
|
|
|
|
|
|
|
function ext_SDTMToMDTM(Const DTM: TSDTM): TMDTM;
|
|
|
|
begin
|
|
|
|
result := SDTMToMDTM(DTM);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function ext_InputQuery(const ACaption, APrompt : String; var Value : String) : Boolean;
|
|
|
|
begin
|
|
|
|
result := InputQuery(acaption,aprompt,value);
|
|
|
|
end;
|
2010-09-26 06:54:37 -04:00
|
|
|
|
|
|
|
function ext_ScriptText: string;
|
|
|
|
begin
|
|
|
|
Result := SimbaForm.CurrScript.SynEdit.Lines.Text;
|
|
|
|
Result := ReplaceRegExpr('Players\[(.*?)\]\.([N|n][A|a][M|m][E|e]|[P|p][A|a][S|s]{2}|[P|p][I|i][N|n])\s*\:\=\s*\''.*?\'';', Result, 'Players[$1].$2 := ''*********'';', True);
|
|
|
|
end;
|
2010-09-26 06:57:34 -04:00
|
|
|
|
|
|
|
function ext_GetPageEx(const URL, PostData, MimeType: string): string;
|
|
|
|
var
|
|
|
|
HTTPSend: THTTPSend;
|
|
|
|
begin
|
|
|
|
HTTPSend := THTTPSend.Create;
|
|
|
|
try
|
|
|
|
HTTPSend.MimeType := MimeType;
|
|
|
|
HTTPSend.Document.Clear;
|
|
|
|
HTTPSend.Document.Write(PostData[1], Length(PostData));
|
|
|
|
try
|
|
|
|
if HTTPSend.HTTPMethod('POST', URL) then
|
|
|
|
begin;
|
|
|
|
SetLength(Result, HTTPSend.Document.Size);
|
|
|
|
HTTPSend.Document.Read(Result[1], Length(Result));
|
|
|
|
end else
|
|
|
|
Result := '';
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
mDebugLn('Exception in GetPage in Extensions: ' + e.message);
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
HTTPSend.Free;
|
|
|
|
end;
|
|
|
|
end;
|