2010-06-12 08:29:56 -04:00
|
|
|
{
|
|
|
|
This file is part of the Simba Project
|
|
|
|
Copyright (c) 2009 by Raymond van Venetië and Merlijn Wajer
|
|
|
|
|
|
|
|
Simba 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.
|
|
|
|
|
|
|
|
Simba 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.
|
|
|
|
|
|
|
|
Script Manager for the Simba project.
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:05:39 -05:00
|
|
|
{
|
|
|
|
Raymond`, 11-9-2010 20:26:27:
|
|
|
|
ScriptManager/General/Settings.xml (Lijst van alle geinstaleerde scripts)
|
|
|
|
ScriptManager/General/<Scriptname>/Info.xml (Informatie over het script)
|
|
|
|
ScriptManager/<ScriptName>/<Files> (Alle files die het script nodig heeft)
|
|
|
|
}
|
2010-06-06 07:05:15 -04:00
|
|
|
unit scriptmanager;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2010-09-12 08:27:42 -04:00
|
|
|
{$IFDEF UNIX}cthreads,cmem,{$ENDIF} Classes, SysUtils, FileUtil, Forms,
|
|
|
|
Controls, Graphics, Dialogs, StdCtrls,
|
|
|
|
ExtCtrls, ComCtrls, ActnList, Menus, settings, updater,strutils, MufasaTypes,
|
|
|
|
dom;
|
2010-06-06 07:05:15 -04:00
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TForm1 }
|
|
|
|
|
|
|
|
TForm1 = class(TForm)
|
2010-07-20 14:26:49 -04:00
|
|
|
Button1: TButton;
|
|
|
|
SearchIn: TComboBox;
|
|
|
|
Edit1: TEdit;
|
2010-06-06 07:05:15 -04:00
|
|
|
ImageList1: TImageList;
|
2010-07-20 14:26:49 -04:00
|
|
|
Label1: TLabel;
|
|
|
|
Label2: TLabel;
|
2010-06-06 07:05:15 -04:00
|
|
|
ListView1: TListView;
|
2010-06-12 18:07:35 -04:00
|
|
|
Memo1: TMemo;
|
|
|
|
MenuItem1: TMenuItem;
|
|
|
|
MenuItem2: TMenuItem;
|
|
|
|
ScriptPopup: TPopupMenu;
|
2010-06-06 07:05:15 -04:00
|
|
|
TreeView1: TTreeView;
|
2010-09-11 17:24:53 -04:00
|
|
|
procedure Button1Click(Sender: TObject);
|
2010-06-12 18:07:35 -04:00
|
|
|
procedure ClickItem(Sender: TObject; Button: TMouseButton;
|
|
|
|
Shift: TShiftState; X, Y: Integer);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
2010-06-06 07:05:15 -04:00
|
|
|
private
|
|
|
|
{ private declarations }
|
|
|
|
public
|
|
|
|
{ public declarations }
|
2010-06-07 18:15:20 -04:00
|
|
|
end;
|
|
|
|
|
2010-09-11 17:24:53 -04:00
|
|
|
{ TSimbaScript }
|
2010-06-07 18:15:20 -04:00
|
|
|
|
2010-09-11 17:24:53 -04:00
|
|
|
TSimbaScript = class(TObject)
|
|
|
|
private
|
|
|
|
procedure LoadFromNode( Script : TDOMNode);
|
2010-06-07 18:15:20 -04:00
|
|
|
public
|
|
|
|
Name, Version, Author, Description: String;
|
2010-09-11 17:24:53 -04:00
|
|
|
Tags, Files: TStringList;
|
|
|
|
procedure Dbg;
|
|
|
|
constructor Create;
|
|
|
|
destructor Destroy; override;
|
|
|
|
end;
|
2010-06-07 18:15:20 -04:00
|
|
|
|
2010-09-11 17:24:53 -04:00
|
|
|
{ TLSimbaScript }
|
2010-06-07 18:15:20 -04:00
|
|
|
|
2010-09-11 17:24:53 -04:00
|
|
|
TLSimbaScript = class(TSimbaScript) //Installed Script (Local Simba Script)
|
2010-06-07 18:15:20 -04:00
|
|
|
public
|
2010-11-10 14:05:39 -05:00
|
|
|
AutoCheckUpdates : boolean;
|
|
|
|
OnlineScript : TSimbaScript;
|
2010-09-11 17:24:53 -04:00
|
|
|
procedure LoadFromFile(const filename : string);
|
2010-11-10 14:05:39 -05:00
|
|
|
function LoadFromName(const ScriptName,maindir : string) : boolean; //Maindir = maindir of ScriptManager
|
2010-09-11 17:24:53 -04:00
|
|
|
procedure SaveToFile(const FileName : string);
|
|
|
|
procedure Save(const MainDir : string); //MainDir = maindir of ScriptManager
|
2010-11-10 14:05:39 -05:00
|
|
|
constructor create;
|
2010-09-11 17:24:53 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
{ TScriptManager }
|
|
|
|
|
|
|
|
TScriptManager = class (TObject)
|
|
|
|
private
|
2010-11-10 14:05:39 -05:00
|
|
|
FMaindir: string;
|
2010-09-11 17:24:53 -04:00
|
|
|
FScripts : TList; //Array of the online scripts
|
|
|
|
FLScripts: TList; //Array of the local scripts
|
|
|
|
FVersion : String;
|
|
|
|
FUpdating : boolean;
|
|
|
|
function GetLScriptCount: integer;
|
2010-11-10 14:05:39 -05:00
|
|
|
function GetMainDir: string;
|
2010-09-11 17:24:53 -04:00
|
|
|
function GetScriptCount: integer;
|
|
|
|
public
|
2010-11-10 14:05:39 -05:00
|
|
|
property MainDir : string read GetMainDir write FMaindir;
|
|
|
|
procedure Update; //Gets the online scripts
|
2010-09-11 17:24:53 -04:00
|
|
|
procedure LUpdate; //Loads the local scripts, uses MainDir
|
2010-11-10 14:05:39 -05:00
|
|
|
function NewVersion(Script : integer) : boolean; //Checks for updates for Script
|
|
|
|
procedure InstallNewScript(Script : integer); //Installs Script (Online -> Local)
|
|
|
|
procedure UpdateScript(Script : integer); //Updates all the info/files of local script
|
2010-09-11 17:24:53 -04:00
|
|
|
procedure LSave; //Saves the local scripts, uses MainDir
|
|
|
|
property LScriptCount : integer read GetLScriptCount; //LScript = Local Script = Installed Script
|
|
|
|
property ScriptCount : integer read GetScriptCount; //Online script
|
|
|
|
property Version : string read FVersion;
|
2010-06-12 08:29:56 -04:00
|
|
|
constructor Create;
|
2010-09-11 17:24:53 -04:00
|
|
|
destructor Destroy; override;
|
2010-06-07 18:15:20 -04:00
|
|
|
end;
|
2010-06-06 07:05:15 -04:00
|
|
|
|
2010-09-11 17:24:53 -04:00
|
|
|
|
|
|
|
|
2010-06-06 07:05:15 -04:00
|
|
|
var
|
|
|
|
Form1: TForm1;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2010-09-11 17:24:53 -04:00
|
|
|
uses
|
|
|
|
XMLRead,XMLWrite;
|
2010-06-06 07:05:15 -04:00
|
|
|
{$R *.lfm}
|
|
|
|
|
|
|
|
{ TForm1 }
|
2010-06-07 18:15:20 -04:00
|
|
|
procedure fill(s: TMMLSettings);
|
|
|
|
var
|
|
|
|
i:integer;
|
|
|
|
ss: TSimbaScript;
|
2010-06-12 08:29:56 -04:00
|
|
|
LI: TListItem;
|
|
|
|
strarr: TStringArray;
|
2010-07-20 14:26:49 -04:00
|
|
|
b: TButton;
|
|
|
|
|
2010-06-07 18:15:20 -04:00
|
|
|
begin
|
2010-06-12 08:29:56 -04:00
|
|
|
if not s.ListKeys('Scripts/ScriptList', strarr) then
|
|
|
|
writeln('ListKeys returned false');
|
|
|
|
writeln('strarr length: ' + inttostr(length(strarr)));
|
|
|
|
for i := 0 to high(strarr) do
|
2010-06-07 18:15:20 -04:00
|
|
|
begin
|
2010-06-12 08:29:56 -04:00
|
|
|
writeln(s.GetKeyValue('Scripts/ScriptList/Script/Name'));
|
|
|
|
ss := TSimbaScript.Create();
|
|
|
|
ss.Name := s.GetKeyValue('Scripts/ScriptList/Script/Name');
|
2010-06-12 18:07:35 -04:00
|
|
|
ss.Author:= s.GetKeyValue('Scripts/ScriptList/Script/Author');
|
|
|
|
ss.Description:= s.GetKeyValue('Scripts/ScriptList/Script/Description');
|
2010-06-12 08:29:56 -04:00
|
|
|
LI := Form1.ListView1.Items.Add;
|
|
|
|
LI.Caption := ss.Name;
|
|
|
|
LI.Data := ss;
|
|
|
|
LI.ImageIndex:= 0;
|
|
|
|
|
|
|
|
s.DeleteKey('Scripts/ScriptList/Script');
|
2010-06-07 18:15:20 -04:00
|
|
|
end;
|
|
|
|
end;
|
2010-06-06 07:05:15 -04:00
|
|
|
|
2010-06-12 18:07:35 -04:00
|
|
|
procedure TForm1.FormCreate(Sender: TObject);
|
2010-06-07 18:15:20 -04:00
|
|
|
var
|
|
|
|
s: TMMLSettings;
|
|
|
|
begin
|
2010-09-11 17:24:53 -04:00
|
|
|
{ s := TMMLSettings.Create(TreeView1.Items);
|
2010-06-07 18:15:20 -04:00
|
|
|
s.LoadFromXML('/scratch/gittest/list.xml');
|
|
|
|
fill(s);
|
2010-09-11 17:24:53 -04:00
|
|
|
s.Free();}
|
2010-06-12 18:07:35 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TForm1.ClickItem(Sender: TObject; Button: TMouseButton;
|
|
|
|
Shift: TShiftState; X, Y: Integer);
|
|
|
|
var
|
|
|
|
item: TListItem;
|
|
|
|
begin
|
|
|
|
item := Form1.ListView1.GetItemAt(x, y);
|
|
|
|
if item = nil then
|
|
|
|
exit;
|
|
|
|
if item.data = nil then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
{ Any selection causes the description to change }
|
|
|
|
form1.Memo1.Lines.Clear();
|
|
|
|
form1.Memo1.Lines.Append(TSimbaScript(item.data).Description);
|
|
|
|
|
|
|
|
if Button = mbLeft then
|
|
|
|
begin
|
|
|
|
|
|
|
|
end else if Button = mbRight then
|
|
|
|
begin
|
|
|
|
{ Popup Actions }
|
|
|
|
Form1.ScriptPopup.Items[0].Caption:= 'Install ' + TSimbaScript(item.data).Name;
|
|
|
|
Form1.ScriptPopup.PopUp();
|
|
|
|
end;
|
|
|
|
//form1.Memo1.Text := TSimbaScript(item.data).Description;
|
2010-06-07 18:15:20 -04:00
|
|
|
end;
|
|
|
|
|
2010-09-11 17:24:53 -04:00
|
|
|
procedure TForm1.Button1Click(Sender: TObject);
|
|
|
|
var
|
|
|
|
Mngr : TScriptManager;
|
|
|
|
begin
|
|
|
|
Mngr := TScriptManager.Create;
|
|
|
|
Mngr.Update;
|
|
|
|
Mngr.free;
|
|
|
|
end;
|
|
|
|
|
2010-06-07 18:15:20 -04:00
|
|
|
{ TSimbaScript }
|
|
|
|
|
2010-09-11 17:24:53 -04:00
|
|
|
procedure TSimbaScript.LoadFromNode(Script: TDOMNode);
|
|
|
|
function NodeContents(ItemStr : string; node : TDOMNode) : string;
|
|
|
|
var
|
|
|
|
tmpNode : TDOMNode;
|
|
|
|
begin
|
|
|
|
result := '';
|
|
|
|
if node = nil then
|
|
|
|
exit;
|
|
|
|
tmpNode := node.FindNode(itemstr);
|
|
|
|
if tmpNode <> nil then
|
|
|
|
result := Trim(tmpNode.TextContent);
|
|
|
|
end;
|
|
|
|
function NodeSubContents(ItemStr : string; node : TDOMNode) : TStringList;
|
|
|
|
var
|
|
|
|
tmpNode : TDOMNode;
|
|
|
|
begin
|
|
|
|
Result := TStringList.Create;
|
|
|
|
if node = nil then
|
|
|
|
exit;
|
|
|
|
tmpNode := node.FindNode(itemstr);
|
|
|
|
if tmpNode <> nil then
|
|
|
|
begin
|
|
|
|
tmpNode := tmpNode.FirstChild;
|
|
|
|
while tmpNode <> nil do
|
|
|
|
begin
|
|
|
|
Result.add(trim(tmpNode.TextContent));
|
|
|
|
tmpNode := tmpNode.NextSibling;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
begin
|
|
|
|
Author:= NodeContents('Author',script);
|
|
|
|
Name := NodeContents('Name',script);
|
|
|
|
Version := NodeContents('Version',script);
|
|
|
|
Description:= NodeContents('Description',script);
|
|
|
|
Tags := NodeSubContents('Tags',script);
|
|
|
|
Files := NodeSubContents('Files',script);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TSimbaScript.Dbg;
|
|
|
|
var
|
|
|
|
i : integer;
|
|
|
|
begin
|
|
|
|
Writeln(Name);
|
|
|
|
Writeln(' Author: ' + Author);
|
|
|
|
Writeln(' Version: ' + Version);
|
|
|
|
Writeln(' Description: ' + Description);
|
|
|
|
Writeln(' Tags:');
|
|
|
|
for i := 0 to Tags.Count - 1 do
|
|
|
|
Writeln(' ' + Tags[i]);
|
|
|
|
Writeln(' Files:');
|
|
|
|
for i := 0 to Files.Count - 1 do
|
|
|
|
Writeln(' ' + Files[i]);
|
|
|
|
end;
|
|
|
|
|
2010-06-12 08:29:56 -04:00
|
|
|
constructor TSimbaScript.Create;
|
2010-06-06 07:05:15 -04:00
|
|
|
begin
|
2010-06-12 08:29:56 -04:00
|
|
|
inherited;
|
2010-06-07 18:15:20 -04:00
|
|
|
|
2010-06-12 08:29:56 -04:00
|
|
|
{stuff here}
|
2010-06-07 18:15:20 -04:00
|
|
|
end;
|
|
|
|
|
2010-09-11 17:24:53 -04:00
|
|
|
destructor TSimbaScript.Destroy;
|
2010-06-07 18:15:20 -04:00
|
|
|
begin
|
2010-09-11 17:24:53 -04:00
|
|
|
if Files <> nil then
|
|
|
|
FreeAndNil(Files);
|
|
|
|
if Tags <> nil then
|
|
|
|
FreeAndNil(Tags);
|
2010-06-12 08:29:56 -04:00
|
|
|
{stuff here}
|
|
|
|
|
|
|
|
inherited;
|
2010-06-06 07:05:15 -04:00
|
|
|
end;
|
|
|
|
|
2010-09-11 17:24:53 -04:00
|
|
|
{ TScriptManager }
|
|
|
|
|
|
|
|
function TScriptManager.GetLScriptCount: integer;
|
|
|
|
begin
|
|
|
|
result := FLScripts.Count;
|
|
|
|
end;
|
|
|
|
|
2010-11-10 14:05:39 -05:00
|
|
|
function TScriptManager.GetMainDir: string;
|
|
|
|
begin
|
|
|
|
result := IncludeTrailingPathDelimiter(FMainDir);
|
|
|
|
end;
|
|
|
|
|
2010-09-11 17:24:53 -04:00
|
|
|
function TScriptManager.GetScriptCount: integer;
|
|
|
|
begin
|
|
|
|
result := FScripts.Count;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TScriptManager.Update;
|
|
|
|
var
|
|
|
|
XMLFile : string;
|
|
|
|
Stream : TStringStream;
|
|
|
|
XMLDoc : TXMLDocument;
|
|
|
|
Node,Script : TDOMNode;
|
|
|
|
Subs : TStringList;
|
|
|
|
Down : TDownloadThread;
|
2010-11-10 14:05:39 -05:00
|
|
|
SimbaScript : TSimbaScript;
|
2010-09-11 17:24:53 -04:00
|
|
|
begin
|
|
|
|
if FUpdating then
|
|
|
|
exit;
|
|
|
|
FUpdating := True;
|
|
|
|
Down := TDownloadThread.Create('http://old.villavu.com/sm',@XMLFile);
|
|
|
|
down.Execute;
|
|
|
|
while down.Done = false do
|
|
|
|
begin
|
|
|
|
Application.ProcessMessages;
|
|
|
|
Sleep(25);
|
|
|
|
end;
|
|
|
|
Stream := TStringStream.Create(XMLFile);
|
|
|
|
ReadXMLFile(XMLDoc,Stream);
|
|
|
|
Stream.Free;
|
|
|
|
Node := XMLDoc.FirstChild.FindNode('Version');
|
|
|
|
if node <> nil then
|
|
|
|
FVersion:= Node.TextContent;
|
|
|
|
Node := XMLDoc.FirstChild.FindNode('ScriptList');
|
|
|
|
if node <> nil then
|
|
|
|
begin
|
|
|
|
script := Node.FirstChild;
|
|
|
|
while Script <> nil do
|
|
|
|
begin
|
2010-11-10 14:05:39 -05:00
|
|
|
SimbaScript := TSimbaScript.Create;
|
2010-09-11 17:24:53 -04:00
|
|
|
SimbaScript.LoadFromNode(Script);
|
2010-11-10 14:05:39 -05:00
|
|
|
FScripts.Add(SimbaScript);
|
2010-09-11 17:24:53 -04:00
|
|
|
SimbaScript.Dbg;
|
|
|
|
Script := Script.NextSibling;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
XMLDoc.Free;
|
|
|
|
FUpdating := false;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TScriptManager.LUpdate;
|
2010-11-10 14:05:39 -05:00
|
|
|
var
|
|
|
|
XMLDoc : TXMLDocument;
|
|
|
|
Node,Script : TDOMNode;
|
|
|
|
Subs : TStringList;
|
|
|
|
Down : TDownloadThread;
|
|
|
|
SimbaScript : TLSimbaScript;
|
2010-09-11 17:24:53 -04:00
|
|
|
begin
|
|
|
|
if DirectoryExists(MainDir) = false then
|
|
|
|
exit;
|
2010-11-10 14:05:39 -05:00
|
|
|
if FileExists(maindir + 'General' + DirectorySeparator+ 'scripts.xml') then
|
2010-09-11 17:24:53 -04:00
|
|
|
begin
|
2010-11-10 14:05:39 -05:00
|
|
|
ReadXMLFile(XMLDoc,maindir + 'General' + DirectorySeparator+ 'scripts.xml');
|
|
|
|
Node := XMLDoc.FirstChild.FindNode('Scripts');
|
|
|
|
if node <> nil then
|
|
|
|
begin
|
|
|
|
script := Node.FirstChild;
|
|
|
|
while Script <> nil do
|
|
|
|
begin
|
|
|
|
SimbaScript := TLSimbaScript.Create;
|
|
|
|
SimbaScript.LoadFromName(Node.TextContent,maindir);
|
|
|
|
FLScripts.Add(SimbaScript);
|
|
|
|
SimbaScript.Dbg;
|
|
|
|
Script := Script.NextSibling;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
XMLDoc.Free;
|
|
|
|
end;
|
|
|
|
end;
|
2010-09-11 17:24:53 -04:00
|
|
|
|
2010-11-10 14:05:39 -05:00
|
|
|
function TScriptManager.NewVersion(Script: integer): boolean;
|
|
|
|
var
|
|
|
|
Scrpt : TLSimbaScript;
|
|
|
|
I : integer;
|
|
|
|
begin
|
|
|
|
Scrpt := TLSimbaScript(FLScripts[Script]);
|
|
|
|
if Scrpt.OnlineScript = nil then
|
|
|
|
for i := 0 to ScriptCount-1 do
|
|
|
|
if TSimbaScript(FScripts[i]).Name = Scrpt.Name then
|
|
|
|
begin
|
|
|
|
Scrpt.OnlineScript = TSimbaScript(FScripts[i]);
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
result := Scrpt.OnlineScript.Version <> Scrpt.Version;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TScriptManager.InstallNewScript(Script: integer);
|
|
|
|
var
|
|
|
|
Scrpt : TSimbaScript;
|
|
|
|
LScrpt: TLSimbaScript;
|
|
|
|
Dir : string;
|
|
|
|
begin
|
|
|
|
Scrpt := TSimbaScript(FScripts[Script]);
|
|
|
|
LScrpt := TLSimbaScript.create;
|
|
|
|
FLScripts.Add(LScrpt);
|
|
|
|
LScrpt.Name:= Scrpt.Name;
|
|
|
|
LScrpt.OnlineScript := Scrpt;
|
|
|
|
Dir := MainDir + LScrpt.Name + DirectorySeparator;
|
|
|
|
if DirectoryExists(dir) then
|
|
|
|
Writeln('Directory already exists, yet continue?');
|
|
|
|
if not CreateDir(Dir) then
|
|
|
|
Writeln('Failed to create dir..');
|
|
|
|
UpdateScript(FLScripts.Count - 1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TScriptManager.UpdateScript(Script: integer);
|
|
|
|
var
|
|
|
|
LScript : TLSimbaScript;
|
|
|
|
Scrpt : TSimbaScript;
|
|
|
|
begin
|
|
|
|
LScript := TLSimbaScript(FLScripts[Script]);
|
|
|
|
if not NewVersion(Script) then
|
|
|
|
Exit;
|
|
|
|
Scrpt := LScript.OnlineScript;
|
|
|
|
with LScrpt do
|
|
|
|
begin
|
|
|
|
Version:= Scrpt.Version;
|
|
|
|
Name:= Scrpt.Name;
|
|
|
|
Author := Scrpt.Author;
|
|
|
|
Description:= Scrpt.Version;
|
|
|
|
Tags.Assign(Scrpt.Tags);
|
|
|
|
Files.Assign(Scrpt.Files);
|
2010-09-11 17:24:53 -04:00
|
|
|
end;
|
2010-11-10 14:05:39 -05:00
|
|
|
LScrpt.Save(MainDir); //Saves the setting file, now we only need to update the files
|
|
|
|
//Download files & write to folder
|
2010-09-11 17:24:53 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TScriptManager.LSave;
|
|
|
|
var
|
|
|
|
XMLDoc : TXMLDocument;
|
|
|
|
procedure AddTextElement(root : TDOMNode; Element : string; Text : string);
|
|
|
|
var
|
|
|
|
node : TDOMNode;
|
|
|
|
begin
|
|
|
|
Node := XMLDoc.createElement(Element);
|
|
|
|
root.AppendChild(node);
|
|
|
|
node.TextContent:= Text;
|
|
|
|
end;
|
|
|
|
var
|
|
|
|
Node : TDOMNode;
|
|
|
|
i : integer;
|
|
|
|
begin
|
|
|
|
if DirectoryExists(MainDir) = false then
|
|
|
|
exit;
|
|
|
|
XMLDoc := TXMLDocument.Create;
|
|
|
|
Node := XMLDoc.CreateElement('Scripts');
|
|
|
|
XMLDoc.AppendChild(node);
|
|
|
|
for i := 0 to FLScripts.Count - 1 do
|
|
|
|
AddTextElement(node,'Script', TLSimbaScript(FLScripts[i]).Name);
|
2010-11-10 14:05:39 -05:00
|
|
|
WriteXMLFile(XMLDoc,maindir + 'General' + DirectorySeparator+ 'scripts.xml');
|
2010-09-11 17:24:53 -04:00
|
|
|
XMLDoc.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TScriptManager.Create;
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
FLScripts := TList.Create;
|
|
|
|
FScripts := TList.Create;
|
|
|
|
FVersion := '';
|
|
|
|
FUpdating:= False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TScriptManager.Destroy;
|
|
|
|
begin
|
|
|
|
while FScripts.Count > 0 do
|
|
|
|
begin
|
|
|
|
TSimbaScript(FScripts[0]).Free;
|
|
|
|
FScripts.Delete(0);
|
|
|
|
end;
|
|
|
|
while FLScripts.Count > 0 do
|
|
|
|
begin
|
|
|
|
TLSimbaScript(FLScripts[0]).Free;
|
|
|
|
FLScripts.Delete(0);
|
|
|
|
end;
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TLSimbaScript }
|
|
|
|
|
|
|
|
procedure TLSimbaScript.LoadFromFile(const filename: string);
|
|
|
|
var
|
|
|
|
XMLDoc : TXMLDocument;
|
|
|
|
begin
|
|
|
|
ReadXMLFile(XMLDoc,filename);
|
|
|
|
Self.LoadFromNode(XMLDoc.FirstChild);
|
2010-11-10 14:05:39 -05:00
|
|
|
XMLDoc.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TLSimbaScript.LoadFromName(const ScriptName,MainDir : string) : boolean;
|
|
|
|
begin
|
|
|
|
Result := false;
|
|
|
|
if FileExists(MainDir + 'General' + DirectorySeparator + ScriptName +
|
|
|
|
'info.xml') then
|
|
|
|
begin
|
|
|
|
Result := true;
|
|
|
|
LoadFromFile(MainDir + 'General' + DirectorySeparator + ScriptName +
|
|
|
|
'info.xml');
|
|
|
|
|
|
|
|
end;
|
2010-09-11 17:24:53 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TLSimbaScript.SaveToFile(const FileName: string);
|
|
|
|
|
|
|
|
var
|
|
|
|
XMLDoc : TXMLDocument;
|
|
|
|
procedure AddTextElement(root : TDOMNode; Element : string; Text : string);
|
|
|
|
var
|
|
|
|
node : TDOMNode;
|
|
|
|
begin
|
|
|
|
Node := XMLDoc.createElement(Element);
|
|
|
|
root.AppendChild(node);
|
|
|
|
node.TextContent:= Text;
|
|
|
|
end;
|
|
|
|
var
|
|
|
|
Node,SubNode : TDOMNode;
|
|
|
|
i : integer;
|
|
|
|
begin
|
|
|
|
XMLDoc := TXMLDocument.Create;
|
|
|
|
Node := XMLDoc.CreateElement('Script');
|
|
|
|
XMLDoc.AppendChild(Node);
|
|
|
|
AddTextElement(node,'Name',Name);
|
|
|
|
AddTextElement(node,'Author',Author);
|
|
|
|
AddTextElement(node,'Version',Version);
|
|
|
|
AddTextElement(node,'Description',description);
|
2010-11-10 14:05:39 -05:00
|
|
|
AddTextElement(node,'AutoCheckUpdates', BoolToStr(AutoCheckUpdates,true));
|
2010-09-11 17:24:53 -04:00
|
|
|
SubNode := XMLDoc.CreateElement('Tags');
|
|
|
|
Node.AppendChild(SubNode);
|
|
|
|
for i := 0 to Tags.Count - 1 do
|
|
|
|
AddTextElement(SubNode,'Tag',Tags[i]);
|
|
|
|
SubNode := XMLDoc.CreateElement('Files');
|
|
|
|
Node.AppendChild(SubNode);
|
|
|
|
for i := 0 to Files.Count - 1 do
|
|
|
|
AddTextElement(SubNode,'File',Files[i]);
|
|
|
|
WriteXMLFile(XMLDoc,FileName);
|
|
|
|
XMLDoc.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TLSimbaScript.Save(const MainDir: string);
|
|
|
|
begin
|
2010-11-10 14:05:39 -05:00
|
|
|
if not DirectoryExists(MainDir + 'General' + DirectorySeparator + Name) then
|
|
|
|
CreateDir(MainDir + 'General' + DirectorySeparator + Name);
|
|
|
|
SaveToFile(MainDir + 'General' + DirectorySeparator + Name + DirectorySeparator +
|
|
|
|
'info.xml');
|
|
|
|
end;
|
2010-09-11 17:24:53 -04:00
|
|
|
|
2010-11-10 14:05:39 -05:00
|
|
|
constructor TLSimbaScript.create;
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
AutoCheckUpdates:= true;
|
2010-09-11 17:24:53 -04:00
|
|
|
end;
|
|
|
|
|
2010-06-06 07:05:15 -04:00
|
|
|
end.
|
|
|
|
|