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;
|
2011-01-12 20:14:38 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
function ext_GetSelectedText: string;
|
|
|
|
var
|
|
|
|
I: integer;
|
|
|
|
begin
|
|
|
|
with SimbaForm.CurrScript.SynEdit do
|
|
|
|
begin
|
|
|
|
if (not (BlockBegin.Y = BlockEnd.Y)) then
|
|
|
|
begin
|
|
|
|
Result := Copy(Lines[BlockBegin.Y - 1], BlockBegin.X, Length(Lines[BlockBegin.Y - 1])) + MEOL;
|
|
|
|
for I := BlockBegin.Y + 1 to BlockEnd.Y - 1 do
|
|
|
|
Result := Result + Lines[I - 1] + MEOL;
|
|
|
|
Result := Result + Copy(Lines[BlockEnd.Y - 1], 1, BlockEnd.X - 1);
|
|
|
|
end else
|
|
|
|
Result := Copy(Lines[BlockBegin.Y - 1], BlockBegin.X, BlockEnd.X - BlockBegin.X);
|
|
|
|
end;
|
2010-09-30 08:50:04 -04:00
|
|
|
end;
|
|
|
|
|
2010-12-25 04:27:51 -05:00
|
|
|
procedure ext_OpenScript(vName, Data: string; Run: boolean);
|
2010-09-30 08:50:04 -04:00
|
|
|
begin
|
2010-12-25 04:27:51 -05:00
|
|
|
if (vName = '') then
|
|
|
|
vName := 'Untitled';
|
2010-12-23 02:03:13 -05:00
|
|
|
|
|
|
|
with SimbaForm do
|
|
|
|
begin
|
|
|
|
AddTab();
|
|
|
|
with CurrScript do
|
|
|
|
begin
|
|
|
|
SynEdit.Lines.Text := Data;
|
2010-12-25 04:27:51 -05:00
|
|
|
ScriptName := vName;
|
|
|
|
ScriptChanged := True;
|
2010-12-23 02:03:13 -05:00
|
|
|
end;
|
|
|
|
RefreshTab();
|
|
|
|
UpdateTitle();
|
|
|
|
end;
|
2010-12-25 04:00:37 -05:00
|
|
|
|
|
|
|
if (Run) then
|
|
|
|
SimbaForm.RunScript();
|
2010-12-23 02:03:13 -05:00
|
|
|
end;
|
|
|
|
|
2010-12-25 04:00:37 -05:00
|
|
|
procedure ext_OpenScriptEx(FileName: string; Run: boolean);
|
2010-12-23 02:03:13 -05:00
|
|
|
begin
|
|
|
|
FileName := SetDirSeparators(FileName);
|
2011-02-08 10:20:28 -05:00
|
|
|
SimbaForm.LoadScriptFile(FileName,True,false);
|
2010-12-25 04:00:37 -05:00
|
|
|
if (Run) then
|
|
|
|
SimbaForm.RunScript();
|
2010-09-26 06:54:37 -04:00
|
|
|
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;
|
2010-09-29 06:07:55 -04:00
|
|
|
|
|
|
|
function ext_GetJSONValue(const Data, Value: string): string;
|
|
|
|
var
|
|
|
|
SuperObject: ISuperObject;
|
|
|
|
begin
|
|
|
|
SuperObject := SO(Data);
|
|
|
|
Result := SuperObject.AsObject.S[Value];
|
|
|
|
end;
|