mirror of
https://github.com/moparisthebest/Simba
synced 2025-02-07 02:30:19 -05:00
Added SRL-update extension. Made a decompress/untar thread, so that this is no long thread-blocking :).
This commit is contained in:
parent
f1587b0209
commit
9c21ec3ae9
@ -135,6 +135,7 @@ begin
|
|||||||
Sender.AddFunction(@ext_UnTarEx,'function UnTarEx(const Input : string;const outputdir : string; overwrite : boolean): boolean;');
|
Sender.AddFunction(@ext_UnTarEx,'function UnTarEx(const Input : string;const outputdir : string; overwrite : boolean): boolean;');
|
||||||
Sender.AddFunction(@DirectoryExists,'Function DirectoryExists (Const Directory : String) : Boolean;');
|
Sender.AddFunction(@DirectoryExists,'Function DirectoryExists (Const Directory : String) : Boolean;');
|
||||||
Sender.AddFunction(@FileExists,'Function FileExists (Const FileName : String) : Boolean;');
|
Sender.AddFunction(@FileExists,'Function FileExists (Const FileName : String) : Boolean;');
|
||||||
|
Sender.AddFunction(@ForceDirectories,'function ForceDirectories(Const Dir: string): Boolean;');
|
||||||
Sender.AddFunction(@GetFiles, 'function GetFiles(Path, Ext: string): TStringArray;');
|
Sender.AddFunction(@GetFiles, 'function GetFiles(Path, Ext: string): TStringArray;');
|
||||||
Sender.AddFunction(@GetDirectories,'function GetDirectories(Path: string): TstringArray;');
|
Sender.AddFunction(@GetDirectories,'function GetDirectories(Path: string): TstringArray;');
|
||||||
Sender.AddFunction(@ext_MessageDlg,'function MessageDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;');
|
Sender.AddFunction(@ext_MessageDlg,'function MessageDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;');
|
||||||
|
@ -1098,7 +1098,6 @@ end;
|
|||||||
procedure TForm1.CreateDefaultEnvironment;
|
procedure TForm1.CreateDefaultEnvironment;
|
||||||
var
|
var
|
||||||
PluginsPath,extensionsPath : string;
|
PluginsPath,extensionsPath : string;
|
||||||
FontUpdater : TProcThread;
|
|
||||||
begin
|
begin
|
||||||
CreateSetting('Settings/Updater/CheckForUpdates','True');
|
CreateSetting('Settings/Updater/CheckForUpdates','True');
|
||||||
CreateSetting('Settings/Updater/CheckEveryXMinutes','30');
|
CreateSetting('Settings/Updater/CheckEveryXMinutes','30');
|
||||||
@ -2606,12 +2605,19 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.FontUpdate;
|
procedure TForm1.FontUpdate;
|
||||||
|
procedure Idler;
|
||||||
|
begin
|
||||||
|
Application.ProcessMessages;
|
||||||
|
Sleep(25);
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
CurrVersion : integer;
|
CurrVersion : integer;
|
||||||
LatestVersion : integer;
|
LatestVersion : integer;
|
||||||
FontDownload : TDownloadThread;
|
FontDownload : TDownloadThread;
|
||||||
Stream : TStringStream;
|
Stream : TStringStream;
|
||||||
Decompressed : TMemoryStream;
|
UnTarrer : TUntarThread;
|
||||||
|
Decompress : TDecompressThread;
|
||||||
begin
|
begin
|
||||||
if UpdatingFonts then
|
if UpdatingFonts then
|
||||||
exit;
|
exit;
|
||||||
@ -2625,23 +2631,32 @@ begin
|
|||||||
FontDownload.InputURL:= LoadSettingDef('Settings/Fonts/UpdateLink',FontURL + 'Fonts.tar.bz2');
|
FontDownload.InputURL:= LoadSettingDef('Settings/Fonts/UpdateLink',FontURL + 'Fonts.tar.bz2');
|
||||||
FontDownload.resume;
|
FontDownload.resume;
|
||||||
while FontDownload.Done = false do
|
while FontDownload.Done = false do
|
||||||
begin
|
Idler;
|
||||||
Application.ProcessMessages;
|
|
||||||
Sleep(25);
|
|
||||||
end;
|
|
||||||
Stream := TStringStream.Create(FontDownload.ResultStr);
|
Stream := TStringStream.Create(FontDownload.ResultStr);
|
||||||
try
|
try
|
||||||
Decompressed := DecompressBZip2(stream);
|
Decompress := TDecompressThread.Create(Stream);
|
||||||
if UnTar(decompressed, FontPath,true) then
|
Decompress.Resume;
|
||||||
|
while Decompress.Finished = false do
|
||||||
|
Idler;
|
||||||
|
if Decompress.Result <> nil then
|
||||||
begin;
|
begin;
|
||||||
FormWriteln('Succesfully installed the new fonts!');
|
UnTarrer := TUntarThread.Create(Decompress.Result,FontPath,True);
|
||||||
SetSetting('Settings/Fonts/Version',IntToStr(LatestVersion),true);
|
UnTarrer.Resume;
|
||||||
if Assigned(self.OCR_Fonts) then
|
while UnTarrer.Finished = false do
|
||||||
self.OCR_Fonts.Free;
|
Idler;
|
||||||
Self.OCR_Fonts := TMOCR.Create(nil);
|
if UnTarrer.Result then
|
||||||
OCR_Fonts.InitTOCR(fontPath);
|
begin;
|
||||||
|
FormWriteln('Succesfully installed the new fonts!');
|
||||||
|
SetSetting('Settings/Fonts/Version',IntToStr(LatestVersion),true);
|
||||||
|
if Assigned(self.OCR_Fonts) then
|
||||||
|
self.OCR_Fonts.Free;
|
||||||
|
Self.OCR_Fonts := TMOCR.Create(nil);
|
||||||
|
OCR_Fonts.InitTOCR(fontPath);
|
||||||
|
end;
|
||||||
|
UnTarrer.Free;
|
||||||
|
Decompress.Result.Free;
|
||||||
end;
|
end;
|
||||||
Decompressed.free;
|
Decompress.free;
|
||||||
finally
|
finally
|
||||||
Stream.Free;
|
Stream.Free;
|
||||||
FontDownload.Free;
|
FontDownload.Free;
|
||||||
|
@ -40,35 +40,52 @@ end;
|
|||||||
function ext_UnTarEx(const Input : string;const outputdir : string; overwrite : boolean): boolean;
|
function ext_UnTarEx(const Input : string;const outputdir : string; overwrite : boolean): boolean;
|
||||||
var
|
var
|
||||||
Stream : TStringStream;
|
Stream : TStringStream;
|
||||||
MS : TMemoryStream;
|
Untarrer : TUntarThread;
|
||||||
begin
|
begin
|
||||||
result := false;
|
result := false;
|
||||||
try
|
try
|
||||||
Stream := TStringStream.Create(Input);
|
Stream := TStringStream.Create(Input);
|
||||||
result := UnTar(stream,outputdir,overwrite);
|
Untarrer := TUntarThread.Create(stream,outputdir,overwrite);
|
||||||
|
Untarrer.Resume;
|
||||||
|
while Untarrer.Finished = false do
|
||||||
|
begin
|
||||||
|
Application.ProcessMessages;
|
||||||
|
sleep(25);
|
||||||
|
end;
|
||||||
|
result := Untarrer.Result;
|
||||||
finally
|
finally
|
||||||
|
Untarrer.Free;
|
||||||
stream.free;
|
stream.free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
function ext_DecompressBZip2(const input: string;out output : string; const BlockSize: Cardinal): boolean;
|
function ext_DecompressBZip2(const input: string;out output : string; const BlockSize: Cardinal): boolean;
|
||||||
var
|
var
|
||||||
Stream : TStringStream;
|
Stream : TStringStream;
|
||||||
|
Decompress : TDecompressThread;
|
||||||
MS : TMemoryStream;
|
MS : TMemoryStream;
|
||||||
begin
|
begin
|
||||||
result := false;
|
result := false;
|
||||||
try
|
try
|
||||||
Stream := TStringStream.Create(Input);
|
Stream := TStringStream.Create(Input);
|
||||||
ms := DecompressBZip2(Stream,blocksize);
|
Decompress := TDecompressThread.Create(Stream);
|
||||||
|
Decompress.Resume;
|
||||||
|
while Decompress.Finished = false do
|
||||||
|
begin
|
||||||
|
Application.ProcessMessages;
|
||||||
|
sleep(25);
|
||||||
|
end;
|
||||||
|
ms := Decompress.Result;
|
||||||
if ms.size > 0 then
|
if ms.size > 0 then
|
||||||
begin
|
begin
|
||||||
ms.Position:= 0;
|
ms.Position:= 0;
|
||||||
SetLength(output,ms.Size);
|
SetLength(output,ms.Size);
|
||||||
MS.Read(output[1],MS.size);
|
MS.Read(output[1],MS.size);
|
||||||
ms.free;
|
|
||||||
result := true;
|
result := true;
|
||||||
end;
|
end;
|
||||||
|
ms.free;
|
||||||
finally
|
finally
|
||||||
stream.free;
|
stream.free;
|
||||||
|
Decompress.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -21,6 +21,35 @@ type
|
|||||||
procedure Execute; override;
|
procedure Execute; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TDecompressThread }
|
||||||
|
|
||||||
|
TDecompressThread = class(TThread)
|
||||||
|
private
|
||||||
|
FFinished : boolean;
|
||||||
|
Finput : TStream;
|
||||||
|
FBlockSize : Cardinal;
|
||||||
|
public
|
||||||
|
Result : TMemoryStream;
|
||||||
|
constructor Create(const input : TStream; const BlockSize : Cardinal = 4096);
|
||||||
|
procedure Execute; override;
|
||||||
|
property Finished : boolean read FFinished;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TUntarThread }
|
||||||
|
|
||||||
|
TUntarThread = class(TThread)
|
||||||
|
private
|
||||||
|
FFinished : boolean;
|
||||||
|
Finput : TStream;
|
||||||
|
FOverWrite : boolean;
|
||||||
|
FOutputDir : string;
|
||||||
|
public
|
||||||
|
Result : boolean;
|
||||||
|
constructor Create(const Input : TStream;const outputdir : string; overwrite : boolean);
|
||||||
|
procedure Execute; override;
|
||||||
|
property Finished : boolean read FFinished;
|
||||||
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
function DecompressBZip2(const input: TStream; const BlockSize: Cardinal): TMemoryStream;
|
function DecompressBZip2(const input: TStream; const BlockSize: Cardinal): TMemoryStream;
|
||||||
@ -116,5 +145,44 @@ begin
|
|||||||
ClassProc;
|
ClassProc;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
constructor TDecompressThread.Create(const input: TStream;
|
||||||
|
const BlockSize: Cardinal);
|
||||||
|
begin
|
||||||
|
inherited Create(True);
|
||||||
|
FFinished:= False;
|
||||||
|
FBlockSize:= BlockSize;
|
||||||
|
FInput := Input;
|
||||||
|
Result := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TDecompressThread }
|
||||||
|
|
||||||
|
procedure TDecompressThread.Execute;
|
||||||
|
begin
|
||||||
|
if Finput <> nil then
|
||||||
|
result := DecompressBZip2(Finput,FBlocksize);
|
||||||
|
Ffinished := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TUntarThread }
|
||||||
|
|
||||||
|
constructor TUntarThread.Create(const Input: TStream; const outputdir: string;
|
||||||
|
overwrite: boolean);
|
||||||
|
begin
|
||||||
|
inherited Create(true);
|
||||||
|
FFinished:= false;
|
||||||
|
FInput := Input;
|
||||||
|
FOutputDir:= OutputDir;
|
||||||
|
FOverWrite:= overwrite;
|
||||||
|
Result:= False;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUntarThread.Execute;
|
||||||
|
begin
|
||||||
|
if (Finput <> nil) and (FOutputDir <> '') then
|
||||||
|
result := UnTar(FInput,Foutputdir,FOverWrite);
|
||||||
|
FFinished:= True;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user