* Some cleanup

This commit is contained in:
Michaël Van Canneyt 2024-08-28 22:31:26 +02:00
parent 4dda20fc64
commit 8802cf610b
3 changed files with 32 additions and 26 deletions

View File

@ -19,12 +19,16 @@
<p>
You can use the utility to construct a file tree of the ZenFS filesystem. At the same time, you can
use the helper routines to create a download link and to download the (virtual) files from browser to disk.
You can use the "Reset" button to clear the filesystem and re-populate it.
</p>
</div> <!-- .box -->
<div class="box columns" style="min-height: 400px;">
<div class="column">
<div id="treeFiles" style="min-height: 300px;">
</div>
<div>
<button class="button is-small" id="btnReset">Reset</button>
</div>
<div class="field is-horizontal">
<div class="field-label is-normal">
<label class="label">File</label>

View File

@ -17,10 +17,11 @@ Type
DivDownloads : TJSHTMLElement;
FTreeBuilder : THTMLZenFSTree;
procedure CreateFiles;
procedure DoReset(Event: TJSEvent); async;
procedure DoSelectFile(Sender: TObject; aFileName: String; aType: TFileType);
procedure MaybeCreateFiles;
procedure SetupFS; async;
procedure DoDownload(Event : TJSEvent);
procedure SelectFile(Sender: TObject; aFileName: String; aType : TFileType);
Public
constructor Create(aOwner : TComponent); override;
procedure DoRun; override;
@ -34,12 +35,14 @@ begin
// Allow to load file specified in hash: index.html#mywasmfile.wasm
BtnDownload:=TJSHTMLButtonElement(GetHTMLElement('btnDownload'));
BtnDownload.AddEVentListener('click',@DoDownload);
BtnDownload:=TJSHTMLButtonElement(GetHTMLElement('btnReset'));
BtnDownload.AddEVentListener('click',@DoReset);
EdtFileName:=TJSHTMLInputElement(GetHTMLElement('edtFilename'));
DivDownloads:=GetHTMLElement('divDownloads');
FTreeBuilder:=THTMLZenFSTree.Create(Self);
FTreeBuilder.MaxHeight:='300px';
FTreeBuilder.ParentElementID:='treeFiles';
FTreeBuilder.OnFileSelected:=@SelectFile;
FTreeBuilder.OnFileSelected:=@DoSelectFile;
end;
procedure TMyApplication.DoRun;
@ -123,24 +126,13 @@ begin
EdtFileName.Value:=aFileName;
end;
procedure TMyApplication.SetupFS;
procedure TMyApplication.MaybeCreateFiles;
var
Stat : TZenFSStats;
begin
Terminate;
// Set up filesystem
aWait(TJSObject,ZenFS.configure(
New([
'mounts', New([
'/',DomBackends.WebStorage
])
])));
// Allow to load file specified in hash: index.html#mywasmfile.wasm
try
Stat:=ZenFS.statSync('/tmp/file1.txt');
except
Writeln('Directory structure does not exist, creating one');
end;
@ -148,8 +140,28 @@ begin
CreateFiles
else
Writeln('Directory structure already exists.');
end;
procedure TMyApplication.SetupFS;
begin
Terminate;
aWait(TJSObject,ZenFS.configure(
New([
'mounts', New([
'/',DomBackends.WebStorage
])
])));
MaybeCreateFiles;
FTreeBuilder.ShowDir('/');
FTreeBuilder.OnFileSelected:=@DoSelectFile;
end;
procedure TMyApplication.DoReset(Event : TJSEvent);
begin
window.localStorage.removeItem('0');
FTreeBuilder.Clear;
SetupFS;
end;
procedure TMyApplication.DoDownload(Event : TJSEvent);
@ -160,11 +172,6 @@ begin
a.click;
end;
procedure TMyApplication.SelectFile(Sender: TObject; aFileName: String; aType : TFileType);
begin
if aType=ftFile then
EdtFileName.Value:=aFileName;
end;
var
Application : TMyApplication;

View File

@ -583,12 +583,6 @@ begin
end;
Function CreateFileTree(const aStartDir : string; aParent : TJSHTMLElement) : TJSHTMLELement;
begin
end;
const base64abc : Array of char = (
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
@ -757,6 +751,7 @@ begin
Result:=TJSHTMLAnchorElement(Document.createElement('a'));
Result.href:=CreateDataURL(aFileName,aMimetype);
Result.Download:=ExtractFileName(aFileName);
aParent.AppendChild(Result);
end;
initialization