From: Ketmar Dark Date: Fri, 15 Apr 2016 10:35:47 +0000 (+0300) Subject: sfs: added API to add temporary volume X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=4d17c87d4865a7e2a7089a226238a144bb6c8de2;p=d2df-sdl.git sfs: added API to add temporary volume --- diff --git a/src/sfs/sfs.pas b/src/sfs/sfs.pas index 0153c91..7588ae7 100644 --- a/src/sfs/sfs.pas +++ b/src/sfs/sfs.pas @@ -1,6 +1,7 @@ // streaming file system (virtual) {$MODE DELPHI} {.$R-} +{.$DEFINE SFS_VOLDEBUG} unit sfs; interface @@ -168,6 +169,9 @@ procedure SFSUnregisterVolumeFactory (factory: TSFSVolumeFactory); // ïðèíèìàåòñÿ âî âíèìàíèå òîëüêî ïîñëåäíÿÿ òðóáà. function SFSAddDataFile (const dataFileName: TSFSString; top: Boolean=false): Boolean; +// äîáàâèòü ñáîðíèê âðåìåííî +function SFSAddDataFileTemp (const dataFileName: TSFSString; top: Boolean=false): Boolean; + // äîáàâèòü â ïîñòîÿííûé ñïèñîê ñáîðíèê èç ïîòîêà ds. // åñëè âîçâðàùàåò èñòèíó, òî SFS ñòàíîâèòñÿ âëÿäåëüöåì ïîòîêà ds è ñàìà // óãðîáèò ñåé ïîòîê ïî íåîáõîäèìîñòè. @@ -753,7 +757,11 @@ begin if not fOwner.fPermanent and (fOwner.fOpenedFilesCount < 1) then begin f := volumes.IndexOf(fOwner); - if f <> -1 then volumes[f] := nil; // this will destroy the volume + if f <> -1 then + begin + {$IFDEF SFS_VOLDEBUG}writeln('destroying volume "', TVolumeInfo(volumes[f]).fPackName, '"');{$ENDIF} + volumes[f] := nil; // this will destroy the volume + end; end; end; end; @@ -918,8 +926,11 @@ begin if fVolume <> nil then Dec(fVolume.fRC); Dec(TVolumeInfo(volumes[f]).fOpenedFilesCount); // óáü¸ì çàïèñü, åñëè îíà âðåìåííàÿ, è â íåé íåò áîëüøå íè÷åãî îòêðûòîãî - if not TVolumeInfo(volumes[f]).fPermanent and - (TVolumeInfo(volumes[f]).fOpenedFilesCount < 1) then volumes[f] := nil; + if not TVolumeInfo(volumes[f]).fPermanent and (TVolumeInfo(volumes[f]).fOpenedFilesCount < 1) then + begin + {$IFDEF SFS_VOLDEBUG}writeln('destroying volume "', TVolumeInfo(volumes[f]).fPackName, '"');{$ENDIF} + volumes[f] := nil; + end; inherited Destroy(); end; @@ -1094,8 +1105,7 @@ begin vi.fOpenedFilesCount := 0; end; -function SFSAddSubDataFile (const virtualName: TSFSString; ds: TStream; - top: Boolean = false): Boolean; +function SFSAddSubDataFile (const virtualName: TSFSString; ds: TStream; top: Boolean=false): Boolean; var tv: Integer; begin @@ -1109,7 +1119,7 @@ begin end; end; -function SFSAddDataFile (const dataFileName: TSFSString; top: Boolean = false): Boolean; +function SFSAddDataFile (const dataFileName: TSFSString; top: Boolean=false): Boolean; var tv: Integer; begin @@ -1122,6 +1132,20 @@ begin end; end; +function SFSAddDataFileTemp (const dataFileName: TSFSString; top: Boolean=false): Boolean; +var + tv: Integer; +begin + try + if top then tv := -1 else tv := 1; + SFSAddDataFileEx(dataFileName, nil, tv, 0); + result := true; + except + result := false; + end; +end; + + function SFSExpandDirName (const s: TSFSString): TSFSString; var