diff --git a/trunk/Projects/SAMufasaGUI/project1.lpi b/trunk/Projects/SAMufasaGUI/project1.lpi index fb9a1d7..e850aba 100644 --- a/trunk/Projects/SAMufasaGUI/project1.lpi +++ b/trunk/Projects/SAMufasaGUI/project1.lpi @@ -36,7 +36,7 @@ - + @@ -137,8 +137,9 @@ - - + + + @@ -195,9 +196,11 @@ - - + + + + @@ -242,7 +245,7 @@ - + @@ -264,9 +267,11 @@ - - + + + + @@ -346,7 +351,7 @@ - + @@ -361,7 +366,7 @@ - + @@ -483,7 +488,7 @@ - + @@ -497,7 +502,7 @@ - + @@ -537,9 +542,11 @@ - - + + + + @@ -1704,7 +1711,7 @@ - + @@ -1731,7 +1738,7 @@ - + @@ -2000,124 +2007,144 @@ + + + + + + + + + + + + + + + + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - - + + - - + + - - + + - - + + - + - + + + + + @@ -2128,7 +2155,7 @@ - + diff --git a/trunk/Projects/SAMufasaGUI/project1.lpr b/trunk/Projects/SAMufasaGUI/project1.lpr index ac88d62..dcf306d 100644 --- a/trunk/Projects/SAMufasaGUI/project1.lpr +++ b/trunk/Projects/SAMufasaGUI/project1.lpr @@ -31,7 +31,8 @@ uses {$ENDIF}{$ENDIF} Interfaces, // this includes the LCL widgetset LResources, Forms, testunit, colourhistory, About, internets, debugimage, - framefunctionlist, simpleanalyzer, updater, updateform, simbasettings; + framefunctionlist, simpleanalyzer, updater, updateform, simbasettings, +libloader; {$IFDEF WINDOWS}{$R project1.rc}{$ENDIF} begin diff --git a/trunk/Projects/SAMufasaGUI/testunit.lfm b/trunk/Projects/SAMufasaGUI/testunit.lfm index b2c3644..f08b393 100644 --- a/trunk/Projects/SAMufasaGUI/testunit.lfm +++ b/trunk/Projects/SAMufasaGUI/testunit.lfm @@ -1,7 +1,7 @@ object Form1: TForm1 - Left = 316 + Left = 593 Height = 557 - Top = 105 + Top = 321 Width = 734 ActiveControl = ScriptPanel Caption = 'THA FUKING SIMBA' @@ -202,7 +202,7 @@ object Form1: TForm1 object StatusBar: TStatusBar Left = 0 Height = 21 - Top = 536 + Top = 511 Width = 734 Panels = < item @@ -220,7 +220,7 @@ object Form1: TForm1 object PanelMemo: TPanel Left = 0 Height = 154 - Top = 382 + Top = 357 Width = 734 Align = alBottom ClientHeight = 154 @@ -240,19 +240,19 @@ object Form1: TForm1 Cursor = crVSplit Left = 0 Height = 5 - Top = 377 + Top = 352 Width = 734 Align = alBottom ResizeAnchor = akBottom end object ScriptPanel: TPanel Left = 0 - Height = 353 + Height = 328 Top = 24 Width = 734 Align = alClient BevelOuter = bvNone - ClientHeight = 353 + ClientHeight = 328 ClientWidth = 734 DockSite = True TabOrder = 4 @@ -260,7 +260,7 @@ object Form1: TForm1 OnDockOver = ScriptPanelDockOver object PageControl1: TPageControl Left = 155 - Height = 318 + Height = 293 Top = 0 Width = 579 Align = alClient @@ -279,7 +279,7 @@ object Form1: TForm1 object SearchPanel: TPanel Left = 0 Height = 35 - Top = 318 + Top = 293 Width = 734 Align = alBottom BevelOuter = bvSpace @@ -409,21 +409,21 @@ object Form1: TForm1 end object SplitterFunctionList: TSplitter Left = 150 - Height = 318 + Height = 293 Top = 0 Width = 5 OnCanResize = SplitterFunctionListCanResize Visible = False end inline frmFunctionList: TFunctionListFrame - Height = 318 + Height = 293 Width = 150 - ClientHeight = 318 + ClientHeight = 293 ClientWidth = 150 OnEndDock = nil TabOrder = 3 inherited FunctionList: TTreeView - Height = 269 + Height = 244 Top = 22 Width = 150 DefaultItemHeight = 19 @@ -434,7 +434,7 @@ object Form1: TForm1 end inherited editSearchList: TEdit Height = 27 - Top = 291 + Top = 266 Width = 150 OnExit = editSearchListExit OnKeyDown = editSearchListKeyDown diff --git a/trunk/Projects/SAMufasaGUI/testunit.lrs b/trunk/Projects/SAMufasaGUI/testunit.lrs index 6884e82..44be78d 100644 --- a/trunk/Projects/SAMufasaGUI/testunit.lrs +++ b/trunk/Projects/SAMufasaGUI/testunit.lrs @@ -1,22 +1,22 @@ { This is an automatically generated lazarus resource file } LazarusResources.Add('TForm1','FORMDATA',[ - 'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'<'#1#6'Height'#3'-'#2#3'Top'#2'i'#5'Width' - +#3#222#2#13'ActiveControl'#7#11'ScriptPanel'#7'Caption'#6#16'THA FUKING SIMB' - +'A'#12'ClientHeight'#3#20#2#11'ClientWidth'#3#222#2#10'KeyPreview'#9#4'Menu' - +#7#8'MainMenu'#7'OnClose'#7#9'FormClose'#8'OnCreate'#7#10'FormCreate'#9'OnDe' - +'stroy'#7#11'FormDestroy'#10'OnShortCut'#7#13'FormShortCuts'#8'Position'#7#14 - +'poScreenCenter'#10'LCLVersion'#6#6'0.9.29'#7'Visible'#9#0#8'TToolBar'#8'Too' - +'lBar1'#4'Left'#2#0#6'Height'#2#24#3'Top'#2#0#5'Width'#3#222#2#7'Caption'#6#8 - +'ToolBar1'#6'Images'#7#17'Mufasa_Image_List'#14'ParentShowHint'#8#8'ShowHint' - +#9#8'TabOrder'#2#0#0#11'TToolButton'#6'TB_Run'#4'Left'#3#168#0#4'Hint'#6#3'R' - +'un'#3'Top'#2#2#6'Action'#7#15'ActionRunScript'#10'ImageIndex'#2#6#0#0#11'TT' - +'oolButton'#8'TB_Pause'#4'Left'#3#191#0#4'Hint'#6#5'Pause'#3'Top'#2#2#6'Acti' - +'on'#7#17'ActionPauseScript'#7'Enabled'#8#10'ImageIndex'#2#5#0#0#11'TToolBut' - +'ton'#7'TB_Stop'#4'Left'#3#214#0#4'Hint'#6#4'Stop'#3'Top'#2#2#6'Action'#7#16 - +'ActionStopScript'#7'Enabled'#8#10'ImageIndex'#2#7#0#0#11'TToolButton'#11'To' - +'olButton1'#4'Left'#3#237#0#3'Top'#2#2#5'Width'#2#3#7'Caption'#6#11'ToolButt' - +'on1'#5'Style'#7#10'tbsDivider'#0#0#11'TToolButton'#9'TB_NewTab'#4'Left'#3 + 'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'Q'#2#6'Height'#3'-'#2#3'Top'#3'A'#1#5'Wid' + +'th'#3#222#2#13'ActiveControl'#7#11'ScriptPanel'#7'Caption'#6#16'THA FUKING ' + +'SIMBA'#12'ClientHeight'#3#20#2#11'ClientWidth'#3#222#2#10'KeyPreview'#9#4'M' + +'enu'#7#8'MainMenu'#7'OnClose'#7#9'FormClose'#8'OnCreate'#7#10'FormCreate'#9 + +'OnDestroy'#7#11'FormDestroy'#10'OnShortCut'#7#13'FormShortCuts'#8'Position' + +#7#14'poScreenCenter'#10'LCLVersion'#6#6'0.9.29'#7'Visible'#9#0#8'TToolBar'#8 + +'ToolBar1'#4'Left'#2#0#6'Height'#2#24#3'Top'#2#0#5'Width'#3#222#2#7'Caption' + +#6#8'ToolBar1'#6'Images'#7#17'Mufasa_Image_List'#14'ParentShowHint'#8#8'Show' + +'Hint'#9#8'TabOrder'#2#0#0#11'TToolButton'#6'TB_Run'#4'Left'#3#168#0#4'Hint' + +#6#3'Run'#3'Top'#2#2#6'Action'#7#15'ActionRunScript'#10'ImageIndex'#2#6#0#0 + +#11'TToolButton'#8'TB_Pause'#4'Left'#3#191#0#4'Hint'#6#5'Pause'#3'Top'#2#2#6 + +'Action'#7#17'ActionPauseScript'#7'Enabled'#8#10'ImageIndex'#2#5#0#0#11'TToo' + +'lButton'#7'TB_Stop'#4'Left'#3#214#0#4'Hint'#6#4'Stop'#3'Top'#2#2#6'Action'#7 + +#16'ActionStopScript'#7'Enabled'#8#10'ImageIndex'#2#7#0#0#11'TToolButton'#11 + +'ToolButton1'#4'Left'#3#237#0#3'Top'#2#2#5'Width'#2#3#7'Caption'#6#11'ToolBu' + +'tton1'#5'Style'#7#10'tbsDivider'#0#0#11'TToolButton'#9'TB_NewTab'#4'Left'#3 +#240#0#4'Hint'#6#7'Add tab'#3'Top'#2#2#6'Action'#7#12'ActionNewTab'#0#0#11'T' +'ToolButton'#11'TB_CloseTab'#4'Left'#3#7#1#4'Hint'#6#9'Close tab'#3'Top'#2#2 +#6'Action'#7#14'ActionCloseTab'#0#0#11'TToolButton'#11'ToolButton4'#4'Left'#3 @@ -53,27 +53,27 @@ LazarusResources.Add('TForm1','FORMDATA',[ +'T_Paste'#4'Left'#3#142#0#3'Top'#2#2#6'Action'#7#11'ActionPaste'#0#0#11'TToo' +'lButton'#11'ToolButton9'#4'Left'#3#165#0#3'Top'#2#2#5'Width'#2#3#7'Caption' +#6#11'ToolButton9'#5'Style'#7#10'tbsDivider'#0#0#0#10'TStatusBar'#9'StatusBa' - +'r'#4'Left'#2#0#6'Height'#2#21#3'Top'#3#24#2#5'Width'#3#222#2#6'Panels'#14#1 + +'r'#4'Left'#2#0#6'Height'#2#21#3'Top'#3#255#1#5'Width'#3#222#2#6'Panels'#14#1 +#5'Width'#2'<'#0#1#4'Text'#6#8'Untitled'#5'Width'#3#150#0#0#1#5'Width'#2'2'#0 +#0#11'SimplePanel'#8#0#0#6'TPanel'#9'PanelMemo'#4'Left'#2#0#6'Height'#3#154#0 - +#3'Top'#3'~'#1#5'Width'#3#222#2#5'Align'#7#8'alBottom'#12'ClientHeight'#3#154 + +#3'Top'#3'e'#1#5'Width'#3#222#2#5'Align'#7#8'alBottom'#12'ClientHeight'#3#154 +#0#11'ClientWidth'#3#222#2#8'TabOrder'#2#2#0#5'TMemo'#5'Memo1'#4'Left'#2#1#6 +'Height'#3#152#0#3'Top'#2#1#5'Width'#3#220#2#5'Align'#7#8'alClient'#10'Scrol' +'lBars'#7#10'ssAutoBoth'#8'TabOrder'#2#0#0#0#0#9'TSplitter'#19'SplitterMemoS' - +'ynedit'#6'Cursor'#7#8'crVSplit'#4'Left'#2#0#6'Height'#2#5#3'Top'#3'y'#1#5'W' + +'ynedit'#6'Cursor'#7#8'crVSplit'#4'Left'#2#0#6'Height'#2#5#3'Top'#3'`'#1#5'W' +'idth'#3#222#2#5'Align'#7#8'alBottom'#12'ResizeAnchor'#7#8'akBottom'#0#0#6'T' - +'Panel'#11'ScriptPanel'#4'Left'#2#0#6'Height'#3'a'#1#3'Top'#2#24#5'Width'#3 + +'Panel'#11'ScriptPanel'#4'Left'#2#0#6'Height'#3'H'#1#3'Top'#2#24#5'Width'#3 +#222#2#5'Align'#7#8'alClient'#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#3 - +'a'#1#11'ClientWidth'#3#222#2#8'DockSite'#9#8'TabOrder'#2#4#10'OnDockDrop'#7 + +'H'#1#11'ClientWidth'#3#222#2#8'DockSite'#9#8'TabOrder'#2#4#10'OnDockDrop'#7 ,#19'ScriptPanelDockDrop'#10'OnDockOver'#7#19'ScriptPanelDockOver'#0#12'TPage' - +'Control'#12'PageControl1'#4'Left'#3#155#0#6'Height'#3'>'#1#3'Top'#2#0#5'Wid' + +'Control'#12'PageControl1'#4'Left'#3#155#0#6'Height'#3'%'#1#3'Top'#2#0#5'Wid' +'th'#3'C'#2#5'Align'#7#8'alClient'#6'Images'#7#17'Mufasa_Image_List'#9'Popup' +'Menu'#7#8'TabPopup'#8'TabOrder'#2#0#8'OnChange'#7#18'PageControl1Change'#10 +'OnChanging'#7#20'PageControl1Changing'#14'OnContextPopup'#7#24'PageControl1' +'ContextPopup'#10'OnDragDrop'#7#20'PageControl1DragDrop'#10'OnDragOver'#7#20 +'PageControl1DragOver'#11'OnMouseDown'#7#21'PageControl1MouseDown'#9'OnMouse' +'Up'#7#19'PageControl1MouseUp'#13'OnPageChanged'#7#18'PageControl1Change'#0#0 - +#6'TPanel'#11'SearchPanel'#4'Left'#2#0#6'Height'#2'#'#3'Top'#3'>'#1#5'Width' + +#6'TPanel'#11'SearchPanel'#4'Left'#2#0#6'Height'#2'#'#3'Top'#3'%'#1#5'Width' +#3#222#2#5'Align'#7#8'alBottom'#10'BevelOuter'#7#7'bvSpace'#12'ClientHeight' +#2'#'#11'ClientWidth'#3#222#2#8'TabOrder'#2#1#7'Visible'#8#0#12'TSpeedButton' +#17'SpeedButtonSearch'#4'Left'#2' '#6'Height'#2#19#3'Top'#2#7#5'Width'#2#16#5 @@ -155,14 +155,14 @@ LazarusResources.Add('TForm1','FORMDATA',[ +#25'LabeledEditSearchKeyPress'#0#0#9'TCheckBox'#17'CheckBoxMatchCase'#4'Left' +#3'@'#1#6'Height'#2#22#3'Top'#2#7#5'Width'#2'b'#7'Caption'#6#10'Match case'#7 +'OnClick'#7#22'CheckBoxMatchCaseClick'#8'TabOrder'#2#1#0#0#0#9'TSplitter'#20 - +'SplitterFunctionList'#4'Left'#3#150#0#6'Height'#3'>'#1#3'Top'#2#0#5'Width'#2 + +'SplitterFunctionList'#4'Left'#3#150#0#6'Height'#3'%'#1#3'Top'#2#0#5'Width'#2 +#5#11'OnCanResize'#7#29'SplitterFunctionListCanResize'#7'Visible'#8#0#0#244 - +#18'TFunctionListFrame'#15'frmFunctionList'#6'Height'#3'>'#1#5'Width'#3#150#0 - +#12'ClientHeight'#3'>'#1#11'ClientWidth'#3#150#0#9'OnEndDock'#13#8'TabOrder' - +#2#3#0#241#9'TTreeView'#12'FunctionList'#6'Height'#3#13#1#3'Top'#2#22#5'Widt' - +'h'#3#150#0#17'DefaultItemHeight'#2#19#8'OnChange'#7#18'FunctionListChange' + +#18'TFunctionListFrame'#15'frmFunctionList'#6'Height'#3'%'#1#5'Width'#3#150#0 + +#12'ClientHeight'#3'%'#1#11'ClientWidth'#3#150#0#9'OnEndDock'#13#8'TabOrder' + +#2#3#0#241#9'TTreeView'#12'FunctionList'#6'Height'#3#244#0#3'Top'#2#22#5'Wid' + +'th'#3#150#0#17'DefaultItemHeight'#2#19#8'OnChange'#7#18'FunctionListChange' +#10'OnDeletion'#13#7'OnEnter'#7#17'FunctionListEnter'#6'OnExit'#7#16'Functio' - +'nListExit'#0#0#241#5'TEdit'#14'editSearchList'#6'Height'#2#27#3'Top'#3'#'#1 + +'nListExit'#0#0#241#5'TEdit'#14'editSearchList'#6'Height'#2#27#3'Top'#3#10#1 +#5'Width'#3#150#0#6'OnExit'#7#18'editSearchListExit'#9'OnKeyDown'#7#21'editS' +'earchListKeyDown'#10'OnKeyPress'#7#22'editSearchListKeyPress'#0#0#241#6'TLa' +'bel'#17'FunctionListLabel'#6'Height'#2#18#5'Width'#3#146#0#0#0#0#0#9'TMainM' diff --git a/trunk/Projects/SAMufasaGUI/testunit.pas b/trunk/Projects/SAMufasaGUI/testunit.pas index 0dcf5dc..0aa0751 100644 --- a/trunk/Projects/SAMufasaGUI/testunit.pas +++ b/trunk/Projects/SAMufasaGUI/testunit.pas @@ -33,7 +33,7 @@ uses {$ifdef linux}cthreads,{$endif}Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus, ComCtrls, ExtCtrls, SynEdit, SynHighlighterPas, SynMemo, //Client, - MufasaTypes, + MufasaTypes, plugins, mmlpsthread,synedittypes, window, // for the comp picker and selector colourpicker, framescript, windowselector, lcltype, ActnList, StdActns, @@ -309,6 +309,7 @@ type OCR_Fonts: TMOCR; Picker: TMColorPicker; Selector: TMWindowSelector; + PluginsGlob: TMPlugins; procedure FunctionListShown( ShowIt : boolean); property ScriptState : TScriptState read GetScriptState write SetScriptState; procedure SafeCallThread; @@ -351,7 +352,7 @@ var implementation uses - lclintf,plugins, + lclintf, syncobjs, // for the critical sections debugimage, bitmaps, diff --git a/trunk/Units/MMLAddon/mmlpsthread.pas b/trunk/Units/MMLAddon/mmlpsthread.pas index 6eacc79..a0b1f0b 100644 --- a/trunk/Units/MMLAddon/mmlpsthread.pas +++ b/trunk/Units/MMLAddon/mmlpsthread.pas @@ -29,7 +29,9 @@ unit mmlpsthread; interface uses - Classes, SysUtils, client, uPSComponent,uPSCompiler,uPSRuntime,stdCtrls, uPSPreProcessor,MufasaTypes, web,bitmaps; + Classes, SysUtils, client, uPSComponent, uPSCompiler, + uPSRuntime, stdCtrls, uPSPreProcessor, MufasaTypes, + web, bitmaps, plugins; type { TMMLPSThread } @@ -86,6 +88,7 @@ type //DebugTo : TMemo; DebugTo: TWritelnProc; DebugImg : TDbgImgInfo; + PluginsGlob: TMPlugins; PluginsToload : Array of integer; FOnError : TOnError; procedure OnCompile(Sender: TPSScript); diff --git a/trunk/Units/MMLAddon/plugins.pas b/trunk/Units/MMLAddon/plugins.pas index 35bdaf7..54603e5 100644 --- a/trunk/Units/MMLAddon/plugins.pas +++ b/trunk/Units/MMLAddon/plugins.pas @@ -34,7 +34,7 @@ unit plugins; interface uses - Classes, SysUtils, dynlibs; + Classes, SysUtils, dynlibs, LibLoader; type TMPluginMethod = record @@ -48,28 +48,6 @@ type end; TMPluginArray = array of TMPlugin; - TGenericLib = record - filename: string; - handle: TLibHandle; - end; - TGenericLibArray = array of TGenericLib; - - TGenericLoader = class(TObject) - private - PluginLen : integer; - Loaded: TGenericLibArray; - procedure FreePlugins; - protected - function InitPlugin(plugin: TLibHandle): boolean; virtual; abstract; - public - PluginDirs : TStringList; - constructor Create; - destructor Destroy; override; - procedure ValidateDirs; - procedure LoadPluginsDir(DirIndex : integer); - function LoadPlugin(PluginName : string) : integer; - end; - { TMPlugins } @@ -91,115 +69,6 @@ uses { TMPlugins } -procedure TGenericLoader.FreePlugins; -var - I : integer; -begin - for i := 0 to PluginLen - 1 do - begin; - if (Loaded[i].handle > 0) then - try - Writeln(inttostr(I)); - FreeLibrary(Loaded[i].handle); - except - end; - end; - SetLength(Loaded,0); - PluginLen:= 0; -end; - -procedure TGenericLoader.ValidateDirs; -var - i : integer; - TempStr : string; -begin - for i := 0 to PluginDirs.Count - 1 do - begin; - if DirectoryExists(PluginDirs.Strings[i]) = false then - raise Exception.createFMT('Directory(%s) does not exist',[PluginDirs[i]]); - TempStr := PluginDirs.Strings[i]; - if (TempStr[Length(TempStr)] <> DS) then - begin; - if (TempStr[Length(TempStr)] = '\') or (TempStr[Length(TempStr)] = '/') then - TempStr[Length(TempStr)] := DS - else - TempStr := TempStr + DS; - PluginDirs.Strings[i] := TempStr; - end; - end; -end; - -procedure TGenericLoader.LoadPluginsDir(DirIndex: integer); -var - PlugExt: String = {$IFDEF LINUX}'*.so';{$ELSE}'*.dll';{$ENDIF} - FileSearcher : TSearchRec; -begin - if (DirIndex < 0) or (DirIndex >= PluginDirs.Count) then - Exit; - if FindFirst(PluginDirs.Strings[DirIndex] + PlugExt, faAnyFile, FileSearcher) <> 0 then - begin; - FindClose(FileSearcher); - Exit; - end; - repeat - LoadPlugin(FileSearcher.Name); - until FindNext(FileSearcher) <> 0; - FindClose(FileSearcher); -end; - - -function TGenericLoader.LoadPlugin(PluginName: string): Integer; -var - i, ii : integer; - Status : LongInt; - PlugExt: String = {$IFDEF LINUX}'.so';{$ELSE}'.dll';{$ENDIF} -begin - ii := -1; - result := -1; - if PluginDirs.Count = 0 then - Exit; - ValidateDirs; - PluginName := ExtractFileNameWithoutExt(PluginName); - for i := 0 to PluginDirs.Count - 1 do - if FileExists(PluginDirs.Strings[i] + Pluginname + PlugExt) then - begin; - if ii <> -1 then - Raise Exception.CreateFmt('Plugin(%s) has been found multiple times',[PluginName]); - ii := i; - end; - if ii = -1 then - raise Exception.CreateFMT('Plugins(%s) has not been found',[PluginName]); - for i := 0 to PluginLen - 1 do - if Loaded[i].filename = (PluginDirs.Strings[ii] + PluginName + PlugExt) then - Exit(i); - SetLength(Loaded,PluginLen + 1); - Writeln(Format('Loading plugin %s at %s',[PluginName,PluginDirs.Strings[ii]])); - Loaded[PluginLen].filename:= PluginDirs.Strings[ii] + Pluginname + PlugExt; - Loaded[PluginLen].handle:= LoadLibrary(PChar(Loaded[PluginLen].filename)); - if Loaded[PluginLen].handle = 0 then - Raise Exception.CreateFMT('Error loading plugin %s',[Loaded[PluginLen].filename]); - if InitPlugin(Loaded[PluginLen].handle) then - inc(PluginLen) - else - FreeLibrary(Loaded[PluginLen].handle); - Result := PluginLen; -end; - - -constructor TGenericLoader.Create; -begin - inherited Create; - PluginLen := 0; - PluginDirs := TStringList.Create; -end; - -destructor TGenericLoader.Destroy; -begin - FreePlugins; - PluginDirs.Free; - inherited Destroy; -end; - function TMPlugins.InitPlugin(plugin: TLibHandle): boolean; var pntrArrc : function : integer; stdcall; diff --git a/trunk/Units/MMLCore/libloader.pas b/trunk/Units/MMLCore/libloader.pas new file mode 100644 index 0000000..66fbeec --- /dev/null +++ b/trunk/Units/MMLCore/libloader.pas @@ -0,0 +1,171 @@ +{ + 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 . + + See the file COPYING, included in this distribution, + for details about the copyright. + + Super unit for loading libraries for the Mufasa Macro Library +} + +unit libloader; + +{$mode objfpc} + +interface + + uses + Classes, SysUtils, dynlibs; + + type + TGenericLib = record + filename: string; + handle: TLibHandle; + end; + TGenericLibArray = array of TGenericLib; + + TGenericLoader = class(TObject) + private + PluginLen : integer; + Loaded: TGenericLibArray; + procedure FreePlugins; + protected + function InitPlugin(plugin: TLibHandle): boolean; virtual; abstract; + public + PluginDirs : TStringList; + constructor Create; + destructor Destroy; override; + procedure ValidateDirs; + procedure LoadPluginsDir(DirIndex : integer); + function LoadPlugin(PluginName : string) : integer; + end; + +implementation + + uses + MufasaTypes,FileUtil; + + procedure TGenericLoader.FreePlugins; + var + I : integer; + begin + for i := 0 to PluginLen - 1 do + begin; + if (Loaded[i].handle > 0) then + try + Writeln(inttostr(I)); + FreeLibrary(Loaded[i].handle); + except + end; + end; + SetLength(Loaded,0); + PluginLen:= 0; + end; + + procedure TGenericLoader.ValidateDirs; + var + i : integer; + TempStr : string; + begin + for i := 0 to PluginDirs.Count - 1 do + begin; + if DirectoryExists(PluginDirs.Strings[i]) = false then + raise Exception.createFMT('Directory(%s) does not exist',[PluginDirs[i]]); + TempStr := PluginDirs.Strings[i]; + if (TempStr[Length(TempStr)] <> DS) then + begin; + if (TempStr[Length(TempStr)] = '\') or (TempStr[Length(TempStr)] = '/') then + TempStr[Length(TempStr)] := DS + else + TempStr := TempStr + DS; + PluginDirs.Strings[i] := TempStr; + end; + end; + end; + + procedure TGenericLoader.LoadPluginsDir(DirIndex: integer); + var + PlugExt: String = {$IFDEF LINUX}'*.so';{$ELSE}'*.dll';{$ENDIF} + FileSearcher : TSearchRec; + begin + if (DirIndex < 0) or (DirIndex >= PluginDirs.Count) then + Exit; + if FindFirst(PluginDirs.Strings[DirIndex] + PlugExt, faAnyFile, FileSearcher) <> 0 then + begin; + FindClose(FileSearcher); + Exit; + end; + repeat + LoadPlugin(FileSearcher.Name); + until FindNext(FileSearcher) <> 0; + FindClose(FileSearcher); + end; + + + function TGenericLoader.LoadPlugin(PluginName: string): Integer; + var + i, ii : integer; + Status : LongInt; + PlugExt: String = {$IFDEF LINUX}'.so';{$ELSE}'.dll';{$ENDIF} + begin + ii := -1; + result := -1; + if PluginDirs.Count = 0 then + Exit; + ValidateDirs; + PluginName := ExtractFileNameWithoutExt(PluginName); + for i := 0 to PluginDirs.Count - 1 do + if FileExists(PluginDirs.Strings[i] + Pluginname + PlugExt) then + begin; + if ii <> -1 then + Raise Exception.CreateFmt('Plugin(%s) has been found multiple times',[PluginName]); + ii := i; + end; + if ii = -1 then + raise Exception.CreateFMT('Plugins(%s) has not been found',[PluginName]); + for i := 0 to PluginLen - 1 do + if Loaded[i].filename = (PluginDirs.Strings[ii] + PluginName + PlugExt) then + Exit(i); + SetLength(Loaded,PluginLen + 1); + Writeln(Format('Loading plugin %s at %s',[PluginName,PluginDirs.Strings[ii]])); + Loaded[PluginLen].filename:= PluginDirs.Strings[ii] + Pluginname + PlugExt; + Loaded[PluginLen].handle:= LoadLibrary(PChar(@Loaded[PluginLen].filename)); + if Loaded[PluginLen].handle = 0 then + Raise Exception.CreateFMT('Error loading plugin %s',[Loaded[PluginLen].filename]); + if InitPlugin(Loaded[PluginLen].handle) then + inc(PluginLen) + else + FreeLibrary(Loaded[PluginLen].handle); + Result := PluginLen; + end; + + + constructor TGenericLoader.Create; + begin + inherited Create; + PluginLen := 0; + PluginDirs := TStringList.Create; + end; + + destructor TGenericLoader.Destroy; + begin + FreePlugins; + PluginDirs.Free; + inherited Destroy; + end; + +end. + diff --git a/trunk/Units/MMLCore/mufasatypes.pas b/trunk/Units/MMLCore/mufasatypes.pas index a12581b..265ec25 100644 --- a/trunk/Units/MMLCore/mufasatypes.pas +++ b/trunk/Units/MMLCore/mufasatypes.pas @@ -29,7 +29,7 @@ interface uses - Classes, SysUtils,plugins; + Classes, SysUtils, LibLoader; const DS = DirectorySeparator; MEOL = {$ifdef MSWINDOWS}#13+{$endif}#10; @@ -115,8 +115,6 @@ type SubPoints: TDTMPointDefArray; end; -var - PluginsGlob : TMPlugins; type VirtualKeyInfo = record Str : string;