Hi
In my 'PluginMgr', I'm trying to detect changes in the "plugin-directory", i.e.: if someone added a new plugin...
If my manager is running in mode 'ActiveOnly', it learns what plugins are actually used and loads only them, cutting the load-times to ~1/10
But I'd like it to automagically detect /new-arrivals/ and reset 'active-cache' and load all plugins to let the user use the new plugin ...and then start learning anew...
So I'm fiddling with code like this, to ascertain if the directory has been modified:
program gda; /// (g)et (d)irectory (a)ge ///
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads, baseunix,
{$ENDIF}
Classes,sysutils;
function DirAge(const FileName : rawbytestring; out aStat: stat): ptrint;
var
Info : baseunix.stat;
SystemFileName: RawByteString;
begin
SystemFileName:= ToSingleByteFileSystemEncodedFileName(FileName);
if fpstat(PAnsiChar(SystemFileName),Info) < 0 then
exit(-1)
else
Result:= Info.st_mtime; /// we're mostly interested in 'modified'
aStat:= Info; /// record copy, but can't use pointer, 'cause info is local and goes outta scope
end;
var
da: ptrint;
dn: string;
st: baseunix.stat;
begin
writeln('>> (g)et (d)irectory (a)ge <<');
writeln('(i) usage: gda <directory-name>');
if ParamCount < 1 then halt(1);
dn:= ParamStr(1);
da:= DirAge(dn,st);
writeln('>- - - -[ Info about "',dn,'" ]- - - -<');
writeln('(i) Dir-Mod: ',da,', as DateTime: ',DateTimeToStr(FileDateToDateTime(da)));
writeln('(i) Dir-Cre: ',st.st_ctime,', as DateTime: ',DateTimeToStr(FileDateToDateTime(st.st_ctime)));
writeln('(i) Dir-Acc: ',st.st_atime,', as DateTime: ',DateTimeToStr(FileDateToDateTime(st.st_atime)));
writeln('________________________________________');
end.
'DirAge' is a modified version of 'FileAge' in the RTL and I'm wondering if there are some snags ahead that I can't foresee, since it's not in the RTL?!?
I'll be happy for any input...
Regards Benny
edit: typo