00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "PPageFileInfoRes.h"
00028 #include ".\ppagefileinfores.h"
00029
00030
00031
00032 IMPLEMENT_DYNAMIC(CPPageFileInfoRes, CPPageBase)
00033 CPPageFileInfoRes::CPPageFileInfoRes(CString fn, IFilterGraph* pFG)
00034 : CPPageBase(CPPageFileInfoRes::IDD, CPPageFileInfoRes::IDD)
00035 , m_fn(fn)
00036 , m_hIcon(NULL)
00037 , m_pFG(pFG)
00038 {
00039 }
00040
00041 CPPageFileInfoRes::~CPPageFileInfoRes()
00042 {
00043 if(m_hIcon) DestroyIcon(m_hIcon);
00044 }
00045
00046 void CPPageFileInfoRes::DoDataExchange(CDataExchange* pDX)
00047 {
00048 __super::DoDataExchange(pDX);
00049 DDX_Control(pDX, IDC_DEFAULTICON, m_icon);
00050 DDX_Text(pDX, IDC_EDIT1, m_fn);
00051 DDX_Control(pDX, IDC_LIST1, m_list);
00052 }
00053
00054 BEGIN_MESSAGE_MAP(CPPageFileInfoRes, CPPageBase)
00055 ON_BN_CLICKED(IDC_BUTTON1, OnSaveAs)
00056 ON_UPDATE_COMMAND_UI(IDC_BUTTON1, OnUpdateSaveAs)
00057 ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnNMDblclkList1)
00058 END_MESSAGE_MAP()
00059
00060
00061
00062 BOOL CPPageFileInfoRes::OnInitDialog()
00063 {
00064 __super::OnInitDialog();
00065
00066 if(m_hIcon = LoadIcon(m_fn, false))
00067 m_icon.SetIcon(m_hIcon);
00068
00069 m_fn.TrimRight('/');
00070 int i = max(m_fn.ReverseFind('\\'), m_fn.ReverseFind('/'));
00071 if(i >= 0 && i < m_fn.GetLength()-1)
00072 m_fn = m_fn.Mid(i+1);
00073
00074 m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_FULLROWSELECT);
00075
00076 m_list.InsertColumn(0, _T("Name"), LVCFMT_LEFT, 187);
00077 m_list.InsertColumn(1, _T("Mime Type"), LVCFMT_LEFT, 127);
00078
00079 BeginEnumFilters(m_pFG, pEF, pBF)
00080 {
00081 if(CComQIPtr<IDSMResourceBag> pRB = pBF)
00082 if(pRB && pRB->ResGetCount() > 0)
00083 {
00084 for(DWORD i = 0; i < pRB->ResGetCount(); i++)
00085 {
00086 CComBSTR name, desc, mime;
00087 BYTE* pData = NULL;
00088 DWORD len = 0;
00089 if(SUCCEEDED(pRB->ResGet(i, &name, &desc, &mime, &pData, &len, NULL)))
00090 {
00091 CDSMResource r;
00092 r.name = name;
00093 r.desc = desc;
00094 r.mime = mime;
00095 r.data.SetSize(len);
00096 memcpy(r.data.GetData(), pData, r.data.GetSize());
00097 CoTaskMemFree(pData);
00098 POSITION pos = m_res.AddTail(r);
00099 int iItem = m_list.InsertItem(m_list.GetItemCount(), CString(name));
00100 m_list.SetItemText(iItem, 1, CString(mime));
00101 m_list.SetItemData(iItem, (DWORD_PTR)pos);
00102 }
00103 }
00104 }
00105 }
00106 EndEnumFilters
00107
00108 UpdateData(FALSE);
00109
00110 return TRUE;
00111
00112 }
00113
00114 void CPPageFileInfoRes::OnSaveAs()
00115 {
00116 int i = m_list.GetSelectionMark();
00117 if(i < 0) return;
00118
00119 CDSMResource& r = m_res.GetAt((POSITION)m_list.GetItemData(i));
00120
00121 CFileDialog fd(FALSE, NULL, CString(r.name),
00122 OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
00123 _T("All files|*.*||"), this, 0);
00124 if(fd.DoModal() == IDOK)
00125 {
00126 if(FILE* f = _tfopen(fd.GetPathName(), _T("wb")))
00127 {
00128 fwrite(r.data.GetData(), 1, r.data.GetSize(), f);
00129 fclose(f);
00130 }
00131 }
00132 }
00133
00134 void CPPageFileInfoRes::OnUpdateSaveAs(CCmdUI* pCmdUI)
00135 {
00136 pCmdUI->Enable(m_list.GetSelectedCount());
00137 }
00138
00139 void CPPageFileInfoRes::OnNMDblclkList1(NMHDR *pNMHDR, LRESULT *pResult)
00140 {
00141 int i = m_list.GetSelectionMark();
00142 if(i < 0) return;
00143
00144 CDSMResource& r = m_res.GetAt((POSITION)m_list.GetItemData(i));
00145
00146 CString url;
00147 url.Format(_T("http://localhost:%d/convres.html?id=%x"), AfxGetAppSettings().nWebServerPort, (DWORD)&r);
00148 ShellExecute(NULL, _T("open"), url, NULL, NULL, SW_SHOWDEFAULT);
00149
00150 *pResult = 0;
00151 }