- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# SaveDlg.cpp

    00001 /*
    00002  *      Copyright (C) 2003-2005 Gabest
    00003  *      http://www.gabest.org
    00004  *
    00005  *  This Program is free software; you can redistribute it and/or modify
    00006  *  it under the terms of the GNU General Public License as published by
    00007  *  the Free Software Foundation; either version 2, or (at your option)
    00008  *  any later version.
    00009  *
    00010  *  This Program is distributed in the hope that it will be useful,
    00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    00013  *  GNU General Public License for more details.
    00014  *
    00015  *  You should have received a copy of the GNU General Public License
    00016  *  along with GNU Make; see the file COPYING.  If not, write to
    00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    00018  *  http://www.gnu.org/copyleft/gpl.html
    00019  *
    00020  */
    00021
    00022 // SaveDlg.cpp : implementation file
    00023 //
    00024
    00025 #include "stdafx.h"
    00026 #include "mplayerc.h"
    00027 #include "SaveDlg.h"
    00028 #include "..\..\filters\filters.h"
    00029
    00030
    00031 // CSaveDlg dialog
    00032
    00033 IMPLEMENT_DYNAMIC(CSaveDlg, CCmdUIDialog)
    00034 CSaveDlg::CSaveDlg(CString in, CString out, CWnd* pParent /*=NULL*/)
    00035         : CCmdUIDialog(CSaveDlg::IDD, pParent)
    00036         , m_in(in), m_out(out)
    00037         , m_nIDTimerEvent(-1)
    00038 {
    00039 }
    00040
    00041 CSaveDlg::~CSaveDlg()
    00042 {
    00043 }
    00044
    00045 void CSaveDlg::DoDataExchange(CDataExchange* pDX)
    00046 {
    00047         CCmdUIDialog::DoDataExchange(pDX);
    00048         DDX_Control(pDX, IDC_ANIMATE1, m_anim);
    00049         DDX_Control(pDX, IDC_PROGRESS1, m_progress);
    00050         DDX_Control(pDX, IDC_REPORT, m_report);
    00051         DDX_Control(pDX, IDC_FROMTO, m_fromto);
    00052 }
    00053
    00054
    00055 BEGIN_MESSAGE_MAP(CSaveDlg, CCmdUIDialog)
    00056         ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
    00057         ON_MESSAGE(WM_GRAPHNOTIFY, OnGraphNotify)
    00058         ON_WM_TIMER()
    00059 END_MESSAGE_MAP()
    00060
    00061
    00062 // CSaveDlg message handlers
    00063
    00064 BOOL CSaveDlg::OnInitDialog()
    00065 {
    00066         CCmdUIDialog::OnInitDialog();
    00067
    00068         m_anim.Open(IDR_AVI1);
    00069         m_anim.Play(0, -1, -1);
    00070
    00071         CString str, in = m_in, out = m_out;
    00072         if(in.GetLength() > 60) in = in.Left(17) + _T("..") + in.Right(43);
    00073         if(out.GetLength() > 60) out = out.Left(17) + _T("..") + out.Right(43);
    00074         str.Format(_T("%s\r\n%s"), in, out);
    00075         m_fromto.SetWindowText(str);
    00076
    00077         m_progress.SetRange(0, 100);
    00078
    00079         if(FAILED(pGB.CoCreateInstance(CLSID_FilterGraph)) || !(pMC = pGB) || !(pME = pGB) || !(pMS = pGB)
    00080         || FAILED(pME->SetNotifyWindow((OAHWND)m_hWnd, WM_GRAPHNOTIFY, 0)))
    00081         {
    00082                 m_report.SetWindowText(_T("Error"));
    00083                 return FALSE;
    00084         }
    00085
    00086         HRESULT hr;
    00087
    00088         CStringW fnw = m_in;
    00089         CComPtr<IFileSourceFilter> pReader;
    00090
    00091         if(!pReader && m_in.Mid(m_in.ReverseFind('.')+1).MakeLower() == _T("cda"))
    00092         {
    00093                 hr = S_OK;
    00094                 CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)new CCDDAReader(NULL, &hr);
    00095                 if(FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL)))
    00096                         pReader.Release();
    00097         }
    00098
    00099         if(!pReader)
    00100         {
    00101                 hr = S_OK;
    00102                 CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)new CCDXAReader(NULL, &hr);
    00103                 if(FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL)))
    00104                         pReader.Release();
    00105         }
    00106
    00107         if(!pReader /*&& ext == _T("ifo")*/)
    00108         {
    00109                 hr = S_OK;
    00110                 CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)new CVTSReader(NULL, &hr);
    00111                 if(FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL)))
    00112                         pReader.Release();
    00113                 else
    00114                 {
    00115                         CPath pout(m_out);
    00116                         pout.RenameExtension(_T(".ifo"));
    00117                         CopyFile(m_in, pout, FALSE);
    00118                 }
    00119         }
    00120
    00121         if(!pReader)
    00122         {
    00123                 hr = S_OK;
    00124                 CComPtr<IUnknown> pUnk;
    00125                 pUnk.CoCreateInstance(CLSID_AsyncReader);
    00126                 if(FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL)))
    00127                         pReader.Release();
    00128         }
    00129
    00130         if(!pReader)
    00131         {
    00132                 hr = S_OK;
    00133                 CComPtr<IUnknown> pUnk;
    00134                 pUnk.CoCreateInstance(CLSID_URLReader);
    00135                 if(FAILED(hr) || !(pReader = pUnk) || FAILED(hr = pReader->Load(fnw, NULL)))
    00136                         pReader.Release();
    00137         }
    00138
    00139         CComQIPtr<IBaseFilter> pSrc = pReader;
    00140         if(FAILED(pGB->AddFilter(pSrc, fnw)))
    00141         {
    00142                 m_report.SetWindowText(_T("Sorry, can't save this file, press cancel"));
    00143                 return FALSE;
    00144         }
    00145
    00146         CComQIPtr<IBaseFilter> pMid = new CStreamDriveThruFilter(NULL, &hr);
    00147         if(FAILED(pGB->AddFilter(pMid, L"StreamDriveThru")))
    00148         {
    00149                 m_report.SetWindowText(_T("Error"));
    00150                 return FALSE;
    00151         }
    00152
    00153         CComQIPtr<IBaseFilter> pDst;
    00154         pDst.CoCreateInstance(CLSID_FileWriter);
    00155         CComQIPtr<IFileSinkFilter2> pFSF = pDst;
    00156         pFSF->SetFileName(CStringW(m_out), NULL);
    00157         pFSF->SetMode(AM_FILE_OVERWRITE);
    00158         if(FAILED(pGB->AddFilter(pDst, L"File Writer")))
    00159         {
    00160                 m_report.SetWindowText(_T("Error"));
    00161                 return FALSE;
    00162         }
    00163
    00164         hr = pGB->Connect(
    00165                 GetFirstPin((pSrc), PINDIR_OUTPUT),
    00166                 GetFirstPin((pMid), PINDIR_INPUT));
    00167
    00168         hr = pGB->Connect(
    00169                 GetFirstPin((pMid), PINDIR_OUTPUT),
    00170                 GetFirstPin((pDst), PINDIR_INPUT));
    00171
    00172 pMS = pMid;
    00173
    00174         pMC->Run();
    00175
    00176         m_nIDTimerEvent = SetTimer(1, 1000, NULL);
    00177
    00178         return TRUE;  // return TRUE unless you set the focus to a control
    00179         // EXCEPTION: OCX Property Pages should return FALSE
    00180 }
    00181
    00182 void CSaveDlg::OnBnClickedCancel()
    00183 {
    00184         if(pMC) pMC->Stop();
    00185
    00186         OnCancel();
    00187 }
    00188
    00189 LRESULT CSaveDlg::OnGraphNotify(WPARAM wParam, LPARAM lParam)
    00190 {
    00191         LONG evCode, evParam1, evParam2;
    00192     while(pME && SUCCEEDED(pME->GetEvent(&evCode, (LONG_PTR*)&evParam1, (LONG_PTR*)&evParam2, 0)))
    00193     {
    00194                 HRESULT hr = pME->FreeEventParams(evCode, evParam1, evParam2);
    00195
    00196         if(EC_COMPLETE == evCode)
    00197         {
    00198                         EndDialog(IDOK);
    00199                 }
    00200                 else if(EC_ERRORABORT == evCode)
    00201                 {
    00202                         TRACE(_T("CSaveDlg::OnGraphNotify / EC_ERRORABORT, hr = %08x\n"), (HRESULT)evParam1);
    00203                         m_report.SetWindowText(_T("Copying unexpectedly terminated!"));
    00204                 }
    00205         }
    00206
    00207         return 0;
    00208 }
    00209
    00210 void CSaveDlg::OnTimer(UINT nIDEvent)
    00211 {
    00212         if(nIDEvent == m_nIDTimerEvent && pGB)
    00213         {
    00214                 if(pMS)
    00215                 {
    00216                         CString str;
    00217                         REFERENCE_TIME pos = 0, dur = 0;
    00218                         pMS->GetCurrentPosition(&pos);
    00219                         pMS->GetDuration(&dur);
    00220                         REFERENCE_TIME time = 0;
    00221                         CComQIPtr<IMediaSeeking>(pGB)->GetCurrentPosition(&time);
    00222                         REFERENCE_TIME speed = time > 0 ? pos*10000000/time / 1024 : 0i64;
    00223                         str.Format(_T("%I64d/%I64d KB, %I64d KB/s, %I64d s"),
    00224                                 pos/1024, dur/1024, speed, speed > 0 ? (dur-pos)/1024 / speed : 0);
    00225                         m_report.SetWindowText(str);
    00226
    00227                         m_progress.SetPos(dur > 0 ? (int)(100*pos/dur) : 0);
    00228                 }
    00229         }
    00230
    00231         CCmdUIDialog::OnTimer(nIDEvent);
    00232 }