ghisler(Author) wrote:Maybe you solve it by reporting a different file name, e.g.
Service x (stopped)
Since this is not what I want, I looked a little deeper into the issue and found a kind of "hacky" solution. The plugin now caches what it returns to TC. That includes the service name, the service state and the timestamp of its executable file, or in code:
Code: Select all
type TCachedService = class
private
FName: string;
FState: TServiceState;
FTimestamp: Cardinal;
end;
TCachedServicesList = class(TObjectList)
protected
function GetItem(AIndex: Integer): TCachedService; virtual;
procedure SetItem(AIndex: Integer; AObjekt: TCachedService); virtual;
public
function Add(AObjekt: TCachedService): Integer; virtual;
function Remove(AObjekt: TCachedService): Integer; virtual;
function IndexOf(AObjekt: TCachedService): Integer; virtual;
function IndexOfName(const AName: string): integer;
procedure Insert(AIndex: Integer; AObjekt: TCachedService); virtual;
function First: TCachedService; virtual;
function Last: TCachedService; virtual;
property Items[Index: Integer]: TCachedService read GetItem write SetItem; default;
end;
When the service list is refreshed by the user using Ctrl+R (or by the plugin sending cm_RereadSource to TC), the plugin checks if the service is in the cache list and if its state has changed. If so, it returns a different timestamp, if not, it returns the same timestamp:
Code: Select all
[...]
LState:= svc.State;
[...]
LsvcIndex:= CachedServicesList.IndexOfName(LsvcName);
if LsvcIndex > -1 then
begin
// If the service's state changed we must return a different timestamp
// to force TC to call FsExtractCustomIcon (for that service at least)
LsvcCached:= CachedServicesList[LsvcIndex];
if (LsvcCached.FState <> LState) then
begin
if (LsvcCached.FTimestamp = Lwfd.ftLastWriteTime.dwLowDateTime) then
Inc(FindData.ftLastWriteTime.dwLowDateTime);
end
else
[...]
(This code is called in FsFindFirst and FsFindNext)
Returning a different timestamp seems to force TC to call FsExtractCustomIcon which is exactly what I want it to do.
If I understand the MSDN article about the
FILETIME structure correctly it has a resolution of 100 nanoseconds, so the different timestamp should not be visible to the user.
Nevertheless it would be nice to have a function in the plugin interface (or an additional optional argument to an existing function like FsFindFirst/FsFindNext) to force TC to call FsExtractCustomIcon.
Regards
Dalai