buff;
if(buff.Allocate(4+len)) {
BYTE* p = buff;
*(DWORD*)p = cmdln.GetCount();
p += sizeof(DWORD);
POSITION pos = cmdln.GetHeadPosition();
while(pos) {
CString& str = cmdln.GetNext(pos);
len = (str.GetLength()+1)*sizeof(TCHAR);
memcpy(p, (LPCTSTR)str, len);
p += len;
}
COPYDATASTRUCT cds;
cds.dwData = 0x6ABE51;
cds.cbData = p - buff;
cds.lpData = (void*)(BYTE*)buff;
m_pMainFrame->SendMessage(WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds);
}
CPath p(path);
p.RemoveFileSpec();
path = (LPCTSTR)p;
}
} else {
path = m_pMainFrame->m_wndPlaylistBar.GetCurFileName();
if(CFileGetStatus(path, fs) && !(fs.m_attribute&CFile::directory)) {
CPath p(path);
p.RemoveFileSpec();
path = (LPCTSTR)p;
}
}
if(path.Find(_T("://")) >= 0) {
path.Empty();
}
if(CFileGetStatus(path, fs) && (fs.m_attribute&CFile::directory)
|| path.Find(_T("\\")) == 0) { // FIXME
CPath p(path);
p.Canonicalize();
p.MakePretty();
p.AddBackslash();
path = (LPCTSTR)p;
}
CStringA files;
if(path.IsEmpty()) {
POSITION pos = rootdrives.GetHeadPosition();
while(pos) {
CStringA& drive = rootdrives.GetNext(pos);
files += "\r\n";
files +=
"" + drive + " | "
"Directory | "
"  | \r\n"
"  | ";
files += "
\r\n";
}
path = "Root";
} else {
CString parent;
if(path.GetLength() > 3) {
CPath p(path + "..");
p.Canonicalize();
p.AddBackslash();
parent = (LPCTSTR)p;
}
files += "\r\n";
files +=
".. | "
"Directory | "
"  | \r\n"
"  | ";
files += "
\r\n";
WIN32_FIND_DATA fd = {0};
HANDLE hFind = FindFirstFile(path + "*.*", &fd);
if(hFind != INVALID_HANDLE_VALUE) {
do {
if(!(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) || fd.cFileName[0] == '.') {
continue;
}
CString fullpath = path + fd.cFileName;
files += "\r\n";
files +=
"" + UTF8(fd.cFileName) + " | "
"Directory | "
"  | \r\n"
"" + CStringA(CTime(fd.ftLastWriteTime).Format(_T("%Y.%m.%d %H:%M"))) + " | ";
files += "
\r\n";
} while(FindNextFile(hFind, &fd));
FindClose(hFind);
}
hFind = FindFirstFile(path + "*.*", &fd);
if(hFind != INVALID_HANDLE_VALUE) {
do {
if(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) {
continue;
}
CString fullpath = path + fd.cFileName;
TCHAR *ext = _tcsrchr(fd.cFileName, '.');
if (ext != NULL) {
ext++;
}
CStringA size;
size.Format("%I64dK", ((UINT64)fd.nFileSizeHigh<<22)|(fd.nFileSizeLow>>10));
CString type(_T(" "));
LoadType(fullpath, type);
if (ext != NULL) {
files += "\r\n";
} else {
files += "
\r\n";
}
files +=
"" + UTF8(fd.cFileName) + " | "
"" + UTF8(type) + " | "
"" + size + " | \r\n"
"" + CStringA(CTime(fd.ftLastWriteTime).Format(_T("%Y.%m.%d %H:%M"))) + " | ";
files += "
\r\n";
} while(FindNextFile(hFind, &fd));
FindClose(hFind);
}
}
m_pWebServer->LoadPage(IDR_HTML_BROWSER, body, m_path);
body.Replace("[charset]", "UTF-8"); // FIXME: win9x build...
body.Replace("[currentdir]", UTF8(path));
body.Replace("[currentfiles]", files);
return true;
}
bool CWebClientSocket::OnControls(CStringA& hdr, CStringA& body, CStringA& mime)
{
CString path = m_pMainFrame->m_wndPlaylistBar.GetCurFileName();
CString dir;
if(!path.IsEmpty()) {
CPath p(path);
p.RemoveFileSpec();
dir = (LPCTSTR)p;
}
OAFilterState fs = m_pMainFrame->GetMediaState();
CString state;
state.Format(_T("%d"), fs);
CString statestring;
switch(fs) {
case State_Stopped:
statestring = ResStr(IDS_CONTROLS_STOPPED);
break;
case State_Paused:
statestring = ResStr(IDS_CONTROLS_PAUSED);
break;
case State_Running:
statestring = ResStr(IDS_CONTROLS_PLAYING);
break;
default:
statestring = _T("n/a");
break;
}
int pos = (int)(m_pMainFrame->GetPos()/10000);
int dur = (int)(m_pMainFrame->GetDur()/10000);
CString position, duration;
position.Format(_T("%d"), pos);
duration.Format(_T("%d"), dur);
CString positionstring, durationstring, playbackrate;
// positionstring.Format(_T("%02d:%02d:%02d.%03d"), (pos/3600000), (pos/60000)%60, (pos/1000)%60, pos%1000);
// durationstring.Format(_T("%02d:%02d:%02d.%03d"), (dur/3600000), (dur/60000)%60, (dur/1000)%60, dur%1000);
positionstring.Format(_T("%02d:%02d:%02d"), (pos/3600000), (pos/60000)%60, (pos/1000)%60);
durationstring.Format(_T("%02d:%02d:%02d"), (dur/3600000), (dur/60000)%60, (dur/1000)%60);
playbackrate = _T("1"); // TODO
CString volumelevel, muted;
volumelevel.Format(_T("%d"), m_pMainFrame->m_wndToolBar.m_volctrl.GetPos());
muted.Format(_T("%d"), m_pMainFrame->m_wndToolBar.Volume == -10000 ? 1 : 0);
CString reloadtime(_T("0")); // TODO
m_pWebServer->LoadPage(IDR_HTML_CONTROLS, body, m_path);
body.Replace("[charset]", "UTF-8"); // FIXME: win9x build...
body.Replace("[filepatharg]", UTF8Arg(path));
body.Replace("[filepath]", UTF8(path));
body.Replace("[filedirarg]", UTF8Arg(dir));
body.Replace("[filedir]", UTF8(dir));
body.Replace("[state]", UTF8(state));
body.Replace("[statestring]", UTF8(statestring));
body.Replace("[position]", UTF8(position));
body.Replace("[positionstring]", UTF8(positionstring));
body.Replace("[duration]", UTF8(duration));
body.Replace("[durationstring]", UTF8(durationstring));
body.Replace("[volumelevel]", UTF8(volumelevel));
body.Replace("[muted]", UTF8(muted));
body.Replace("[playbackrate]", UTF8(playbackrate));
body.Replace("[reloadtime]", UTF8(reloadtime));
return true;
}
bool CWebClientSocket::OnStatus(CStringA& hdr, CStringA& body, CStringA& mime)
{
/*
CString path = m_pMainFrame->m_wndPlaylistBar.GetCur(), dir;
if(!path.IsEmpty()) {CPath p(path); p.RemoveFileSpec(); dir = (LPCTSTR)p;}
path.Replace(_T("'"), _T("\\'"));
dir.Replace(_T("'"), _T("\\'"));
CString volumelevel, muted;
volumelevel.Format(_T("%d"), m_pMainFrame->m_wndToolBar.m_volctrl.GetPos());
muted.Format(_T("%d"), m_pMainFrame->m_wndToolBar.Volume == -10000 ? 1 : 0);
body.Replace("[volumelevel]", UTF8(volumelevel));
body.Replace("[muted]", UTF8(muted));
*/
CString title;
m_pMainFrame->GetWindowText(title);
CPath file(m_pMainFrame->m_wndPlaylistBar.GetCurFileName());
CString status;// = m_pMainFrame->GetStatusMessage();
OAFilterState fs = m_pMainFrame->GetMediaState();
switch (fs) {
case State_Stopped:
status = ResStr(IDS_CONTROLS_STOPPED);
break;
case State_Paused:
status = ResStr(IDS_CONTROLS_PAUSED);
break;
case State_Running:
status = ResStr(IDS_CONTROLS_PLAYING);
break;
default:
status = _T("n/a");
break;
}
int pos = (int)(m_pMainFrame->GetPos()/10000);
int dur = (int)(m_pMainFrame->GetDur()/10000);
CString posstr, durstr;
posstr.Format(_T("%02d:%02d:%02d"), (pos/3600000), (pos/60000)%60, (pos/1000)%60);
durstr.Format(_T("%02d:%02d:%02d"), (dur/3600000), (dur/60000)%60, (dur/1000)%60);
title.Replace(_T("'"), _T("\\'"));
status.Replace(_T("'"), _T("\\'"));
body.Format("OnStatus('%s', '%s', %d, '%s', %d, '%s', %d, %d, '%s')", // , '%s'
UTF8(title), UTF8(status),
pos, UTF8(posstr), dur, UTF8(durstr),
m_pMainFrame->IsMuted(), m_pMainFrame->GetVolume(),
UTF8(file)/*, UTF8(dir)*/);
return true;
}
bool CWebClientSocket::OnError404(CStringA& hdr, CStringA& body, CStringA& mime)
{
m_pWebServer->LoadPage(IDR_HTML_404, body, m_path);
return true;
}
bool CWebClientSocket::OnPlayer(CStringA& hdr, CStringA& body, CStringA& mime)
{
m_pWebServer->LoadPage(IDR_HTML_PLAYER, body, m_path);
return true;
}
#include "jpeg.h"
bool CWebClientSocket::OnSnapShotJpeg(CStringA& hdr, CStringA& body, CStringA& mime)
{
// TODO: add quality control and return logo when nothing is loaded
bool fRet = false;
BYTE* pData = NULL;
long size = 0;
CAtlArray jpeg;
if(m_pMainFrame->GetDIB(&pData, size, true)) {
if(CJpegEncoderMem().Encode(pData, jpeg)) {
hdr +=
"Expires: Thu, 19 Nov 1981 08:52:00 GMT\r\n"
"Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0\r\n"
"Pragma: no-cache\r\n";
body = CStringA((char*)jpeg.GetData(), jpeg.GetCount());
mime = "image/jpeg";
fRet = true;
}
delete [] pData;
}
return fRet;
}
#include "ConvertDlg.h"
bool CWebClientSocket::OnConvRes(CStringA& hdr, CStringA& body, CStringA& mime)
{
CString id;
if(!m_get.Lookup(_T("id"), id)) {
return false;
}
DWORD key = 0;
if(1 != _stscanf_s(id, _T("%x"), &key) || key == 0) {
return false;
}
CAutoLock cAutoLock(&CDSMResource::m_csResources);
CDSMResource* res = NULL;
if(!CDSMResource::m_resources.Lookup(key, res) || !res) {
return false;
}
body = CStringA((const char*)res->data.GetData(), res->data.GetCount());
mime = CString(res->mime);
return true;
}