1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-12-22 15:28:50 -05:00

Kinda completed the backend of ScriptManager, left is GUI and some small adjustments!

This commit is contained in:
Raymond 2010-12-26 14:50:04 +01:00
parent e6ee7f378c
commit 48a43fa897
3 changed files with 54 additions and 13 deletions

View File

@ -12,10 +12,10 @@ object Form1: TForm1
object Button1: TButton
Left = 16
Height = 33
Top = 365
Top = 384
Width = 680
Anchors = [akLeft, akBottom]
Caption = 'Button1'
Caption = 'Refresh'
OnClick = Button1Click
TabOrder = 0
end
@ -52,4 +52,13 @@ object Form1: TForm1
TabOrder = 2
OnChange = ListView1Change
end
object Button2: TButton
Left = 21
Height = 38
Top = 338
Width = 672
Caption = 'Install'
OnClick = Button2Click
TabOrder = 3
end
end

View File

@ -37,7 +37,7 @@ uses
{$IFDEF UNIX}cthreads,cmem,{$ENDIF} Classes, SysUtils, FileUtil, Forms,
Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, ComCtrls, ActnList, Menus, settings, updater,strutils, MufasaTypes,
dom;
dom, mmisc;
type
@ -48,7 +48,7 @@ type
function IsInstalled: boolean;
procedure LoadFromNode( Script : TDOMNode);
public
Name, Version, Author, Description: String;
Name, Version, Author, Description, URL: String;
Tags, Files: TStringList;
LocalScript : TSimbaScript;
property Installed : boolean read IsInstalled;
@ -79,21 +79,21 @@ type
FLScripts: TList; //Array of the local scripts
FVersion : String;
FUpdating : boolean;
function FindScriptByName(name : string) : Integer;
function FindLScriptByName(name : string) : Integer;
function GetLScriptCount: integer;
function GetMainDir: string;
function GetScript(index : integer): TSimbaScript;
function GetScriptCount: integer;
procedure MatchLocalOnline;
public
function FindScriptByName(name : string) : Integer;
function FindLScriptByName(name : string) : Integer;
property MainDir : string read GetMainDir write FMaindir;
property SimbaScript[index : integer] : TSimbaScript read GetScript;
procedure Update; //Gets the online scripts
procedure LUpdate; //Loads the local scripts, uses MainDir
function NewVersion(Script : integer) : boolean; //Checks for updates for Script
procedure InstallNewScript(Script : integer); //Installs Script (Online -> Local)
procedure UpdateScript(Script : integer; ignoreupdating : boolean = false); //Updates all the info/files of local script
function UpdateScript(Script : integer; ignoreupdating : boolean = false) : boolean; //Updates all the info/files of local script
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
@ -106,10 +106,12 @@ type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
GroupBox1: TGroupBox;
ListView1: TListView;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ClickItem(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
@ -190,6 +192,7 @@ var
Item : TListItem;
begin
Mng.Update;
ListView1.Items.Clear;
for i := 0 to Mng.ScriptCount - 1 do
begin
Item := ListView1.Items.Add;
@ -198,6 +201,17 @@ begin
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Script : TSimbaScript;
begin
if (ListView1.Selected <> nil) and (ListView1.Selected.Data <> nil) then
begin
Script := TSimbaScript(ListView1.Selected.Data);
Mng.InstallNewScript(mng.FindScriptByName(Script.Name));
end;
end;
{ TSimbaScript }
function TSimbaScript.IsInstalled: boolean;
@ -242,6 +256,7 @@ begin
Description:= NodeContents('Description',script);
Tags := NodeSubContents('Tags',script);
Files := NodeSubContents('Files',script);
URL := 'http://old.villavu.com/sm/scripts/'+Name+'.tar.bz2';
end;
procedure TSimbaScript.Dbg;
@ -459,12 +474,13 @@ begin
UpdateScript(FLScripts.Count - 1,true);
end;
procedure TScriptManager.UpdateScript(Script: integer; ignoreupdating : boolean = false);
function TScriptManager.UpdateScript(Script: integer; ignoreupdating : boolean = false) : boolean;
var
LScrpt : TLSimbaScript;
Scrpt : TSimbaScript;
DownloadThread : TDownloadThread;
DownloadThread : TDownloadDecompressThread;
begin
Result := true;
if not NewVersion(Script) then
Exit;
if FUpdating and not ignoreupdating then
@ -480,10 +496,19 @@ begin
Description:= Scrpt.Version;
Tags.Assign(Scrpt.Tags);
Files.Assign(Scrpt.Files);
URL := 'http://old.villavu.com/sm/scripts/'+name+ '.tar.bz2';
end;
LScrpt.Save(MainDir); //Saves the setting file, now we only need to update the files
//Download files & write to folder
DownloadThread := TDownloadDecompressThread.Create(LScrpt.URL,MainDir + LScrpt.Name + DS,true);
DownloadThread.execute;
while DownloadThread.Done = false do
begin
Application.ProcessMessages;
Sleep(25);
end;
Result := DownloadThread.Succeeded;
DownloadThread.Free;
LSave; //Update the scripts XML file
FUPdating := false;
end;
@ -520,6 +545,8 @@ begin
FScripts := TList.Create;
FVersion := '';
FUpdating:= False;
FMainDir:= ExtractFileDir(Application.ExeName);
CreateDir(MainDir + 'General');
end;
destructor TScriptManager.Destroy;
@ -607,6 +634,8 @@ end;
constructor TLSimbaScript.create;
begin
inherited;
Tags := TStringList.Create; //Might leak, but careface
Files := TStringList.create; //Same ^
AutoCheckUpdates:= true;
end;

View File

@ -18,6 +18,9 @@
<CharSet Value="04B0"/>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
@ -307,8 +310,8 @@
<Filename Value="../../Simba"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)/;$(ProjPath)../../Units/MMLAddon/PSInc/"/>
<OtherUnitFiles Value="$(ProjPath)/;$(ProjPath)../../Units/MMLCore/;$(ProjPath)../../Units/MMLAddon/;$(ProjPath)../../Units/PascalScript/;$(ProjPath)../../Units/Misc/;$(ProjPath)../../Units/MMLAddon/PSInc/;$(ProjPath)../../Units/Linux/;$(ProjPath)../../Units/Synapse/;$(LazarusDir)/components/mouseandkeyinput/;$(ProjPath)../../Units/RUTIS/"/>
<IncludeFiles Value="$(ProjOutDir);$(ProjPath)../../Units/MMLAddon/PSInc"/>
<OtherUnitFiles Value="$(ProjPath);$(ProjPath)../../Units/MMLCore;$(ProjPath)../../Units/MMLAddon;$(ProjPath)../../Units/PascalScript;$(ProjPath)../../Units/Misc;$(ProjPath)../../Units/MMLAddon/PSInc;$(ProjPath)../../Units/Linux;$(ProjPath)../../Units/Synapse;$(LazarusDir)/components/mouseandkeyinput;$(ProjPath)../../Units/RUTIS"/>
<UnitOutputDirectory Value="$(ProjPath)../../build/$(TargetOS)"/>
</SearchPaths>
<Parsing>