summaryrefslogtreecommitdiff
path: root/plugins/Watrack/srv_format.pas
diff options
context:
space:
mode:
authorAlexey Kulakov <panda75@bk.ru>2014-04-24 14:55:20 +0000
committerAlexey Kulakov <panda75@bk.ru>2014-04-24 14:55:20 +0000
commitc3a168743616db6606702db5ad0fecab4dfee3da (patch)
tree523ef1399093917f3565d769826ceecb7eb2ef6c /plugins/Watrack/srv_format.pas
parent90ad600cb38a04c9272a3599c72d6559c822b155 (diff)
Miranda API update
Watrack refactoring, API changes git-svn-id: http://svn.miranda-ng.org/main/trunk@9068 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Watrack/srv_format.pas')
-rw-r--r--plugins/Watrack/srv_format.pas313
1 files changed, 153 insertions, 160 deletions
diff --git a/plugins/Watrack/srv_format.pas b/plugins/Watrack/srv_format.pas
index 58c046c712..c5f2cef6ed 100644
--- a/plugins/Watrack/srv_format.pas
+++ b/plugins/Watrack/srv_format.pas
@@ -5,25 +5,30 @@ interface
uses windows,wat_api;
+// dialog procedures
procedure DefFillFormatList (hwndList:HWND);
procedure DefCheckFormatList(hwndList:HWND);
-function ProcessFormatLink:integer;
-function GetFileFormatInfo(var dst:tSongInfo):integer;
-function CheckExt(fname:pWideChar):integer;
+// init/free procedures
+function ProcessFormatLink:integer;
+procedure ClearFormats;
-function DeleteKnownExt(src:pWideChar):pWideChar;
-function KnownFileType(fname:PWideChar):boolean;
-function isContainer(fname:PWideChar):boolean;
+function CheckExt (fname:pWideChar):integer;
+// support functions
+function DeleteKnownExt(fname:pWideChar):pWideChar;
+function KnownFileType (fname:PWideChar):boolean;
+function isContainer (fname:PWideChar):boolean;
+// miranda-like service function
function ServiceFormat(wParam:WPARAM;lParam:LPARAM):integer;cdecl;
+// internal helper (can be moved to implementation section)
procedure RegisterFormat(ext:PAnsiChar;proc:tReadFormatProc;flags:dword=0);
-procedure ClearFormats;
type
MusEnumProc = function(param:PAnsiChar;lParam:LPARAM):bool;stdcall;
function EnumFormats(param:MusEnumProc;lParam:LPARAM):bool;
+function GetActiveFormat:pMusicFormat;
type
pwFormat = ^twFormat;
@@ -35,10 +40,12 @@ type
const
FormatLink:pwFormat=nil;
+
implementation
uses
CommCtrl,common;
+
type
pFmtArray = ^tFmtArray;
tFmtArray = array [0..10] of tMusicFormat;
@@ -52,18 +59,10 @@ const
FmtNum:integer=0;
FmtMax:integer=0;
-function ProcessFormatLink:integer;
-var
- ptr:pwFormat;
+
+function GetActiveFormat:pMusicFormat;
begin
- result:=0;
- ptr:=FormatLink;
- while ptr<>nil do
- begin
- RegisterFormat(@ptr.This.ext,ptr.This.proc,ptr.This.flags);
- inc(result);
- ptr:=ptr^.Next;
- end;
+ result:=@fmtLink^[0];
end;
function EnumFormats(param:MusEnumProc;lParam:LPARAM):bool;
@@ -111,6 +110,8 @@ begin
result:=WAT_RES_NOTFOUND;
end;
+//----- dialog procedures -----
+
procedure DefFillFormatList(hwndList:HWND);
var
item:LV_ITEMA;
@@ -173,218 +174,210 @@ begin
end;
end;
-function DeleteKnownExt(src:pWideChar):pWideChar;
-var
- s :array [0..7] of WideChar;
- ss:array [0..7] of AnsiChar;
- i,j:integer;
-begin
- GetExt(src,s);
- if s[0]<>#0 then
- begin
- int64(ss):=0;
- i:=0;
- while (s[i]<>#0) and (i<8) do
- begin
- ss[i]:=AnsiChar(s[i]);
- inc(i);
- end;
- j:=0;
- while j<FmtNum do
- begin
- if int64(fmtLink^[j].ext)=int64(ss) then
- begin
- i:=StrLenW(s);
- src[integer(StrLenW(src))-i-1]:=#0;
- break;
- end;
- inc(j);
- end;
- end;
- result:=src;
-end;
-function KnownFileType(fname:PWideChar):boolean;
+//!! case-sensitive (but GetExt return Upper case ext)
+function FindExt(fname:pWideChar):integer;
var
- i:integer;
s :array [0..7] of WideChar;
ss:array [0..7] of AnsiChar;
+ i:integer;
begin
- result:=false;
- if (fname=nil) or (fname^=#0) then
- exit;
GetExt(fname,s);
- int64(ss):=0;
if s[0]<>#0 then
begin
+ // translate ext to int64
i:=0;
+ int64(ss):=0;
while (s[i]<>#0) and (i<8) do
begin
ss[i]:=AnsiChar(s[i]);
inc(i);
end;
+
+ // search number
i:=0;
while i<FmtNum do
begin
- if (int64(fmtLink^[i].ext)=int64(ss)) then
+ if int64(fmtLink^[i].ext)=int64(ss) then
begin
- if ((fmtLink^[i].flags and WAT_OPT_DISABLED)=0) then
- result:=true;
- break;
+ result:=i;
+ exit;
end;
inc(i);
end;
end;
+
+ result:=-1;
end;
-function isContainer(fname:PWideChar):boolean;
+function DeleteKnownExt(fname:pWideChar):pWideChar;
+var
+ i:integer;
begin
- if CheckExt(fname)=WAT_RES_OK then
+ i:=FindExt(fname);
+ if i>=0 then
begin
- result:=(fmtLink^[0].flags and WAT_OPT_CONTAINER)<>0;
- end
- else
- result:=false;
+ i:=StrLen(fmtLink^[i].ext);
+ fname[integer(StrLenW(fname))-i-1]:=#0;
+ end;
+
+ result:=fname;
end;
-function GetFileFormatInfo(var dst:tSongInfo):integer;
+function KnownFileType(fname:PWideChar):boolean;
+var
+ i:integer;
begin
- result:=CheckExt(dst.mfile);
- if result=WAT_RES_OK then
+ result:=false;
+
+ i:=FindExt(fname);
+ if i>=0 then
begin
- fmtLink^[0].proc(dst);
+ if ((fmtLink^[i].flags and WAT_OPT_DISABLED)=0) then
+ result:=true;
end;
end;
function CheckExt(fname:pWideChar):integer;
var
- i:integer;
tmp:tMusicFormat;
- ls:array [0..7] of WideChar;
- ss:array [0..7] of AnsiChar;
+ i:integer;
begin
- GetExt(fname,ls);
- i:=0;
- int64(ss):=0;
- while (ls[i]<>#0) and (i<8) do
+ i:=FindExt(fname);
+ if i>=0 then
begin
- ss[i]:=AnsiChar(ls[i]);
- inc(i);
- end;
- i:=0;
- while i<FmtNum do
- begin
- if (int64(fmtLink^[i].ext)=int64(ss)) then
+ if (fmtLink^[i].flags and WAT_OPT_DISABLED)=0 then
begin
- if ((fmtLink^[i].flags and WAT_OPT_DISABLED)=0) then
- begin
- if i>0 then
- begin
- tmp:=fmtLink^[i];
- move(fmtLink^[0],fmtLink^[1],SizeOf(tMusicFormat)*i);
- fmtLink^[0]:=tmp;
- end;
- result:=WAT_RES_OK;
- exit;
- end
- else
- break;
- end;
- inc(i);
- end;
- result:=WAT_RES_NOTFOUND;
+ // move to top
+ tmp:=fmtLink^[i];
+ move(fmtLink^[0],fmtLink^[1],SizeOf(tMusicFormat)*i);
+ fmtLink^[0]:=tmp;
+
+ result:=WAT_RES_OK;
+ end
+ else
+ result:=WAT_RES_DISABLED;
+ end
+ else
+ result:=WAT_RES_NOTFOUND;
end;
+function isContainer(fname:PWideChar):boolean;
+begin
+ if CheckExt(fname)=WAT_RES_OK then
+ begin
+ result:=(fmtLink^[0].flags and WAT_OPT_CONTAINER)<>0;
+ end
+ else
+ result:=false;
+end;
+
+
function ServiceFormat(wParam:WPARAM;lParam:LPARAM):integer;cdecl;
var
p:integer;
nl:pFmtArray;
begin
result:=WAT_RES_NOTFOUND;
- if LoWord(wParam)<>WAT_ACT_REGISTER then
- p:=FindFormat(PAnsiChar(lParam))
- else
- p:=0;
- case LoWord(wParam) of
- WAT_ACT_REGISTER: begin
- if @pMusicFormat(lParam)^.proc=nil then
+
+ if LoWord(wParam)=WAT_ACT_REGISTER then
+ begin
+ if @pMusicFormat(lParam)^.proc=nil then
+ exit;
+
+ p:=FindFormat(pMusicFormat(lParam)^.ext);
+ if (p=WAT_RES_NOTFOUND) or ((wParam and WAT_ACT_REPLACE)<>0) then
+ begin
+ if (p<>WAT_RES_NOTFOUND) and ((fmtLink^[p].flags and WAT_OPT_ONLYONE)<>0) then
exit;
- p:=FindFormat(pMusicFormat(lParam)^.ext);
- if (p=WAT_RES_NOTFOUND) or ((wParam and WAT_ACT_REPLACE)<>0) then
+
+ if FmtNum=FmtMax then // expand array when append
begin
- if (p<>WAT_RES_NOTFOUND) and ((fmtLink^[p].flags and WAT_OPT_ONLYONE)<>0) then
- exit;
- if FmtNum=FmtMax then // expand array when append
+ if FmtMax=0 then
+ FmtMax:=StartSize
+ else
+ inc(FmtMax,Step);
+ GetMem(nl,FmtMax*SizeOf(tMusicFormat));
+ if fmtLink<>nil then
begin
- if FmtMax=0 then
- FmtMax:=StartSize
- else
- inc(FmtMax,Step);
- GetMem(nl,FmtMax*SizeOf(tMusicFormat));
- if fmtLink<>nil then
- begin
- move(fmtLink^,nl^,FmtNum*SizeOf(tMusicFormat));
- FreeMem(fmtLink);
- end;
- fmtLink:=nl;
+ move(fmtLink^,nl^,FmtNum*SizeOf(tMusicFormat));
+ FreeMem(fmtLink);
end;
- if p=WAT_RES_NOTFOUND then
- begin
- p:=FmtNum;
- result:=WAT_RES_OK;
- inc(FmtNum);
- end
- else
- result:=int_ptr(@fmtLink^[p].proc);
- move(pMusicFormat(lParam)^,fmtLink^[p],SizeOf(tMusicFormat));// fill
+ fmtLink:=nl;
end;
- end;
- WAT_ACT_UNREGISTER: begin
- if p<>WAT_RES_NOTFOUND then
+
+ if p=WAT_RES_NOTFOUND then
begin
- dec(FmtNum);
- if p<FmtNum then // last
- Move(fmtLink^[p+1],fmtLink^[p],SizeOf(tMusicFormat)*(FmtNum-p));
+ p:=FmtNum;
result:=WAT_RES_OK;
- end;
- end;
- WAT_ACT_DISABLE: begin
- if p<>WAT_RES_NOTFOUND then
- begin
- fmtLink^[p].flags:=fmtLink^[p].flags or WAT_OPT_DISABLED;
- result:=WAT_RES_DISABLED
- end;
- end;
- WAT_ACT_ENABLE: begin
- if p<>WAT_RES_NOTFOUND then
- begin
- fmtLink^[p].flags:=fmtLink^[p].flags and not WAT_OPT_DISABLED;
- result:=WAT_RES_ENABLED
- end;
+ inc(FmtNum);
+ end
+ else
+ result:=int_ptr(@fmtLink^[p].proc);
+
+ move(pMusicFormat(lParam)^,fmtLink^[p],SizeOf(tMusicFormat));// fill
end;
- WAT_ACT_GETSTATUS: begin
- if p<>WAT_RES_NOTFOUND then
- begin
- if (fmtLink^[p].flags and WAT_OPT_DISABLED)<>0 then
- result:=WAT_RES_DISABLED
- else
+ end
+ else
+ begin
+ p:=FindFormat(PAnsiChar(lParam));
+ if p<>WAT_RES_NOTFOUND then
+ case LoWord(wParam) of
+ WAT_ACT_UNREGISTER: begin
+ dec(FmtNum);
+ if p<FmtNum then // last
+ Move(fmtLink^[p+1],fmtLink^[p],SizeOf(tMusicFormat)*(FmtNum-p));
+ result:=WAT_RES_OK;
+ end;
+
+ WAT_ACT_DISABLE: begin
+ fmtLink^[p].flags:=fmtLink^[p].flags or WAT_OPT_DISABLED;
+ result:=WAT_RES_DISABLED;
+ end;
+
+ WAT_ACT_ENABLE: begin
+ fmtLink^[p].flags:=fmtLink^[p].flags and not WAT_OPT_DISABLED;
result:=WAT_RES_ENABLED;
+ end;
+
+ WAT_ACT_GETSTATUS: begin
+ if (fmtLink^[p].flags and WAT_OPT_DISABLED)<>0 then
+ result:=WAT_RES_DISABLED
+ else
+ result:=WAT_RES_ENABLED;
+ end;
end;
- end;
+
end;
end;
+//----- init/free procedures -----
+
procedure RegisterFormat(ext:PAnsiChar;proc:tReadFormatProc;flags:dword=0);
var
tmp:tMusicFormat;
begin
FillChar(tmp,SizeOf(tMusicFormat),0);
StrCopy (tmp.ext,ext,7);
- tmp.proc:=proc;
+ tmp.proc :=proc;
tmp.flags:=flags;
ServiceFormat(WAT_ACT_REGISTER,LPARAM(@tmp));
end;
+function ProcessFormatLink:integer;
+var
+ ptr:pwFormat;
+begin
+ result:=0;
+ ptr:=FormatLink;
+ while ptr<>nil do
+ begin
+ RegisterFormat(@ptr.This.ext, ptr.This.proc, ptr.This.flags);
+ inc(result);
+ ptr:=ptr^.Next;
+ end;
+end;
+
procedure ClearFormats;
begin
if FmtNum>0 then