forked from geraldholdsworth/DiscImageManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscImage_Spark.pas
612 lines (599 loc) · 21 KB
/
DiscImage_Spark.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
//++++++++++++++++++ !Spark ++++++++++++++++++++++++++++++++++++++++++++++++
{-------------------------------------------------------------------------------
Identifies a Spark archive
-------------------------------------------------------------------------------}
function TDiscImage.ID_Spark: Boolean;
begin
Result:=False;
if(FFormat=diInvalidImg)or(FSparkAsFS)then
begin
if(GetDataLength>0)and(FFilename<>'')then //Any data?
begin
//Open the file in TSpark
SparkFile:=TSpark.Create(FFilename);
//And make sure it is valid
if SparkFile.IsSpark then
begin
//Set the format
FFormat:=diSpark<<4;
FDirType:=diADFSNewDir; //Just to fool some of the methods
end
else SparkFile.Free; //Otherwise free the instance
Result:=FFormat<>diInvalidImg; //Return a result
end;
end;
end;
{-------------------------------------------------------------------------------
Read Spark archive
-------------------------------------------------------------------------------}
function TDiscImage.ReadSparkArchive: Boolean;
var
index,
ref : Integer;
d,
e : Cardinal;
pnt : String;
// OldDisc: TDisc;
begin
//In order to be able to use FileExists, we need to populate FDisc
// OldDisc:=FDisc; //So take a note
//We will be returning a TDisc in Result
Result:=False;
//Set up the array for the basic root entry
SetLength(FDisc,1);
ResetDir(FDisc[0]);
FDisc[0].Directory:='$';
FDisc[0].BeenRead:=True;
//Now go through all the entries in the spark and add them
for index:=0 to Length(SparkFile.FileList)-1 do
begin
//Work out the parent, relative to root
pnt:=SparkFile.FileList[index].Parent;
if pnt='' then pnt:='$' else pnt:='$.'+pnt;
//Directory reference, default
ref:=-1;
//Now, does the parent exist?
if FileExists(pnt,d,e) then
begin
//Are we adding a directory
if SparkFile.FileList[index].Directory then
begin
//Take a note of the array reference
ref:=Length(FDisc);
//And increase the array length
SetLength(FDisc,ref+1);
//Reset the new entry
ResetDir(FDisc[ref]);
//And add the filename
FDisc[ref].Directory:=SparkFile.FileList[index].Filename;
if d<>$FFFF then
begin
FDisc[ref].Parent:=FDisc[d].Entries[e].DirRef;
FDisc[ref].Sector:=FDisc[d].Entries[e].Sector;
FDisc[ref].BeenRead:=True;
end
else
begin
FDisc[ref].Parent:=0;
FDisc[ref].Sector:=root;
FDisc[ref].BeenRead:=True;
end;
end;
//FileExists returns pointers to what it found
if pnt='$' then d:=0 //But we need to up it to take account of root
else d:=FDisc[d].Entries[e].DirRef;
//Get the pointer into the entries
e:=Length(FDisc[d].Entries);
//And extend the entries array
SetLength(FDisc[d].Entries,e+1);
//Populate it
FDisc[d].Entries[e].Filename:=SparkFile.FileList[index].Filename;
FDisc[d].Entries[e].Parent:=pnt;
FDisc[d].Entries[e].LoadAddr:=SparkFile.FileList[index].LoadAddr;
FDisc[d].Entries[e].ExecAddr:=SparkFile.FileList[index].ExecAddr;
FDisc[d].Entries[e].Length:=SparkFile.FileList[index].Length;
FDisc[d].Entries[e].Sector:=SparkFile.FileList[index].DataOffset;
FDisc[d].Entries[e].Track:=Index;//Reference into the archive
FDisc[d].Entries[e].DirRef:=ref; //Directory reference from earlier
//Collate the attributes
FDisc[d].Entries[e].Attributes:=
SparkFile.ConvertAttribute(SparkFile.FileList[index].Attributes);
//Calculate the timestamp and filetype
ADFSCalcFileDate(FDisc[d].Entries[e]);
end;
end;
//Disc size (total uncompressed size)
disc_size[0]:=SparkFile.UncompressedSize;
//Return a result
Result:=Length(FDisc)>0;
//And restore FDisc to what it was
//FDisc:=OldDisc;
end;
{-------------------------------------------------------------------------------
Extract a file from Spark archive
-------------------------------------------------------------------------------}
function TDiscImage.ExtractSparkFile(filename: String;
var buffer: TDIByteArray): Boolean;
var
d,e : Cardinal;
index: Integer;
begin
//Default return result
Result :=False;
//Does the file actually exist?
if FileExists(filename,d,e) then
begin
//And is within range
if d<Length(FDisc) then
if e<Length(FDisc[d].Entries) then
begin
//Get the index, stashed away in the track parameter
index:=FDisc[d].Entries[e].Track;
//And inflate the file
buffer:=SparkFile.ExtractFileData(index);
//Return an OK, if something got read
Result:=Length(buffer)>0;
end;
end;
end;
{-------------------------------------------------------------------------------
Create a new Spark archive
-------------------------------------------------------------------------------}
function TDiscImage.FormatSpark(Zipfilename: String): Boolean;
begin
Result:=True;
if Zipfilename='' then exit;
//Set up the TDisc structure for return
SetLength(FDisc,1);
ResetDir(FDisc[0]);
//Set the root directory name
root_name:='$';
FDisc[0].Directory:=root_name;
FDisc[0].BeenRead:=True;
//Set the format
FFormat:=diSpark<<4;
//Create a blank file
SparkFile:=TSpark.Create(Zipfilename,True);
//Set the filename
imagefilename:=Zipfilename;
end;
{-------------------------------------------------------------------------------
Delete a file from a Spark archive
-------------------------------------------------------------------------------}
function TDiscImage.DeleteSparkFile(filename: String): Boolean;
var
dirref : Integer;
index,
dir,
entry : Cardinal;
olddir : String;
begin
Result:=False;
//Ensure the file actually exists
if FileExists(filename,dir,entry) then
begin
//Convert the filename
SparkFile.SwapDirSep(filename);
dirref:=FDisc[dir].Entries[entry].DirRef;
if dirref<>-1 then filename:=filename+'/';
if filename[1]='$' then filename:=Copy(filename,3);
//Delete the file/directory
SparkFile.DeleteFile(filename);
//Return a postive result (the above method will return a false)
Result:=True;
//This needs to replicate when the Spark class is doing for the local copy
//i.e., for directories, delete all contents as well as the directory
if entry<Length(FDisc[dir].Entries)-1 then
for index:=entry to Length(FDisc[dir].Entries)-2 do
FDisc[dir].Entries[index]:=FDisc[dir].Entries[index+1];
SetLength(FDisc[dir].Entries,Length(FDisc[dir].Entries)-1);
//Update all the directory references
if dirref<>-1 then UpdateDirRef(dirref);
//Did we remove the last child of the directory?
if Length(FDisc[dir].Entries)=0 then
begin
//Then we'll recreate it, as it will have gone
olddir:=GetParent(dir);
SparkFile.SwapDirSep(olddir);
olddir:=olddir+'/';
SparkFile.CreateDirectory(olddir);
end;
end;
end;
{-------------------------------------------------------------------------------
Update the file attributes of a file
-------------------------------------------------------------------------------}
function TDiscImage.UpdateSparkAttributes(filename,attributes: String): Boolean;
var
dir,
entry : Cardinal;
begin
Result:=False;
//Ensure the file actually exists
if FileExists(filename,dir,entry) then
begin
if FDisc[dir].Entries[entry].DirRef<>-1 then attributes:=attributes+'D'
else attributes:=ReplaceStr(attributes,'D','');
//Convert the filename
SparkFile.SwapDirSep(filename);
if FDisc[dir].Entries[entry].DirRef<>-1 then filename:=filename+'/';
if filename[1]='$' then filename:=Copy(filename,3);
//Update the attributes
if SparkFile.UpdateAttributes(filename,SparkFile.ConvertAttribute(attributes)) then
begin
//And update the local copy of the attributes
FDisc[dir].Entries[entry].Attributes:=attributes;
//And set a positive result
Result:=True;
end;
end;
end;
{-------------------------------------------------------------------------------
Move a file from one directory to another
-------------------------------------------------------------------------------}
function TDiscImage.MoveSparkFile(filename, dest: String): Integer;
var
sdir,sentry,
ddir,dentry : Cardinal;
olddir : String;
entry,
index : Integer;
begin
Result:=-1;
//Moving is just the same as renaming, but supplying the entire path for both
//source and destination.
if FileExists(filename,sdir,sentry) then //Make sure the source file exists
if FileExists(dest,ddir,dentry) then //And the destination exists
begin
//As we are just renaming, tag the filename onto the end of the destination
dest:=dest+dir_sep+FDisc[sdir].Entries[sentry].Filename;
//Swap the directory separators for both
SparkFile.SwapDirSep(filename);
SparkFile.SwapDirSep(dest);
//Add the trailing '/' if the source is a directory
if FDisc[sdir].Entries[sentry].DirRef<>-1 then
begin
filename:=filename+'/';
dest:=dest+'/';
end;
//Rename it
SparkFile.RenameFile(filename,dest);
//Update the local copy - destination
entry:=FDisc[ddir].Entries[dentry].DirRef;
SetLength(FDisc[entry].Entries,Length(FDisc[entry].Entries)+1);
FDisc[entry].Entries[Length(FDisc[entry].Entries)-1]:=FDisc[sdir].Entries[sentry];
Result:=Length(FDisc[entry].Entries)-1;
//Update the local copy - source
if Length(FDisc[sdir].Entries)=1 then SetLength(FDisc[sdir].Entries,0)
else
begin
//If not the end one
if sentry<Length(FDisc[sdir].Entries)-1 then
//Move everything down one
for index:=sentry to Length(FDisc[sdir].Entries)-2 do
FDisc[sdir].Entries[index]:=FDisc[sdir].Entries[index+1];
//And drop the last one off the list
SetLength(FDisc[sdir].Entries,Length(FDisc[sdir].Entries)-1);
end;
//Did we remove the last child of the source directory?
if Length(FDisc[sdir].Entries)=0 then
begin
//Then we'll recreate it, as it will have gone
olddir:=GetParent(sdir);
SparkFile.SwapDirSep(olddir);
olddir:=olddir+'/';
SparkFile.CreateDirectory(olddir);
end;
end;
end;
{-------------------------------------------------------------------------------
Add a file to an existing archive
-------------------------------------------------------------------------------}
function TDiscImage.WriteSparkFile(var file_details: TDirEntry;
var buffer: TDIByteArray): Integer;
var
dir : Integer;
timestamp : Int64;
ref,ptr : Cardinal;
filetozip : TFileEntry;
begin
dir :=0;
//Start with a negative result
Result:=-3;//File already exists
//First make sure it doesn't exist already
if not FileExists(file_details.Parent+dir_sep+file_details.Filename,ref)then
//Get the directory where we are adding it to, and make sure it exists
if FileExists(file_details.Parent,ref)then
begin
//Where we are inserting this into
if file_details.Parent='$' then
dir :=0
else
dir :=FDisc[ref div $10000].Entries[ref mod $10000].DirRef;
//Has it been read in?
if not FDisc[dir].BeenRead then ReadDirectory(file_details.Parent);
//Get the length of the file
Result:=-7; //Map full
//Now update the directory (local copy)
if file_details.filename<>'$' then
begin
//Get the number of entries in the directory
ref:=Length(FDisc[dir].Entries);
//Convert load/exec address into filetype and datestamp, if necessary
ADFSCalcFileDate(file_details); //Spark is based on ADFS
//Now we add the entry into the directory catalogue
ptr:=ExtendADFSCat(dir,file_details); //Spark is based on ADFS
//Not a directory
FDisc[dir].Entries[ptr].DirRef:=-1;
//Filetype and Timestamp for Arthur and RISC OS ADFS
if (FDisc[dir].Entries[ptr].LoadAddr=0)
and(FDisc[dir].Entries[ptr].ExecAddr=0)
then
begin
FDisc[dir].Entries[ptr].LoadAddr:=$FFF00000;
//Set the filetype, if not already set
if FDisc[dir].Entries[ptr].ShortFileType<>'' then
begin
FDisc[dir].Entries[ptr].LoadAddr:=FDisc[dir].Entries[ptr].LoadAddr OR
(StrToIntDef('$'+FDisc[dir].Entries[ptr].ShortFileType,0)<<8);
FDisc[dir].Entries[ptr].FileType:=
GetFiletypeFromNumber(StrToIntDef('$'+FDisc[dir].Entries[ptr].ShortFileType,0));
end;
//Timestamp it, if not already done
timestamp:=TimeDateToRISCOS(Now);
FDisc[dir].Entries[ptr].TimeStamp:=Now;
FDisc[dir].Entries[ptr].LoadAddr:=FDisc[dir].Entries[ptr].LoadAddr OR
(timestamp DIV $100000000);
FDisc[dir].Entries[ptr].ExecAddr:=timestamp MOD $100000000;
end;
//File imported from DFS, expand the tube address, if needed
if (FDisc[dir].Entries[ptr].LoadAddr>>16=$00FF)
and(FDisc[dir].Entries[ptr].ExecAddr>>16=$00FF)then
begin
FDisc[dir].Entries[ptr].LoadAddr:=
(FDisc[dir].Entries[ptr].LoadAddr AND $0000FFFF)
OR$FFFF0000;
FDisc[dir].Entries[ptr].ExecAddr:=
(FDisc[dir].Entries[ptr].ExecAddr AND $0000FFFF)
OR$FFFF0000;
end;
//Is the file actually a directory?
if Pos('D',file_details.Attributes)>0 then
begin
//Increase the number of directories by one
SetLength(FDisc,Length(FDisc)+1);
//Then assign DirRef
FDisc[dir].Entries[ptr].DirRef:=Length(FDisc)-1;
//Assign the directory properties
FDisc[Length(FDisc)-1].Directory:=FDisc[dir].Entries[ptr].Filename;
FDisc[Length(FDisc)-1].Title :=FDisc[dir].Entries[ptr].Filename;
FDisc[Length(FDisc)-1].Broken :=False;
FDisc[Length(FDisc)-1].Parent :=dir;
FDisc[Length(FDisc)-1].Sector :=FDisc[dir].Entries[ptr].Sector;
SetLength(FDisc[Length(FDisc)-1].Entries,0);
end;
//And send the result back to the client
Result:=ptr;
//Write the result to the ZIP file
filetozip.Filename:=FDisc[dir].Entries[ptr].Filename; //RISC OS filename
filetozip.Parent:=FDisc[dir].Entries[ptr].Parent; //RISC OS parent
//The actual name in the archive
filetozip.ArchiveName:=FDisc[dir].Entries[ptr].Parent
+'.'+FDisc[dir].Entries[ptr].Filename;
//Remove the root name, if present
if LeftStr(filetozip.ArchiveName,2)='$.' then
filetozip.ArchiveName:=Copy(filetozip.ArchiveName,3);
//Need to swap ADFS directory and extension separators
SparkFile.SwapDirSep(filetozip.ArchiveName);
//Convert the attributes from a string to a byte
filetozip.Attributes:=
SparkFile.ConvertAttribute(FDisc[dir].Entries[ptr].Attributes);
//Is it a directory?
filetozip.Directory:=FDisc[dir].Entries[ptr].DirRef<>-1;
//Load and execution addresses (i.e., filetype and datestamp)
filetozip.ExecAddr:=FDisc[dir].Entries[ptr].ExecAddr;
filetozip.LoadAddr:=FDisc[dir].Entries[ptr].LoadAddr;
//File length
filetozip.Size:=FDisc[dir].Entries[ptr].Length;
//Write the file
SparkFile.WriteFile(filetozip,buffer);
//Update the used space
disc_size[0]:=SparkFile.UncompressedSize;
end else Result:=0;
end else Result:=-6; //Directory does not exist
end;
{-------------------------------------------------------------------------------
Rename a file
-------------------------------------------------------------------------------}
function TDiscImage.RenameSparkFile(filename, newfilename: String): Integer;
var
dir,
entry,
ptr : Cardinal;
begin
Result:=-1;
//Does the file exist?
if FileExists(filename,dir,entry) then
//And the proposed filename not exist?
if not FileExists(GetParent(dir)+dir_sep+newfilename,ptr) then
begin
//Swap the directory separators
SparkFile.SwapDirSep(filename);
//Update our local copy
FDisc[dir].Entries[entry].Filename:=newfilename;
//Are we renaming a directory?
if FDisc[dir].Entries[entry].DirRef<>-1 then
begin
//If the title is the same, change it also
if FDisc[FDisc[dir].Entries[entry].DirRef].Title=FDisc[dir].Entries[entry].Filename then
FDisc[FDisc[dir].Entries[entry].DirRef].Title:=newfilename;
//And the directory name
FDisc[FDisc[dir].Entries[entry].DirRef].Directory:=newfilename;
end;
//Add the path for the proposed filename
newfilename:=GetParent(dir)+dir_sep+newfilename;
//And swap the separators
SparkFile.SwapDirSep(newfilename);
//Is it a directory?
if FDisc[dir].Entries[entry].DirRef<>-1 then
begin
//Add the trailing '/'
filename:=filename+'/';
newfilename:=newfilename+'/';
end;
SparkFile.RenameFile(filename,newfilename);
//Return the original entry point
Result:=entry;
end;
end;
{-------------------------------------------------------------------------------
Update the file type of a file
-------------------------------------------------------------------------------}
function TDiscImage.UpdateSparkFileType(filename: String; newtype: String): Boolean;
var
dir,
entry,
load,
exec : Cardinal;
newft : Integer;
begin
Result:=False;
load:=0;
exec:=0;
//Ensure the file actually exists
if FileExists(filename,dir,entry) then
begin
//Hex number?
if IntToHex(StrToIntDef('$'+newtype,0),3)<>UpperCase(newtype) then
newft:=GetFileTypeFromName(newtype) //No, so translate
else
newft:=StrToInt('$'+newtype); //Yes, just convert
//Valid filetype?
if newft>=0 then
begin
//Get the execution address
exec:=FDisc[dir].Entries[entry].ExecAddr;
//Calculate the new load address
load:=FDisc[dir].Entries[entry].LoadAddr;
//Set the top 12 bits to indicate filetyped
load:=load OR$FFF00000;
//Clear the filetype area, preserving the rest
load:=load AND$FFF000FF;
//Set the filetype
load:=load OR(newft<<8);
//Convert the filename
SparkFile.SwapDirSep(filename);
if FDisc[dir].Entries[entry].DirRef<>-1 then filename:=filename+'/';
if filename[1]='$' then filename:=Copy(filename,3);
//Update the load and exec addresses
if SparkFile.UpdateLoadExecAddress(filename,load,exec) then
begin
//And update the local copy of the filetypes
FDisc[dir].Entries[entry].ShortFileType:=IntToHex(newft,3);
FDisc[dir].Entries[entry].Filetype:=GetFileTypeFromNumber(newft);
//And set a positive result
Result:=True;
end;
end;
end;
end;
{-------------------------------------------------------------------------------
Update the timestamp of a file
-------------------------------------------------------------------------------}
function TDiscImage.UpdateSparkTimeStamp(filename: String;newtimedate:TDateTime): Boolean;
var
dir,
entry,
load,
exec : Cardinal;
rotd : QWord;
begin
Result:=False;
load:=0;
exec:=0;
//Ensure the file actually exists
if FileExists(filename,dir,entry) then
begin
//Convert to RISC OS time format
rotd:=TimeDatetoRISCOS(newtimedate);//RISC OS TimeDate is 40 bits long
//Calculate the new load address
load:=FDisc[dir].Entries[entry].LoadAddr;
//Set the top 12 bits to indicate filetyped, and preserve the rest
load:=load OR$FFF00000;
//Clear the bottom 8 bits
load:=load AND$FFFFFF00;
//Set the bottom 8 bits with the new time
load:=load OR(rotd>>32);
//Now calculate the new exec address
exec:=rotd AND $FFFFFFFF;
//Convert the filename
SparkFile.SwapDirSep(filename);
if FDisc[dir].Entries[entry].DirRef<>-1 then filename:=filename+'/';
if filename[1]='$' then filename:=Copy(filename,3);
//Update the load and exec addresses
if SparkFile.UpdateLoadExecAddress(filename,load,exec) then
begin
//Update the local copy
FDisc[dir].Entries[entry].LoadAddr:=load;
FDisc[dir].Entries[entry].ExecAddr:=exec;
FDisc[dir].Entries[entry].TimeStamp:=newtimedate;
//Return a positive result
Result:=True;
end;
end;
end;
{-------------------------------------------------------------------------------
Update the file type of a file
-------------------------------------------------------------------------------}
function TDiscImage.UpdateSparkFileAddr(filename: String; newaddr: Cardinal;
load: Boolean): Boolean;
var
dir,
entry,
loadad,
execad : Cardinal;
begin
Result:=False;
loadad:=0;
execad:=0;
//Ensure the file actually exists
if FileExists(filename,dir,entry) then
begin
//Get the current load address
loadad:=FDisc[dir].Entries[entry].LoadAddr;
//Get the current exec address
execad:=FDisc[dir].Entries[entry].LoadAddr;
//Change the one specified
if load then loadad:=newaddr else execad:=newaddr;
//Convert the filename
SparkFile.SwapDirSep(filename);
if FDisc[dir].Entries[entry].DirRef<>-1 then filename:=filename+'/';
//Send to the class
if SparkFile.UpdateLoadExecAddress(filename,loadad,execad) then
begin
//Update the local copy
FDisc[dir].Entries[entry].LoadAddr:=loadad;
FDisc[dir].Entries[entry].ExecAddr:=execad;
//Return a positive result
Result:=True;
end;
end;
end;
{-------------------------------------------------------------------------------
Create a directory
-------------------------------------------------------------------------------}
function TDiscImage.CreateSparkDirectory(filename, parent, attributes: String): Integer;
var
file_details: TDirEntry;
buffer : TDIByteArray;
begin
buffer:=nil;
SetLength(buffer,0);
//Set up the TDirEntry
file_details.Filename:=filename;
file_details.Parent:=parent;
if Pos('D',attributes)<1 then attributes:='D'+attributes;
file_details.Attributes:=attributes;
//And just pass to the WriteFile function above
Result:=WriteSparkFile(file_details,buffer);
end;