rejetto forum

Software => HFS ~ HTTP File Server => Programmers corner => Topic started by: Mars on February 02, 2010, 06:51:56 PM

Title: broken links
Post by: Mars on February 02, 2010, 06:51:56 PM
I tried for a long time how to bring to light the elements of the vfs which could become inaccessible. Here is a rather elegant solution the joined image of which lets augur of the obtained result.

I shall not put this comment in the vote, but this addition will largely be appreciated in the future versions of hfs  
Ami rejetto, il n'y a plus qu'à effectuer un copier-coller.  ;)

Quote from: main.pas
 ICON_EASY = 29;
  ICON_EXPERT = 35;
  ICON_STOP = 11;            // mars (brocken resource)
  ICON_EXCLAMATION = 9;      // mars (brocken resource)
  USER_ICON_MASKS_OFS = 10000;
.......

  function fileHint():string;
  ...
  begin
  result:=if_(HintsfornewcomersChk.checked,'Drag your files here');
  f:=pointedFile();
  if f = NIL then exit;
  parent:=f.parent;
  //(start of brocken resource)
  result:='';
  if f.node.StateIndex=ICON_EXCLAMATION then
  result:=result
   +'********************************************'#13
   +'* PATH NOT FOUND FOR THIS ITEM *'#13
   +'********************************************'#13;
  //(end of brocken resource)
  result:=result+'URL: '+f.url()                        // mars(brocken resource)
    +if_(f.isRealFolder() or f.isFile(), #13'Path: '+f.resource);
  if f.isFile() then
    result:=result+format(#13'Size: %s'#13'Downloads: %d',
      [ smartsize(sizeofFile(f.resource)), f.DLcount ]);
.......

procedure TmainFrm.filesBoxCustomDrawItem(Sender: TCustomTreeView;
  Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var
  f: Tfile;
  a: TStringDynArray;
  onlyAnon: boolean;
  s: string;   //mars (brocken resource)
begin
if not sender.visible then exit;
f:=Tfile(node.data);
if f = NIL then exit;
if f.hasRecursive([FA_HIDDEN, FA_HIDDENTREE], TRUE) then
   with sender.Canvas.Font do
     style:=style+[fsItalic];
a:=f.accounts[FA_ACCESS];
onlyAnon:= onlyString(USER_ANONYMOUS, a);
//(start of brocken resource)
if f.islink then
  begin         //search if link has a local resource        
  s:=xtpl(lowercase(f.resource),['%host%','127.0.0.1','localhost','127.0.0.1']);
  if pos('127.0.0.1',s)>0 then
    chop('127.0.0.1',s);
  if (s>'') and (s[1]=':') then
    s:='/'+chop('/',s);
  end;
if (f.isLink and (s>'') and (s[1]='/') and (findFilebyURL(s)=NIL))
  or (f.isrealFolder and not directoryexists(f.resource))
  or (f.isFile and not fileexists(f.resource)) then
  begin
  node.StateIndex:=ICON_EXCLAMATION;  
  with sender.Canvas.Font do
    begin
    style:=style+[fsBold,fsItalic];
    color:=clTeal;
    end;
  end
else //(end of brocken resource)
  if (f.user > '') or (assigned(a) and not onlyAnon) then node.StateIndex:=ICON_LOCK
else node.StateIndex:=-1;
end;
Title: Re: broken links
Post by: rejetto on February 09, 2010, 05:14:22 PM
good point.
i'll let you know.