summaryrefslogtreecommitdiff
path: root/plugins/Watrack/i_cover.inc
blob: 96aec9da47e526319760b6e792259681d32d5ef5 (plain)
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
{any utils}
function GetCover(var dst:pWideChar;MFile:pWideChar):boolean;
var
  line,line1:array [0..511] of WideChar;
  p,p1:PWideChar;
  i:integer;
  fdata:WIN32_FIND_DATAW;
  hTmp:THANDLE;
  wr,wr1:pWideChar;
begin
  result:=false;
  dst:=nil;
  if (CoverPaths=nil) or (CoverPaths^=#0) then exit;
  p:=CoverPaths;
  repeat
    p1:=p;
    while p^>=' ' do inc(p);
    i:=p-p1;
    if i>0 then
    begin
      move(p1^,line,i*SizeOf(WideChar));
      line[i]:=#0;
      if ServiceExists(MS_WAT_REPLACETEXT)<>0 then
        wr:=pWideChar(CallService(MS_WAT_REPLACETEXT,0,lparam(@line)))
      else
        wr:=@line;

      if isPathAbsolute(wr) then
      begin
        hTmp:=FindFirstFileW(wr,fdata);
      end
      else
      begin
        wr1:=ExtractW(MFile,false);
        StrCopyW(line,wr1);
        mFreeMem(wr1);
        StrCatW(line,wr);
        hTmp:=FindFirstFileW(line,fdata);
      end;
      if THANDLE(hTmp)<>INVALID_HANDLE_VALUE then
      begin
        wr1:=ExtractW(line,false);
        StrCopyW(line1,wr1);
        mFreeMem(wr1);
        StrCatW(line1,pWideChar(@fdata.cFileName));

        GetFullPathNameW(line1,SizeOf(line) div SizeOf(WideChar),line,wr1);
        StrDupW(dst,line);
        result:=true;
        FindClose(hTmp); //!!
      end;
      if wr<>@line then mFreeMem(wr);
      if result then break;
    end;
    while p^<' ' do
    begin
      if p^=#0 then break;
      inc(p);
    end;
  until p^=#0;
end;

function GetLyric(var dst:pWideChar;MFile:pWideChar):boolean;
var
  buf:array [0..511] of WideChar;
  f:THANDLE;
  size:integer;
  tmp:PAnsiChar;
begin
  StrCopyW(buf,MFile);
  ChangeExtW(buf,'txt');
  f:=Reset(buf);
  if f=THANDLE(INVALID_HANDLE_VALUE) then
  begin
    dst:=nil;
    result:=false;
    exit;
  end;
  size:=FileSize(f);
  if size>0 then
  begin
    mGetMem(tmp,size+1);
    BlockRead(f,tmp^,size);
    tmp[size]:=#0;
    AnsiToWide(tmp,dst);
    mFreeMem(tmp);
  end;
  CloseHandle(f);
  result:=true;
end;