/*****************************************************************************
*
* This program is free software ; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: tools.c 585 2006-01-16 09:48:55Z picard $
*
* The Core Pocket Media Player
* Copyright (c) 2004-2005 Gabor Kovacs
*
****************************************************************************/
#include "common.h"
#include "../splitter/asf.h"
void BuildChapter(tchar_t* s,int slen,int No,int64_t Time,int Rate)
{
int Hour,Min,Sec;
if (Time<0) Time=0;
Time /= Rate;
Hour = (int)(Time / 3600000);
Time -= Hour * 3600000;
Min = (int)(Time / 60000);
Time -= Min * 60000;
Sec = (int)(Time / 1000);
Time -= Sec * 1000;
stprintf_s(s,slen,T("CHAPTER%02d=%02d:%02d:%02d.%03d"),No,Hour,Min,Sec,(int)Time);
}
bool_t SetFileExt(tchar_t* URL, int URLLen, const tchar_t* Ext)
{
tchar_t *p,*q;
bool_t HasHost;
p = (tchar_t*) GetMime(URL,NULL,0,&HasHost);
q = p;
p = tcsrchr(q,'\\');
if (!p)
p = tcsrchr(q,'/');
if (p)
q = p+1;
else
if (HasHost) // only hostname
return 0;
if (!q[0]) // no filename at all?
return 0;
p = tcsrchr(q,'.');
if (p)
*p = 0;
tcscat_s(URL,URLLen,T("."));
tcscat_s(URL,URLLen,Ext);
return 1;
}
void SplitURL(const tchar_t* URL, tchar_t* Mime, int MimeLen, tchar_t* Dir, int DirLen, tchar_t* Name, int NameLen, tchar_t* Ext, int ExtLen)
{
const tchar_t* p;
const tchar_t* p2;
bool_t HasHost;
bool_t MergeMime = Mime && Mime == Dir;
// mime
p = GetMime(URL,MergeMime?NULL:Mime,MimeLen,&HasHost);
if (!MergeMime)
URL = p;
// dir
p2 = tcsrchr(p,'\\');
if (!p2)
p2 = tcsrchr(p,'/');
if (p2)
{
if (Dir)
tcsncpy_s(Dir,DirLen,URL,p2-URL);
URL = p2+1;
}
else
if (HasHost) // no filename, only host
{
if (Dir)
tcscpy_s(Dir,DirLen,URL);
URL += tcslen(URL);
}
else // no directory
{
if (Dir)
tcsncpy_s(Dir,DirLen,URL,p-URL);
URL = p;
}
// name
if (Name && Name == Ext)
tcscpy_s(Name,NameLen,URL);
else
{
p = tcsrchr(URL,'.');
if (p)
{
if (Name)
tcsncpy_s(Name,NameLen,URL,p-URL);
if (Ext)
tcscpy_s(Ext,ExtLen,p+1);
}
else
{
if (Name)
tcscpy_s(Name,NameLen,URL);
if (Ext)
Ext[0] = 0;
}
}
}
void RelPath(tchar_t* Rel, int RelLen, const tchar_t* Any, const tchar_t* Base)
{
size_t n;
bool_t HasHost;
const tchar_t* p = GetMime(Base,NULL,0,&HasHost);
if (p != Base)
{
if (HasHost)
{
// include host name too
tchar_t *a,*b;
a = tcschr(p,'\\');
b = tcschr(p,'/');
if (!a || (b && b=c && (*a=='\\' || *a=='/'))
*a = 0;
return 1;
}
void AbsPath(tchar_t* Abs, int AbsLen, const tchar_t* Any, const tchar_t* Base)
{
if (GetMime(Base,NULL,0,NULL)!=Base && (Any[0] == '/' || Any[0] == '\\'))
{
tchar_t* s;
bool_t HasHost;
tcscpy_s(Abs,AbsLen,Base);
s = (tchar_t*)GetMime(Abs,NULL,0,&HasHost);
if (!HasHost)
{
// keep "mime://" from Base
++Any;
*s = 0;
}
else
{
// keep "mime://host" from Base
tchar_t *a,*b;
a = tcschr(s,'\\');
b = tcschr(s,'/');
if (!a || (b && bError.Func)
Context()->Error.Func(Context()->Error.This,Sender,(int)s);
else
ShowMessage(LangStr(PLATFORM_ID,PLATFORM_ERROR),s);
}
void DebugBinary(const tchar_t* Msg,const void* Data,int Length)
{
const uint8_t* p = (const uint8_t*)Data;
int i;
tchar_t s[256];
while (Length>0)
{
tcscpy_s(s,TSIZEOF(s),Msg);
for (i=0;Length>0 && i<16;++i,--Length,++p)
stcatprintf_s(s,TSIZEOF(s),T(" %02x"),*p);
DebugMessage(s);
}
}
const nodedef WMVF =
{
0, // parent size
WMVF_ID,
ASF_ID,
PRI_DEFAULT,
};
const nodedef WMAF =
{
0, // parent size
WMAF_ID,
ASF_ID,
PRI_DEFAULT,
};